577 lines
25 KiB
PHP
577 lines
25 KiB
PHP
<?php
|
|
|
|
namespace app\admin\service;
|
|
|
|
use app\admin\model\MatchCompetition;
|
|
use app\admin\model\MatchRanking;
|
|
use app\admin\model\User;
|
|
use think\Db;
|
|
use app\admin\model\ClubInvate;
|
|
use app\admin\model\Players;
|
|
use app\admin\model\Club;
|
|
use think\Exception;
|
|
use app\admin\controller\cms\Leagueround;
|
|
|
|
class LeagueService extends Service
|
|
{
|
|
private int $round;
|
|
private int $fist_row = 3;
|
|
private array $array_round;
|
|
private $BAST_SCORE = "最优成绩";
|
|
|
|
public function __construct()
|
|
{
|
|
$this->matchRankingModel = new MatchRanking();
|
|
}
|
|
|
|
//排位赛
|
|
public function bestplayersen($match_id,$course,$export = false){
|
|
$matchRankingModel = new MatchRanking();
|
|
$player_res = $matchRankingModel->field('*')->where('match_id',$match_id)->where('course',$course)->group('player_id')->select();
|
|
$h = 0;
|
|
foreach ($player_res as $k => &$value){
|
|
$dan_fly = $matchRankingModel->where('match_id',$match_id)->where('course',$course)->where('player_id',$value['player_id'])->select();
|
|
$player_info = $matchRankingModel->field('player_id,player_name,grouping,led_color,channel')->where('match_id',$match_id)->where('course',$course)->where('player_id',$value['player_id'])->find()->toArray();
|
|
// var_dump($player_info);exit;
|
|
$dan_data = [];$i = 0;
|
|
$sum = 0;
|
|
foreach ($dan_fly as $q){
|
|
if(preg_match('/\d/',$q['first_fly_time'])) {
|
|
$dan_data[$i] = $this->getAllMs($q['first_fly_time']);
|
|
$sum = $sum + $dan_data[$i];
|
|
$i++;
|
|
}
|
|
if(preg_match('/\d/',$q['second_fly_time'])) {
|
|
$dan_data[$i] = $this->getAllMs($q['second_fly_time']);
|
|
$sum = $sum + $dan_data[$i];
|
|
$i++;
|
|
}
|
|
if(preg_match('/\d/',$q['third_fly_time'])) {
|
|
$dan_data[$i] = $this->getAllMs($q['third_fly_time']);
|
|
$sum = $sum + $dan_data[$i];
|
|
$i++;
|
|
}
|
|
}
|
|
sort($dan_data);
|
|
// if($player_info['player_id'] == '10160'){var_dump($sum);exit;}
|
|
//
|
|
if($i >= 3){
|
|
$player_data[$h]['sum'] = $this->getAllSeconds(intval($sum));
|
|
// if($player_info['player_id'] == '10160'){var_dump($sum);var_dump($player_data[$h]['sum']);exit;}
|
|
$player_data[$h]['info'] = $player_info;
|
|
$player_data[$h]['fly_num'] = $i;
|
|
$player_data[$h]['first'] = $dan_data[0];
|
|
$player_data[$h]['second'] = $dan_data[1];
|
|
$player_data[$h]['third'] = $dan_data[2];
|
|
}elseif($i == 2){
|
|
$player_data[$h]['sum'] = $this->getAllSeconds(intval($sum));
|
|
// var_dump($player_data[$h]['sum']);exit;
|
|
$player_data[$h]['info'] = $player_info;
|
|
$player_data[$h]['fly_num'] = $i;
|
|
$player_data[$h]['first'] = $dan_data[0];
|
|
$player_data[$h]['second'] = $dan_data[1];
|
|
$player_data[$h]['third'] = '0';
|
|
}elseif($i == 1){
|
|
$player_data[$h]['sum'] = $this->getAllSeconds(intval($sum));
|
|
// var_dump($player_data[$h]['sum']);exit;
|
|
$player_data[$h]['info'] = $player_info;
|
|
$player_data[$h]['fly_num'] = $i;
|
|
$player_data[$h]['first'] = $dan_data[0];
|
|
$player_data[$h]['second'] = '0';
|
|
$player_data[$h]['third'] = '0';
|
|
}elseif($i == 0){
|
|
$player_data[$h]['sum'] = $this->getAllSeconds(intval($sum));
|
|
// var_dump($player_data[$h]['sum']);exit;
|
|
$player_data[$h]['info'] = $player_info;
|
|
$player_data[$h]['fly_num'] = $i;
|
|
$player_data[$h]['first'] = '0';
|
|
$player_data[$h]['second'] = '0';
|
|
$player_data[$h]['third'] = '0';
|
|
}
|
|
$h++;
|
|
// var_dump($value);exit;
|
|
// var_dump(($avg_socre));exit;
|
|
}
|
|
array_multisort(array_column($player_data,'fly_num'), SORT_DESC, array_column($player_data, 'sum'), SORT_ASC, array_column($player_data, 'first'), SORT_ASC,array_column($player_data, 'second'), SORT_ASC,array_column($player_data, 'third'), SORT_ASC,$player_data);
|
|
// var_dump($player_data);exit;
|
|
if($export === true){
|
|
$round = $this->matchRankingModel->where("match_id", "eq", $match_id)
|
|
->where("course", "eq", $course)
|
|
->max("other_round");
|
|
// $round = 3;
|
|
$a = 1;
|
|
foreach ($player_data as $k => $val){
|
|
|
|
for ($a = 1; $a <= $round; $a++){
|
|
$round_res = $this->matchRankingModel->field('first_fly_time,second_fly_time,third_fly_time')->where("match_id", "eq", $match_id)->where("course", "eq", $course)->where('other_round',$a)->where('player_id',$val['info']['player_id'])->find();
|
|
$player_data[$k]['round'.$a] = $round_res;
|
|
}
|
|
|
|
}
|
|
// var_dump($player_data);exit;
|
|
}
|
|
return $player_data;
|
|
}
|
|
|
|
//资格赛
|
|
public function bestplayerqua($match_id,$course,$export = false){
|
|
// $match_id = 468; $course = 4;
|
|
$user = new User();
|
|
$club = new Club();
|
|
$palyer = new Players();
|
|
$ClubInvate = new ClubInvate();
|
|
$matchRankingModel = new MatchRanking();
|
|
if($course == 103) $course = 101;
|
|
$player_res = $matchRankingModel->field('*')->where('match_id',$match_id)->where('course',$course)->group('player_id')->select();
|
|
// var_dump($player_res);exit;
|
|
$h = 0;
|
|
foreach ($player_res as $k => &$value){
|
|
$club_res = [];
|
|
// $user_res = $user->where('member_number',$value['player_id'])->find();
|
|
// $player_ress = $palyer->where('member_id',$user_res['id'])->find();
|
|
// $invate_res = $ClubInvate->where('player_id',$player_ress['id'])->where('status',6)->where('deletetime',null)->find();
|
|
// if($invate_res)
|
|
// $club_res = $club->field('name_short')->where('id',$invate_res['club_id'])->find();
|
|
|
|
$dan_fly = $matchRankingModel->where('match_id',$match_id)->where('course',$course)->where('player_id',$value['player_id'])->select();
|
|
$player_info = $matchRankingModel->field('player_id,player_name,grouping,led_color,channel,name_short,country,national_flag')->where('match_id',$match_id)->where('course',$course)->where('player_id',$value['player_id'])->find()->toArray();
|
|
// var_dump($player_info);exit;
|
|
$dan_data = [];$i = 0; $z = 0;
|
|
|
|
foreach ($dan_fly as $q){
|
|
if(preg_match('/\d/',$q['first_fly_time'])) {
|
|
$dan_data[$i] = $this->getAllMs($q['first_fly_time']);
|
|
$i++;
|
|
}
|
|
if(preg_match('/\d/',$q['second_fly_time'])) {
|
|
$dan_data[$i] = $this->getAllMs($q['second_fly_time']);
|
|
$i++;
|
|
}
|
|
if(preg_match('/\d/',$q['third_fly_time'])) {
|
|
$dan_data[$i] = $this->getAllMs($q['third_fly_time']);
|
|
$i++;
|
|
}
|
|
if($q['first_fly_time'] == 'DNF' || $q['second_fly_time'] == 'DNF' || $q['third_fly_time'] == 'DNF'){
|
|
$z++;
|
|
}
|
|
|
|
}
|
|
sort($dan_data);
|
|
// var_dump($dan_data);exit;
|
|
$j = 0;
|
|
if($i >=3 ){
|
|
$avg_socre = ($dan_data[0] + $dan_data[1] + $dan_data[2])/3;
|
|
// var_dump($avg_socre);exit;
|
|
// var_dump($this->getAllSeconds(intval($avg_socre)));exit;
|
|
// exit;
|
|
$integerPart = floor($avg_socre); // 获取整数部分
|
|
$decimalPart = fmod($avg_socre, $integerPart); // 获取小数部分
|
|
$lastTwoDigits = substr((string)number_format($decimalPart, 1), -1);
|
|
// var_dump($lastTwoDigits);exit;
|
|
$player_data[$h]['avg'] = ($this->getAllSeconds(intval($avg_socre))).$lastTwoDigits;
|
|
// var_dump($player_data[$h]['avg']);exit;
|
|
$player_data[$h]['info'] = $player_info;
|
|
$player_data[$h]['club'] = $club_res;
|
|
$player_data[$h]['fly_num'] = 3;
|
|
$player_data[$h]['first'] = $dan_data[0];
|
|
$player_data[$h]['second'] = $dan_data[1];
|
|
$player_data[$h]['third'] = $dan_data[2];
|
|
$player_data[$h]['dnf'] = 0;
|
|
}elseif($i == 2){
|
|
$avg_socre = ($dan_data[0] + $dan_data[1])/2;
|
|
$integerPart = floor($avg_socre); // 获取整数部分
|
|
$decimalPart = fmod($avg_socre, $integerPart); // 获取小数部分
|
|
$lastTwoDigits = substr((string)number_format($decimalPart, 1), -1);
|
|
|
|
$player_data[$h]['avg'] = ($this->getAllSeconds(intval($avg_socre))).$lastTwoDigits;
|
|
$player_data[$h]['info'] = $player_info;
|
|
$player_data[$h]['club'] = $club_res;
|
|
$player_data[$h]['fly_num'] = 2;
|
|
$player_data[$h]['first'] = $dan_data[0];
|
|
$player_data[$h]['second'] = $dan_data[1];
|
|
$player_data[$h]['third'] = '0';
|
|
$player_data[$h]['dnf'] = 0;
|
|
}elseif($i == 1){
|
|
$avg_socre = $dan_data[0];
|
|
$player_data[$h]['avg'] = $this->getAllSeconds(intval($avg_socre));
|
|
$player_data[$h]['info'] = $player_info;
|
|
$player_data[$h]['club'] = $club_res;
|
|
$player_data[$h]['fly_num'] = 1;
|
|
$player_data[$h]['first'] = $dan_data[0];
|
|
$player_data[$h]['second'] = '0';
|
|
$player_data[$h]['third'] = '0';
|
|
$player_data[$h]['dnf'] = 0;
|
|
}elseif($i == 0){
|
|
if($z > 0){
|
|
$player_data[$h]['avg'] = 'DNF';
|
|
$player_data[$h]['info'] = $player_info;
|
|
$player_data[$h]['club'] = $club_res;
|
|
$player_data[$h]['fly_num'] = 0;
|
|
$player_data[$h]['first'] = '0';
|
|
$player_data[$h]['second'] = '0';
|
|
$player_data[$h]['third'] = '0';
|
|
$player_data[$h]['dnf'] = 0;
|
|
}else{
|
|
$player_data[$h]['avg'] = '';
|
|
$player_data[$h]['info'] = $player_info;
|
|
$player_data[$h]['club'] = $club_res;
|
|
$player_data[$h]['fly_num'] = 0;
|
|
$player_data[$h]['first'] = '0';
|
|
$player_data[$h]['second'] = '0';
|
|
$player_data[$h]['third'] = '0';
|
|
$player_data[$h]['dnf'] = 1;
|
|
}
|
|
|
|
}
|
|
$h++;
|
|
// var_dump($value);exit;
|
|
// var_dump(($avg_socre));exit;
|
|
}
|
|
// var_dump($player_data);exit;
|
|
sort($player_data);
|
|
// $player_info = $player_info;
|
|
array_multisort(array_column($player_data,'fly_num'), SORT_DESC, array_column($player_data, 'dnf'), SORT_ASC,array_column($player_data, 'avg'), SORT_ASC, array_column($player_data, 'first'), SORT_ASC,array_column($player_data, 'second'), SORT_ASC,array_column($player_data, 'third'), SORT_ASC,$player_data);
|
|
|
|
if($export === true){
|
|
$round = $this->matchRankingModel->where("match_id", "eq", $match_id)
|
|
->where("course", "eq", $course)
|
|
->max("other_round");
|
|
// $round = 3;
|
|
$a = 1;
|
|
foreach ($player_data as $k => $val){
|
|
|
|
for ($a = 1; $a <= $round; $a++){
|
|
$round_res = $this->matchRankingModel->field('first_fly_time,second_fly_time,third_fly_time')->where("match_id", "eq", $match_id)->where("course", "eq", $course)->where('other_round',$a)->where('player_id',$val['info']['player_id'])->find();
|
|
$player_data[$k]['round'.$a] = $round_res;
|
|
}
|
|
|
|
}
|
|
// var_dump($player_data);exit;
|
|
}
|
|
|
|
|
|
return $player_data;
|
|
// var_dump($player_data);exit;
|
|
}
|
|
|
|
|
|
public function qqq($match_id,$course,$export = false){
|
|
$user = new User();
|
|
$club = new Club();
|
|
$palyer = new Players();
|
|
$ClubInvate = new ClubInvate();
|
|
$matchRankingModel = new MatchRanking();
|
|
if($course == 103) $course = 101;
|
|
$player_res = $matchRankingModel->field('*')->where('match_id',$match_id)->where('course',$course)->group('player_id')->order('id')->select();
|
|
// var_dump($player_res);exit;
|
|
$round = $matchRankingModel->where("match_id", "eq", $match_id)
|
|
->where("course", "eq", $course)
|
|
->max("other_round");
|
|
$new_arr = [];
|
|
foreach ($player_res as $k => &$val){
|
|
$player_rank = $matchRankingModel->where('match_id',$match_id)->where('course',$course)->where('player_id',$val['player_id'])->select();
|
|
$a = 1;
|
|
for ($a = 1; $a <= $round; $a++){
|
|
$round_res = $this->matchRankingModel->field('first_fly_time,second_fly_time,third_fly_time')->where("match_id", "eq", $match_id)->where("course", "eq", $course)->where('other_round',$a)->where('player_id',$val['player_id'])->find();
|
|
$player_data[$k]['round'.$a] = $round_res;
|
|
$player_data[$k]['info'] = $val;
|
|
}
|
|
// var_dump($player_data);exit;
|
|
// $new_arr=1;
|
|
}
|
|
// var_dump($player_data);exit;
|
|
return $player_data;
|
|
}
|
|
|
|
public function group_people($match_id,$course = 101,$export = false){
|
|
// var_dump($course);exit;
|
|
$matchRankingModel = new MatchRanking();
|
|
$player_res = $matchRankingModel->field('*')->where('match_id',$match_id)->where('course',$course)->group('grouping')->order('id')->find();
|
|
$people_count = $matchRankingModel->field('*')->where('match_id',$match_id)->where('course',$course)->where('grouping',$player_res['grouping'])->where('other_round',1)->count();
|
|
return $people_count;
|
|
// var_dump($people_count);exit;
|
|
}
|
|
|
|
|
|
public function setPlayerScore($param){
|
|
// 判读是否存在该条数据
|
|
$info = $this->getOneRanking([
|
|
'player_id' => $param['player_id'],
|
|
'match_id' => $param['match_id'],
|
|
'is_finals' => 1,
|
|
'course' => $param['course'],
|
|
'other_round' => $param['other_round'],
|
|
]);
|
|
|
|
|
|
$add_data['match_id'] = $param['match_id'];
|
|
$add_data['player_id'] = $param['player_id'];
|
|
$add_data['fly_num'] = $param['fly_num'];
|
|
// $add_data['times'] = $param['achievement'];
|
|
$add_data['player_name'] = $param['player_name'];
|
|
$add_data['course'] = $param['course'];
|
|
// $add_data['id'] = $param['id'];
|
|
$add_data['led_color'] = $param['led_color'];
|
|
$add_data['channel'] = $param['channel'];
|
|
$add_data['other_round'] = $param['other_round'];
|
|
$add_data['integral'] = $param['integral'];
|
|
$add_data['first_fly_time'] = $param['first_fly_time'];
|
|
$add_data['second_fly_time'] = $param['second_fly_time'];
|
|
$add_data['third_fly_time'] = $param['third_fly_time'];
|
|
$num = 0;
|
|
if (preg_match('/\d/',$add_data['first_fly_time'])){
|
|
$first_fly_time = $this->getAllMs($param['first_fly_time']);
|
|
$num++;
|
|
}else{
|
|
$first_fly_time = 0;
|
|
}
|
|
if (preg_match('/\d/',$add_data['second_fly_time'])){
|
|
$second_fly_time = $this->getAllMs($param['second_fly_time']);
|
|
$num++;
|
|
}else{
|
|
$second_fly_time = 0;
|
|
}
|
|
if (preg_match('/\d/',$add_data['third_fly_time'])){
|
|
$third_fly_time = $this->getAllMs($param['third_fly_time']);
|
|
$num++;
|
|
}else{
|
|
$third_fly_time = 0;
|
|
}
|
|
|
|
// if ($num > 0) {
|
|
// $add_data['ranking'] = "Y";
|
|
// $first_fly_time = $this->getAllMs($param['first_fly_time']);
|
|
// $second_fly_time = $this->getAllMs($param['second_fly_time']);
|
|
// $third_fly_time = $this->getAllMs($param['third_fly_time']);
|
|
$add_data['achievement'] = $first_fly_time + $second_fly_time + $third_fly_time;
|
|
// var_dump($add_data['achievement']);exit;
|
|
$add_data['times'] = $this->getAllSeconds($add_data['achievement']);
|
|
// } else {
|
|
// $add_data['ranking'] = "N";
|
|
// $add_data['achievement'] = 999999999;
|
|
// }
|
|
// var_dump($param);exit;
|
|
if($param['course'] == 103 || $param['course'] == 104){
|
|
$add_data['times'] = $param['times'];
|
|
if (preg_match('/\d/',$param['times'])){
|
|
$add_data['achievement'] = $this->getAllMs($param['times']);
|
|
}else{
|
|
$add_data['times'] = $param['times'];
|
|
$add_data['datetime_value'] = "2023-12-12 00:00:00.000";
|
|
$add_data['achievement'] = 999999999;
|
|
}
|
|
}
|
|
// var_dump($add_data['times']);exit;
|
|
// $add_data['times'] = '12:05.877';
|
|
if(!empty($add_data['times'])) {
|
|
$strs = explode(":", $add_data['times']);
|
|
// var_dump($strs);exit;
|
|
if (strlen($strs[0]) == 1) {
|
|
$add_data['datetime_value'] = "2023-12-12 00:0{$add_data['times']}";
|
|
} elseif (strlen($strs[0]) == 2) {
|
|
$add_data['datetime_value'] = "2023-12-12 00:{$add_data['times']}";
|
|
}
|
|
}else{
|
|
$add_data['datetime_value'] = "2023-12-12 00:00:00.000";
|
|
}
|
|
// var_dump($add_data['datetime_value']);exit;
|
|
|
|
|
|
$add_data['updatetime'] = date("Y-m-d H:i:s", time());
|
|
// var_dump($add_data);exit;
|
|
// 更新最新数据
|
|
$res = $this->matchRankingModel->save($add_data,['id'=>$param['id']]);
|
|
$this->success('修改成功');
|
|
// var_dump($res);exit;
|
|
}
|
|
|
|
public function get_final_integral_rank($match_id, $course){
|
|
$matchranking = new MatchRanking();
|
|
$row = $matchranking->field('id,player_id, match_id, player_name, led_color, channel, sum(integral) as sum_integral,grouping,qua_rank')->where('match_id',$match_id)->where('course',104)->group('player_id')->orderRaw('sum_integral desc,CAST(qua_rank AS UNSIGNED)')->select();
|
|
return $row;
|
|
}
|
|
//->where('id','<',80183)
|
|
public function get_final_integral($match_id, $course){
|
|
$matchranking = new MatchRanking();
|
|
$row = $matchranking->field('id,player_id, match_id, player_name, led_color, channel, sum(integral) as sum_integral,grouping,qua_rank')->where('match_id',$match_id)->where('course',104)->group('player_id')->orderRaw('sum_integral desc,CAST(qua_rank AS UNSIGNED)')->select();
|
|
return $row;
|
|
}
|
|
|
|
public function getrank_course($match_id, $course, $other_round,$all = false,$is_pic = 0){
|
|
$user = new User();
|
|
$club = new Club();
|
|
$player = new Players();
|
|
$ClubInvate = new ClubInvate();
|
|
$matchranking = new MatchRanking();
|
|
$Leagueround = new Leagueround();
|
|
// $row = $matchranking->where('match_id',$match_id)->where('course',$course)->where('other_round',$other_round)->order('id')->select();
|
|
// var_dump($is_pic);exit;
|
|
// if($match_id == 1036){
|
|
$row = $matchranking->where('match_id',$match_id)->where('course',$course)->where('other_round',$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();
|
|
// }
|
|
if($is_pic == 1){
|
|
foreach ($row as &$value){
|
|
$user_res = $user->where('member_number',$value['player_id'])->find();
|
|
$player_res = $player->where('member_id',$user_res['id'])->find();
|
|
$value['player_pic'] = $player_res['player_pic'];
|
|
}
|
|
}
|
|
|
|
// if($course == 104){
|
|
// $result = $matchranking->where(['match_id'=>$match_id,'course'=>104,'other_round'=>1])->find();
|
|
// // var_dump($result['is_extra']);exit;
|
|
// if(!empty($result)){
|
|
// if($result['is_extra'] == 1){
|
|
|
|
// $row = $matchranking->where(['match_id'=>$match_id,'course'=>104,'other_round'=>1])->order('custom_sorting')->select();
|
|
// $j = 1;
|
|
// if(!empty($row)){
|
|
// // var_dump($row);exit;
|
|
// foreach ($row as $v){
|
|
// $q = $v->toArray();
|
|
// $q['group_sort'] = $j;
|
|
// $obj_arr[] = $q;
|
|
// $j++;
|
|
// }
|
|
// $row = $obj_arr;
|
|
// $row = $this->array_sort($row,'id','asc');
|
|
// }
|
|
// }else{
|
|
// $row = $Leagueround->final_rank($match_id);
|
|
// $row = $this->array_sort($row,'id','asc');
|
|
// // var_dump($row);exit;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
return $row;
|
|
}
|
|
|
|
public function array_sort($array,$keys,$type='asc'){
|
|
if(!isset($array) || !is_array($array) || empty($array)){
|
|
return $array;
|
|
}
|
|
if(!isset($keys) || trim($keys)==''){
|
|
return $array;
|
|
}
|
|
if(!isset($type) || $type=='' || !in_array(strtolower($type),array('asc','desc'))){
|
|
return $array;
|
|
}
|
|
$keysvalue=array();
|
|
foreach($array as $key=>$val){
|
|
$val[$keys] = str_replace('-','',$val[$keys]);
|
|
$val[$keys] = str_replace(' ','',$val[$keys]);
|
|
$val[$keys] = str_replace(':','',$val[$keys]);
|
|
$keysvalue[] =$val[$keys];
|
|
}
|
|
asort($keysvalue); //key值排序
|
|
reset($keysvalue); //指针重新指向数组第一个
|
|
foreach($keysvalue as $key=>$vals) {
|
|
$keysort[] = $key;
|
|
}
|
|
$keysvalue = array();
|
|
$count=count($keysort);
|
|
if(strtolower($type) != 'asc'){
|
|
for($i=$count-1; $i>=0; $i--) {
|
|
$keysvalue[] = $array[$keysort[$i]];
|
|
}
|
|
}else{
|
|
for($i=0; $i<$count; $i++){
|
|
$keysvalue[] = $array[$keysort[$i]];
|
|
}
|
|
}
|
|
return $keysvalue;
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取指定选手成绩
|
|
* @Author:Soar
|
|
* @Time:2023/11/20 10:58
|
|
* @param $where
|
|
* @return array|bool|\PDOStatement|string|\think\Model|null
|
|
*/
|
|
public function getOneRanking($where)
|
|
{
|
|
try {
|
|
return $this->matchRankingModel->where($where)->find();
|
|
} catch (\Exception $exception) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 计时换算成毫秒
|
|
* @Created by PhpStorm.
|
|
* @Author:Soar
|
|
* @Time:2023/11/15 15:11
|
|
* @param $times
|
|
* @return float|int|mixed|string
|
|
*/
|
|
private function getAllMs($times)
|
|
{
|
|
$minute_ms = 0;
|
|
$second_ms = 0;
|
|
$ms = 0;
|
|
// 截取最后的毫秒
|
|
$allTime = explode(".", $times);
|
|
// var_dump($allTime);exit;
|
|
if (count($allTime) != 2) {
|
|
$this->error("成绩格式有误!");
|
|
}
|
|
$ms = $allTime[1];
|
|
// 截取分秒
|
|
$minute = explode(":", $allTime[0]);
|
|
if (count($minute) != 2) {
|
|
$this->error("成绩格式有误!");
|
|
}
|
|
if ($minute[0] != 00) {
|
|
// 如果第一位不是 00 则代表每分钟
|
|
$minute_ms = $minute[0] * 60 * 1000;
|
|
}
|
|
|
|
if ($minute[1] != 00) {
|
|
$second_ms = $minute[1] * 1000;
|
|
}
|
|
// var_dump($second_ms);exit;
|
|
return $ms + $second_ms + $minute_ms;
|
|
}
|
|
|
|
|
|
private function getAllSeconds($seconds){
|
|
// var_dump($seconds);
|
|
$lastTwoDigits = substr((string)$seconds, -3);
|
|
$newStr = substr((string)$seconds, 0, -3);
|
|
// var_dump(floor($newStr / 60));exit;
|
|
$minutes = floor($newStr / 60);
|
|
$remainingSeconds = $newStr % 60;
|
|
$res = sprintf("%02d:%02d", $minutes, $remainingSeconds);
|
|
// var_dump($res.'.'.$lastTwoDigits);exit;
|
|
return $res.'.'.$lastTwoDigits;
|
|
}
|
|
|
|
private function getSeconds($seconds){
|
|
// $number = 123.456;
|
|
$seconds = '2,242.667';
|
|
if(intval($seconds) != $seconds){
|
|
// var_dump($seconds);exit;
|
|
$integerPart = floor($seconds); // 获取整数部分
|
|
$decimalPart = fmod($seconds, $integerPart); // 获取小数部分
|
|
}
|
|
// var_dump($seconds);exit;
|
|
$lastTwoDigits = substr((string)$integerPart, -2);
|
|
$newStr = substr((string)$integerPart, 0, -2);
|
|
// var_dump($seconds);exit;
|
|
$minutes = floor($newStr / 60);
|
|
$remainingSeconds = $newStr % 60;
|
|
$res = sprintf("%02d:%02d", $minutes, $remainingSeconds);
|
|
// var_dump($res.'.'.$lastTwoDigits);exit;
|
|
return $res.'.'.$lastTwoDigits.$decimalPart;
|
|
}
|
|
|
|
} |