[ '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(); } }