776 lines
26 KiB
PHP
776 lines
26 KiB
PHP
|
<?php
|
|||
|
/**
|
|||
|
* @Created by PhpStorm.
|
|||
|
* @Author:Soar
|
|||
|
* @Time:2023/11/15 15:13
|
|||
|
*/
|
|||
|
|
|||
|
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\RankingService;
|
|||
|
use app\common\exception\UploadException;
|
|||
|
use app\common\library\Upload;
|
|||
|
use fast\Random;
|
|||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|||
|
use think\Cookie;
|
|||
|
use think\Session;
|
|||
|
use app\admin\model\cms\Archives;
|
|||
|
|
|||
|
class Ranking extends Backend
|
|||
|
{
|
|||
|
protected $noNeedLogin = ['*'];
|
|||
|
|
|||
|
public function _initialize()
|
|||
|
{
|
|||
|
parent::_initialize();
|
|||
|
$this->rankingService = new RankingService();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 上传参赛选手和成绩
|
|||
|
* @Author:Soar
|
|||
|
* @Time:2023/11/23 9:58
|
|||
|
* @return void
|
|||
|
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
|||
|
* @throws \think\db\exception\DataNotFoundException
|
|||
|
* @throws \think\db\exception\ModelNotFoundException
|
|||
|
* @throws \think\exception\DbException
|
|||
|
*/
|
|||
|
public function addRanking()
|
|||
|
{
|
|||
|
$this->error("开发中...");
|
|||
|
$attachment = null;
|
|||
|
//默认普通上传文件
|
|||
|
$file = $this->request->file('file');
|
|||
|
$course = $this->request->post('course');
|
|||
|
$match_id = $this->request->post('match_id');
|
|||
|
if (empty($match_id)) {
|
|||
|
$this->error("id不能为空!");
|
|||
|
}
|
|||
|
try {
|
|||
|
$upload = new Upload($file);
|
|||
|
$attachment = $upload->upload();
|
|||
|
|
|||
|
$rankingService = new RankingService();
|
|||
|
$upload_excel = $rankingService->upload_excel($attachment->url, $course, $match_id);
|
|||
|
} catch (UploadException $e) {
|
|||
|
$this->error($e->getMessage());
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 上传参赛选手
|
|||
|
* @Author:Soar
|
|||
|
* @Time:2023/11/23 9:58
|
|||
|
* @return void
|
|||
|
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
|||
|
* @throws \think\db\exception\DataNotFoundException
|
|||
|
* @throws \think\db\exception\ModelNotFoundException
|
|||
|
* @throws \think\exception\DbException
|
|||
|
*/
|
|||
|
public function addPlayerList()
|
|||
|
{
|
|||
|
$Archives = new Archives();
|
|||
|
$attachment = null;
|
|||
|
//默认普通上传文件
|
|||
|
$file = $this->request->file('file');
|
|||
|
$match_id = $this->request->param('match_id');
|
|||
|
$course = $this->request->param('course', '32');
|
|||
|
// var_dump($match_id);exit;
|
|||
|
$rachives_res = $Archives->where('id',$match_id)->find();
|
|||
|
try {
|
|||
|
$upload = new Upload($file);
|
|||
|
$attachment = $upload->upload();
|
|||
|
|
|||
|
$rankingService = new RankingService();
|
|||
|
if($rachives_res['model_id'] == 6){
|
|||
|
//联赛导入
|
|||
|
$upload_excel = $rankingService->uploadPlayers($attachment->url, $match_id, $course);
|
|||
|
}else{
|
|||
|
//公开赛
|
|||
|
// var_dump(123);exit;
|
|||
|
$upload_excel = $rankingService->uploadPlayer($attachment->url, $match_id, $course);
|
|||
|
}
|
|||
|
|
|||
|
if ($upload_excel === true) {
|
|||
|
$this->result("导入成功", 1);
|
|||
|
} else {
|
|||
|
$this->error("导入失败", '',$upload_excel);
|
|||
|
}
|
|||
|
} catch (UploadException $e) {
|
|||
|
$this->error($e->getMessage());
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//单轮导入
|
|||
|
public function singleRoundExport()
|
|||
|
{
|
|||
|
$Archives = new Archives();
|
|||
|
$attachment = null;
|
|||
|
//默认普通上传文件
|
|||
|
$file = $this->request->file('file');
|
|||
|
$match_id = $this->request->param('match_id');
|
|||
|
$course = $this->request->param('course', '32');
|
|||
|
try {
|
|||
|
$upload = new Upload($file);
|
|||
|
$attachment = $upload->upload();
|
|||
|
|
|||
|
$rankingService = new RankingService();
|
|||
|
|
|||
|
//联赛导入
|
|||
|
$upload_excel = $rankingService->singleRoundExport($attachment->url, $match_id, $course);
|
|||
|
|
|||
|
|
|||
|
if ($upload_excel === true) {
|
|||
|
$this->result("导入成功", 1);
|
|||
|
} else {
|
|||
|
$this->error("导入失败", '',$upload_excel);
|
|||
|
}
|
|||
|
} catch (UploadException $e) {
|
|||
|
$this->error($e->getMessage());
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//大师赛单轮导入
|
|||
|
public function singleRoundMasterExport()
|
|||
|
{
|
|||
|
$Archives = new Archives();
|
|||
|
$attachment = null;
|
|||
|
//默认普通上传文件
|
|||
|
$file = $this->request->file('file');
|
|||
|
$match_id = $this->request->param('match_id');
|
|||
|
$course = $this->request->param('course', '32');
|
|||
|
try {
|
|||
|
$upload = new Upload($file);
|
|||
|
$attachment = $upload->upload();
|
|||
|
|
|||
|
$rankingService = new RankingService();
|
|||
|
|
|||
|
//联赛导入
|
|||
|
$upload_excel = $rankingService->singleRoundMasterExport($attachment->url, $match_id, $course);
|
|||
|
|
|||
|
|
|||
|
if ($upload_excel === true) {
|
|||
|
$this->result("导入成功", 1);
|
|||
|
} else {
|
|||
|
$this->error("导入失败", '',$upload_excel);
|
|||
|
}
|
|||
|
} catch (UploadException $e) {
|
|||
|
$this->error($e->getMessage());
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 添加、更新参赛选手信息
|
|||
|
* @Author:Soar
|
|||
|
* @Time:2023/11/23 9:58
|
|||
|
* @return \think\response\Json
|
|||
|
* @throws \think\db\exception\DataNotFoundException
|
|||
|
* @throws \think\db\exception\ModelNotFoundException
|
|||
|
* @throws \think\exception\DbException
|
|||
|
*/
|
|||
|
public function setPlayerRanking()
|
|||
|
{
|
|||
|
$param['player_id'] = $this->request->param("player_id", 0); // 飞手id
|
|||
|
$param['match_id'] = $this->request->param("match_id", 0); // 赛事id
|
|||
|
$param['course'] = $this->request->param("course", 32); // 赛程
|
|||
|
$param['group'] = $this->request->param("group"); // 分组
|
|||
|
$param['achievement'] = $this->request->param("achievement"); // 成绩
|
|||
|
$param['integral'] = $this->request->param("integral", 0); // 积分
|
|||
|
$param['fly_num'] = $this->request->param("fly_num"); // 飞行圈数
|
|||
|
$param['is_finals'] = $this->request->param("is_finals", 0); // 是否是决赛
|
|||
|
$param['finals_round'] = $this->request->param("finals_round"); // 决赛轮次
|
|||
|
$param['player_name'] = $this->request->param("player_name"); // 选手姓名
|
|||
|
$param['led_color'] = $this->request->param("led_color"); // 选手姓名
|
|||
|
$param['channel'] = $this->request->param("channel"); // 选手姓名
|
|||
|
$param['other_round'] = $this->request->param("other_round"); // 选手姓名
|
|||
|
|
|||
|
$res = $this->rankingService->setToPlayer($param);
|
|||
|
|
|||
|
if (!empty($res)) {
|
|||
|
$result['code'] = 1;
|
|||
|
$result['data'] = [];
|
|||
|
$result['msg'] = "成功";
|
|||
|
} else {
|
|||
|
$result['code'] = 0;
|
|||
|
$result['data'] = [];
|
|||
|
$result['msg'] = "失败";
|
|||
|
}
|
|||
|
|
|||
|
return json($result);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 删除指定选手信息
|
|||
|
* @Author:Soar
|
|||
|
* @Time:2023/11/23 9:57
|
|||
|
* @return \think\response\Json
|
|||
|
*/
|
|||
|
public function delRanking()
|
|||
|
{
|
|||
|
$id = $this->request->post("id");
|
|||
|
|
|||
|
if (empty($id)) {
|
|||
|
$this->error("id不能为空!");
|
|||
|
}
|
|||
|
|
|||
|
$row = $this->rankingService->delRanking($id);
|
|||
|
|
|||
|
if (!empty($row)) {
|
|||
|
$res['code'] = 1;
|
|||
|
$res['data'] = [];
|
|||
|
$res['msg'] = "删除成功";
|
|||
|
} else {
|
|||
|
$res['code'] = 0;
|
|||
|
$res['data'] = [];
|
|||
|
$res['msg'] = "删除失败";
|
|||
|
}
|
|||
|
|
|||
|
return json($res);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 根据赛事id获取所有参赛选手
|
|||
|
* @Author:Soar
|
|||
|
* @Time:2023/11/20 11:00
|
|||
|
* @param $match_id
|
|||
|
* @return void
|
|||
|
*/
|
|||
|
public function getCompetitionList()
|
|||
|
{
|
|||
|
$match_id = $this->request->param("match_id");
|
|||
|
|
|||
|
if (empty($match_id)) {
|
|||
|
$this->error("赛事id不能为空!");
|
|||
|
}
|
|||
|
|
|||
|
$row = $this->rankingService->getCompetitionList($match_id);
|
|||
|
|
|||
|
if (!empty($row)) {
|
|||
|
$res['code'] = 1;
|
|||
|
$res['data'] = $row;
|
|||
|
$res['msg'] = "获取成功";
|
|||
|
} else {
|
|||
|
$res['code'] = 0;
|
|||
|
$res['data'] = [];
|
|||
|
$res['msg'] = "数据为空";
|
|||
|
}
|
|||
|
|
|||
|
return json($res);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 获取半决赛选手
|
|||
|
* @Author:Soar
|
|||
|
* @Time:2023/11/23 10:00
|
|||
|
* @return \think\response\Json
|
|||
|
*/
|
|||
|
public function getSemifinal()
|
|||
|
{
|
|||
|
$match_id = $this->request->param("match_id");
|
|||
|
|
|||
|
if (empty($match_id)) {
|
|||
|
$this->error("赛事id不能为空!");
|
|||
|
}
|
|||
|
|
|||
|
$row = $this->rankingService->getSemifinalListForRanking($match_id);
|
|||
|
|
|||
|
if (!empty($row)) {
|
|||
|
$res['code'] = 1;
|
|||
|
$res['data'] = $row;
|
|||
|
$res['msg'] = "获取成功";
|
|||
|
} else {
|
|||
|
$res['code'] = 0;
|
|||
|
$res['data'] = [];
|
|||
|
$res['msg'] = "数据为空";
|
|||
|
}
|
|||
|
|
|||
|
return json($res);
|
|||
|
}
|
|||
|
|
|||
|
public function customSorting()
|
|||
|
{
|
|||
|
$match_id = $this->request->param("match_id");
|
|||
|
$form_sort = $this->request->param("form_sort");
|
|||
|
$to_sort = $this->request->param("to_sort");
|
|||
|
$course = $this->request->param("course");
|
|||
|
|
|||
|
if (empty($match_id)) {
|
|||
|
$this->error("赛事id不能为空!");
|
|||
|
}
|
|||
|
|
|||
|
$this->rankingService->CustomSorting($form_sort, $to_sort, $match_id, $course);
|
|||
|
|
|||
|
$this->result("修改成功");
|
|||
|
}
|
|||
|
|
|||
|
public function soar()
|
|||
|
{
|
|||
|
print_r(4725 / 365);exit;
|
|||
|
return $this->rankingService->getRankingSort();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 根据赛事ID和赛程清空数据
|
|||
|
* @Author:Soar
|
|||
|
* @Time:2023/11/23 9:56
|
|||
|
* @return \think\response\Json
|
|||
|
*/
|
|||
|
public function clearRanking()
|
|||
|
{
|
|||
|
$param['match_id'] = $this->request->param("match_id");
|
|||
|
$param['course'] = $this->request->param("course"); // 赛程
|
|||
|
|
|||
|
if (empty($param['match_id'])) {
|
|||
|
$this->error("赛事id不能为空!");
|
|||
|
}
|
|||
|
|
|||
|
$row = $this->rankingService->clearRanking($param);
|
|||
|
|
|||
|
if (!empty($row)) {
|
|||
|
$res['code'] = 1;
|
|||
|
$res['data'] = [];
|
|||
|
$res['msg'] = "清空成功";
|
|||
|
} else {
|
|||
|
$res['code'] = 0;
|
|||
|
$res['data'] = [];
|
|||
|
$res['msg'] = "清空失败";
|
|||
|
}
|
|||
|
|
|||
|
return json($res);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 根据指定赛事ID和赛程信息获取参赛选手
|
|||
|
* @Author:Soar
|
|||
|
* @Time:2023/11/23 9:56
|
|||
|
* @return \think\response\Json
|
|||
|
*/
|
|||
|
public function getRankingforcourse()
|
|||
|
{
|
|||
|
$param['match_id'] = $this->request->param("match_id");
|
|||
|
$param['course'] = $this->request->param("course"); // 赛程
|
|||
|
$param['sorting'] = $this->request->param("sorting", false);
|
|||
|
$param['other_round'] = $this->request->param("other_round", false); // 轮次
|
|||
|
|
|||
|
if ($param['sorting'] == "false") {
|
|||
|
$param['sorting'] = false;
|
|||
|
}
|
|||
|
if (empty($param['match_id'])) {
|
|||
|
$this->error("赛事id不能为空!");
|
|||
|
}
|
|||
|
|
|||
|
$row = $this->rankingService->getRankingForCourse($param['match_id'], $param['course'], $param['sorting'], $param['other_round']);
|
|||
|
|
|||
|
if (!empty($row)) {
|
|||
|
$res['code'] = 1;
|
|||
|
$res['data'] = $row;
|
|||
|
$res['msg'] = "获取成功";
|
|||
|
} else {
|
|||
|
$res['code'] = 0;
|
|||
|
$res['data'] = [];
|
|||
|
$res['msg'] = "获取失败";
|
|||
|
}
|
|||
|
|
|||
|
return json($res);
|
|||
|
}
|
|||
|
|
|||
|
public function getFinalsList()
|
|||
|
{
|
|||
|
$param['match_id'] = $this->request->post("match_id");
|
|||
|
$param['other_round'] = $this->request->post("other_round"); // 轮次
|
|||
|
$param['sorting'] = $this->request->post("sorting");
|
|||
|
|
|||
|
if (empty($param['match_id'])) {
|
|||
|
$this->error("赛事id不能为空!");
|
|||
|
}
|
|||
|
|
|||
|
$row = $this->rankingService->getFinals($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 export()
|
|||
|
{
|
|||
|
$this->exportmatch_id = $this->request->param("match_id");
|
|||
|
$this->exportcourse = $this->request->param("course"); // 赛程
|
|||
|
$this->exportsorting = $this->request->param("sorting", false);
|
|||
|
|
|||
|
if ($this->exportsorting == "false") {
|
|||
|
$this->exportsorting = false;
|
|||
|
}
|
|||
|
|
|||
|
if (empty($this->exportmatch_id)) {
|
|||
|
$this->error("赛事id不能为空!");
|
|||
|
} else if (empty($this->exportcourse)) {
|
|||
|
$this->error("赛程不可为空!");
|
|||
|
}
|
|||
|
|
|||
|
$row = $this->rankingService->getRankingForCourse($this->exportmatch_id, $this->exportcourse, $this->exportsorting, "最佳成绩");
|
|||
|
$archives = new \app\admin\model\cms\Archives();
|
|||
|
$PDOStatement = $archives->find($this->exportmatch_id);
|
|||
|
if (empty($PDOStatement)) {
|
|||
|
$this->error('导出数据为空');
|
|||
|
}
|
|||
|
$cellTitles = [
|
|||
|
'num' => '序号',
|
|||
|
'player_id' => '编号',
|
|||
|
'player_name' => '姓名',
|
|||
|
'fly_num' => '飞行圈数',
|
|||
|
'times' => '时间',
|
|||
|
'grouping' => '组别',
|
|||
|
'channel' => '频道',
|
|||
|
'led_color' => 'LED颜色',
|
|||
|
|
|||
|
];
|
|||
|
|
|||
|
// 数据总条数
|
|||
|
$total = count($row['item']);
|
|||
|
if ($total <= 0) {
|
|||
|
$this->error('导出数据为空');
|
|||
|
}
|
|||
|
switch ($this->exportcourse) {
|
|||
|
case 32:
|
|||
|
if ($this->exportsorting == false) {
|
|||
|
$PDOStatement->title = $PDOStatement->title."【决出前32】-未排序";
|
|||
|
} else {
|
|||
|
$PDOStatement->title = $PDOStatement->title."【决出前32】-已排序";
|
|||
|
}
|
|||
|
break;
|
|||
|
case 16:
|
|||
|
if ($this->exportsorting == false) {
|
|||
|
$PDOStatement->title = $PDOStatement->title."【32进16】-未排序";
|
|||
|
} else {
|
|||
|
$PDOStatement->title = $PDOStatement->title."【32进16】-已排序";
|
|||
|
}
|
|||
|
break;
|
|||
|
case 8:
|
|||
|
if ($this->exportsorting == false) {
|
|||
|
$PDOStatement->title = $PDOStatement->title."【16进8】-未排序";
|
|||
|
} else {
|
|||
|
$PDOStatement->title = $PDOStatement->title."【16进8】-已排序";
|
|||
|
}
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
if ($this->exportsorting == false) {
|
|||
|
$PDOStatement->title = $PDOStatement->title."【8进4】-未排序";
|
|||
|
} else {
|
|||
|
$PDOStatement->title = $PDOStatement->title."【8进4】-已排序";
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
if ($this->exportsorting == false) {
|
|||
|
$PDOStatement->title = $PDOStatement->title."【决赛】-未排序";
|
|||
|
} else {
|
|||
|
$PDOStatement->title = $PDOStatement->title."【决赛】-已排序";
|
|||
|
}
|
|||
|
break;
|
|||
|
|
|||
|
}
|
|||
|
$export = new \addons\shopro\library\Export();
|
|||
|
$params = [
|
|||
|
'file_name' => $PDOStatement->title,
|
|||
|
'cell_titles' => $cellTitles,
|
|||
|
'total' => $total,
|
|||
|
'is_sub_cell' => false,
|
|||
|
];
|
|||
|
|
|||
|
$total_commission = 0;
|
|||
|
$config = $export->getConfig();
|
|||
|
$result = $export->exportRanking($params, function ($pages) use (&$total_commission, $total) {
|
|||
|
$datas = $this->rankingService->getRankingForCourse($this->exportmatch_id, $this->exportcourse, $this->exportsorting, "最佳成绩");
|
|||
|
$datas = collection($datas['item']);
|
|||
|
$datas->each(function ($order) {
|
|||
|
})->toArray();
|
|||
|
|
|||
|
$newDatas = [];
|
|||
|
$nums = 0;
|
|||
|
foreach ($datas as &$reward) {
|
|||
|
$data = [
|
|||
|
'num' => ++$nums,
|
|||
|
'player_id' => $reward['player_id'] ? $reward['player_id'] : 0,
|
|||
|
'player_name' => $reward['player_name'],
|
|||
|
'fly_num' => $reward['fly_num'],
|
|||
|
'times' => $reward['times'],
|
|||
|
'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 export_young()
|
|||
|
{
|
|||
|
$match_id = $this->request->param("match_id");
|
|||
|
$birthday = $this->request->param("birthday");
|
|||
|
if (empty($match_id)) {
|
|||
|
$this->error("非法请求");
|
|||
|
}
|
|||
|
$players = new Players();
|
|||
|
if (!empty($birthday)) {
|
|||
|
// 按照生日日期获取所有参赛选手
|
|||
|
$players_list = $players
|
|||
|
->alias("a")
|
|||
|
->join('user users', 'users.id = a.member_id', 'LEFT')
|
|||
|
->where("a.birthday", ">=", $birthday)
|
|||
|
->field("a.id, users.member_number, a.birthday")
|
|||
|
->order("a.birthday")
|
|||
|
->select();
|
|||
|
} else {
|
|||
|
// 按照性别获取所有参赛选手
|
|||
|
$players_list = $players
|
|||
|
->alias("a")
|
|||
|
->join('user users', 'users.id = a.member_id', 'LEFT')
|
|||
|
->where("a.gender", "eq", "女")
|
|||
|
->field("a.id, users.member_number")
|
|||
|
->select();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
$ids = array_column($players_list, "id");
|
|||
|
// $player_ids = array_column($players_list, "member_number");
|
|||
|
// 获取所有参赛选手
|
|||
|
$matchContestant = new MatchContestant();
|
|||
|
// 去报名表查询所有参赛的飞手
|
|||
|
$match_list = $matchContestant->whereIn("player_id", $ids)
|
|||
|
->where("match_id", "eq", $match_id)
|
|||
|
->select();
|
|||
|
// 根据参赛选手 加上player_member_id
|
|||
|
foreach ($match_list as $vals) {
|
|||
|
foreach ($players_list as $values) {
|
|||
|
if ($vals->player_id == $values->id) {
|
|||
|
$vals->player_member_id = $values->member_number;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
// $players_list = collection($players_list)->toArray();
|
|||
|
|
|||
|
$member_number_ids = array_column($match_list, "player_member_id");
|
|||
|
// 根据User表中的 member_number 获取比赛信息 权重 决赛 > 半决赛 > 8强 > 16强 > 32强 > 预选赛
|
|||
|
// 决赛数据
|
|||
|
$rankingService = new \app\index\service\RankingService();
|
|||
|
$achievement['finals'] = $rankingService->getRankFinals($match_id);
|
|||
|
|
|||
|
|
|||
|
if (empty($achievement['finals'])) {
|
|||
|
$this->error("决赛暂未结束");
|
|||
|
}
|
|||
|
unset($achievement['finals']['integral_list']);
|
|||
|
// 遍历查询是否有
|
|||
|
foreach ($achievement['finals'] as $key => $item) {
|
|||
|
if (!in_array($item->player_id, $member_number_ids)) {
|
|||
|
unset($achievement['finals'][$key]);
|
|||
|
} else {
|
|||
|
unset($member_number_ids[array_search($item->player_id, $member_number_ids)]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// 初始化model
|
|||
|
$matchRanking = new MatchRanking();
|
|||
|
// 查询 进入半决赛的成绩
|
|||
|
$achievement['semifinal'] = $matchRanking->whereIn("player_id", $member_number_ids)
|
|||
|
->where("match_id", "eq", $match_id)
|
|||
|
->where("bast_performance", 1)
|
|||
|
->where("course", "eq", 4)
|
|||
|
->order("group_score")
|
|||
|
->select();
|
|||
|
|
|||
|
foreach ($achievement['semifinal'] as $val) {
|
|||
|
unset($member_number_ids[array_search($val->player_id, $member_number_ids)]);
|
|||
|
}
|
|||
|
|
|||
|
// 查询 进入8强的成绩
|
|||
|
$achievement['final_eight'] = $matchRanking->whereIn("player_id", $member_number_ids)
|
|||
|
->where("match_id", "eq", $match_id)
|
|||
|
->where("bast_performance", 1)
|
|||
|
->where("course", "eq", 8)
|
|||
|
->order("group_score")
|
|||
|
->select();
|
|||
|
|
|||
|
foreach ($achievement['final_eight'] as $val) {
|
|||
|
unset($member_number_ids[array_search($val->player_id, $member_number_ids)]);
|
|||
|
}
|
|||
|
|
|||
|
// 查询 进入16强数据
|
|||
|
$achievement['final_sixteen'] = $matchRanking->whereIn("player_id", $member_number_ids)
|
|||
|
->where("match_id", "eq", $match_id)
|
|||
|
->where("bast_performance", 1)
|
|||
|
->where("course", "eq", 16)
|
|||
|
->order("group_score")
|
|||
|
->select();
|
|||
|
foreach ($achievement['final_sixteen'] as $val) {
|
|||
|
unset($member_number_ids[array_search($val->player_id, $member_number_ids)]);
|
|||
|
}
|
|||
|
// 查询 进入32强数据
|
|||
|
$achievement['final_thirty_two'] = $matchRanking->whereIn("player_id", $member_number_ids)
|
|||
|
->where("match_id", "eq", $match_id)
|
|||
|
->where("bast_performance", 1)
|
|||
|
->where("course", "eq", 32)
|
|||
|
->order("group_score")
|
|||
|
->select();
|
|||
|
|
|||
|
foreach ($achievement['final_thirty_two'] as $val) {
|
|||
|
unset($member_number_ids[array_search($val->player_id, $member_number_ids)]);
|
|||
|
}
|
|||
|
|
|||
|
if (!empty($member_number_ids)) {
|
|||
|
$user = new User();
|
|||
|
$keys = 0;
|
|||
|
foreach ($member_number_ids as $val) {
|
|||
|
$user_info = $user->with("players")->where("member_number", $val)->find();
|
|||
|
$user_info = $user_info->toArray();
|
|||
|
|
|||
|
$achievement['other_list'][$keys]['match_id'] = $match_id;
|
|||
|
$achievement['other_list'][$keys]['player_name'] = $user_info['players']['real_name'];
|
|||
|
$achievement['other_list'][$keys]['fly_num'] = null;
|
|||
|
$achievement['other_list'][$keys]['times'] = null;
|
|||
|
$achievement['other_list'][$keys]['grouping'] = null;
|
|||
|
$achievement['other_list'][$keys]['course'] = "DNF";
|
|||
|
$achievement['other_list'][$keys]['player_id'] = $val;
|
|||
|
|
|||
|
$keys++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
$this->achievement = $achievement;
|
|||
|
// 数据总条数
|
|||
|
$total = count($achievement['semifinal']) + count($achievement['final_eight']) +
|
|||
|
count($achievement['final_sixteen']) + count($achievement['final_thirty_two']) + count($achievement['finals']);
|
|||
|
if ($total <= 0) {
|
|||
|
$this->error('导出数据为空');
|
|||
|
}
|
|||
|
|
|||
|
$cellTitles = [
|
|||
|
'num' => '序号',
|
|||
|
'player_id' => '编号',
|
|||
|
'player_name' => '姓名',
|
|||
|
'course' => '赛程',
|
|||
|
'times' => '最佳成绩',
|
|||
|
'fly_num' => '飞行圈数',
|
|||
|
|
|||
|
];
|
|||
|
$archives = new \app\admin\model\cms\Archives();
|
|||
|
$PDOStatement = $archives->find($match_id);
|
|||
|
$export = new \addons\shopro\library\Export();
|
|||
|
if (empty($birthday)) {
|
|||
|
$params = [
|
|||
|
'file_name' => $PDOStatement->title."《女子组排名》",
|
|||
|
'cell_titles' => $cellTitles,
|
|||
|
'total' => $total,
|
|||
|
'is_sub_cell' => false,
|
|||
|
];
|
|||
|
} else {
|
|||
|
$params = [
|
|||
|
'file_name' => $PDOStatement->title."《青少年组排名》",
|
|||
|
'cell_titles' => $cellTitles,
|
|||
|
'total' => $total,
|
|||
|
'is_sub_cell' => false,
|
|||
|
];
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
$total_commission = 0;
|
|||
|
$config = $export->getConfig();
|
|||
|
$result = $export->exportRankingYoung($params, function ($pages) use (&$total_commission, $total) {
|
|||
|
$datas = $this->achievement;
|
|||
|
|
|||
|
|
|||
|
$newDatas = [];
|
|||
|
$nums = 0;
|
|||
|
foreach ($datas as $vals) {
|
|||
|
if (!is_array($vals)) {
|
|||
|
$datas_info = collection($vals);
|
|||
|
$datas_info->each(function ($order) {
|
|||
|
})->toArray();
|
|||
|
} else {
|
|||
|
$datas_info = $vals;
|
|||
|
}
|
|||
|
|
|||
|
foreach ($datas_info as $reward) {
|
|||
|
|
|||
|
if (!empty($reward->achievement_list)) {
|
|||
|
$data = [
|
|||
|
'num' => ++$nums,
|
|||
|
'player_id' => $reward['player_id'],
|
|||
|
'player_name' => $reward['player_name'],
|
|||
|
'course' => "决赛",
|
|||
|
'times' => $reward['times'],
|
|||
|
'fly_num' => $reward['fly_num'],
|
|||
|
];
|
|||
|
} else {
|
|||
|
$data = [
|
|||
|
'num' => ++$nums,
|
|||
|
'player_id' => $reward['player_id'],
|
|||
|
'player_name' => $reward['player_name'],
|
|||
|
'course' => $reward['course'],
|
|||
|
'times' => $reward['times'] ? $reward['times'] : "DNF",
|
|||
|
'fly_num' => $reward['fly_num'] ? $reward['fly_num'] : "DNF"
|
|||
|
];
|
|||
|
}
|
|||
|
|
|||
|
if ($data['course'] == 4) {
|
|||
|
$data['course'] = "8进4";
|
|||
|
} elseif ($data['course'] == 8) {
|
|||
|
$data['course'] = "16进8";
|
|||
|
} elseif ($data['course'] == 16) {
|
|||
|
$data['course'] = "32进16";
|
|||
|
} elseif ($data['course'] == 32) {
|
|||
|
$data['course'] = "排位赛";
|
|||
|
} else {
|
|||
|
if ($data['course'] != "决赛") {
|
|||
|
$data['course'] = $reward['course'];
|
|||
|
}
|
|||
|
}
|
|||
|
$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 update_sort()
|
|||
|
{
|
|||
|
$this->rankingService->testRanking();
|
|||
|
}
|
|||
|
}
|