380 lines
15 KiB
PHP
380 lines
15 KiB
PHP
<?php
|
|
|
|
namespace app\index\controller;
|
|
|
|
use app\common\controller\Frontend;
|
|
use addons\third\library\Wechat;
|
|
use app\admin\model\Userwechat;
|
|
use think\Session;
|
|
use think\Config;
|
|
use app\admin\model\ClubInvate;
|
|
use app\admin\model\Club as ClubModel;
|
|
use app\admin\model\ClubPlayercheck;
|
|
use app\common\model\Players;
|
|
use app\admin\model\ClubMatchApply;
|
|
use app\admin\model\shopro\ClubThirdOauth;
|
|
use app\index\controller\Wxmb;
|
|
use app\admin\model\MatchContestant;
|
|
use app\admin\model\User;
|
|
|
|
class Club extends Frontend
|
|
{
|
|
|
|
protected $noNeedLogin = '*';
|
|
protected $noNeedRight = '*';
|
|
protected $layout = 'defaults';
|
|
|
|
public function sociaty(){
|
|
$this->view->assign('title', "飞手公会");
|
|
$this->confirmed_club();
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
public function confirmed_club(){
|
|
$club = new ClubModel();
|
|
$user_id = $this->auth->id;
|
|
$club_info = $club->where("user_id", $user_id)->find();
|
|
|
|
if (empty($club_info)){
|
|
$this->error(__("请先申请成为队伍!"), url('players/registeredflyers')) ;
|
|
}
|
|
|
|
if ($club_info['status'] != 9){
|
|
$this->error(__("您还不是正式队伍!"), url('user/index'));
|
|
}
|
|
}
|
|
|
|
public function registerclub(){
|
|
$this->view->assign('title', "认证队伍");
|
|
//获取用户id
|
|
$this->view->engine->layout('layout/defaultsRegister');
|
|
$user_id = $this->auth->id;
|
|
|
|
if (empty($user_id)){
|
|
$this->error("请先登录!",url('user/login'));
|
|
}
|
|
$club = new ClubModel();
|
|
$club_info = $club
|
|
->where('user_id', $user_id)
|
|
->find();
|
|
|
|
if (empty($club_info)){
|
|
// $this->view->assign('playerinfo', $club_info);
|
|
return $this->view->fetch();
|
|
}
|
|
// var_dump($club_info);exit;
|
|
$this->view->assign('clubinfo', $club_info);
|
|
return $this->view->fetch();
|
|
// return $this->fetch('registerclub');
|
|
}
|
|
|
|
//单个赛事下的所有报名飞手
|
|
public function club_allplayer(){
|
|
$user_id = $this->auth->id;
|
|
if (empty($user_id)){
|
|
$this->error("请先登录!",url('user/login'));
|
|
}
|
|
$match_id = $this->request->param('match_id');
|
|
$player = new Players();
|
|
$club_model = new ClubModel();
|
|
$MatchContestant = new MatchContestant();
|
|
// var_dump($match_id);exit;
|
|
$club_info = $club_model->field('id,name')->where('user_id',$user_id)->where('status',9)->find();
|
|
if(empty($club_info)){
|
|
$this->error('请先注册俱乐部并通过认证');
|
|
}
|
|
$allplayer = $MatchContestant->where('club_id',$club_info['id'])->where('match_id',$match_id)->select();
|
|
// var_dump($club_info);exit;
|
|
// unset($allplayer[0]);
|
|
foreach ($allplayer as &$v){
|
|
// $player_info = [];
|
|
$player_info = $player->where('id',$v['player_id'])->find();
|
|
// if(!empty($player_info)) $player_info = $player_info->toArray();
|
|
// var_dump($club_appleyres['club_player']);exit;
|
|
$v['player'] = $player_info;
|
|
}
|
|
$data['code'] = 1;
|
|
$data['msg'] = 'success';
|
|
$data['data']['player'] = $allplayer;
|
|
$data['data']['club'] = $club_info;
|
|
return json($data);
|
|
}
|
|
|
|
//俱乐部报名
|
|
public function club_submit(){
|
|
$user_id = $this->auth->id;
|
|
if (empty($user_id)){
|
|
$this->error("请先登录!",url('user/login'));
|
|
}
|
|
$match_id = $this->request->param('match_id');
|
|
$select_player = $this->request->param('select_player');
|
|
$player = new Players();
|
|
$club_model = new ClubModel();
|
|
$club_match_apply = new ClubMatchApply();
|
|
$clubinvate = new ClubInvate();
|
|
// var_dump($select_player);exit;
|
|
$select_player = explode(",", $select_player);
|
|
// var_dump($select_player);exit;
|
|
$club_info = $club_model->where('user_id',$user_id)->where('status',9)->find();
|
|
if(empty($club_info)){
|
|
$this->error('请先注册俱乐部并通过认证');
|
|
}
|
|
$club_appleyres = $club_match_apply->where('match_id',$match_id)->where('club_id',$club_info['id'])->find();
|
|
if(empty($club_appleyres)){
|
|
$club_match_apply->save([
|
|
'match_id' => $match_id,
|
|
'club_id'=> $club_info['id'],
|
|
'status' => 1,
|
|
'club_player' => json_encode($select_player),
|
|
'createtime' => time(),
|
|
'updatetime' => time(),
|
|
]);
|
|
}else{
|
|
$club_match_apply->save([
|
|
'match_id' => $match_id,
|
|
'club_id'=> $club_info['id'],
|
|
'status' => 4,
|
|
'club_player' => json_encode($select_player),
|
|
'updatetime' => time(),
|
|
],['id'=> $club_appleyres['id']]);
|
|
}
|
|
$this->success('提交成功');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->view->assign('title', "身份认证");
|
|
//获取用户id
|
|
$user_id = $this->auth->id;
|
|
|
|
if (empty($user_id)){
|
|
$this->error("请先登录!",url('user/login'));
|
|
}
|
|
$club_model = new ClubModel();
|
|
|
|
$club_info = $club_model
|
|
->where('user_id', $user_id)
|
|
->find();
|
|
if(empty($club_info)){
|
|
return $this->redirect('players/registeredflyers');
|
|
}
|
|
// var_dump($club_info);exit;
|
|
$club_info['createtime'] = date('Y-m-d H:i:s', $club_info['createtime']);
|
|
$club_info['updatetime'] = date('Y-m-d H:i:s', $club_info['updatetime']);
|
|
$this->view->assign('clubinfo', $club_info);
|
|
|
|
// $this->view->assign('clubinfo', '');
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
//飞手公会
|
|
public function club_sociaty(){
|
|
header('Access-Control-Allow-Origin: *');
|
|
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
|
|
header('Access-Control-Allow-Methods: GET,POST');
|
|
|
|
$this->confirmed_club();
|
|
$club = new ClubModel();
|
|
$clubinvate = new ClubInvate();
|
|
$player = new Players();
|
|
$user_id = $this->auth->id;
|
|
$page = $this->request->param('page');
|
|
$club_info = $club->where("user_id", $user_id)->find();
|
|
$allplayer = $player->where('is_sociaty',1)->where('player_status',9)->select();
|
|
$allplayer1 = $player->where('is_sociaty',1)->where('player_status',9)->page($page,10)->orderRaw('rand()')->select();
|
|
foreach ($allplayer1 as &$val){
|
|
$val['send_status'] = 0;
|
|
$res = $clubinvate->where('club_id',$club_info['id'])->where('player_id',$val['id'])->where('deletetime',null)->where('status',1)->find();
|
|
if(!empty($res)) {
|
|
$val['send_status'] = 1;
|
|
$val['invate_id'] = $res['id'];
|
|
}
|
|
}
|
|
$data['total'] = count($allplayer);
|
|
$data['data'] = $allplayer1;
|
|
$data['user_data'] = $user_id;
|
|
return json($data);
|
|
}
|
|
|
|
public function search_player(){
|
|
$this->confirmed_club();
|
|
$club = new ClubModel();
|
|
$player = new Players();
|
|
$clubinvate = new ClubInvate();
|
|
$user_id = $this->auth->id;
|
|
$name = $this->request->param('name');
|
|
$page = $this->request->param('page');
|
|
// var_dump($name);exit;
|
|
$club_info = $club->where("user_id", $user_id)->find();
|
|
$allplayer = $player->where('is_sociaty',1)->where('player_status',9)->where('real_name','like','%'.$name.'%')->select();
|
|
$allplayer1 = $player->where('is_sociaty',1)->where('player_status',9)->where('real_name','like','%'.$name.'%')->page($page,10)->select();
|
|
foreach ($allplayer1 as &$val){
|
|
$val['send_status'] = 0;
|
|
$res = $clubinvate->where('club_id',$club_info['id'])->where('player_id',$val['id'])->where('deletetime',null)->where('status',1)->find();
|
|
if(!empty($res)) {
|
|
$val['send_status'] = 1;
|
|
$val['invate_id'] = $res['id'];
|
|
}
|
|
|
|
}
|
|
$data['total'] = count($allplayer);
|
|
$data['data'] = $allplayer1;
|
|
return json($data);
|
|
// $club = new ClubModel();
|
|
// $club_info = $club->where("user_id", $user_id)->find();
|
|
|
|
// $clubinvate->where('club_id',$club_info['id'])->where('deletetime',null)->find();
|
|
}
|
|
|
|
|
|
//队伍向飞手发送邀请
|
|
public function invate_player(){
|
|
$this->confirmed_club();
|
|
$club = new ClubModel();
|
|
$clubinvate = new ClubInvate();
|
|
$player = new Players();
|
|
$ClubThirdOauth = new ClubThirdOauth();
|
|
$Wxmb = new Wxmb();
|
|
$user = new User();
|
|
$user_id = $this->auth->id;
|
|
$player_id = $this->request->param('id');
|
|
$club_info = $club->where("user_id", $user_id)->find();
|
|
$player_info = $player->where('id',$player_id)->find();
|
|
$user_info = $user->where('id',$player_info['member_id'])->find();
|
|
$res = $clubinvate->where('club_id',$club_info['id'])->where('player_id',$player_id)->where('status',6)->where('deletetime',null)->find();
|
|
$res1 = $clubinvate->where('club_id',$club_info['id'])->where('player_id',$player_id)->where('status',1)->where('deletetime',null)->find();
|
|
$res2 = $clubinvate->where('club_id',$club_info['id'])->where('player_id',$player_id)->where('status',5)->where('deletetime',null)->find();
|
|
if(!empty($res2)) $this->error('该飞手已接受邀请等待平台审核');
|
|
if(!empty($res)){
|
|
$this->error('该飞手已成为某支队伍成员');
|
|
}
|
|
if(!empty($res1)){
|
|
$this->error('您已发送过邀请');
|
|
}
|
|
$clubinvate->save([
|
|
'club_id' => $club_info['id'],
|
|
'player_id' => $player_id,
|
|
'club_name' => $club_info['name'],
|
|
'player_name' => $player_info['real_name'],
|
|
'status' => 1,
|
|
'name_short' => $club_info['name_short'],
|
|
'member_number' => $user_info['member_number'],
|
|
'createtime' => time(),
|
|
'updatetime' => time(),
|
|
]);
|
|
|
|
$oauth_res = $ClubThirdOauth->where('user_id',$player_info['member_id'])->find();
|
|
if(!empty($oauth_res)){
|
|
$oauth_res = $oauth_res->toArray();
|
|
$push_arr = array('title'=>'您有一条新的队伍邀请通知','username'=> $club_info['name'],'type'=>'队伍邀请');
|
|
$Wxmb->leaguepush($push_arr,$oauth_res['openid']);
|
|
}
|
|
$this->success('邀请成功','',$clubinvate->id);
|
|
}
|
|
|
|
//撤销邀请
|
|
public function invate_player_cancel(){
|
|
$this->confirmed_club();
|
|
$club = new ClubModel();
|
|
$clubinvate = new ClubInvate();
|
|
$player = new Players();
|
|
$user_id = $this->auth->id;
|
|
$player_id = $this->request->param('id');
|
|
$invate_id = $this->request->param('invate_id');
|
|
$club_info = $club->where("user_id", $user_id)->find();
|
|
// $player->where('id',$player_id)->find();
|
|
$res = $clubinvate->where('club_id',$club_info['id'])->where('player_id',$player_id)->where('status',6)->where('deletetime',null)->find();
|
|
$res1 = $clubinvate->where('club_id',$club_info['id'])->where('player_id',$player_id)->where('status',4)->where('deletetime',null)->find();
|
|
$res2 = $clubinvate->where('club_id',$club_info['id'])->where('player_id',$player_id)->where('status',5)->where('deletetime',null)->find();
|
|
if(!empty($res2)) $this->error('该飞手已接受邀请等待平台审核');
|
|
if(!empty($res)){
|
|
$this->error('该飞手已成为某支队伍成员');
|
|
}
|
|
if(!empty($res1)){
|
|
$this->error('您已撤销过邀请');
|
|
}
|
|
$clubinvate->save([
|
|
'club_id' => $club_info['id'],
|
|
'player_id' => $player_id,
|
|
'status' => 4,
|
|
'createtime' => time(),
|
|
'updatetime' => time(),
|
|
'deletetime' => time(),
|
|
],['id'=> $invate_id]);
|
|
$this->success('撤销邀请成功');
|
|
}
|
|
|
|
|
|
public function myplayer(){
|
|
$this->view->assign('title', "管理飞手");
|
|
$user_id = $this->auth->id;
|
|
$player = new Players();
|
|
$club_model = new ClubModel();
|
|
// var_dump($player_res['id']);exit;
|
|
$club_info = $club_model->where('user_id',$user_id)->where('status',9)->find();
|
|
if(empty($club_info)){
|
|
$this->error('请先注册俱乐部并通过认证');
|
|
}
|
|
return $this->view->fetch();
|
|
|
|
}
|
|
|
|
public function myplayer_data(){
|
|
$user_id = $this->auth->id;
|
|
$page = $this->request->param('page');
|
|
if(empty($page)) $this->error('参数异常');
|
|
$player = new Players();
|
|
$club_model = new ClubModel();
|
|
$clubinvate = new ClubInvate();
|
|
$club_info = $club_model->where('user_id',$user_id)->where('status',9)->find();
|
|
// var_dump($user_id);exit;
|
|
if(empty($club_info)){
|
|
$this->error('请先注册俱乐部并通过');
|
|
}
|
|
// $res = $club_model->where('user_id',$user_id)->find();
|
|
|
|
$res = $clubinvate->where('club_id',$club_info['id'])->where('status in (1,3,5,6,7,8,9)')->where('deletetime',null)->select();
|
|
$res1 = $clubinvate->where('club_id',$club_info['id'])->where('status in (1,3,5,6,7,8,9)')->where('deletetime',null)->page($page,10)->select();
|
|
// var_dump($club_info['id']);exit;
|
|
$info = [];$i = 0;
|
|
foreach ($res1 as $v){
|
|
$player_res = $player->where('id',$v['player_id'])->find();
|
|
// $user_info = $this->model->where('id',$player_res['member_id'])->find();
|
|
// if(!empty($player_res)) {
|
|
$info[$i]['player'] = $player_res;
|
|
$info[$i]['status'] = $v['status'];
|
|
$info[$i]['check_id'] = $v['id'];
|
|
$info[$i]['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
|
|
$i++;
|
|
// }
|
|
}
|
|
$data['code'] = 1;
|
|
$data['msg'] = 'success';
|
|
$data['total'] = count($res);
|
|
$data['data'] = $info;
|
|
return json($data);
|
|
}
|
|
|
|
//上传协议
|
|
public function send_protocol(){
|
|
$club_model = new ClubModel();
|
|
$clubinvate = new ClubInvate();
|
|
$user_id = $this->auth->id;
|
|
$protocol = $this->request->post('protocol');
|
|
$player_id = $this->request->post('player_id');
|
|
if(empty($protocol)) $this->error('上传材料不能为空');
|
|
$club_info = $club_model
|
|
->where('user_id', $user_id)
|
|
->where('status', 9)
|
|
->find();
|
|
if(empty($club_info)) $this->error('您无权限操作');
|
|
$clubinvate->save([
|
|
'status' => 5,
|
|
'protocol' => $protocol,
|
|
'updatetime' => time()
|
|
],['player_id'=> $player_id, 'club_id' => $club_info['id'],'deletetime' => null]);
|
|
$this->success('上传成功',url('club/myplayer'));
|
|
}
|
|
|
|
}
|