model = new TeamModel; } public function getlist(){ $uid = $this->auth->id; //判断我是否是主理人 if($this->auth->is_main_people){ $pid = $uid; $return['myteam_id'] = 0; }else{ //查询我所在的队伍 $pidinfo = $this->model->where('uid',$uid)->order('create','asc')->where("is_del",0)->find(); $pid = $pidinfo['pid']; $return['myteam_id'] = !empty($pidinfo)?$pidinfo['id']:0; } //获取队员列表信息 $list = $this->model->where('pid',$pid)->order('create','asc')->where("is_del",0)->select(); foreach($list as $key => $value){ $user = Db::name('user')->where('id',$value['uid'])->field('nickname,avatar,is_main_people')->find(); $list[$key]['avatar'] = $user['avatar']; $list[$key]['nickname'] = empty($value['nickname'])?$user['nickname']:$value['nickname']; $list[$key]['is_main_people'] = $user['is_main_people']; } $return['list'] = $list; $return['count'] = count($list); $this->success('获取成功',$return); } public function exitteam(){ $data = $this->request->post(); if($this->request->post()){ $id = $data['id']; $team = $this->model->get($id); if($team->pid!=$this->auth->id) return $this->error("非法操作"); $team->is_del = 1; if(!$team->save()) return $this->error("操作频繁,请休息一下再试"); return $this->success("退出队伍成功"); } } public function addteam(){ $data = $this->request->post(); if($this->request->post()){ $insert['uid'] = $this->auth->id; $insert['pid'] = $data['pid']; $insert['nickname'] = !isset($data['nickname'])||empty($data['nickname'])?$this->auth->nickname:$data['nickname']; //查询是否已经加入队伍 $team = $this->model->where(['uid'=>$insert['uid'],'is_del'=>0])->find(); //查询是否是主理人 if($this->auth->is_main_people) return $this->error("已经加入队伍"); if($team) return $this->error("已经加入队伍"); $insert['create'] = time(); if(!$this->model->insertGetId($insert)) return $this->error("加入队伍失败"); //加入队伍消息记录 $minfo = [ 'uid'=>$insert['pid'], 'error'=>1, 'create'=>time(), 'type'=>"team", 'content'=>"{$insert['nickname']}已加入您的队伍", 'title'=>'入队成功', 'is_read'=>0 ]; $message = new \app\admin\model\system\Message; $message->addmessage($minfo); return $this->success('加入队伍成功'); } } }