dao = new UserDao(); } /** * 列表 * @param array $param */ public function getList(array $param = [],string $field = '*',string $order = 'id desc') { [$page,$limit] = $this->getPageValue(); $list = $this->dao->getList($this->searchFilter($param),$field,$page,$limit,$order); $count = $this->dao->count($this->searchFilter($param)); return compact('list','count'); } protected function searchFilter(array $param = []): array { $filter = []; !empty($param['status']) && $filter[] = ["status", '=', $param['status']]; !empty($param['is_del']) && $filter[] = ["is_del", '=', $param['is_del']]; return $filter; } /** * 用户详情 * @param array $data * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getUserInfo(array $data):array { $user = $this->dao->getOne(['openid'=>$data['openid'],'is_del'=>0]); if($user->isEmpty()){ $user = $this->dao->save(['openid'=>$data['openid'],'nickname'=>'wx'.time().rand(1000,9999),'login_ip'=>$data['login_ip'],'login_at'=>$data['login_at']]); }else if($user['status'] == 0){ throw new BusinessException('用户已被封禁'); } return $user->toArray(); } /** * 个人中心数据 * @param array $user * @return array */ public function getUserProfile(array $user) { if($user['is_del']) throw new BusinessException('用户已注销'); if(!$user['status']) throw new BusinessException('用户已被封禁'); $cutterOrderService = new CutterOrderService(); $userBrokerageService = new UserBrokerageService(); $user['order_count'] = $cutterOrderService->count(['uid'=>$user['uid']]); $user['brokerage_sum'] = $userBrokerageService->sum([['uid','=',$user['uid']],['pm','=',1],['type','not in',['extract_fail']]],'number'); if($user['level']){ $userLevelService = new UserLevelService(); $user['vip'] = $userLevelService->getOne(['id'=>$user['level']],'name,icon'); } return $user; } public function rank(int $type,array $user):array { $where = ['is_del'=>0,'status'=>1]; $list = $this->dao->getRank($where,'uid,nickname,avatar',$type); $where['uid'] = $user['uid']; $self = $this->dao->getSelfRank($where,'uid,nickname,avatar',$type); $self['brokerage_sum'] = $self['brokerage_sum']?:0; $jackpot = 20000; return compact('list','self','jackpot'); } }