[ 'uf.sn', 'uf.frozen', '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['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 { $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,uf.thaw_time,uf.frozen'; $field .= ',u.account,u.sn as u_sn,u.mobile,u.country_code'; $where = " 1 = 1 "; $join_table = "user t"; $join_require = 't.id = uf.user_id'; if(isset($this->params['parent_sn']) && $this->params['parent_sn'] !=""){ $join_table = "user_relation_agent ur"; $join_require = 'uf.user_id = ur.user_id'; $user = User::where(['sn' => $this->params['parent_sn']]) -> findOrEmpty(); $parent_id = 0; if (!$user->isEmpty()) $parent_id = $user['id']; $where .= " AND ur.parent_id = $parent_id "; if(isset($this->params['level']) && $this->params['level'] !=""){ $level = $this->params['level']; $where .= " AND ur.level = $level "; } $field .= ',ur.level'; } $lists = UserFinance::alias('uf') ->join('user u', 'u.id = uf.user_id') ->join($join_table, $join_require) ->field($field) ->append(['team_top']) ->where($where) ->where($this->queryWhere()) ->where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->order(['uf.id' => 'desc']) ->select() ->toArray(); foreach ($lists as &$item) { if(isset($item['level']) && isset($item['team_top']['level'])){ $item['team_top']['level'] = $item['level']; } } return $lists; } /** * @notes 获取资金明细数量 * @return int * @author BD * @date 2024/03/07 13:10 */ public function count(): int { $where = " 1 = 1 "; $join_table = "user t"; $join_require = 't.id = uf.user_id'; if(isset($this->params['parent_sn']) && $this->params['parent_sn'] !=""){ $join_table = "user_relation_agent ur"; $join_require = 'uf.user_id = ur.user_id'; $user = User::where(['sn' => $this->params['parent_sn']]) -> findOrEmpty(); $parent_id = 0; if (!$user->isEmpty()) $parent_id = $user['id']; $where .= " AND ur.parent_id = $parent_id "; if(isset($this->params['level']) && $this->params['level'] !=""){ $level = $this->params['level']; $where .= " AND ur.level = $level "; } } return UserFinance::alias('uf') ->join('user u', 'u.id = uf.user_id') ->join($join_table, $join_require) ->where($where) ->where($this->queryWhere()) ->where($this->searchWhere) ->count(); } }