苗总组局小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 lines
3.3 KiB

<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\admin\model\user\Team as TeamModel;
use app\admin\model\system\Message;
use think\Db;
use think\Exception;
class Userteam extends Api{
protected $model = null;
protected $noNeedRight = '*';
protected $noNeedLogin = [];
public function _initialize(){
parent::_initialize();
$this->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('加入队伍成功');
}
}
}