800 lines
37 KiB
PHP
800 lines
37 KiB
PHP
<?php
|
||
|
||
namespace app\testapp\controller;
|
||
|
||
|
||
use think\Db;
|
||
|
||
use Exception;
|
||
|
||
class Sportstesting extends Base{
|
||
|
||
protected $color = ['#FF5656','#FF5656','#5AD06D','#6492F6','#3967D6'];
|
||
protected $sportstesting_use_db_name = [
|
||
'1'=>'test_admin_estimate',
|
||
'2'=>'test_app_sportstesting_data',
|
||
'3'=>'test_app_user_data',
|
||
];
|
||
protected $page_num = 10;
|
||
protected $default_address = '上海';
|
||
protected $city_data_rule_name = [
|
||
'xc'=>'现场类项目',
|
||
'xc_1'=>'第一类:素质项目Ⅰ(8分)',
|
||
'xc_2'=>'第二类:素质项目Ⅱ(8分)',
|
||
'xc_3'=>'第三类:运动能力Ⅰ(8分)',
|
||
'xc_4'=>'第四类:运动能力Ⅱ(6分)',
|
||
'gc'=>'过程类项目',
|
||
'gc_8_m'=>'8年级体质健康统测(10分)',
|
||
'gc_8_r'=>'8年级体育与健康知识机考(10分)',
|
||
];
|
||
protected $city_data_rule_is_choice = ['xc_2','xc_3','xc_4'];
|
||
|
||
protected $type_all = [
|
||
'1'=>'整数填数字(例肺活量)',
|
||
'2'=>'小数(例50米跑)',
|
||
'3'=>'拖动区间(例坐位体前屈:-15至30之间,需要有小数1位)',
|
||
'4'=>'分钟秒钟(例1000米跑)',
|
||
];
|
||
|
||
|
||
// 加 bcadd(,,20)
|
||
// 减 bcsub(,,20)
|
||
// 乘 bcmul(,,20)
|
||
// 除 bcdiv(,,20)
|
||
################################################################接口################################################################
|
||
################################################################接口################################################################
|
||
################################################################接口################################################################
|
||
// 获取单个类型列表
|
||
public function sportstesting_get_type_list($data = ['address'=>'上海','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('address', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){
|
||
$return_data = $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->sportstesting_get_type_list_action($data);
|
||
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
// 获取地区类型列表
|
||
public function sportstesting_get_region_list($data = ['parameter_data'=>'上海','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('gender', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('token', $data)){
|
||
$return_data = $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->sportstesting_get_region_list_action($data);
|
||
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
// 获取估分最后一次数据
|
||
public function sportstesting_get_last_data($data = ['aud_id'=>'83','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
|
||
$return_data = $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->sportstesting_get_last_data_action($data);
|
||
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
// 计算并存储数据
|
||
public function sportstesting_set_once_data($data = ['aud_id'=>'83','parameter_data'=>'辽宁,沈阳市','result_data'=>'','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('result_data', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){
|
||
$return_data = $this->msg(10001);
|
||
}
|
||
if(is_array($data['result_data']) && !empty($data['result_data'])){
|
||
// 是个数组且不为空数组
|
||
foreach ($data['result_data'] as $key => $value) {
|
||
foreach ($value['list'] as $k => $v) {
|
||
if(count($v['list']) <= 0){
|
||
$return_data = $this->msg(10010,$v['name'].'内并未选择内容');
|
||
}
|
||
if($v['is_choice'] >= 0 && count($v['list']) < $v['is_choice']){
|
||
$return_data = $this->msg(10010,$v['name'].'内并缺少选项,请选择'.$v['is_choice'].'个选项');
|
||
}
|
||
}
|
||
}
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->sportstesting_set_once_data_action2($data);
|
||
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
|
||
}
|
||
// 获取估分历史列表
|
||
public function sportstesting_get_all_list($data = ['aud_id'=>'25','page'=>'1','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data) || !array_key_exists('page', $data)){
|
||
$return_data = $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->sportstesting_get_all_list_action($data);
|
||
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
// 获取估分历史详情
|
||
public function sportstesting_get_one_details($data = ['id'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){
|
||
$return_data = $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->sportstesting_get_one_details_action($data);
|
||
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
|
||
// 获取估分已有的地区列表
|
||
public function sportstesting_get_city_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','type'=>'1']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('token', $data) || !array_key_exists('type', $data)){
|
||
$return_data = $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->sportstesting_get_city_list_action($data);
|
||
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
|
||
################################################################业务################################################################
|
||
################################################sportstesting_get_type_list
|
||
public function sportstesting_get_type_list_action($data){
|
||
|
||
$parameter_data = explode(',',$data['address']);
|
||
$gender = $data['gender'];
|
||
// 精准查询地市规则start
|
||
// if(count($parameter_data) == 1){
|
||
// $db_condition = "province = '".$parameter_data[0]."'";
|
||
// }else if(count($parameter_data) == 2){
|
||
// $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'";
|
||
// }else if(count($parameter_data) == 3){
|
||
// $db_condition = "province = ".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'";
|
||
// }else{
|
||
// return $this->msg(10005);
|
||
// }
|
||
// 精准查询地市规则end
|
||
// 全省地市一个规则start
|
||
$db_condition = "province = '".$parameter_data[0]."'";
|
||
// 全省地市一个规则end
|
||
|
||
$data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->find();
|
||
$data = json_decode($data['content'],true);
|
||
$result = $this->handle_default_rule_list_content($data,$gender);
|
||
return $this->msg($result);
|
||
}
|
||
################################################sportstesting_get_region_list
|
||
public function sportstesting_get_region_list_action($data){
|
||
|
||
$parameter_data = explode(',',$data['parameter_data']);
|
||
$gender = $data['gender'];
|
||
// 精准查询地市规则start
|
||
// if(count($parameter_data) == 1){
|
||
// $db_condition = "province = '".$parameter_data[0]."'";
|
||
// }else if(count($parameter_data) == 2){
|
||
// $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'";
|
||
// }else if(count($parameter_data) == 3){
|
||
// $db_condition = "province = ".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'";
|
||
// }else{
|
||
// return $this->msg(10005);
|
||
// }
|
||
// 精准查询地市规则end
|
||
// 全省地市一个规则start
|
||
$db_condition = "province = '".$parameter_data[0]."'";
|
||
// 全省地市一个规则end
|
||
|
||
$result['list'] = [];
|
||
$result['total_score'] = 0;
|
||
$data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->select();
|
||
if(count($data) > 0){
|
||
if(count($data) > 1){
|
||
// 查到不止一条规则
|
||
return $this->msg(10004,'查询地址不够详细,请重新选择省市地区');
|
||
}
|
||
$data = json_decode($data[0]['content'],true);
|
||
$result = $this->handle_default_rule_list($data,$gender);
|
||
return $this->msg($result);
|
||
}else{
|
||
return $this->msg(10004,'暂无该地区的估分规则,请选择其它地区');
|
||
}
|
||
|
||
}
|
||
################################################sportstesting_get_last_data
|
||
public function sportstesting_get_last_data_action($data){
|
||
$user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->order('id desc')->find();
|
||
|
||
if($user_data){
|
||
$address = explode(',',$user_data['address']);
|
||
$temporary_data = json_decode($user_data['content'],true);
|
||
|
||
$result['list'] = $temporary_data;
|
||
$result['total_score'] = $user_data['score'];
|
||
$result['max_score'] = $user_data['max_score'];
|
||
$result['province'] = count($address)>=1?$address[0]:'';
|
||
$result['city'] = count($address)>=2?$address[1]:'';
|
||
$result['area'] = count($address)>=3?$address[2]:'';
|
||
return $this->msg($result);
|
||
}else{
|
||
$user_msg_data = Db::table($this->sportstesting_use_db_name['3'])->where(['id'=>$data['aud_id']])->field('id,gender')->find();
|
||
if(!$user_msg_data){
|
||
return $this->msg(10004);
|
||
}
|
||
$address = $this->default_address;
|
||
$address_data = $this->sportstesting_get_region_list_action(['parameter_data'=>$address,'gender'=>$user_msg_data['gender']]);
|
||
$address_data = json_decode($address_data->getContent(),true);
|
||
if($address_data['code'] == 10004){
|
||
return $this->msg(10004);
|
||
}
|
||
$address = explode(',',$address);
|
||
$result['list'] = $address_data['data'];
|
||
$result['total_score'] = 0;
|
||
$result['province'] = count($address)>=1?$address[0]:'';
|
||
$result['city'] = count($address)>=2?$address[1]:'';
|
||
$result['area'] = count($address)>=3?$address[2]:'';
|
||
return $this->msg($result);
|
||
}
|
||
}
|
||
################################################sportstesting_get_all_list
|
||
public function sportstesting_get_all_list_action($data){
|
||
$user_data_num = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->count();
|
||
$user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->page($data['page'],$this->page_num)->order('id desc')->select();
|
||
if($user_data){
|
||
$result = [];
|
||
$result['totalrows'] = $user_data_num;
|
||
$result['rows'] = [];
|
||
$result['pageno'] = $data['page'];
|
||
$result['pagesize'] = $this->page_num;
|
||
$result['totalpage'] = ceil($result['totalrows']/$this->page_num);
|
||
foreach ($user_data as $key => $value) {
|
||
array_push($result['rows'],[
|
||
'id'=>$value['id'],
|
||
'create_time'=>$value['create_time'],
|
||
'score'=>$value['score'],
|
||
'max_score'=>$value['max_score'],
|
||
'address'=>$value['address'],
|
||
]);
|
||
}
|
||
return $this->msg($result);
|
||
}else{
|
||
return $this->msg(10004);
|
||
}
|
||
}
|
||
################################################sportstesting_get_one_details
|
||
public function sportstesting_get_one_details_action($data){
|
||
$user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['id'=>$data['id']])->find();
|
||
|
||
if($user_data){
|
||
|
||
$temporary_data['list'] = json_decode($user_data['content'],true);
|
||
// 压入表头
|
||
foreach ($temporary_data['list'] as $key => $value) {
|
||
foreach ($value['list'] as $v1k => $v1v) {
|
||
array_unshift($temporary_data['list'][$key]['list'][$v1k]['list'],[
|
||
'name'=>'项目名',
|
||
'value'=>'成绩',
|
||
'total_score'=>'满分',
|
||
'proportion_value'=>'得分',
|
||
]);
|
||
}
|
||
}
|
||
$temporary_data['score'] = $user_data['score'];
|
||
$temporary_data['max_score'] = $user_data['max_score'];
|
||
$temporary_data['address'] = $user_data['address'];
|
||
$temporary_data['create_time'] = $user_data['create_time'];
|
||
return $this->msg($temporary_data);
|
||
}else{
|
||
return $this->msg(10004);
|
||
}
|
||
}
|
||
################################################sportstesting_set_once_data
|
||
public function sportstesting_set_once_data_action2($data){
|
||
$return_result['total_score'] = 0;
|
||
$return_result['max_score'] = 0;
|
||
|
||
$parameter_data = explode(',',$data['parameter_data']);
|
||
$gender = $data['gender'];
|
||
if(count($parameter_data) == 1){
|
||
$db_condition = "province = '".$parameter_data[0]."'";
|
||
}else if(count($parameter_data) == 2){
|
||
$db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'";
|
||
}else if(count($parameter_data) == 3){
|
||
$db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'";
|
||
}else{
|
||
return $this->msg(10005);
|
||
}
|
||
$find_data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->find();
|
||
$find_data = json_decode($find_data['content'],true);
|
||
$recognition_rule = $find_data[$gender];
|
||
foreach ($data['result_data'] as $key => $value) {
|
||
// 遍历一级($value['key'] = 现场考试)
|
||
// dump($value);
|
||
foreach ($value['list'] as $k2 => $v2) {
|
||
// 遍历二级级($v2['key'] = 第一类项目
|
||
// dump($v2);
|
||
foreach ($v2['list'] as $k3 => $v3) {
|
||
// 遍历二级级($v3['name'] = 1000米跑)
|
||
$temporary_result = $this->obtaining_grades($recognition_rule[$value['key']][$v2['key']]['list'][$v3['name']]['content'],$v3);
|
||
$data['result_data'][$key]['list'][$k2]['list'][$k3] = $temporary_result;
|
||
// $data['result_data'][$key]['list'][$k2]['list'][$k3]['name'] = $temporary_result['name']."(该项满分:".$temporary_result['total_score'].")";
|
||
$return_result['total_score'] = bcadd($return_result['total_score'],$temporary_result['proportion_value'],2);
|
||
$return_result['max_score'] = bcadd($return_result['max_score'],bcmul($v3['total_score'],$v3['proportion'],2),2);
|
||
}
|
||
}
|
||
}
|
||
$return_result['list'] = $data['result_data'];
|
||
$user_sportstesting_set = Db::table($this->sportstesting_use_db_name['2'])->insert([
|
||
'aud_id'=>$data['aud_id'],
|
||
'content'=>json_encode($return_result['list']),
|
||
'score'=>$return_result['total_score'],
|
||
'max_score'=>$return_result['max_score'],
|
||
'create_time'=>date('Y-m-d H:i:s'),
|
||
'address'=>$data['parameter_data'],
|
||
]);
|
||
|
||
if($user_sportstesting_set){
|
||
foreach ($return_result['list'] as $key => $value) {
|
||
foreach ($value['list'] as $v1k => $v1v) {
|
||
array_unshift($return_result['list'][$key]['list'][$v1k]['list'],[
|
||
'name'=>'项目名',
|
||
'value'=>'成绩',
|
||
'total_score'=>'满分',
|
||
'proportion_value'=>'得分',
|
||
]);
|
||
}
|
||
}
|
||
return $this->msg($return_result);
|
||
}else{
|
||
return $this->msg(10002);
|
||
}
|
||
|
||
}
|
||
################################################sportstesting_get_city_list
|
||
public function sportstesting_get_city_list_action($type){
|
||
if($type['type'] == '1'){
|
||
// 已有地区列表
|
||
$data = Db::table($this->sportstesting_use_db_name['1'])->field('id,province,city,area')->select();
|
||
$result = [];
|
||
// 添加省份
|
||
foreach ($data as $key => $value) {
|
||
if(!array_key_exists($value['province'],$result)){
|
||
$result[$value['province']] = [];
|
||
}
|
||
}
|
||
// 添加市
|
||
foreach ($data as $key => $value) {
|
||
if($value['city'] == '无'){
|
||
continue;
|
||
}else{
|
||
if(array_key_exists($value['province'],$result)){
|
||
if(!array_key_exists($value['city'],$result[$value['province']])){
|
||
$result[$value['province']][$value['city']] = [];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// 添加区县
|
||
foreach ($data as $key => $value) {
|
||
if($value['area'] == '无'){
|
||
continue;
|
||
}else{
|
||
if(array_key_exists($value['province'],$result)){
|
||
if(array_key_exists($value['city'],$result[$value['province']])){
|
||
if(!array_key_exists($value['area'],$result[$value['province']][$value['city']])){
|
||
array_push($result[$value['province']][$value['city']],$value['area']);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$return_result = [];
|
||
foreach ($result as $key => $value) {
|
||
$num = array_push($return_result,['name'=>$key,'list'=>[]]);
|
||
if(count($value)>0){
|
||
foreach ($value as $city_k => $city_v) {
|
||
$num2 = array_push($return_result[$num-1]['list'],['name'=>$city_k,'list'=>$city_v]);
|
||
}
|
||
}
|
||
}
|
||
return $this->msg($result);
|
||
}else if($type['type'] == '2'){
|
||
$data = Db::table($this->sportstesting_use_db_name['1'])->where(['type' => '2'])->field('id,content,city,area')->find();
|
||
$result = json_decode($data['content'],true);
|
||
return $this->msg($result);
|
||
}else{
|
||
return $this->msg(10005);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
################################################################其他################################################################
|
||
|
||
public function calculate_minutes_seconds($a,$b){
|
||
// 分解时间字符串
|
||
$sjA = explode(':', $a);
|
||
$sjB = explode(':', $b);
|
||
$minutesA = $sjA[0];
|
||
$secondsA = $sjA[1];
|
||
$minutesB = $sjB[0];
|
||
$secondsB = $sjB[1];
|
||
// 转换为秒
|
||
$totalSecondsA = intval($minutesA) * 60 + intval($secondsA);
|
||
$totalSecondsB = intval($minutesB) * 60 + intval($secondsB);
|
||
|
||
$result = $totalSecondsB - $totalSecondsA;
|
||
if($result <= 0){
|
||
return [true,$result];
|
||
}else{
|
||
return [false,$result];
|
||
}
|
||
}
|
||
|
||
|
||
// 处理默认规则列表
|
||
public function handle_default_rule_list($data,$gender){
|
||
$temporary_arr = $data[$gender];
|
||
$result = [];
|
||
foreach ($temporary_arr as $key => $value) {
|
||
$num = array_push($result,['name'=>$key,'key'=>$key,'list'=>[]]);
|
||
foreach ($value as $s_c_k => $s_c_v) {
|
||
if($s_c_v['choose_num'] == 0){
|
||
$num2 = array_push($result[$num-1]['list'],[
|
||
'name'=>$s_c_k,
|
||
'key'=>$s_c_k,
|
||
'is_choice'=>$s_c_v['choose_num'],
|
||
'list'=>[]
|
||
]);
|
||
foreach ($s_c_v['list'] as $x_m_k => $x_m_v) {
|
||
array_push($result[$num-1]['list'][$num2-1]['list'],[
|
||
'name'=>$x_m_k,
|
||
'proportion'=>$x_m_v['proportion'],
|
||
'value'=>$x_m_v['value'],
|
||
'proportion_value'=>null,
|
||
'unit'=>$x_m_v['unit_data'],
|
||
'type'=>$x_m_v['type'],
|
||
'describe'=>$x_m_v['describe'],
|
||
'total_score'=>$x_m_v['score'],
|
||
]);
|
||
}
|
||
}else{
|
||
$num2 = array_push($result[$num-1]['list'],['name'=>$s_c_k,'key'=>$s_c_k,'is_choice'=>$s_c_v['choose_num'],'list'=>[]]);
|
||
}
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
// 获取所有选择项内容
|
||
public function handle_default_rule_list_content($data,$gender){
|
||
$temporary_arr = $data[$gender];
|
||
$result['list'] = [];
|
||
foreach ($temporary_arr as $key => $value) {
|
||
|
||
foreach ($value as $k2 => $v2) {
|
||
if($v2['choose_num'] != 0){
|
||
$temporary_arr = [];
|
||
$temporary_arr['key'] = $k2;
|
||
$temporary_arr['list'] = [];
|
||
// dump($v2);
|
||
foreach ($v2['list'] as $k3 => $v3) {
|
||
// dump($v3);
|
||
array_push($temporary_arr['list'],[
|
||
'name'=>$k3,
|
||
'proportion'=>$v3['proportion'],
|
||
'value'=>$v3['value'],
|
||
'proportion_value'=>null,
|
||
'unit'=>$v3['unit_data'],
|
||
'type'=>$v3['type'],
|
||
'describe'=>$v3['describe'],
|
||
'total_score'=>$v3['score'],
|
||
]);
|
||
}
|
||
// dump($temporary_arr);
|
||
array_push($result['list'],$temporary_arr);
|
||
}
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
// 取得成绩
|
||
public function obtaining_grades($rule,$data){
|
||
|
||
// 加 bcadd(,,20)
|
||
// 减 bcsub(,,20)
|
||
// 乘 bcmul(,,20)
|
||
// 除 bcdiv(,,20)
|
||
if($data['value'] != ''){
|
||
if(count($rule) > 0){
|
||
foreach ($rule as $key => $value) {
|
||
if($data['unit'] == '分/秒'){
|
||
$rule_result = $this->convertMinutesSecondsToStringSeconds($value[0]);
|
||
$data_result = $this->convertMinutesSecondsToStringSeconds($data['value']);
|
||
}else{
|
||
$rule_result = $value[0];
|
||
$data_result = $data['value'];
|
||
}
|
||
switch ($value[1]) {
|
||
case "<=":
|
||
$result = $data_result <= $rule_result;
|
||
break;
|
||
case ">=":
|
||
$result = $data_result >= $rule_result;
|
||
break;
|
||
case "<":
|
||
$result = $data_result < $rule_result;
|
||
break;
|
||
case ">":
|
||
$result = $data_result > $rule_result;
|
||
break;
|
||
case "==":
|
||
$result = $data_result == $rule_result;
|
||
break;
|
||
case "!=":
|
||
$result = $data_result != $rule_result;
|
||
break;
|
||
default:
|
||
// 如果比较符号不是上述任何一个,可以抛出一个异常或错误
|
||
throw new Exception("Unsupported comparison operator: " . $value[1]);
|
||
}
|
||
// dump($result);
|
||
if($result == true){
|
||
$data['score'] = $value[2];
|
||
// 计算比例后分值
|
||
$proportional_post_score = bcmul($data['total_score'],$data['proportion'],2);
|
||
$data['proportion_value'] = bcmul($data['score'],bcdiv($proportional_post_score,100,2),2);
|
||
// 四舍五入一下结果
|
||
$data['proportion_value'] = $this->roundToString($data['proportion_value'],1);
|
||
break;
|
||
}
|
||
}
|
||
}else{
|
||
$data['score'] = $data['value'] <= $data['total_score']?bcmul(bcdiv($data['value'],$data['total_score'],20),100,2):100;
|
||
// 计算比例后分值
|
||
$data['proportion_value'] = $data['value'] <= $data['total_score']?$data['value']:$data['total_score'];
|
||
}
|
||
|
||
}else{
|
||
$data['score'] = 0;
|
||
// 计算比例后分值
|
||
$proportional_post_score = bcmul($data['total_score'],$data['proportion'],2);
|
||
$data['proportion_value'] = bcmul($data['score'],bcdiv($proportional_post_score,100,2),1);
|
||
}
|
||
|
||
return $data;
|
||
}
|
||
|
||
// 弄一套可以计算的返回数据(删)
|
||
public function handle_default_rule_list2($data,$gender){
|
||
$temporary_arr = $data[$gender];
|
||
$result = [];
|
||
foreach ($temporary_arr as $key => $value) {
|
||
$num = array_push($result,['name'=>$key,'key'=>$key,'list'=>[]]);
|
||
|
||
foreach ($value as $s_c_k => $s_c_v) {
|
||
if($s_c_v['choose_num'] == 0){
|
||
$num2 = array_push($result[$num-1]['list'],[
|
||
'name'=>$s_c_k,
|
||
'key'=>$s_c_k,
|
||
'is_choice'=>$s_c_v['choose_num'],
|
||
'list'=>[]
|
||
]);
|
||
foreach ($s_c_v['list'] as $x_m_k => $x_m_v) {
|
||
$num3 = array_push($result[$num-1]['list'][$num2-1]['list'],[
|
||
'name'=>$x_m_k,
|
||
'proportion'=>$x_m_v['proportion'],
|
||
'value'=>'',
|
||
'proportion_value'=>null,
|
||
'unit'=>$x_m_v['unit_data'],
|
||
'type'=>$x_m_v['type'],
|
||
'describe'=>$x_m_v['describe'],
|
||
'total_score'=>$x_m_v['score'],
|
||
]);
|
||
// dump($x_m_k);
|
||
if($x_m_k == '1000米跑'){
|
||
// dump('11');
|
||
$result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '4:08';
|
||
}else if($x_m_k == '50米跑'){
|
||
$result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '7.3';
|
||
}else if($x_m_k == '乒乓球'){
|
||
$result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '25';
|
||
}else if($x_m_k == '足球运球'){
|
||
$result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '9.5';
|
||
}else if($x_m_k == '机考'){
|
||
$result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '8.3';
|
||
}else if($x_m_k == '1000米'){
|
||
// dump('22');
|
||
$result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '4:08';
|
||
}
|
||
// break;
|
||
}
|
||
}else{
|
||
//循环次数
|
||
$xh_num = $s_c_v['choose_num'];
|
||
$num2 = array_push($result[$num-1]['list'],['name'=>$s_c_k,'key'=>$s_c_k,'is_choice'=>$s_c_v['choose_num'],'list'=>[]]);
|
||
foreach ($s_c_v['list'] as $x_m_k => $x_m_v) {
|
||
array_push($result[$num-1]['list'][$num2-1]['list'],[
|
||
'name'=>$x_m_k,
|
||
'proportion'=>$x_m_v['proportion'],
|
||
'value'=>'',
|
||
'proportion_value'=>null,
|
||
'unit'=>$x_m_v['unit_data'],
|
||
'type'=>$x_m_v['type'],
|
||
'describe'=>$x_m_v['describe'],
|
||
'total_score'=>$x_m_v['score'],
|
||
]);
|
||
// dump($x_m_k);
|
||
if($x_m_k == '1000米跑'){
|
||
$result[$num-1]['list'][$num2-1]['list'][0]['value'] = '4:07';
|
||
}else if($x_m_k == '50米跑'){
|
||
$result[$num-1]['list'][$num2-1]['list'][0]['value'] = '7.3';
|
||
}else if($x_m_k == '乒乓球'){
|
||
$result[$num-1]['list'][$num2-1]['list'][0]['value'] = '25';
|
||
}else if($x_m_k == '足球运球'){
|
||
$result[$num-1]['list'][$num2-1]['list'][0]['value'] = '9.5';
|
||
}else if($x_m_k == '引体向上'){
|
||
$result[$num-1]['list'][$num2-1]['list'][0]['value'] = '8';
|
||
}else if($x_m_k == '足球--运球射门'){
|
||
$result[$num-1]['list'][$num2-1]['list'][0]['value'] = '40';
|
||
}else if($x_m_k == '体操双杠组合Ⅰ'){
|
||
$result[$num-1]['list'][$num2-1]['list'][0]['value'] = '4';
|
||
}
|
||
$xh_num = $xh_num -1;
|
||
if($xh_num <= 0){
|
||
break;
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
|
||
|
||
} |