params), $allowSearch); } /** * @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 { $params = $this->params; $field = "id,id contract,sn,nickname,sex,avatar,account,mobile,channel,create_time,admin_id,company_id,street,street as street_name,is_contract,group_id,invite_code"; $lists = User::withSearch($this->setSearch(), $this->params) ->when(!empty($params['nickname']),function($query)use($params){ $query->where('nickname', 'like', '%' . $this->params['nickname'] . '%'); }) ->when(!empty($params['group_id']),function($query)use($params){ $query->where('group_id', $params['group_id']); }) ->append(['role_name']) ->with(['company']) ->withAttr('role_name', function ($value, $data){ $role = UserRole::where('id', $data['group_id'])->find(); return $role? $role['name']: "无"; }) ->limit($this->limitOffset, $this->limitLength) ->field($field) ->order('id desc') ->select() ->toArray(); foreach ($lists as &$item) { $item['channel'] = UserTerminalEnum::getTermInalDesc($item['channel']); $inviteUserStatistics = ShopRequestLogic::getInviteUserInfo(['promotion_code' => $item['invite_code']]); $item['register_num'] = $inviteUserStatistics['data']['user_count']; // $data['merchant_num'] = $inviteUserStatistics['data']['merchant_count']; $item['trade_amount'] = Db::name('user_invite_first_order_log')->where('user_id', $item['id'])->sum('order_money'); } return $lists; } /** * @notes 获取数量 * @return int * @author 段誉 * @date 2022/9/22 15:51 */ public function count(): int { $params = $this->params; return User::withSearch($this->setSearch(), $this->params) ->when(!empty($params['nickname']),function($query)use($params){ $query->where('nickname', 'like', '%' . $this->params['nickname'] . '%'); }) ->when(!empty($params['group_id']),function($query)use($params){ $query->where('group_id', $params['group_id']); })->count(); } /** * @notes 导出文件名 * @return string * @author 段誉 * @date 2022/11/24 16:17 */ public function setFileName(): string { return '用户列表'; } /** * @notes 导出字段 * @return string[] * @author 段誉 * @date 2022/11/24 16:17 */ public function setExcelFields(): array { return [ 'sn' => '用户编号', 'nickname' => '用户昵称', 'account' => '账号', 'mobile' => '手机号码', 'channel' => '注册来源', 'role_name' => '用户角色', 'register_num' => '成功邀请人数', 'trade_amount' => '总计首单金额', 'create_time' => '注册时间', ]; } }