www_fpvone_cn/application/index/service/ScreenService.php

210 lines
7.4 KiB
PHP

<?php
/**
* @Created by PhpStorm.
* @Author:Soar
* @Time:2023/11/16 13:46
*/
namespace app\index\service;
use addons\cms\model\Archives as ArchivesModel;
use app\admin\model\MatchRanking;
use app\admin\model\Players;
use app\common\model\MatchContestant;
use app\common\model\MatchScreen;
use app\common\model\User;
class ScreenService extends Service
{
//赛事ID
public $match_id = 180;
public function __construct()
{
$this->playerModel = new Players();
$this->rankingModel = new MatchRanking();
$this->userModel = new User();
$this->rankingService = new RankingService();
$this->matchContestantModel = new MatchContestant();
$this->matchScreenModel = new MatchScreen();
}
public function screenList($match_id)
{
$archives = ArchivesModel::get($match_id, ['channel']);
if (empty($archives)) {
return false;
}
// 获取进32强数据
$collection['thirty_two'] = $this->rankingService->getRank(32, $match_id);
$collection['sixteen'] = $this->rankingService->getRank(16, $match_id);
$collection['eight'] = $this->rankingService->getRank(8, $match_id);
$collection['four'] = $this->rankingService->getRank(4, $match_id);
$collection['finals'] = $this->rankingService->getRank(1, $match_id);
// 获取参赛人员信息
$this->matchList = $this->matchContestantModel->alias("a")->with('players')->where([
'a.match_id' => $match_id,
'a.status' => 2
])->field("player_id")->select();
if (empty($this->matchList)) {
return [];
}
foreach ($collection as $vals) {
// var_dump($vals);exit;
foreach ($vals as $val) {
// var_dump($val['player_name']);exit;
//名字加*号
$str = $val['player_name'];
$strlen = mb_strlen($str,'UTF8');
if($strlen == 2){
$real_name=mb_substr($str,0,1,'UTF8').'*';
}
if($strlen > 2){
$tmp_str=mb_substr($str,0,$strlen-2,'UTF8').'*';
$real_name=$tmp_str.mb_substr($str,-1,1,'UTF8');
}
$val['player_name']= $real_name;
$user_info = $this->userModel->where(['member_number' => $val->player_id])->find();
if (!empty($user_info)) {
$player_info = $this->playerModel->where(['member_id' => $user_info->id])->find();
if (!empty($player_info)) {
$val->photo = $player_info->player_pic ? $player_info->player_pic : "";
// $val->photo = base64_encode(file_get_contents($val->photo));
$val->province = $player_info->province;
} else {
$val->photo = " ";
$val->province = " ";
}
}
}
}
$i = 0;
// 获取所有参赛飞手
foreach ($this->matchList as $key => $val) {
$user_info = $this->userModel->where(['id' => $val->players->member_id])->find();
$collection['allPlayer'][$i]['player_id'] = 'Null';
if (!empty($user_info)) {
$collection['allPlayer'][$i]['player_id'] = $user_info->member_number;
}
//名字加*号
$str = $val->players->real_name;
$strlen = mb_strlen($str,'UTF8');
if($strlen == 2){
$real_name=mb_substr($str,0,1,'UTF8').'*';
}
if($strlen > 2){
$tmp_str=mb_substr($str,0,$strlen-2,'UTF8').'*';
$real_name=$tmp_str.mb_substr($str,-1,1,'UTF8');
}
$collection['allPlayer'][$i]['real_name'] = $real_name;
$collection['allPlayer'][$i]['age'] = $val->players->age;
$collection['allPlayer'][$i]['gender'] = $val->players->gender;
$collection['allPlayer'][$i]['province'] = $val->players->province;
$collection['allPlayer'][$i]['player_pic'] = $val->players->player_pic;
$collection['allPlayer'][$i]['member_id'] = $val->players->member_id;
++$i;
}
$collection['count'] = $this->sumPlayer($match_id);
$collection['title'] = $archives->title;
return $collection;
}
public function sumPlayer($match_id)
{
// 获取参赛人员信息
$this->matchList = $this->matchContestantModel->alias("a")->with('players')->where([
'a.match_id' => $match_id,
])->where('a.status', 'in', '1,2')->field("player_id")->select();
//总数
$countPalyer['count'] = count($this->matchList);
// 男女总数
$countPalyer['gender_man'] = 0;
$countPalyer['gender_woman'] = 0;
// 大于等于五岁但是小于十岁的年龄
$countPalyer['one_level_age'] = 0;
// 大于等于十岁但是小于十五岁的年龄
$countPalyer['two_level_age'] = 0;
// 大于等于十五岁但是小于三十岁的年龄
$countPalyer['three_level_age'] = 0;
// 大于等于三十岁的年龄总和
$countPalyer['four_level_age'] = 0;
// 统计各个省份人数
$countPalyer['province'] = [];
foreach ($this->matchList as $vals) {
if (!empty($vals->players)) {
if ($vals->players->gender == "") {
++$countPalyer['gender_man'];
} else {
++$countPalyer['gender_woman'];
}
if ($vals->players->age >= 5 && $vals->players->age <= 9) {
++$countPalyer['one_level_age'];
} else if ($vals->players->age >= 10 && $vals->players->age <= 14) {
++$countPalyer['two_level_age'];
} else if ($vals->players->age >= 15 && $vals->players->age <= 29) {
++$countPalyer['three_level_age'];
} else if ($vals->players->age >= 30) {
++$countPalyer['four_level_age'];
}
if (empty($countPalyer['province'][$vals->players->province])
&& !empty($vals->players->province)) {
$countPalyer['province'][$vals->players->province] = 1;
} else {
++$countPalyer['province'][$vals->players->province];
}
}
}
return $countPalyer;
}
public function verifyScreen($param)
{
// 查询是否为空密码
$screen_info = $this->matchScreenModel->where([
'match_id' => $param['match_id'],
'type' => $param['type']
])->find();
if (empty($screen_info->look_pwd)) {
return true;
} else {
if (empty($param['look_pwd'])) {
return false;
}
if (md5($param['look_pwd']) == $screen_info->look_pwd) {
return true;
}
}
return false;
}
public function getScreenInfo($param)
{
$res = $this->matchScreenModel
->where("match_id", $param['match_id'])
->where("type", $param['type'])
->field("title, backound_img, font_rgb, match_id")
->find();
return $res;
}
}