['u.sn','u.is_open','u.is_agent','u.country_code','u.register_ip','u.login_ip'], ]; } /** * @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['member_id'])) { $where[] = ['umr.member_id', '=', $this->params['member_id']]; } // 邮箱地址 if (!empty($this->params['email'])) { $where[] = ['ui.email', '=', $this->params['email']]; } // 邮箱认证 if (!empty($this->params['auth_email'])) { $where[] = ['ui.auth_email', '=', $this->params['auth_email']]; } // 所在代数 if (!empty($this->params['level'])) { $where[] = ['ur.level', '=', $this->params['level']]; } // 下单时间 if (!empty($this->params['create_time_start']) && !empty($this->params['create_time_end'])) { $time = [strtotime($this->params['create_time_start']), strtotime($this->params['create_time_end'])]; $where[] = ['u.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 段誉 * @date 2022/9/22 15:50 */ 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 "; } // 金额范围 if (!empty($this->params['recharge_withdraw_min'])) { $recharge_withdraw_min = $this->params['recharge_withdraw_min']; $where .= " AND u.total_recharge - u.total_withdraw >= $recharge_withdraw_min "; } // 金额范围 if (!empty($this->params['recharge_withdraw_max'])) { $recharge_withdraw_max = $this->params['recharge_withdraw_max']; $where .= " AND u.total_recharge - u.total_withdraw <= $recharge_withdraw_max "; } $field = "u.id,u.sn,u.nickname,u.sex,u.avatar,u.account,u.mobile,u.country_code,u.auto_member,u.is_lh,u.is_sn,u.is_open,u.is_agent,u.channel,u.user_money,u.user_point,u.total_recharge,u.total_withdraw,u.total_income,u.total_income_invest,u.total_invest,u.create_time,u.register_ip,u.register_isp,u.remark2,u.login_ip,u.login_time"; $field .= ',ui.email,ui.auth_email'; $field .= ',ur.level'; $lists = User::alias('u') ->join('user_info ui', 'u.id = ui.user_id') ->join('user_relation_agent ur', 'u.id = ur.user_id') ->leftjoin('user_member_record umr', 'u.id = umr.user_id') ->field($field) ->append(['team_num','team_recharge','team_withdraw','item_num','today_item_num','vip_name','unused_money','team_report','agent_team_top','register_ip_num','login_ip_num','mine']) ->where($where) ->where($this->queryWhere()) ->where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->order('u.id desc') ->select() ->toArray(); // foreach ($lists as &$item) { // $item['total_recharge_ing'] = round(RechargeRecord::where(['status' => 0,'user_id' => $item['id']])->sum('amount'), 2); // $item['total_withdraw_ing'] = round(WithdrawRecord::where(['status' => 0,'user_id' => $item['id']])->sum('amount'), 2); // } return $lists; } /** * @notes 获取数量 * @return int * @author 段誉 * @date 2022/9/22 15:51 */ 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 "; } // 金额范围 if (!empty($this->params['recharge_withdraw_min'])) { $recharge_withdraw_min = $this->params['recharge_withdraw_min']; $where .= " AND u.total_recharge - u.total_withdraw >= $recharge_withdraw_min "; } // 金额范围 if (!empty($this->params['recharge_withdraw_max'])) { $recharge_withdraw_max = $this->params['recharge_withdraw_max']; $where .= " AND u.total_recharge - u.total_withdraw <= $recharge_withdraw_max "; } return User::alias('u') ->join('user_info ui', 'u.id = ui.user_id') ->join('user_relation_agent ur', 'u.id = ur.user_id') ->leftjoin('user_member_record umr', 'u.id = umr.user_id') ->where($where) ->where($this->queryWhere()) ->where($this->searchWhere) ->count(); } public function extend(): 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 "; } // 金额范围 if (!empty($this->params['recharge_withdraw_min'])) { $recharge_withdraw_min = $this->params['recharge_withdraw_min']; $where .= " AND u.total_recharge - u.total_withdraw >= $recharge_withdraw_min "; } // 金额范围 if (!empty($this->params['recharge_withdraw_max'])) { $recharge_withdraw_max = $this->params['recharge_withdraw_max']; $where .= " AND u.total_recharge - u.total_withdraw <= $recharge_withdraw_max "; } $total_recharge = User::alias('u') ->join('user_info ui', 'u.id = ui.user_id') ->join('user_relation_agent ur', 'u.id = ur.user_id') ->leftjoin('user_member_record umr', 'u.id = umr.user_id') ->where($where) ->where($this->queryWhere()) ->where($this->searchWhere) ->sum('u.total_recharge'); $total_withdraw = User::alias('u') ->join('user_info ui', 'u.id = ui.user_id') ->join('user_relation_agent ur', 'u.id = ur.user_id') ->leftjoin('user_member_record umr', 'u.id = umr.user_id') ->where($where) ->where($this->queryWhere()) ->where($this->searchWhere) ->sum('u.total_withdraw'); $total_money = User::alias('u') ->join('user_info ui', 'u.id = ui.user_id') ->join('user_relation_agent ur', 'u.id = ur.user_id') ->leftjoin('user_member_record umr', 'u.id = umr.user_id') ->where($where) ->where($this->queryWhere()) ->where($this->searchWhere) ->sum('u.user_money'); $recharge_ing = User::alias('u') ->join('user_info ui', 'u.id = ui.user_id') ->join('user_relation_agent ur', 'u.id = ur.user_id') ->join('recharge_record rr', 'u.id = rr.user_id') ->leftjoin('user_member_record umr', 'u.id = umr.user_id') ->where($where) ->where(['rr.status' => 0]) ->where($this->queryWhere()) ->where($this->searchWhere) ->sum('rr.amount'); $withdraw_ing = User::alias('u') ->join('user_info ui', 'u.id = ui.user_id') ->join('user_relation_agent ur', 'u.id = ur.user_id') ->join('withdraw_record wr', 'u.id = wr.user_id') ->leftjoin('user_member_record umr', 'u.id = umr.user_id') ->where($where) ->where(['wr.status' => 0]) ->where($this->queryWhere()) ->where($this->searchWhere) ->sum('wr.amount'); return [ 'total_money' => round($total_money, 2), 'total_recharge' => round($total_recharge, 2), 'total_withdraw' => round($total_withdraw, 2), 'recharge_withdraw' => round($total_recharge - $total_withdraw, 2), 'recharge_ing' => round($recharge_ing, 2), 'withdraw_ing' => round($withdraw_ing, 2), ]; } }