leagueService = new LeagueService(); } public function arr(){ $a=array("a"=>"red","b"=>"green","c"=>"blue",'d'=>"red"); foreach ($a as $k => $v){ if($v == 'red') $key[] = $k; } var_dump($key);exit; // echo array_search("red",$a);exit; // $array[0] = '王一博'; // $array[3] = '贾乃亮'; // $array[1] = '王梓烨'; // $array[2] = '金传博'; // var_dump($array); // ksort($array); // var_dump($array);exit; } //生成分组 public function click_group(){ $matchranking = new MatchRanking(); $match_id = $this->request->param("match_id"); $course = $this->request->param("course"); // 赛程 $other_round = $this->request->param("other_round"); // 赛程 $result = $matchranking->where('match_id',$match_id)->where('course',103)->where('other_round',$other_round)->find(); if(!empty($result)) {$this->error('该分组已生成过');} if($other_round == 1) $this->click_groups($match_id,$course,$other_round); if($other_round == 2 || $other_round == 3 ) { $leagueround = new Leagueround(); $leagueround->group_round2($match_id,$course,$other_round); } if($other_round == 6 ) { $leagueround = new Leagueround(); $leagueround->group_round6($match_id,$course,$other_round); } if($other_round == 4 || $other_round == 7 || $other_round == 10 || $other_round == 13) { $leagueround = new Leagueround(); $leagueround->group_round4($match_id,$course,$other_round); } if($other_round == 5 || $other_round == 8 || $other_round == 11) { $leagueround = new Leagueround(); $leagueround->group_round5($match_id,$course,$other_round); } } //淘汰赛第一轮 public function click_groups($match_id,$course,$other_round){ $matchranking = new MatchRanking(); $this->exportmatch_id = $match_id; $this->exportcourse = $course; // 赛程 $this->other_round = $other_round; // 赛程 // $this->exportmatch_id = 606;$this->exportcourse= 103; if(empty($this->other_round) || empty($this->exportmatch_id) || empty($this->exportcourse)) $this->error('缺少参数'); $res = $this->export_group($this->exportmatch_id, $this->exportcourse); // var_dump($res);exit; // 启动事务 Db::startTrans(); try{ foreach ($res as $val){ // var_dump($val);exit; $match_rank_res = $matchranking->where([ 'match_id' => $this->exportmatch_id, 'course' => $this->exportcourse, 'other_round' => $this->other_round, 'player_id' => $val['info']['player_id'], ])->find(); $player['match_id'] = $this->exportmatch_id; $player['course'] = $this->exportcourse; $player['other_round'] = $this->other_round; $player['player_id'] = $val['info']['player_id']; $player['player_name'] = $val['info']['player_name']; $player['channel'] = $val['info']['channel']; $player['led_color'] = $val['info']['led_color']; $player['grouping'] = $val['info']['grouping']; $player['name_short'] = $val['info']['name_short']; $player['qua_rank'] = $val['info']['qua_rank']; $player['country'] = $val['info']['country']; $player['national_flag'] = $val['info']['national_flag']; if(empty($match_rank_res)){ $matchranking->insert($player); } } // 提交事务 Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); } $this->success('build success'); } //导出分组 public function export_wash() { $matchranking = new MatchRanking(); $this->exportmatch_id = $this->request->param("match_id"); $this->exportcourse = $this->request->param("course"); // 赛程 $this->other_round = $this->request->param("other_round"); // 赛程 // $this->exportcourse = 101; $archives = new \app\admin\model\cms\Archives(); $PDOStatement = $archives->find($this->exportmatch_id); $row = $matchranking->where([ 'match_id' =>$this->exportmatch_id, 'course' => $this->exportcourse, 'other_round' => $this->other_round, ])->select(); // var_dump($this->exportmatch_id);exit; if (empty($PDOStatement)) { $this->error('导出数据为空'); } $cellTitles = [ 'grouping' => '组别', 'player_id' => '编号', 'player_name' => '姓名', 'name_short' => '所属队伍', 'channel' => '频道', 'led_color' => 'LED颜色', ]; // 数据总条数 $total = count($row); if ($total <= 0) { $this->error('导出数据为空'); } $which_round = $this->win_or_lose_group($this->other_round); switch ($this->exportcourse) { case 103: $PDOStatement->title = $PDOStatement->title."淘汰赛【第".$this->other_round.'轮'.$which_round['which_round'].'组】'.$which_round['status'].'分组名单'; break; case 104: $PDOStatement->title = $PDOStatement->title."决赛分组名单"; break; } $export = new \addons\shopro\library\Export(); // var_dump($PDOStatement->title);exit; $params = [ 'file_name' => $PDOStatement->title, 'cell_titles' => $cellTitles, 'total' => $total, 'is_sub_cell' => false, ]; $total_commission = 0; $config = $export->getConfig(); $result = $export->export_group_wash($params, function ($pages) use (&$total_commission, $total) { $matchranking = new MatchRanking(); $res = $matchranking->where([ 'match_id' =>$this->exportmatch_id, 'course' => $this->exportcourse, 'other_round' => $this->other_round, ]) ->orderRaw('CAST(grouping AS UNSIGNED),CASE led_color WHEN "红" THEN 1 WHEN "黄" THEN 2 WHEN "蓝" THEN 3 WHEN "绿" THEN 4 ELSE 5 END')->select(); // var_dump($res);exit; foreach ($res as &$val){ $val = $val->toArray(); } $datas = $res; $newDatas = []; foreach ($datas as &$reward) { $data = [ 'player_id' => $reward['player_id'] ? $reward['player_id'] : 0, 'player_name' => $reward['player_name'], 'name_short' => $reward['name_short'], 'grouping' => $reward['grouping'], 'channel' => $reward['channel'], 'led_color' => $reward['led_color'], ]; $newDatas[] = $data; } // } $total_commission += array_sum(array_column($newDatas, 'commission')); return $newDatas; }); $this->success('导出成功' . (isset($result['file_path']) && $result['file_path'] ? ',请在服务器: “' . $result['file_path'] . '” 查看' : ''), null, $result); } public function win_or_lose_group($other_round){ switch ($other_round) { case 1: $which_round['which_round'] = '1-16';$which_round['status'] = '胜者组';break; case 2: $which_round['which_round'] = '17-24';$which_round['status'] = '胜者组';break; case 3: $which_round['which_round'] = '25-32';$which_round['status'] = '败者组';break; case 4: $which_round['which_round'] = '33-40';$which_round['status'] = '败者组';break; case 5: $which_round['which_round'] = '41-44';$which_round['status'] = '败者组';break; case 6: $which_round['which_round'] = '45-48';$which_round['status'] = '胜者组';break; case 7: $which_round['which_round'] = '49-52';$which_round['status'] = '败者组';break; case 8: $which_round['which_round'] = '53-54';$which_round['status'] = '败者组';break; case 9: $which_round['which_round'] = '55-56';$which_round['status'] = '胜者组';break; case 10: $which_round['which_round'] = '57-58';$which_round['status'] = '败者组';break; case 11: $which_round['which_round'] = '59';$which_round['status'] = '败者组';break; case 12: $which_round['which_round'] = '60';$which_round['status'] = '胜者组';break; case 13: $which_round['which_round'] = '61';$which_round['status'] = '败者组';break; } return $which_round; } private function taotaiorder(){ $arr = ['0' => 1,'4'=>16,'8'=>8,'12'=>14,'16'=>4,'20'=>12,'24'=>6,'28'=>10,'32'=>9,'36'=>5,'40'=>11,'44'=>3,'48'=>13,'52'=>7,'56'=>15,'60'=>2]; foreach ($arr as $k => $val){ $arr[$k + 1] = $val + 16; $arr[$k + 2] = $val + 32; $arr[$k + 3] = $val + 48; } ksort($arr); return $arr; // var_dump($arr);exit; } public function export_group($match_id,$course){ // $match_id = $this->request->param("match_id"); // $course = $this->request->param("course"); // 赛程 // $match_id = 606;$course = 101; $group_arr = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P']; $group_arr = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16']; $res_data = $this->leagueService->bestplayerqua($match_id,$course); if(count($res_data) < 64) $this->error('资格赛人数小于64'); // var_dump($res_data);exit; $arr = $this->taotaiorder(); // var_dump($arr);exit; $i = 0; $a = 0; $b = 0; foreach ($arr as $val){ if($a == 4) {$a = 0;$b = $b + 1;} $new_arr[$i] = $res_data[$val - 1]; if($a == 0){ $new_arr[$i]['info']['channel'] = 'R1'; $new_arr[$i]['info']['led_color'] = '红'; $new_arr[$i]['info']['grouping'] = $group_arr[$b]; }elseif($a == 1){ $new_arr[$i]['info']['channel'] = 'R2'; $new_arr[$i]['info']['led_color'] = '黄'; $new_arr[$i]['info']['grouping'] = $group_arr[$b]; }elseif($a == 2){ $new_arr[$i]['info']['channel'] = 'R6'; $new_arr[$i]['info']['led_color'] = '蓝'; $new_arr[$i]['info']['grouping'] = $group_arr[$b]; }elseif($a == 3){ $new_arr[$i]['info']['channel'] = 'R8'; $new_arr[$i]['info']['led_color'] = '绿'; $new_arr[$i]['info']['grouping'] = $group_arr[$b]; } $new_arr[$i]['info']['qua_rank'] = $val; $i++; $a++; } return $new_arr; // var_dump($new_arr);exit; } }