www_fpvone_cn/application/index/controller/League.php

405 lines
16 KiB
PHP

<?php
/**
* @Created by PhpStorm.
* @Author:Soar
* @Time:2023/11/15 15:13
*/
namespace app\index\controller;
use app\admin\model\LeagueClubIntegral;
use app\admin\model\ClubInvate;
use app\admin\model\LeagueIntegral;
use app\admin\model\MatchContestant;
use app\admin\model\MatchRanking;
use app\admin\model\MatchScreen;
use app\admin\model\Players;
use app\admin\model\User;
use app\common\controller\Frontend;
use app\admin\service\RankingService;
use app\admin\controller\cms\Leagueround;
use app\admin\service\LeagueService;
use app\admin\model\Club;
use app\admin\model\cms\Archives;
use app\index\service\CertificateService;
class League extends Frontend
{
protected $noNeedLogin = ['*'];
public function _initialize()
{
parent::_initialize();
$this->rankingService = new RankingService();
$this->leagueRound = new Leagueround();
$this->leagueService = new LeagueService();
$this->leagueClubIntegral = new LeagueClubIntegral();
$this->leagueIntegral = new LeagueIntegral();
}
public function get_match_final(){
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');
$res = $this->leagueIntegral->field('number,player_id,player_name,gender,name_short,birthday')->where('match_id',$match_id)->order('number')->limit(64)->select();
if(empty($res)){
$res['code'] = 0;
$res['data'] = '';
$res['msg'] = "最终成绩还未产生";
// $this->error('最终成绩还未产生');
}else{
foreach ($res as &$v){
if($v['birthday'] >= '2006-12-31'){
$v['is_young'] = '是';
}else{
$v['is_young'] = '否';
}
}
}
return json($res);
}
public function judge_league(){
$Archives = new Archives();
$match_id = $this->request->param('match_id');
$arc_res = $Archives->where('id',$match_id)->find();
if($arc_res['model_id'] == 6){
$arr = 'league';
return json($arr);
}elseif($arc_res['model_id'] == 2){
$arr = 'saishi';
return json($arr);
}else{
$arr = 'error';
return json($arr);
}
}
public function get_club_cert(){
$Club = new Club();
$Players= new Players();
$User = new User();
$certificateService = new CertificateService();
$match_id = $this->request->param('match_id');
$club_id = $this->request->param('club_id');
$club_info = $Club->field('id,name_short,competition_slogan,user_id,province,city,district,logo')->where('id',$club_id)->find();
// var_dump($user_info['member_number']);exit;
$integral_club_res = $this->leagueClubIntegral->where(['match_id' => $match_id,'club_id'=>$club_id])->find();
// var_dump($integral_res);exit;
if(empty($integral_club_res)) $this->error('暂未查询到您的成绩');
$club_info['number'] = $integral_club_res['number'];
$club_info['grade'] = $integral_club_res['sum_grade'];
// var_dump($player_info);exit;
$row['club'] = $club_info;
$addonproducts = db("cms_addonproducts");
$row['endtime'] = $addonproducts->where("id", $match_id)->field("match_end_time, match_start_time, stime, etime, club_course_poster, is_open_course")->find();
$row['certificate_number']['certificate_number'] = $certificateService->getCertificate(
[
'match_id' => $match_id,
'club_id' => $club_id,
'member_id' => $club_info['user_id'],
'player_id' => 0,
]
);
if (!empty($row)) {
$res['code'] = 1;
$res['data'] = $row;
$res['msg'] = "获取成功";
} else {
$res['code'] = 0;
$res['data'] = [];
$res['msg'] = "数据为空";
}
return json($res);
}
public function get_cert(){
$Club = new Club();
$Players= new Players();
$User = new User();
$certificateService = new CertificateService();
$match_id = $this->request->param('match_id');
$player_id = $this->request->param('player_id');
$player_info = $Players->field('id,member_id,age,gender,real_name,player_pic,member_id')->where('id',$player_id)->find();
$user_info = $User->where('id',$player_info['member_id'])->find();
// var_dump($user_info['member_number']);exit;
$integral_res = $this->leagueIntegral->where(['match_id' => $match_id,'player_id'=>$user_info['member_number']])->find();
// var_dump($integral_res);exit;
if(empty($integral_res)) $this->error('暂未查询到您的成绩');
$player_info['member_number'] = $user_info['member_number'];
$player_info['number'] = $integral_res['number'];
$player_info['grade'] = $integral_res['grade'];
// if(empty($integral_res)) $this->error('未查询到成绩');
// var_dump($integral_res);exit;
$club_info = $Club->field('id,name_short')->where('id',$integral_res['club_id'])->find();
// var_dump($player_info);exit;
$row['club'] = $club_info;
$row['player'] = $player_info;
$addonproducts = db("cms_addonproducts");
$row['endtime'] = $addonproducts->where("id", $match_id)->field("match_end_time, match_start_time, stime, etime, course_poster, is_open_course")->find();
$row['certificate_number']['certificate_number'] = $certificateService->getCertificate(
[
'match_id' => $match_id,
'player_id' => $player_id,
'member_id' => $player_info['member_id'],
'club_id' => 0,
]
);
if (!empty($row)) {
$res['code'] = 1;
$res['data'] = $row;
$res['msg'] = "获取成功";
} else {
$res['code'] = 0;
$res['data'] = [];
$res['msg'] = "数据为空";
}
return json($res);
}
//队伍总积分排行榜
public function club_allintegral(){
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Expose-Headers: *'); //服务器 headers 白名单,可以让客户端进行访问
header('Access-Control-Allow-Headers: *');
$club = new Club();
// 已参赛
$all_club = $this->leagueClubIntegral->group('club_id')->select();
$arr = $arrs = [];
foreach ($all_club as $value){
$arr = $this->leagueClubIntegral->field('sum(sum_grade) as all_grade,club_id,club_name')->where('club_id',$value['club_id'])->select();
$club_info = $club->field('logo,name_short')->where('id',$value['club_id'])->find();
$arr['club'] = $club_info;
$arrs[] = $arr;
}
// 未参赛的俱乐部
$res = $club->where('status',9)->group('name_short')->where('id','NOT IN',function($query){
$query->table('peewee_league_club_integral')->group('club_id')->field('club_id');
})->select();
$arr1 = $arr1s = [];
foreach ($res as $vvv){
$arr1[0] = array('all_grade'=>0,'club_id'=>$vvv['id'],'club_name'=>$vvv['name']);
$arr1['club'] = array('logo'=>$vvv['logo'],'name_short'=>$vvv['name_short']);
$arr1s[] = $arr1;
}
$volume = [];
foreach ($arrs as $key => $row)
{
$volume[$key] = $row[0]['all_grade'];
// $edition[$key] = $row['edition'];
}
array_multisort($volume, SORT_DESC, $arrs);
$new_arr = array_merge($arrs,$arr1s);
$rank = 1; $i = 0;// 当前排名
$all_grade = null; // 当前分数
foreach ($new_arr as $k => &$value) {
if ($all_grade != $value[0]['all_grade']) {
$rank = $rank + $i;
$i = 0;
}
$value['integral_sort'] = $rank;
$all_grade = $value[0]['all_grade'];
$i++;
}
// var_dump(count($new_arr));exit;
return json($new_arr);
}
//队伍分站赛积分
public function club_integral($match_id,$club_name=null){
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Expose-Headers: *'); //服务器 headers 白名单,可以让客户端进行访问
header('Access-Control-Allow-Headers: *');
$club = new Club();
//正常前端请求
if(empty($club_name)){
$match_id = $this->request->param('match_id');
}
$res = $this->leagueClubIntegral->where('match_id',$match_id)->order('sum_grade desc')->select();
// var_dump($res);exit;
foreach ($res as &$val){
$club_info = $club->field('logo,name_short')->where('id',$val['club_id'])->find();
$val['club'] = $club_info;
}
// 未参赛的俱乐部
$res_not = $club->where('status',9)->group('name_short')->where('id','NOT IN',function($query) use($match_id){
$query->table('peewee_league_club_integral')->where('match_id',$match_id)->group('club_id')->field('club_id');
})->select();
$arr1 = $arr1s = [];
foreach ($res_not as $vvv){
$arr1 = array('sum_grade'=>0,'club_id'=>$vvv['id'],'club_name'=>$vvv['name']);
$arr1['club'] = array('logo'=>$vvv['logo'],'name_short'=>$vvv['name_short']);
$arr1s[] = $arr1;
}
$new_arr = array_merge($res,$arr1s);
$rank = 1; $i = 0;// 当前排名
$all_grade = null; // 当前分数
// var_dump($res);exit;
foreach ($new_arr as $k => &$value) {
// var_dump($value['sum_grade']);exit;
if ($all_grade != $value['sum_grade']) {
$rank = $rank + $i;
$i = 0;
}
$value['integral_sort'] = $rank;
$all_grade = $value['sum_grade'];
$i++;
}
//俱乐部详情分站赛排名
if(!empty($club_name)){
foreach ($new_arr as $zhi){
if($zhi['name_short'] == $club_name){
$new_arr = $zhi;
break;
}
}
return $new_arr;
}
// var_dump(count($new_arr));exit;
return json($new_arr);
}
//飞手总积分排行
public function player_allintegral(){
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Expose-Headers: *'); //服务器 headers 白名单,可以让客户端进行访问
header('Access-Control-Allow-Headers: *');
$club = new Club();
$Players= new Players();
$User = new User();
$LeagueIntegral = new LeagueIntegral();
$gender= $this->request->param('gender');
$birthday = $this->request->param('birthday');
$where = [];
if(!empty($gender)){
$where['gender'] = '女';
}
if(!empty($birthday)){
$where['birthday'] = ['>','2006-12-31'];
}
$all_player = $LeagueIntegral->group('player_id')->where($where)->select();
$arr = $arrs = [];
foreach ($all_player as $value){
$arr = $LeagueIntegral->field('sum(grade) as all_grade,player_id,player_name')->where('player_id',$value['player_id'])->select();
$user_info = $User->where('member_number',$value['player_id'])->find();
$player_info = $Players->field('player_pic')->where('member_id',$user_info['id'])->find();
$club_info = $club->field('name_short')->where('id',$value['club_id'])->find();
$arr['player'] = $player_info;
$arr['club'] = $club_info;
$arrs[] = $arr;
}
$volume = [];
foreach ($arrs as $key => $row)
{
$volume[$key] = $row[0]['all_grade'];
// $edition[$key] = $row['edition'];
}
// var_dump($volume);exit;
array_multisort($volume, SORT_DESC, $arrs);
// $arr = $this->arraySort($arr,'all_grade');
// var_dump($arr);exit;
$rank = 1; $i = 0;// 当前排名
$all_grade = null; // 当前分数
foreach ($arrs as $k => &$value) {
if ($all_grade != $value[0]['all_grade']) {
$rank = $rank + $i;
$i = 0;
}
$value['integral_sort'] = $rank;
$all_grade = $value[0]['all_grade'];
$i++;
}
return json($arrs);
}
//飞手分站赛积分
public function player_integral($match_id,$player_id=null){
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Expose-Headers: *'); //服务器 headers 白名单,可以让客户端进行访问
header('Access-Control-Allow-Headers: *');
$club = new Club();
$Players= new Players();
$User = new User();
$LeagueIntegral = new LeagueIntegral();
if(empty($player_id)){
$match_id = $this->request->param('match_id');
}
$gender= $this->request->param('gender');
$birthday = $this->request->param('birthday');
$where = [];
if(!empty($gender)){
$where['gender'] = '女';
}
if(!empty($birthday)){
$where['birthday'] = ['>','2006-12-31'];
}
$res = $LeagueIntegral->where('match_id',$match_id)->where($where)->select();
foreach ($res as &$val){
$club_info = $club->field('name_short')->where('id',$val['club_id'])->find();
$user_info = $User->where('member_number',$val['player_id'])->find();
$player_info = $Players->field('player_pic')->where('member_id',$user_info['id'])->find();
$val['club'] = $club_info;
$val['player'] = $player_info;
}
$rank = 1; $i = 0;// 当前排名
$all_grade = null; // 当前分数
// var_dump($res);exit;
foreach ($res as $k => &$value) {
// var_dump($value['sum_grade']);exit;
if ($all_grade != $value['grade']) {
$rank = $rank + $i;
$i = 0;
}
$value['number'] = $rank;
$all_grade = $value['grade'];
$i++;
}
if(!empty($player_id)){
foreach ($res as $zhi){
if($zhi['player_id'] == $player_id){
$res = $zhi;
break;
}
}
return $res;
}
// var_dump($all_club);exit;
return json($res);
}
}