SchoolPhysicalExamination/application/testapp/controller/Sportstesting.php

1229 lines
57 KiB
PHP
Raw Normal View History

2024-09-24 18:40:30 +08:00
<?php
2025-04-25 19:02:06 +08:00
namespace app\testapp\controller;
2024-09-24 18:40:30 +08:00
use think\Db;
use Exception;
class Sportstesting extends Base{
protected $color = ['#FF5656','#FF5656','#5AD06D','#6492F6','#3967D6'];
protected $sportstesting_use_db_name = [
2025-09-03 19:09:13 +08:00
'1'=>'admin_estimate',
'2'=>'app_sportstesting_data',
'3'=>'app_user_data',
];
2024-09-24 18:40:30 +08:00
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米跑',
];
2024-12-07 18:56:07 +08:00
protected $ceshiyongde_data_baocun_canshu = '{
"code": 0,
"msg": "操作成功",
"data": [
{
"name": "现场考试",
"key": "现场考试",
"list": [
{
"name": "第一类项目(3选1)",
"key": "第一类项目",
"is_choice": "1",
"list": [
{
"name": "1000米跑",
"proportion": "1",
"value": "4:23",
"proportion_value": null,
"unit": "分/秒",
"type": "4",
"describe": null,
"total_score": 6,
"choice_state": 1
},
{
"name": "200米游泳",
"proportion": "1",
"value": "6:12",
"proportion_value": null,
"unit": "分/秒",
"type": "4",
"describe": null,
"total_score": 6,
"choice_state": 0
},
{
"name": "4分钟跳绳",
"proportion": "1",
"value": 340,
"proportion_value": null,
"unit": "",
"type": "1",
"describe": null,
"total_score": 6,
"choice_state": 0
}
]
},
{
"name": "第二类项目(5选1)",
"key": "第二类项目",
"is_choice": "1",
"list": [
{
"name": "50米跑",
"proportion": "1",
"value": 8.1,
"proportion_value": null,
"unit": "",
"type": "2",
"describe": null,
"total_score": 3,
"choice_state": 1
},
{
"name": "立定跳远",
"proportion": "1",
"value": 2.02,
"proportion_value": null,
"unit": "",
"type": "2",
"describe": null,
"total_score": 3,
"choice_state": 0
},
{
"name": "实心球",
"proportion": "1",
"value": 7.3,
"proportion_value": null,
"unit": "",
"type": "2",
"describe": null,
"total_score": 3,
"choice_state": 0
},
{
"name": "引体向上",
"proportion": "1",
"value": 6,
"proportion_value": null,
"unit": "",
"type": "1",
"describe": null,
"total_score": 3,
"choice_state": 0
},
{
"name": "25米游泳",
"proportion": "1",
"value": 30,
"proportion_value": null,
"unit": "",
"type": "1",
"describe": null,
"total_score": 3,
"choice_state": 0
}
]
},
{
"name": "第三类项目(5选1)",
"key": "第三类项目",
"is_choice": "1",
"list": [
{
"name": "乒乓球",
"proportion": "1",
"value": 15,
"proportion_value": null,
"unit": "",
"type": "1",
"describe": null,
"total_score": 3,
"choice_state": 1
},
{
"name": "羽毛球",
"proportion": "1",
"value": 60,
"proportion_value": null,
"unit": "得分",
"type": "1",
"describe": null,
"total_score": 3,
"choice_state": 0
},
{
"name": "网球",
"proportion": "1",
"value": 55,
"proportion_value": null,
"unit": "得分",
"type": "1",
"describe": null,
"total_score": 3,
"choice_state": 0
},
{
"name": "武术",
"proportion": "1",
"value": "6",
"proportion_value": null,
"unit": "得分",
"type": "2",
"describe": null,
"total_score": 3,
"choice_state": 0
},
{
"name": "体操",
"proportion": "1",
"value": "6",
"proportion_value": null,
"unit": "得分",
"type": "2",
"describe": null,
"total_score": 3,
"choice_state": 0
}
]
},
{
"name": "第四类项目(3选1)",
"key": "第四类项目",
"is_choice": "1",
"list": [
{
"name": "足球运球",
"proportion": "1",
"value": 15.5,
"proportion_value": null,
"unit": "",
"type": "2",
"describe": null,
"total_score": 3,
"choice_state": 1
},
{
"name": "篮球",
"proportion": "1",
"value": 31,
"proportion_value": null,
"unit": "",
"type": "1",
"describe": null,
"total_score": 3,
"choice_state": 0
},
{
"name": "排球",
"proportion": "1",
"value": 23,
"proportion_value": null,
"unit": "40秒/次",
"type": "1",
"describe": null,
"total_score": 3,
"choice_state": 0
}
]
}
]
},
{
"name": "日常考核",
"key": "日常考核",
"list": [
{
"name": "体育与健身",
"key": "体育与健身",
"is_choice": "0",
"list": [
{
"name": "7年级",
"proportion": "1",
"value": "60",
"proportion_value": null,
"unit": "",
"type": "1",
"describe": "满分100分",
"total_score": "2"
},
{
"name": "8年级",
"proportion": "1",
"value": "60",
"proportion_value": null,
"unit": "",
"type": "1",
"describe": "满分100分",
"total_score": "2"
},
{
"name": "9年级",
"proportion": "1",
"value": "60",
"proportion_value": null,
"unit": "",
"type": "1",
"describe": "满分100分",
"total_score": "2"
}
]
},
{
"name": "体质健康综合评定",
"key": "体质健康综合评定",
"is_choice": "0",
"list": [
{
"name": "7年级",
"proportion": "1",
"value": "60",
"proportion_value": null,
"unit": "",
"type": "1",
"describe": "满分100分",
"total_score": "3"
},
{
"name": "8年级",
"proportion": "1",
"value": "60",
"proportion_value": null,
"unit": "",
"type": "1",
"describe": "满分100分",
"total_score": "3"
},
{
"name": "9年级",
"proportion": "1",
"value": "60",
"proportion_value": null,
"unit": "",
"type": "1",
"describe": "满分100分",
"total_score": "3"
}
]
}
]
}
]
}';
2024-09-24 18:40:30 +08:00
// 加 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);
}
2024-11-23 16:46:38 +08:00
if(!$this->verify_data_is_ok($data['address'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['gender'],'intnum')){
return $this->msg(10005);
}
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);
2024-11-23 16:46:38 +08:00
return $this->msg(99999);
2024-09-24 18:40:30 +08:00
}
2024-09-24 18:40:30 +08:00
}
// 获取地区类型列表
2024-12-07 18:56:07 +08:00
public function sportstesting_get_region_list($data = ['parameter_data'=>'上海,上海','gender'=>'1','aud_id'=>'83','choice_last_time'=>'0']){
try {
// 你的业务逻辑
if(count(input('post.')) > 0){
$data = input('post.');
}
2024-12-07 18:56:07 +08:00
if(!array_key_exists('gender', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('choice_last_time', $data) || !array_key_exists('aud_id', $data)){
return $this->msg(10001);
}
2024-11-23 16:46:38 +08:00
if(!$this->verify_data_is_ok($data['parameter_data'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['gender'],'intnum')){
return $this->msg(10005);
}
2024-12-07 18:56:07 +08:00
if(!$this->verify_data_is_ok($data['choice_last_time'],'intnum')){
return $this->msg(10005);
}else{
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005);
}
}
$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);
2024-11-23 16:46:38 +08:00
return $this->msg(99999);
2024-09-24 18:40:30 +08:00
}
2024-09-24 18:40:30 +08:00
}
// 获取估分最后一次数据
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);
}
2024-11-23 16:46:38 +08:00
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005);
}
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);
2024-11-23 16:46:38 +08:00
return $this->msg(99999);
2024-09-24 18:40:30 +08:00
}
2024-09-24 18:40:30 +08:00
}
// 计算并存储数据
2024-12-07 18:56:07 +08:00
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.');
}
2024-12-07 18:56:07 +08:00
// $data['result_data'] = json_decode($this->ceshiyongde_data_baocun_canshu,true)['data'];
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);
}
2024-11-23 16:46:38 +08:00
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['parameter_data'],'str')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['gender'],'intnum')){
return $this->msg(10005);
}
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){
2024-11-23 16:46:38 +08:00
return $this->msg(10010,$v['name'].'内并未选择内容');
}
if($v['is_choice'] >= 0 && count($v['list']) < $v['is_choice']){
2024-11-23 16:46:38 +08:00
return $this->msg(10010,$v['name'].'内并缺少选项,请选择'.$v['is_choice'].'个选项');
}
foreach ($v['list'] as $c_k => $c_v) {
if(count($c_v) <= 0){
return $this->msg(10010,$v['name'].'选项内内容异常');
}
}
2024-09-24 18:40:30 +08:00
}
}
2024-11-23 16:46:38 +08:00
}else{
return $this->msg(10006);
2024-09-24 18:40:30 +08:00
}
2024-12-07 18:56:07 +08:00
// die;
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);
2024-11-23 16:46:38 +08:00
return $this->msg(99999);
2024-09-24 18:40:30 +08:00
}
2024-09-24 18:40:30 +08:00
}
// 获取估分历史列表
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);
}
2024-11-23 16:46:38 +08:00
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005);
}
if(!$this->verify_data_is_ok($data['page'],'intnum')){
return $this->msg(10005);
}
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);
2024-11-23 16:46:38 +08:00
return $this->msg(99999);
2024-09-24 18:40:30 +08:00
}
2024-09-24 18:40:30 +08:00
}
// 获取估分历史详情
2024-12-07 18:56:07 +08:00
public function sportstesting_get_one_details($data = ['id'=>'38','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);
}
2024-11-23 16:46:38 +08:00
if(!$this->verify_data_is_ok($data['id'],'intnum')){
return $this->msg(10005);
}
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);
2024-11-23 16:46:38 +08:00
return $this->msg(99999);
2024-09-24 18:40:30 +08:00
}
2024-09-24 18:40:30 +08:00
}
// 获取估分已有的地区列表
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);
}
2024-11-23 16:46:38 +08:00
if(!$this->verify_data_is_ok($data['type'],'intnum')){
return $this->msg(10005);
}
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);
2024-11-23 16:46:38 +08:00
return $this->msg(99999);
2024-09-24 18:40:30 +08:00
}
2024-09-24 18:40:30 +08:00
}
################################################################业务################################################################
################################################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();
2024-09-24 18:40:30 +08:00
$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
2024-12-07 18:56:07 +08:00
$result = false;
if($data['choice_last_time'] == 1){
2024-11-23 16:46:38 +08:00
2024-12-07 18:56:07 +08:00
$last_tiame_data = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id'],'address'=>$data['parameter_data']])->order('id desc')->find();
if($last_tiame_data){
$result = json_decode($last_tiame_data['content'],true);
}else{
$result = false;
}
2024-09-24 18:40:30 +08:00
}
2024-12-07 18:56:07 +08:00
if($result === false){
$rule_data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->select();
if(count($rule_data) > 0){
if(count($rule_data) > 1){
// 查到不止一条规则
return $this->msg(10004,'查询地址不够详细,请重新选择省市地区');
}
$rule_data = json_decode($rule_data[0]['content'],true);
$result = $this->handle_default_rule_list($rule_data,$gender);
}else{
return $this->msg(10004,'暂无该地区的估分规则,请选择其它地区');
}
}
return $this->msg($result);
2024-09-24 18:40:30 +08:00
}
################################################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();
2024-09-24 18:40:30 +08:00
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();
2024-09-24 18:40:30 +08:00
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();
2024-11-23 16:46:38 +08:00
$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')->field('id,create_time,score,max_score,address')->select();
2024-09-24 18:40:30 +08:00
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'],
2024-11-23 16:46:38 +08:00
'score'=>$value['score'] == '.00'?"0":$value['score'],
2024-09-24 18:40:30 +08:00
'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();
2024-09-24 18:40:30 +08:00
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) {
2024-12-07 18:56:07 +08:00
for( $i=0; $i < count($v1v['list']); $i++ ){
if(array_key_exists('choice_state',$v1v['list'][$i]) && $v1v['list'][$i]['choice_state'] == 0){
2024-12-18 09:19:51 +08:00
2024-12-07 18:56:07 +08:00
unset($temporary_data['list'][$key]['list'][$v1k]['list'][$i]);
}
}
2024-09-24 18:40:30 +08:00
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){
2024-11-23 16:46:38 +08:00
2024-09-24 18:40:30 +08:00
$return_result['total_score'] = 0;
$return_result['max_score'] = 0;
$parameter_data = explode(',',$data['parameter_data']);
$gender = $data['gender'];
if(count($parameter_data) == 1){
2024-11-23 16:46:38 +08:00
// $db_condition = "province = '".$parameter_data[0]."'";
2024-09-24 18:40:30 +08:00
$db_condition = "province = '".$parameter_data[0]."'";
}else if(count($parameter_data) == 2){
2024-11-23 16:46:38 +08:00
// $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'";
$db_condition = "province = '".$parameter_data[0]."'";
2024-09-24 18:40:30 +08:00
}else if(count($parameter_data) == 3){
2024-11-23 16:46:38 +08:00
// $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'";
$db_condition = "province = '".$parameter_data[0]."'";
2024-09-24 18:40:30 +08:00
}else{
return $this->msg(10005);
}
2024-11-23 16:46:38 +08:00
// 只根据省查找,全省一个标准
$find_data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->find();
2024-09-24 18:40:30 +08:00
$find_data = json_decode($find_data['content'],true);
$recognition_rule = $find_data[$gender];
2024-12-18 09:19:51 +08:00
2024-09-24 18:40:30 +08:00
foreach ($data['result_data'] as $key => $value) {
// 遍历一级($value['key'] = 现场考试)
foreach ($value['list'] as $k2 => $v2) {
// 遍历二级级($v2['key'] = 第一类项目
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'].")";
2024-12-07 18:56:07 +08:00
if(array_key_exists('choice_state',$v3) && $v3['choice_state'] == 0){
continue;
}
2024-09-24 18:40:30 +08:00
$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);
2024-12-07 18:56:07 +08:00
// if(array_key_exists('choice_state',$v3)){
// if($v3['choice_state'] == 1){
2024-12-18 09:19:51 +08:00
2024-12-07 18:56:07 +08:00
// $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);
// }else{
// $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);
// }
// }else{
2024-12-18 09:19:51 +08:00
2024-12-07 18:56:07 +08:00
// $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);
// }
2024-09-24 18:40:30 +08:00
}
}
}
2024-12-18 09:19:51 +08:00
2024-09-24 18:40:30 +08:00
$return_result['list'] = $data['result_data'];
$user_sportstesting_set = Db::table($this->sportstesting_use_db_name['2'])->insert([
2024-09-24 18:40:30 +08:00
'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'],
]);
2024-12-07 18:56:07 +08:00
// $user_sportstesting_set = true;
2024-09-24 18:40:30 +08:00
if($user_sportstesting_set){
foreach ($return_result['list'] as $key => $value) {
foreach ($value['list'] as $v1k => $v1v) {
2024-12-07 18:56:07 +08:00
for( $i=0; $i < count($v1v['list']); $i++ ){
if(array_key_exists('choice_state',$v1v['list'][$i]) && $v1v['list'][$i]['choice_state'] == 0){
unset($return_result['list'][$key]['list'][$v1k]['list'][$i]);
}
}
2024-09-24 18:40:30 +08:00
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();
2024-09-24 18:40:30 +08:00
$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();
2024-09-24 18:40:30 +08:00
$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){
2024-11-23 16:46:38 +08:00
if($gender == 1){
$temporary_arr = $data[$gender];
}else{
$temporary_arr = $data[2];
}
2024-12-18 09:19:51 +08:00
2024-09-24 18:40:30 +08:00
$result = [];
foreach ($temporary_arr as $key => $value) {
2024-11-29 18:46:37 +08:00
2024-09-24 18:40:30 +08:00
$num = array_push($result,['name'=>$key,'key'=>$key,'list'=>[]]);
2024-12-18 09:19:51 +08:00
2024-09-24 18:40:30 +08:00
foreach ($value as $s_c_k => $s_c_v) {
if($s_c_v['choose_num'] == 0){
2024-11-29 18:46:37 +08:00
// 如果是必选项
2024-09-24 18:40:30 +08:00
$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{
2024-11-29 18:46:37 +08:00
// 如果不是必选项
$num2 = array_push($result[$num-1]['list'],[
'name'=>$s_c_k."(".count($s_c_v['list'])."".$s_c_v['choose_num'].")",
'key'=>$s_c_k,
'is_choice'=>$s_c_v['choose_num'],
'list'=>[]
]);
$choice_state_num = $s_c_v['choose_num'];
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'],
'choice_state'=>$choice_state_num > 0?1:0,
]);
$choice_state_num = $choice_state_num-1;
}
2024-09-24 18:40:30 +08:00
}
}
}
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'] = [];
foreach ($v2['list'] as $k3 => $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'],
]);
}
array_push($result['list'],$temporary_arr);
}
}
}
return $result;
}
// 取得成绩
public function obtaining_grades($rule,$data){
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
2024-11-23 16:46:38 +08:00
if($data['value'] != '' && $data['value'] != null && $data['value'] != '0' && $data['value'] != '0.0' && $data['value'] != '0.0' && $data['value'] != '0:00'){
2024-09-24 18:40:30 +08:00
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'];
}
2024-11-23 16:46:38 +08:00
2024-09-24 18:40:30 +08:00
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]);
}
if($result == true){
2024-11-23 16:46:38 +08:00
// 判断是不是0分
if($data_result == 0){
$data['score'] = 0;
}else{
$data['score'] = $value[2];
}
2024-09-24 18:40:30 +08:00
// 计算比例后分值
$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'],
]);
if($x_m_k == '1000米跑'){
$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米'){
$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'],
]);
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;
}
}