831 lines
29 KiB
PHP
831 lines
29 KiB
PHP
|
<?php
|
||
|
|
||
|
|
||
|
namespace app\admin\controller\cms;
|
||
|
|
||
|
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\Backend;
|
||
|
use app\admin\service\LeagueService;
|
||
|
use app\common\exception\UploadException;
|
||
|
use app\common\library\Upload;
|
||
|
use fast\Random;
|
||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||
|
use think\Cookie;
|
||
|
use think\Session;
|
||
|
use think\Db;
|
||
|
|
||
|
class Leagueround extends Backend
|
||
|
{
|
||
|
protected $noNeedLogin = ['*'];
|
||
|
|
||
|
public function _initialize()
|
||
|
{
|
||
|
parent::_initialize();
|
||
|
$this->leagueService = new LeagueService();
|
||
|
}
|
||
|
|
||
|
public function final_rank($match_id){
|
||
|
if(empty($match_id)) $this->error('缺少参数');
|
||
|
$matchranking = new MatchRanking();
|
||
|
$oldarr = $matchranking->where([
|
||
|
'match_id' => $match_id,
|
||
|
'course' => 104,
|
||
|
'other_round' => 1,])
|
||
|
->orderRaw("CASE fly_num
|
||
|
WHEN '3' THEN 1
|
||
|
WHEN '2' THEN 2
|
||
|
WHEN '1' THEN 3
|
||
|
WHEN 'DNF' THEN 4
|
||
|
ELSE 5 END,datetime_value asc,CAST(qua_rank AS UNSIGNED)
|
||
|
")
|
||
|
->select();
|
||
|
$j = 1;
|
||
|
if(!empty($oldarr)){
|
||
|
foreach ($oldarr as $v){
|
||
|
$q = $v->toArray();
|
||
|
$q['group_sort'] = $j;
|
||
|
$obj_arr[] = $q;
|
||
|
$j++;
|
||
|
}
|
||
|
}
|
||
|
return $obj_arr;
|
||
|
}
|
||
|
|
||
|
public function final_group(){
|
||
|
$match_id = $this->request->param("match_id");
|
||
|
$this->final_groups($match_id,104);
|
||
|
}
|
||
|
//决赛分组
|
||
|
public function final_groups($match_id,$course,$export = false,$times = 5){
|
||
|
$matchranking = new MatchRanking();
|
||
|
$round13 = $matchranking->where([
|
||
|
'match_id' => $match_id,
|
||
|
'course' => 103,
|
||
|
'other_round' => 13,])
|
||
|
->orderRaw("CASE fly_num
|
||
|
WHEN '3' THEN 1
|
||
|
WHEN '2' THEN 2
|
||
|
WHEN '1' THEN 3
|
||
|
WHEN 'DNF' THEN 4
|
||
|
ELSE 5 END,datetime_value asc,CAST(qua_rank AS UNSIGNED)
|
||
|
")
|
||
|
->select();
|
||
|
$j = 1;
|
||
|
if(!empty($round13)){
|
||
|
foreach ($round13 as $v){
|
||
|
$q = $v->toArray();
|
||
|
$q['group_sort'] = $j;
|
||
|
$arr13[] = $q;
|
||
|
$j++;
|
||
|
}
|
||
|
}
|
||
|
// var_dump($arr13);exit;
|
||
|
$round12 = $matchranking->where([
|
||
|
'match_id' => $match_id,
|
||
|
'course' => 103,
|
||
|
'other_round' => 12,])
|
||
|
->orderRaw("CASE fly_num
|
||
|
WHEN '3' THEN 1
|
||
|
WHEN '2' THEN 2
|
||
|
WHEN '1' THEN 3
|
||
|
WHEN 'DNF' THEN 4
|
||
|
ELSE 5 END,datetime_value asc,CAST(qua_rank AS UNSIGNED)
|
||
|
")
|
||
|
->select();
|
||
|
if(!empty($round12)){
|
||
|
foreach ($round12 as $v){
|
||
|
$q = $v->toArray();
|
||
|
$q['group_sort'] = $j;
|
||
|
$arr12[] = $q;
|
||
|
$j++;
|
||
|
}
|
||
|
}
|
||
|
// $final_arr = $this->specify_order(1,$arr1,$arr2,'','',true);
|
||
|
$final_arr[] = $arr13[1];
|
||
|
$final_arr[] = $arr12[1];
|
||
|
$final_arr[] = $arr12[0];
|
||
|
$final_arr[] = $arr13[0];
|
||
|
$u = 0;
|
||
|
for($i = 1;$i <=$times ;$i++){
|
||
|
foreach ($final_arr as &$b){
|
||
|
if($u == 0){
|
||
|
$b['grouping'] = '1';
|
||
|
$b['channel'] = 'R1';
|
||
|
$b['led_color'] = '红';
|
||
|
}
|
||
|
if($u == 1){
|
||
|
$b['grouping'] = '1';
|
||
|
$b['channel'] = 'R2';
|
||
|
$b['led_color'] = '黄';
|
||
|
}
|
||
|
if($u == 2){
|
||
|
$b['grouping'] = '1';
|
||
|
$b['channel'] = 'R6';
|
||
|
$b['led_color'] = '蓝';
|
||
|
}
|
||
|
if($u == 3){
|
||
|
$b['grouping'] = '1';
|
||
|
$b['channel'] = 'R8';
|
||
|
$b['led_color'] = '绿';
|
||
|
}
|
||
|
$u++;
|
||
|
}
|
||
|
// var_dump($final_arr);exit;
|
||
|
$this->insert_group($final_arr,$match_id,104,$i);
|
||
|
}
|
||
|
$this->success('build success');
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
public function group_round2($match_id,$course,$other_round,$export = false){
|
||
|
$matchranking = new MatchRanking();
|
||
|
$this->exportmatch_id = $match_id;
|
||
|
$this->exportcourse = $course; // 赛程
|
||
|
// var_dump($other_round);exit;
|
||
|
|
||
|
$this->other_round = $other_round; // 赛程
|
||
|
if($other_round == 3 && $export === false) $other_round = 2;
|
||
|
|
||
|
if($export === true) {$other_round = $other_round + 1;}
|
||
|
|
||
|
if(empty($this->other_round) || empty($this->exportmatch_id) || empty($this->exportcourse)) $this->error('缺少参数');
|
||
|
|
||
|
$obj_arr = $this->group_rank_sort($this->exportmatch_id,$this->exportcourse,$other_round - 1);
|
||
|
// var_dump($obj_arr);exit;
|
||
|
if($export === true) return $obj_arr;
|
||
|
// var_dump($this->other_round);exit;
|
||
|
$t = 0;$h1 = 0;$h2 = 0;$h3 = 0;$h4 = 0;$g = 0;
|
||
|
// $group_arr = ['A','B','C','D','E','F','G','H'];
|
||
|
$group_arr = ['17','18','19','20','21','22','23','24'];
|
||
|
// if($this->other_round == 3){
|
||
|
// $group_arr = ['25','26','27','28','29','30','31','32'];
|
||
|
// }
|
||
|
// var_dump($group_arr);exit;
|
||
|
foreach ($obj_arr as $vv){
|
||
|
// if($h == 4) $t++;
|
||
|
if($g == 8) {$g = 0; $t++;}
|
||
|
$vv['grouping'] = $group_arr[$t];
|
||
|
|
||
|
if($vv['group_sort'] == 1){
|
||
|
$arr1[$h1] = $vv;
|
||
|
$h1++;
|
||
|
}
|
||
|
if($vv['group_sort'] == 2){
|
||
|
$arr2[$h2] = $vv;
|
||
|
$h2++;
|
||
|
}
|
||
|
if($vv['group_sort'] == 3){
|
||
|
$arr3[$h3] = $vv;
|
||
|
$h3++;
|
||
|
}
|
||
|
if($vv['group_sort'] == 4){
|
||
|
$arr4[$h4] = $vv;
|
||
|
$h4++;
|
||
|
}
|
||
|
|
||
|
$g++;
|
||
|
}
|
||
|
// var_dump($arr4);exit;
|
||
|
// var_dump($arr2);exit;
|
||
|
//胜者组
|
||
|
for($u = 0;$u < 16;$u++){
|
||
|
if($u % 2 == 0){
|
||
|
$arr2[$u]['channel'] = 'R1';
|
||
|
$arr2[$u]['led_color'] = '红';
|
||
|
// $arr2[$u]['grouping'] = $group_arr[$u];
|
||
|
$arr1[$u]['channel'] = 'R2';
|
||
|
$arr1[$u]['led_color'] = '黄';
|
||
|
// $arr1[$u]['grouping'] = $group_arr[$u];
|
||
|
$win_arr[] = $arr2[$u];
|
||
|
$win_arr[] = $arr1[$u];
|
||
|
}else{
|
||
|
$arr1[$u]['channel'] = 'R6';
|
||
|
$arr1[$u]['led_color'] = '蓝';
|
||
|
// $arr1[$u]['grouping'] = $group_arr[$u];
|
||
|
$arr2[$u]['channel'] = 'R8';
|
||
|
$arr2[$u]['led_color'] = '绿';
|
||
|
// $arr2[$u]['grouping'] = $group_arr[$u];
|
||
|
$win_arr[] = $arr1[$u];
|
||
|
$win_arr[] = $arr2[$u];
|
||
|
}
|
||
|
}
|
||
|
// var_dump($arr3);exit;
|
||
|
//败者组
|
||
|
$lose_arr = $this->specify_order(3,'','',$arr3,$arr4);
|
||
|
// var_dump($win_arr);exit;
|
||
|
|
||
|
// var_dump($lose_arr);exit;
|
||
|
// if($this->other_round == 2) $win_or_lose = $win_arr;
|
||
|
// if($this->other_round == 3) $win_or_lose = $lose_arr;
|
||
|
// var_dump($win_or_lose);exit;
|
||
|
|
||
|
$this->insert_group($win_arr,$this->exportmatch_id,$this->exportcourse,$this->other_round);
|
||
|
$this->insert_group($lose_arr,$this->exportmatch_id,$this->exportcourse,3);
|
||
|
|
||
|
$this->success('build success');
|
||
|
|
||
|
}
|
||
|
|
||
|
public function group_round6($match_id,$course,$other_round,$export = false){
|
||
|
$matchranking = new MatchRanking();
|
||
|
$this->exportmatch_id = $match_id;
|
||
|
$this->exportcourse = $course; // 赛程
|
||
|
// var_dump($other_round);exit;
|
||
|
$other_round = 4;
|
||
|
$this->other_round = $other_round; // 赛程
|
||
|
|
||
|
if($other_round == 4){
|
||
|
$calculate_win_round = $other_round - 2;
|
||
|
}
|
||
|
// $this->exportmatch_id = 606;$this->exportcourse= 103;$this->other_round = 1;
|
||
|
if(empty($this->other_round) || empty($this->exportmatch_id) || empty($this->exportcourse)) $this->error('缺少参数');
|
||
|
|
||
|
$obj_arr = $this->group_rank_sort($this->exportmatch_id,$this->exportcourse,$calculate_win_round);
|
||
|
// var_dump($obj_arr);exit;
|
||
|
if($export === true ){return $obj_arr;}
|
||
|
// var_dump($obj_arr);exit;
|
||
|
$h1 = 0;$h2 = 0;
|
||
|
foreach ($obj_arr as $vv){
|
||
|
// var_dump($vv['group_sort']);exit;
|
||
|
if($vv['group_sort'] == 1){
|
||
|
$arrwin1[$h1] = $vv;
|
||
|
$h1++;
|
||
|
}
|
||
|
if($vv['group_sort'] == 2){
|
||
|
$arrwin2[$h2] = $vv;
|
||
|
$h2++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if($other_round == 4) {$fortimes = 8; $group_arr = ['45','46','47','48'];}
|
||
|
// var_dump($fortimes);exit;
|
||
|
for($u = 0,$j = 0,$h = 0;$u < $fortimes;$u++){
|
||
|
|
||
|
if($u % 2 == 0){
|
||
|
$arrwin2[$u]['channel'] = 'R1';
|
||
|
$arrwin2[$u]['led_color'] = '红';
|
||
|
$arrwin2[$u]['grouping'] = $group_arr[$j];
|
||
|
$arrwin1[$u]['channel'] = 'R2';
|
||
|
$arrwin1[$u]['led_color'] = '黄';
|
||
|
$arrwin1[$u]['grouping'] = $group_arr[$j];
|
||
|
$win_arr[] = $arrwin2[$u];
|
||
|
$win_arr[] = $arrwin1[$u];
|
||
|
$h = $h + 0.5;
|
||
|
}else{
|
||
|
$arrwin1[$u]['channel'] = 'R6';
|
||
|
$arrwin1[$u]['led_color'] = '蓝';
|
||
|
$arrwin1[$u]['grouping'] = $group_arr[$j];
|
||
|
$arrwin2[$u]['channel'] = 'R8';
|
||
|
$arrwin2[$u]['led_color'] = '绿';
|
||
|
$arrwin2[$u]['grouping'] = $group_arr[$j];
|
||
|
$win_arr[] = $arrwin1[$u];
|
||
|
$win_arr[] = $arrwin2[$u];
|
||
|
$h = $h + 0.5;
|
||
|
// var_dump($h == ($j + 1));exit;
|
||
|
if($h == ($j + 1)) {$j++;}
|
||
|
}
|
||
|
// var_dump($h);exit;
|
||
|
|
||
|
}
|
||
|
// var_dump($win_arr);exit;
|
||
|
if($other_round != 13){
|
||
|
$this->insert_group($win_arr,$this->exportmatch_id,$this->exportcourse,$other_round + 2);
|
||
|
}
|
||
|
$this->success('build success');
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
public function group_round4($match_id,$course,$other_round,$export = false){
|
||
|
$matchranking = new MatchRanking();
|
||
|
$this->exportmatch_id = $match_id;
|
||
|
$this->exportcourse = $course; // 赛程
|
||
|
// var_dump($other_round);exit;
|
||
|
|
||
|
$this->other_round = $other_round; // 赛程
|
||
|
|
||
|
if($other_round == 4){
|
||
|
$calculate_round = $other_round - 1;
|
||
|
$calculate_win_round = $other_round - 2;
|
||
|
}
|
||
|
if($other_round == 7 || $other_round == 10 || $other_round == 13){
|
||
|
$calculate_round = $other_round - 2;
|
||
|
$calculate_win_round = $other_round - 1;
|
||
|
}
|
||
|
if($export === true){$calculate_round = $other_round;$calculate_win_round = $other_round;}
|
||
|
|
||
|
// $this->exportmatch_id = 606;$this->exportcourse= 103;$this->other_round = 1;
|
||
|
if(empty($this->other_round) || empty($this->exportmatch_id) || empty($this->exportcourse)) $this->error('缺少参数');
|
||
|
|
||
|
$obj_arr = $this->group_rank_sort($this->exportmatch_id,$this->exportcourse,$calculate_round);
|
||
|
|
||
|
// if($export === true && $other_round == 3){return $obj_arr;}
|
||
|
// var_dump($calculate_win_round);exit;
|
||
|
$h1 = 0;$h2 = 0;$h3 = 0;$h4 = 0;
|
||
|
// $group_arr = ['A','B','C','D','E','F','G','H'];
|
||
|
$group_arr = ['33','34','35','36','37','38','39','40'];
|
||
|
foreach ($obj_arr as $vv){
|
||
|
|
||
|
if($vv['group_sort'] == 1){
|
||
|
$arr1[$h1] = $vv;
|
||
|
$h1++;
|
||
|
}
|
||
|
if($vv['group_sort'] == 2){
|
||
|
$arr2[$h2] = $vv;
|
||
|
$h2++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$obj_arr = $this->group_rank_sort($this->exportmatch_id,$this->exportcourse,$calculate_win_round);
|
||
|
// var_dump($calculate_win_round);exit;
|
||
|
// var_dump($obj_arr);exit;
|
||
|
if($export === true ){return $obj_arr;}
|
||
|
// var_dump($obj_arr);exit;
|
||
|
$h1 = 0;$h2 = 0;$h3 = 0;$h4 = 0;
|
||
|
foreach ($obj_arr as $vv){
|
||
|
// var_dump($vv['group_sort']);exit;
|
||
|
if($vv['group_sort'] == 1){
|
||
|
$arrwin1[$h1] = $vv;
|
||
|
$h1++;
|
||
|
}
|
||
|
if($vv['group_sort'] == 2){
|
||
|
$arrwin2[$h2] = $vv;
|
||
|
$h2++;
|
||
|
}
|
||
|
if($vv['group_sort'] == 3){
|
||
|
$arr3[$h3] = $vv;
|
||
|
$h3++;
|
||
|
}
|
||
|
if($vv['group_sort'] == 4){
|
||
|
$arr4[$h4] = $vv;
|
||
|
$h4++;
|
||
|
}
|
||
|
}
|
||
|
// var_dump($arrwin1);exit;
|
||
|
$final_arr = $this->specify_order($this->other_round,$arr1,$arr2,$arr3,$arr4);
|
||
|
// var_dump($final_arr);exit;
|
||
|
|
||
|
if($other_round == 4) {$fortimes = 8; $group_arr = ['45','46','47','48'];}
|
||
|
if($other_round == 7) {$fortimes = 4; $group_arr = ['55','56'];}
|
||
|
if($other_round == 10) {$fortimes = 2; $group_arr = ['60'];}
|
||
|
if($other_round == 13) {$fortimes = 1; $group_arr = ['61'];}
|
||
|
// var_dump($fortimes);exit;
|
||
|
for($u = 0,$j = 0,$h = 0;$u < $fortimes;$u++){
|
||
|
|
||
|
if($u % 2 == 0){
|
||
|
$arrwin2[$u]['channel'] = 'R1';
|
||
|
$arrwin2[$u]['led_color'] = '红';
|
||
|
$arrwin2[$u]['grouping'] = $group_arr[$j];
|
||
|
$arrwin1[$u]['channel'] = 'R2';
|
||
|
$arrwin1[$u]['led_color'] = '黄';
|
||
|
$arrwin1[$u]['grouping'] = $group_arr[$j];
|
||
|
$win_arr[] = $arrwin2[$u];
|
||
|
$win_arr[] = $arrwin1[$u];
|
||
|
$h = $h + 0.5;
|
||
|
}else{
|
||
|
$arrwin1[$u]['channel'] = 'R6';
|
||
|
$arrwin1[$u]['led_color'] = '蓝';
|
||
|
$arrwin1[$u]['grouping'] = $group_arr[$j];
|
||
|
$arrwin2[$u]['channel'] = 'R8';
|
||
|
$arrwin2[$u]['led_color'] = '绿';
|
||
|
$arrwin2[$u]['grouping'] = $group_arr[$j];
|
||
|
$win_arr[] = $arrwin1[$u];
|
||
|
$win_arr[] = $arrwin2[$u];
|
||
|
$h = $h + 0.5;
|
||
|
// var_dump($h == ($j + 1));exit;
|
||
|
if($h == ($j + 1)) {$j++;}
|
||
|
}
|
||
|
// var_dump($h);exit;
|
||
|
|
||
|
}
|
||
|
// var_dump($win_arr);exit;
|
||
|
$this->insert_group($final_arr,$this->exportmatch_id,$this->exportcourse,$this->other_round);
|
||
|
if($other_round != 13 && $other_round != 4){
|
||
|
$this->insert_group($win_arr,$this->exportmatch_id,$this->exportcourse,$other_round + 2);
|
||
|
}
|
||
|
$this->success('build success');
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
public function group_round5($match_id,$course,$other_round,$export = false){
|
||
|
$matchranking = new MatchRanking();
|
||
|
$this->exportmatch_id = $match_id;
|
||
|
$this->exportcourse = $course; // 赛程
|
||
|
// var_dump($other_round);exit;
|
||
|
if($export === true ) {$other_round = $other_round + 1;}
|
||
|
|
||
|
$this->other_round = $other_round; // 赛程
|
||
|
// $this->exportmatch_id = 606;$this->exportcourse= 103;$this->other_round = 1;
|
||
|
if(empty($this->other_round) || empty($this->exportmatch_id) || empty($this->exportcourse)) $this->error('缺少参数');
|
||
|
|
||
|
$obj_arr = $this->group_rank_sort($this->exportmatch_id,$this->exportcourse,$other_round - 1);
|
||
|
|
||
|
// var_dump($obj_arr);exit;
|
||
|
if( $export === true) {return $obj_arr;}
|
||
|
// var_dump($obj_arr);exit;
|
||
|
$h1 = 0;$h2 = 0;$h3 = 0;$h4 = 0;
|
||
|
// $group_arr = ['A','B','C','D','E','F','G','H'];
|
||
|
$group_arr = ['41','42','43','44'];
|
||
|
foreach ($obj_arr as $vv){
|
||
|
if($vv['group_sort'] == 1){
|
||
|
$arrwin1[$h1] = $vv;
|
||
|
$h1++;
|
||
|
}
|
||
|
if($vv['group_sort'] == 2){
|
||
|
$arrwin2[$h2] = $vv;
|
||
|
$h2++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$final_arr = $this->specify_order($this->other_round,$arrwin1,$arrwin2,'','');
|
||
|
// var_dump($final_arr);exit;
|
||
|
//插入数据
|
||
|
$this->insert_group($final_arr,$this->exportmatch_id,$this->exportcourse,$this->other_round);
|
||
|
|
||
|
$this->success('build success');
|
||
|
|
||
|
}
|
||
|
|
||
|
public function specify_order($round,$arr1,$arr2,$arr3,$arr4,$is_final = false){
|
||
|
if($round == 3){
|
||
|
$final_arr[] = $arr4[0];
|
||
|
$final_arr[] = $arr3[1];
|
||
|
$final_arr[] = $arr3[2];
|
||
|
$final_arr[] = $arr4[3];
|
||
|
|
||
|
$final_arr[] = $arr4[4];
|
||
|
$final_arr[] = $arr3[5];
|
||
|
$final_arr[] = $arr3[6];
|
||
|
$final_arr[] = $arr4[7];
|
||
|
|
||
|
$final_arr[] = $arr4[1];
|
||
|
$final_arr[] = $arr3[0];
|
||
|
$final_arr[] = $arr3[3];
|
||
|
$final_arr[] = $arr4[2];
|
||
|
|
||
|
$final_arr[] = $arr4[5];
|
||
|
$final_arr[] = $arr3[4];
|
||
|
$final_arr[] = $arr3[7];
|
||
|
$final_arr[] = $arr4[6];
|
||
|
|
||
|
$final_arr[] = $arr4[8];
|
||
|
$final_arr[] = $arr3[9];
|
||
|
$final_arr[] = $arr3[10];
|
||
|
$final_arr[] = $arr4[11];
|
||
|
|
||
|
$final_arr[] = $arr4[12];
|
||
|
$final_arr[] = $arr3[13];
|
||
|
$final_arr[] = $arr3[14];
|
||
|
$final_arr[] = $arr4[15];
|
||
|
|
||
|
$final_arr[] = $arr4[9];
|
||
|
$final_arr[] = $arr3[8];
|
||
|
$final_arr[] = $arr3[11];
|
||
|
$final_arr[] = $arr4[10];
|
||
|
|
||
|
$final_arr[] = $arr4[13];
|
||
|
$final_arr[] = $arr3[12];
|
||
|
$final_arr[] = $arr3[15];
|
||
|
$final_arr[] = $arr4[14];
|
||
|
// var_dump($final_arr);exit;
|
||
|
}
|
||
|
if($round == 11){
|
||
|
$final_arr[] = $arr2[0];
|
||
|
$final_arr[] = $arr1[0];
|
||
|
$final_arr[] = $arr1[1];
|
||
|
$final_arr[] = $arr2[1];
|
||
|
}
|
||
|
if($round == 8){
|
||
|
$final_arr[] = $arr2[2];
|
||
|
$final_arr[] = $arr1[0];
|
||
|
$final_arr[] = $arr1[1];
|
||
|
$final_arr[] = $arr2[3];
|
||
|
|
||
|
$final_arr[] = $arr2[0];
|
||
|
$final_arr[] = $arr1[2];
|
||
|
$final_arr[] = $arr1[3];
|
||
|
$final_arr[] = $arr2[1];
|
||
|
}
|
||
|
if($round == 5){
|
||
|
$final_arr[] = $arr2[2];
|
||
|
$final_arr[] = $arr1[0];
|
||
|
$final_arr[] = $arr1[1];
|
||
|
$final_arr[] = $arr2[3];
|
||
|
|
||
|
$final_arr[] = $arr2[0];
|
||
|
$final_arr[] = $arr1[2];
|
||
|
$final_arr[] = $arr1[3];
|
||
|
$final_arr[] = $arr2[1];
|
||
|
|
||
|
$final_arr[] = $arr2[6];
|
||
|
$final_arr[] = $arr1[4];
|
||
|
$final_arr[] = $arr1[5];
|
||
|
$final_arr[] = $arr2[7];
|
||
|
|
||
|
$final_arr[] = $arr2[4];
|
||
|
$final_arr[] = $arr1[6];
|
||
|
$final_arr[] = $arr1[7];
|
||
|
$final_arr[] = $arr2[5];
|
||
|
}
|
||
|
if($round == 4){
|
||
|
$final_arr[] = $arr3[0];
|
||
|
$final_arr[] = $arr2[6];
|
||
|
$final_arr[] = $arr1[7];
|
||
|
$final_arr[] = $arr4[1];
|
||
|
|
||
|
$final_arr[] = $arr3[2];
|
||
|
$final_arr[] = $arr2[4];
|
||
|
$final_arr[] = $arr1[5];
|
||
|
$final_arr[] = $arr4[3];
|
||
|
|
||
|
$final_arr[] = $arr3[1];
|
||
|
$final_arr[] = $arr2[7];
|
||
|
$final_arr[] = $arr1[6];
|
||
|
$final_arr[] = $arr4[0];
|
||
|
|
||
|
$final_arr[] = $arr3[3];
|
||
|
$final_arr[] = $arr2[5];
|
||
|
$final_arr[] = $arr1[4];
|
||
|
$final_arr[] = $arr4[2];
|
||
|
|
||
|
$final_arr[] = $arr3[4];
|
||
|
$final_arr[] = $arr2[1];
|
||
|
$final_arr[] = $arr1[0];
|
||
|
$final_arr[] = $arr4[5];
|
||
|
|
||
|
$final_arr[] = $arr3[6];
|
||
|
$final_arr[] = $arr2[3];
|
||
|
$final_arr[] = $arr1[2];
|
||
|
$final_arr[] = $arr4[7];
|
||
|
|
||
|
$final_arr[] = $arr3[5];
|
||
|
$final_arr[] = $arr2[0];
|
||
|
$final_arr[] = $arr1[1];
|
||
|
$final_arr[] = $arr4[4];
|
||
|
|
||
|
$final_arr[] = $arr3[7];
|
||
|
$final_arr[] = $arr2[2];
|
||
|
$final_arr[] = $arr1[3];
|
||
|
$final_arr[] = $arr4[6];
|
||
|
}
|
||
|
if($round == 7){
|
||
|
$final_arr[] = $arr3[0];
|
||
|
$final_arr[] = $arr2[2];
|
||
|
$final_arr[] = $arr1[3];
|
||
|
$final_arr[] = $arr4[1];
|
||
|
|
||
|
$final_arr[] = $arr3[2];
|
||
|
$final_arr[] = $arr2[0];
|
||
|
$final_arr[] = $arr1[1];
|
||
|
$final_arr[] = $arr4[3];
|
||
|
|
||
|
$final_arr[] = $arr3[1];
|
||
|
$final_arr[] = $arr2[3];
|
||
|
$final_arr[] = $arr1[2];
|
||
|
$final_arr[] = $arr4[0];
|
||
|
|
||
|
$final_arr[] = $arr3[3];
|
||
|
$final_arr[] = $arr2[1];
|
||
|
$final_arr[] = $arr1[0];
|
||
|
$final_arr[] = $arr4[2];
|
||
|
}
|
||
|
if($round == 10){
|
||
|
$final_arr[] = $arr3[0];
|
||
|
$final_arr[] = $arr1[0];
|
||
|
$final_arr[] = $arr2[1];
|
||
|
$final_arr[] = $arr4[1];
|
||
|
|
||
|
$final_arr[] = $arr3[1];
|
||
|
$final_arr[] = $arr1[1];
|
||
|
$final_arr[] = $arr2[0];
|
||
|
$final_arr[] = $arr4[0];
|
||
|
}
|
||
|
if($round == 13){
|
||
|
$final_arr[] = $arr3[0];
|
||
|
$final_arr[] = $arr1[0];
|
||
|
$final_arr[] = $arr2[0];
|
||
|
$final_arr[] = $arr4[0];
|
||
|
}
|
||
|
// $group_arr = ['A','B','C','D','E','F','G','H'];
|
||
|
$group_arr = ['1','2','3','4','5','6','7','8'];
|
||
|
if($round == 3){
|
||
|
$group_arr = ['25','26','27','28','29','30','31','32'];
|
||
|
}elseif($round == 4){
|
||
|
$group_arr = ['33','34','35','36','37','38','39','40'];
|
||
|
}elseif($round == 5){
|
||
|
$group_arr = ['41','42','43','44'];
|
||
|
}elseif($round == 7){
|
||
|
$group_arr = ['49','50','51','52'];
|
||
|
}elseif($round == 8){
|
||
|
$group_arr = ['53','54'];
|
||
|
}elseif($round == 10){
|
||
|
$group_arr = ['57','58'];
|
||
|
}elseif($round == 11){
|
||
|
$group_arr = ['59'];
|
||
|
}elseif($round == 13){
|
||
|
$group_arr = ['61'];
|
||
|
}
|
||
|
$u = 0;$j = 0;
|
||
|
foreach ($final_arr as &$b){
|
||
|
if($u == 4){ $u = 0; $j++;}
|
||
|
if($u == 0){
|
||
|
$b['grouping'] = $group_arr[$j];
|
||
|
$b['channel'] = 'R1';
|
||
|
$b['led_color'] = '红';
|
||
|
}
|
||
|
if($u == 1){
|
||
|
$b['grouping'] = $group_arr[$j];
|
||
|
$b['channel'] = 'R2';
|
||
|
$b['led_color'] = '黄';
|
||
|
}
|
||
|
if($u == 2){
|
||
|
$b['grouping'] = $group_arr[$j];
|
||
|
$b['channel'] = 'R6';
|
||
|
$b['led_color'] = '蓝';
|
||
|
}
|
||
|
if($u == 3){
|
||
|
$b['grouping'] = $group_arr[$j];
|
||
|
$b['channel'] = 'R8';
|
||
|
$b['led_color'] = '绿';
|
||
|
}
|
||
|
$u++;
|
||
|
}
|
||
|
|
||
|
return $final_arr;
|
||
|
}
|
||
|
|
||
|
//加赛
|
||
|
public function extra_match($duplicates,$obj_exist,$obj_old_arr,$match_id,$course,$obj_arr){
|
||
|
$duplicateElements = array_keys($duplicates);
|
||
|
// var_dump($duplicateElements);exit;
|
||
|
$res = $this->search_array($obj_old_arr,$duplicateElements[0]);
|
||
|
// var_dump($res);exit;
|
||
|
$obj_arr1 = $obj_exist;
|
||
|
foreach (array_keys($res) as $vv){
|
||
|
unset($obj_exist[$vv]);
|
||
|
}
|
||
|
// var_dump($obj_unset);exit;
|
||
|
$res1 = $this->find_quarank($match_id,$course);
|
||
|
$i = 0;$array = [];
|
||
|
// var_dump($res1);exit;
|
||
|
foreach ($res as $k => $vvv){
|
||
|
$result = $this->search_array($res1,$obj_arr1[$k]['player_id']);
|
||
|
$array = $array + $result;
|
||
|
$i++;
|
||
|
}
|
||
|
// var_dump($array);exit;
|
||
|
ksort($array);
|
||
|
$ccc = array_keys($res);
|
||
|
// var_dump($array);exit;
|
||
|
$i = 0;
|
||
|
foreach ($array as $vvvv){
|
||
|
foreach ($obj_arr1 as $va){
|
||
|
if($va['player_id'] == $vvvv){
|
||
|
$obj_exist[$ccc[$i]] = $va;
|
||
|
$i++;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
ksort($obj_exist);$j = 1;
|
||
|
// var_dump($obj_exist);exit;
|
||
|
foreach ($obj_exist as &$val){
|
||
|
$val['group_sort'] = $j;
|
||
|
$obj_arr[] = $val;
|
||
|
$j++;
|
||
|
}
|
||
|
// var_dump($obj_arr);exit;
|
||
|
return $obj_arr;
|
||
|
}
|
||
|
|
||
|
public function find_quarank($match_id,$course){
|
||
|
// $match_id = 606;$course = 101;
|
||
|
$res = $this->leagueService->bestplayerqua($match_id,$course);
|
||
|
foreach ($res as $val){
|
||
|
$new_arr[] = $val['info']['player_id'];
|
||
|
}
|
||
|
// var_dump($new_arr);exit;
|
||
|
return $new_arr;
|
||
|
}
|
||
|
|
||
|
public function search_array($array, $value) {
|
||
|
return array_filter($array, function($item) use ($value) {
|
||
|
return $item == $value;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public function group_rank_sort($match_id,$course,$other_round){
|
||
|
$matchranking = new MatchRanking();
|
||
|
$all_group = $matchranking->field('grouping,times')->where([
|
||
|
'match_id' => $match_id,
|
||
|
'course' => $course,
|
||
|
'other_round' => $other_round,])->group('grouping')->orderRaw('CAST(grouping AS UNSIGNED)')->select();
|
||
|
$new_group = [];
|
||
|
// if($all_group['times'])
|
||
|
// var_dump($all_group);exit;
|
||
|
foreach($all_group as $value){
|
||
|
$new_group[] = ($value->toArray())['grouping'];
|
||
|
if(empty(($value->toArray())['times'])) {
|
||
|
return '缺少数据1';
|
||
|
}
|
||
|
|
||
|
}
|
||
|
// var_dump($new_times);exit;
|
||
|
$i = 0;$newarr = [];$obj_arr = [];
|
||
|
//组内排序
|
||
|
foreach ($new_group as $val){
|
||
|
// if($i == 1) {var_dump($val);exit;}
|
||
|
$oldarr = $matchranking->where([
|
||
|
'grouping' => $val,
|
||
|
'match_id' => $match_id,
|
||
|
'course' => $course,
|
||
|
'other_round' => $other_round,])
|
||
|
->orderRaw("CASE fly_num
|
||
|
WHEN '3' THEN 1
|
||
|
WHEN '2' THEN 2
|
||
|
WHEN '1' THEN 3
|
||
|
WHEN 'DNF' THEN 4
|
||
|
ELSE 5 END
|
||
|
")
|
||
|
->orderRaw('datetime_value asc,CAST(qua_rank AS UNSIGNED)')->select();
|
||
|
// var_dump($oldarr);exit;
|
||
|
$j = 1;$obj_old_arr= [];$obj_exist=[];
|
||
|
if(!empty($oldarr)){
|
||
|
foreach ($oldarr as $v){
|
||
|
$q = $v->toArray();
|
||
|
$q['group_sort'] = $j;
|
||
|
// $o = $q['times'];
|
||
|
$obj_arr[] = $q;
|
||
|
// $obj_exist[] = $q;
|
||
|
// $obj_old_arr[] = $o;
|
||
|
// $obj_fly_arr[] = $q['fly_num'];
|
||
|
$j++;
|
||
|
}
|
||
|
}
|
||
|
// var_dump(123);exit;
|
||
|
// $obj_arrs = array_count_values($obj_old_arr);
|
||
|
// $duplicates = array_filter($obj_arrs, function($count) {
|
||
|
// return $count > 1;
|
||
|
// });
|
||
|
// var_dump($obj_arrs);exit;
|
||
|
// if(!empty($duplicates)){
|
||
|
// // var_dump($obj_exist);exit;
|
||
|
// array_splice($obj_arr,-4);
|
||
|
// $obj_arr = $this->extra_match($duplicates,$obj_exist,$obj_old_arr,$match_id,$course,$obj_arr);
|
||
|
// }
|
||
|
|
||
|
$i++;
|
||
|
// var_dump($newarr);exit;
|
||
|
}
|
||
|
|
||
|
return $obj_arr;
|
||
|
}
|
||
|
|
||
|
|
||
|
public function insert_group($data,$match_id,$course,$other_round){
|
||
|
$matchranking = new MatchRanking();
|
||
|
Db::startTrans();
|
||
|
try{
|
||
|
foreach ($data as $val){
|
||
|
// var_dump($val);exit;
|
||
|
$match_rank_res = $matchranking->where([
|
||
|
'match_id' => $match_id,
|
||
|
'course' => $course,
|
||
|
'other_round' => $other_round,
|
||
|
'player_id' => $val['player_id'],
|
||
|
])->find();
|
||
|
$player['match_id'] = $match_id;
|
||
|
$player['course'] = $course;
|
||
|
$player['other_round'] = $other_round;
|
||
|
$player['player_id'] = $val['player_id'];
|
||
|
$player['player_name'] = $val['player_name'];
|
||
|
$player['channel'] = $val['channel'];
|
||
|
$player['led_color'] = $val['led_color'];
|
||
|
$player['grouping'] = $val['grouping'];
|
||
|
$player['name_short'] = $val['name_short'];
|
||
|
$player['qua_rank'] = $val['qua_rank'];
|
||
|
if($match_id = '1888'){
|
||
|
$player['country'] = $val['country'];
|
||
|
$player['national_flag'] = $val['national_flag'];
|
||
|
}
|
||
|
|
||
|
if(empty($match_rank_res)){
|
||
|
$matchranking->insert($player);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 提交事务
|
||
|
Db::commit();
|
||
|
} catch (\Exception $e) {
|
||
|
// 回滚事务
|
||
|
Db::rollback();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|