203 lines
6.6 KiB
PHP
203 lines
6.6 KiB
PHP
<?php
|
|
/**
|
|
* @Created by PhpStorm.
|
|
* @Author:Soar
|
|
* @Time:2023/7/17 9:09
|
|
*/
|
|
|
|
namespace app\index\controller;
|
|
|
|
use addons\shopro\model\Verify;
|
|
use app\admin\model\cms\Archives;
|
|
use app\common\controller\Frontend;
|
|
use app\common\model\MatchContestant;
|
|
use app\common\model\Players;
|
|
use app\index\service\MatchService;
|
|
use app\admin\model\ClubMatchApply;
|
|
use app\admin\model\Club;
|
|
use think\Config;
|
|
use think\Cookie;
|
|
use think\Hook;
|
|
|
|
|
|
class Match extends Frontend
|
|
{
|
|
protected $layout = 'defaults';
|
|
protected $noNeedLogin = '*';
|
|
protected $noNeedRight = '*';
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$auth = $this->auth;
|
|
|
|
if (!Config::get('fastadmin.usercenter')) {
|
|
$this->error(__('User center already closed'), '/');
|
|
}
|
|
|
|
//监听注册登录退出的事件
|
|
Hook::add('user_login_successed', function ($user) use ($auth) {
|
|
$expire = input('post.keeplogin') ? 30 * 86400 : 0;
|
|
Cookie::set('uid', $user->id, $expire);
|
|
Cookie::set('token', $auth->getToken(), $expire);
|
|
});
|
|
Hook::add('user_register_successed', function ($user) use ($auth) {
|
|
Cookie::set('uid', $user->id);
|
|
Cookie::set('token', $auth->getToken());
|
|
});
|
|
Hook::add('user_delete_successed', function ($user) use ($auth) {
|
|
Cookie::delete('uid');
|
|
Cookie::delete('token');
|
|
});
|
|
Hook::add('user_logout_successed', function ($user) use ($auth) {
|
|
Cookie::delete('uid');
|
|
Cookie::delete('token');
|
|
});
|
|
|
|
$this->matchService = new MatchService();
|
|
}
|
|
|
|
public function clubmatch(){
|
|
$this->view->assign('title', "我的赛事");
|
|
$club_match_apply = new ClubMatchApply();
|
|
$MatchContestantModel = new MatchContestant();
|
|
$archivesModel = new Archives();
|
|
$club = new Club();
|
|
|
|
$club_info = $club->where('user_id',$this->auth->id)->find();
|
|
if(empty($club_info)) $this->error('请先注册俱乐部');
|
|
if($club_info['status'] != 9) $this->error('您还不是正式俱乐部');
|
|
$club_match_list = $MatchContestantModel->where('club_id',$club_info['id'])->group('match_id')->paginate(10);
|
|
$page = $club_match_list->render();
|
|
|
|
// var_dump($club_match_list);exit;
|
|
$arr = []; $i = 0;
|
|
if(!empty($club_match_list)){
|
|
foreach ($club_match_list as &$v){
|
|
$match_info = $archivesModel->find($v->match_id);
|
|
$v['match'] = $match_info;
|
|
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
|
}
|
|
}
|
|
$this->assign("club_matchlist", $club_match_list);
|
|
$this->assign('page', $page);
|
|
// var_dump($club_match_list);exit;
|
|
return $this->view->fetch('club_match');
|
|
}
|
|
|
|
public function userMatch()
|
|
{
|
|
//获取用户赛事信息
|
|
$MatchContestantModel = new MatchContestant();
|
|
|
|
$playersModel = new Players();
|
|
|
|
$player_info = $playersModel->where("member_id", $this->auth->id)->find();
|
|
|
|
if (empty($player_info)){
|
|
$this->error(__("请先申请成为飞手!"), url('players/registeredflyers')) ;
|
|
}
|
|
|
|
if ($player_info['player_status'] != 9){
|
|
$this->error(__("您还不是正式飞手!"), url('user/index'));
|
|
}
|
|
|
|
$user_match_list = $MatchContestantModel->where("player_id", $player_info->id)->select();
|
|
|
|
if (!empty($user_match_list)){
|
|
$archivesModel = new Archives();
|
|
foreach ($user_match_list as $key => $val){
|
|
$match_info = $archivesModel->find($val->match_id);
|
|
if (!empty($match_info)) {
|
|
$user_match_list[$key]['match'] = $match_info;
|
|
} else {
|
|
unset($user_match_list[$key]);
|
|
}
|
|
//$user_match_list[$key]['match'] = $archivesModel->find($val->match_id);
|
|
// if ($this->auth->id == 855) {
|
|
// echo "<pre>";
|
|
// $user_match_list = collection($user_match_list)->toArray();
|
|
// print_r($user_match_list);exit;
|
|
// }
|
|
}
|
|
}
|
|
|
|
$this->assign("matchlist", $user_match_list);
|
|
|
|
$this->view->assign('title', "我的赛事");
|
|
return $this->view->fetch();
|
|
}
|
|
|
|
public function my_match_show()
|
|
{
|
|
$match_id = $this->request->param('id');
|
|
|
|
$MatchContestantModel = new MatchContestant();
|
|
|
|
$user_match_info = $MatchContestantModel->find($match_id);
|
|
|
|
if (!empty($user_match_info)){
|
|
$archivesModel = new Archives();
|
|
$user_match_info->match = $archivesModel->find($user_match_info->match_id);
|
|
}
|
|
|
|
return $user_match_info;
|
|
}
|
|
|
|
public function getMatch()
|
|
{
|
|
// 解决跨域请求接口问题
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
|
|
header('Access-Control-Expose-Headers: *'); //服务器 headers 白名单,可以让客户端进行访问
|
|
header('Access-Control-Allow-Headers: *');
|
|
|
|
$param['date'] = $this->request->param("date");
|
|
$param['page'] = $this->request->param("page", 1);
|
|
$param['limit'] = $this->request->param("limit", 10);
|
|
|
|
$row = $this->matchService->getAllMatch($param);
|
|
if (!empty($row)) {
|
|
$res['code'] = 1;
|
|
$res['data'] = $row;
|
|
$res['msg'] = "获取成功";
|
|
} else {
|
|
$res['code'] = 0;
|
|
$res['data'] = [];
|
|
$res['msg'] = "数据为空";
|
|
}
|
|
|
|
return json($res);
|
|
}
|
|
|
|
public function getmatchuser()
|
|
{
|
|
// 解决跨域请求接口问题
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
|
|
header('Access-Control-Expose-Headers: *'); //服务器 headers 白名单,可以让客户端进行访问
|
|
header('Access-Control-Allow-Headers: *');
|
|
|
|
$match_id = $this->request->param("match_id");
|
|
$user_id = $this->request->param("user_id");
|
|
|
|
if (empty($match_id) || empty($user_id)) {
|
|
$this->error("非法请求!");
|
|
}
|
|
|
|
$row = $this->matchService->getMatchUserInfo($match_id, $user_id);
|
|
|
|
if (!empty($row)) {
|
|
$res['code'] = 1;
|
|
$res['data'] = $row;
|
|
$res['msg'] = "获取成功";
|
|
} else {
|
|
$res['code'] = 0;
|
|
$res['data'] = [];
|
|
$res['msg'] = "数据为空";
|
|
}
|
|
|
|
return json($res);
|
|
}
|
|
|
|
} |