160 lines
5.2 KiB
PHP
160 lines
5.2 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\adminapi\lists\finance;
|
||
|
||
|
||
use app\adminapi\lists\BaseAdminDataLists;
|
||
use app\common\model\finance\UserFinance;
|
||
use app\common\model\user\{User,UserRelation,UserRelationAgent};
|
||
use app\common\lists\ListsSearchInterface;
|
||
|
||
|
||
/**
|
||
* 资金明细列表
|
||
* Class AgentUserFinanceLists
|
||
* @package app\adminapi\listsfinance
|
||
*/
|
||
class AgentUserFinanceLists extends BaseAdminDataLists implements ListsSearchInterface
|
||
{
|
||
|
||
/**
|
||
* @notes 设置搜索条件
|
||
* @return \string[][]
|
||
* @author bd
|
||
* @date 2024/01/31 14:07
|
||
*/
|
||
public function setSearch(): array
|
||
{
|
||
return [
|
||
'=' => [ 'uf.sn', 'uf.change_type'],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @notes 搜索条件
|
||
* @author 段誉
|
||
* @date 2023/2/24 16:08
|
||
*/
|
||
public function queryWhere()
|
||
{
|
||
$where = [];
|
||
// 用户编号
|
||
if (!empty($this->params['user_info'])) {
|
||
$where[] = ['u.sn|u.account|u.mobile', '=', $this->params['user_info']];
|
||
}
|
||
|
||
// 所在代数
|
||
if (!empty($this->params['level'])) {
|
||
$where[] = ['ur.level', '=', $this->params['level']];
|
||
}
|
||
|
||
// 下单时间
|
||
if (!empty($this->params['start_time']) && !empty($this->params['end_time'])) {
|
||
$time = [strtotime($this->params['start_time']), strtotime($this->params['end_time'])];
|
||
$where[] = ['uf.create_time', 'between', $time];
|
||
}
|
||
|
||
return $where;
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取资金明细列表
|
||
* @return array
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @author BD
|
||
* @date 2024/03/07 13:10
|
||
*/
|
||
public function lists(): array
|
||
{
|
||
//根据管理员ID获取代理
|
||
$user = User::where(['agent_id' => $this->adminId])->findOrEmpty();
|
||
|
||
$where = " 1 = 1 ";
|
||
|
||
if (!$user->isEmpty()) {
|
||
$top_id = $user['id'];
|
||
$parent_id = $user['id'];
|
||
//查询伞下用户
|
||
if(isset($this->params['parent_sn']) && $this->params['parent_sn'] !=""){
|
||
$userParent = User::where(['sn' => $this->params['parent_sn']]) -> findOrEmpty();
|
||
if (!$userParent->isEmpty()){
|
||
$parent_id = $userParent['id'];
|
||
}
|
||
}
|
||
$where .= " AND ur.top_id = $top_id AND ur.parent_id = $parent_id ";
|
||
}else{
|
||
$where .= " AND 1 = 2 ";
|
||
}
|
||
|
||
$field = 'uf.id,uf.sn,uf.user_id,uf.change_type,uf.action,uf.change_amount,uf.left_amount,uf.source_sn,uf.remark,uf.create_time';
|
||
$field .= ',u.account,u.sn as u_sn,u.mobile,u.country_code';
|
||
$field .= ',ur.level';
|
||
|
||
return UserFinance::alias('uf')
|
||
->join('user u', 'u.id = uf.user_id')
|
||
->join('user_relation_agent ur', 'uf.user_id = ur.user_id')
|
||
->field($field)
|
||
->append(['team_top'])
|
||
->where($where)
|
||
->where($this->queryWhere())
|
||
->where($this->searchWhere)
|
||
->limit($this->limitOffset, $this->limitLength)
|
||
->order(['uf.id' => 'desc'])
|
||
->select()
|
||
->toArray();
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取资金明细数量
|
||
* @return int
|
||
* @author BD
|
||
* @date 2024/03/07 13:10
|
||
*/
|
||
public function count(): int
|
||
{
|
||
//根据管理员ID获取代理
|
||
$user = User::where(['agent_id' => $this->adminId])->findOrEmpty();
|
||
|
||
$where = " 1 = 1 ";
|
||
|
||
if (!$user->isEmpty()) {
|
||
$top_id = $user['id'];
|
||
$parent_id = $user['id'];
|
||
//查询伞下用户
|
||
if(isset($this->params['parent_sn']) && $this->params['parent_sn'] !=""){
|
||
$userParent = User::where(['sn' => $this->params['parent_sn']]) -> findOrEmpty();
|
||
if (!$userParent->isEmpty()){
|
||
$parent_id = $userParent['id'];
|
||
}
|
||
}
|
||
$where .= " AND ur.top_id = $top_id AND ur.parent_id = $parent_id ";
|
||
}else{
|
||
$where .= " AND 1 = 2 ";
|
||
}
|
||
|
||
return UserFinance::alias('uf')
|
||
->join('user u', 'u.id = uf.user_id')
|
||
->join('user_relation_agent ur', 'uf.user_id = ur.user_id')
|
||
->where($where)
|
||
->where($this->queryWhere())
|
||
->where($this->searchWhere)
|
||
->count();
|
||
}
|
||
|
||
} |