944 lines
42 KiB
PHP
944 lines
42 KiB
PHP
<?php
|
||
|
||
namespace app\testapp\controller;
|
||
|
||
use think\Db;
|
||
use Exception;
|
||
|
||
class Cardpublic extends Base{
|
||
|
||
protected $cardpublic_use_db_name = [
|
||
'1'=>'test_app_user_data',
|
||
'2'=>'test_app_card_data_sub_item',
|
||
'3'=>'test_app_card_data_sub_item_data',
|
||
'4'=>'test_admin_estimate',
|
||
];
|
||
|
||
protected $curve_color = ['#f7b03e','#fb7b92','#ff9f40','#3fcba7',];
|
||
protected $level_data = [
|
||
['min_val'=>'0','max_val'=>'59','text'=>'不及格','color'=>'#FB5755'],
|
||
['min_val'=>'60','max_val'=>'79','text'=>'及格','color'=>'#FCAE00'],
|
||
['min_val'=>'80','max_val'=>'89','text'=>'良好','color'=>'#58CF67'],
|
||
['min_val'=>'90','max_val'=>'150','text'=>'优秀','color'=>'#6691EF'],
|
||
];
|
||
|
||
|
||
// 获取卡片数据
|
||
public function get_card_content($data = ['aud_id'=>'83','acd_id'=>'10','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
// try {
|
||
// // 你的业务逻辑
|
||
// // 成功
|
||
// $this->record_api_log($data, null, $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,'接口错误');
|
||
// }
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
$return_data = $this->get_card_content_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,'接口错误');
|
||
}
|
||
|
||
}
|
||
|
||
// {"acd_id":"11","name":"200米","record_time":"2024-09-27","data":"02:00","aud_id":"1","token":"57bd45e3a963b372ea2d873e4bd8d1f8","aan_id":"1"}
|
||
// 存储信息
|
||
public function data_save($data = ['aud_id'=>'1','acd_id'=>'11','name'=>'200米','data'=>'02:00','record_time'=>'2024-09-27','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data) || !array_key_exists('data', $data) || !array_key_exists('record_time', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
$return_data = $this->data_save_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 get_label_list($data = ['aud_id'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
$return_data = $this->get_label_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 card_motion_curve($data = ['aud_id'=>'1','acd_id'=>'10','s_time'=>'2024-04-01','e_time'=>'2024-07-25','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
$return_data = $this->card_motion_curve_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 data_contrast_obtain_data($data = ['aud_id'=>'1','acd_id'=>'10','name'=>'1000米','s_time'=>'2024-04-01','e_time'=>'2024-10-03']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
$return_data = $this->data_contrast_obtain_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 data_contrast_contrast_data($data = ['before_id'=>'1','after_id'=>'3']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
$return_data = $this->data_contrast_contrast_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 obtain_history_record($data = ['aud_id'=>'1','acd_id'=>'10','name'=>'1000米','page'=>'1']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
$return_data = $this->obtain_history_record_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 history_record_del($data = ['id'=>'10']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('id', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
$return_data = $this->history_record_del_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 obtain_manual_record_content($data = ['aud_id'=>1]){
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
$user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find();
|
||
if(!$user_data){
|
||
return $this->msg(10004);
|
||
}
|
||
$card_data = [
|
||
['id'=>'2','height'=>true,'weight'=>true,'number'=>false,'time'=>false,'list'=>[]],
|
||
['id'=>'6','height'=>false,'weight'=>false,'number'=>true,'time'=>true,'list'=>[]],
|
||
[
|
||
'id'=>'10',
|
||
'height'=>false,
|
||
'weight'=>false,
|
||
'number'=>false,
|
||
'time'=>false,
|
||
'list'=>[
|
||
[
|
||
'id'=>'1',
|
||
'name'=>'1000米',
|
||
'number'=>false,
|
||
'type'=>4,
|
||
'time'=>true,
|
||
'describe'=>'时长',
|
||
'unit'=>'',
|
||
],
|
||
[
|
||
'id'=>'2',
|
||
'name'=>'800米',
|
||
'number'=>false,
|
||
'type'=>4,
|
||
'time'=>true,
|
||
'describe'=>'时长',
|
||
'unit'=>'',
|
||
],
|
||
[
|
||
'id'=>'3',
|
||
'name'=>'50米',
|
||
'number'=>true,
|
||
'type'=>2,
|
||
'time'=>false,
|
||
'describe'=>'时长',
|
||
'unit'=>'秒',
|
||
],
|
||
]
|
||
],
|
||
[
|
||
'id'=>'12',
|
||
'height'=>false,
|
||
'weight'=>false,
|
||
'number'=>false,
|
||
'time'=>false,
|
||
'list'=>[
|
||
[
|
||
'id'=>'7',
|
||
'name'=>'立定跳远',
|
||
'number'=>true,
|
||
'type'=>1,
|
||
'time'=>false,
|
||
'describe'=>'距离',
|
||
'unit'=>'CM',
|
||
],
|
||
]
|
||
],
|
||
[
|
||
'id'=>'13',
|
||
'height'=>false,
|
||
'weight'=>false,
|
||
'number'=>false,
|
||
'time'=>false,
|
||
'list'=>[
|
||
[
|
||
'id'=>'8',
|
||
'name'=>'引体向上',
|
||
'number'=>true,
|
||
'type'=>1,
|
||
'time'=>false,
|
||
'describe'=>'个数',
|
||
'unit'=>'个',
|
||
],
|
||
[
|
||
'id'=>'9',
|
||
'name'=>'仰卧起坐',
|
||
'number'=>true,
|
||
'type'=>1,
|
||
'time'=>false,
|
||
'describe'=>'个数',
|
||
'unit'=>'个',
|
||
],
|
||
]
|
||
],
|
||
[
|
||
'id'=>'14',
|
||
'height'=>false,
|
||
'weight'=>false,
|
||
'number'=>false,
|
||
'time'=>false,
|
||
'list'=>[
|
||
[
|
||
'id'=>'10',
|
||
'name'=>'坐位体前屈',
|
||
'number'=>true,
|
||
'type'=>1,
|
||
'time'=>false,
|
||
'describe'=>'距离',
|
||
'unit'=>'CM',
|
||
],
|
||
]
|
||
],
|
||
];
|
||
if($user_data['gender'] == 1){
|
||
unset($card_data[2]['list'][1]);//800米
|
||
unset($card_data[4]['list'][1]);//仰卧起坐
|
||
}else if($user_data['gender'] == 2){
|
||
unset($card_data[2]['list'][0]);//1000米
|
||
unset($card_data[4]['list'][0]);//引体向上
|
||
}
|
||
foreach ($card_data as $key => $value) {
|
||
$card_data[$key]['list'] = array_values($card_data[$key]['list']);
|
||
}
|
||
|
||
return $this->msg($card_data);
|
||
}
|
||
|
||
|
||
|
||
|
||
################################################################action################################################################
|
||
################################################################action################################################################
|
||
|
||
##################################################get_card_content##################################################
|
||
public function get_card_content_action($data){
|
||
// 查找用户是存在
|
||
$user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,gender')->find();
|
||
if(!$user_data){
|
||
return $this->msg(10004);
|
||
}
|
||
// 卡片是否存在,以及是否含有子项
|
||
$card_data_sub_item = Db::table($this->cardpublic_use_db_name['2'])->where("acd_id = ".$data['acd_id']." and is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit')->select();
|
||
if(!$card_data_sub_item){
|
||
return $this->msg(10004);
|
||
}
|
||
$return_data = [
|
||
'icon' => '',
|
||
'label_list' => [],
|
||
'line_list' => [],
|
||
'label_data' => [],
|
||
|
||
];
|
||
$data_this_time = [];
|
||
$today_time = date('Y-m-d');
|
||
foreach ($card_data_sub_item as $key => $value) {
|
||
// 设置单项数据模板
|
||
$temporary_arr_c = [
|
||
'project_name' => $value['name'],
|
||
'score' => '',
|
||
'max_score' => '',
|
||
'standard' => '',
|
||
'this_time_title' => '本次成绩',
|
||
'this_time_value' => '',
|
||
'today_time_title' => '今日总计',
|
||
'today_times' => 0,
|
||
'today_time_value' => 0,
|
||
'all_time_title' => '总计平均',
|
||
'all_times' => 0,
|
||
'all_time_value' => 0,
|
||
'describe' => '',
|
||
'color' => '',
|
||
'offset' => '',
|
||
'unit_data' => '',
|
||
'record_time' => '',
|
||
];
|
||
// 添加标签
|
||
array_push($return_data['label_list'],$value['name']);
|
||
// 添加线性轴描述
|
||
$return_data['line_list'] = $this->level_data;
|
||
// 查询最后一次成绩
|
||
$data_this_time = Db::table($this->cardpublic_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id'],'is_del'=>0])->order('record_time desc')->field('id,detailed_msg,achievement,record_time')->find();
|
||
// dump($data_this_time);
|
||
if($data_this_time){
|
||
$data_this_time['detailed_msg'] = json_decode($data_this_time['detailed_msg'],true);
|
||
// 设置基础数据
|
||
$temporary_arr_c['score'] = $data_this_time['detailed_msg']['score'].'分';
|
||
$temporary_arr_c['max_score'] = $data_this_time['detailed_msg']['max_score'];
|
||
$temporary_arr_c['standard'] = $data_this_time['detailed_msg']['standard'];
|
||
$temporary_arr_c['describe'] = $data_this_time['detailed_msg']['describe'];
|
||
$temporary_arr_c['color'] = $data_this_time['detailed_msg']['color'];
|
||
$temporary_arr_c['offset'] = $data_this_time['detailed_msg']['offset'];
|
||
$temporary_arr_c['unit_data'] = $data_this_time['detailed_msg']['unit_data'];
|
||
$temporary_arr_c['record_time'] = $data_this_time['record_time'];
|
||
// 获取到该项所有数据
|
||
$all_time_title = Db::table($this->cardpublic_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id'],'is_del'=>0])->order('id desc')->field('id,achievement,LEFT(record_time,10) AS r_t')->select();
|
||
// 处理今日,以及总计数据
|
||
if($data_this_time['detailed_msg']['unit_data'] == '分/秒'){
|
||
// 如果是分秒形式的数据
|
||
// 设置今日数据跟总计数据的格式
|
||
$temporary_arr_c['today_time_value'] = "0:00";
|
||
$temporary_arr_c['all_time_value'] = "0:00";
|
||
// 处理本次数据最终格式
|
||
list($minutes, $seconds) = explode(':', $data_this_time['achievement']);
|
||
$temporary_arr_c['this_time_value'] = $minutes . '分' . sprintf('%02d', $seconds) . '秒';
|
||
// 计算今日总计&所有平均
|
||
$temporary_arr_c['all_times'] = count($all_time_title);
|
||
foreach ($all_time_title as $k1 => $v1) {
|
||
$temporary_arr_c['all_time_value'] = $this->sumTimes($temporary_arr_c['all_time_value'],$v1['achievement']);
|
||
if($v1['r_t'] == $today_time){
|
||
$temporary_arr_c['today_times'] = $temporary_arr_c['today_times']+1;
|
||
$temporary_arr_c['today_time_value'] = $this->sumTimes($temporary_arr_c['today_time_value'],$v1['achievement']);
|
||
}
|
||
}
|
||
$temporary_arr_c['all_time_value'] = $this->averageTime($temporary_arr_c['all_time_value'],$temporary_arr_c['all_times']);
|
||
list($minutes, $seconds) = explode(':', $temporary_arr_c['today_time_value']);
|
||
$temporary_arr_c['today_time_value'] = $minutes . '分' . sprintf('%02d', $seconds) . '秒';
|
||
|
||
}else{
|
||
|
||
$temporary_arr_c['this_time_value'] = $data_this_time['achievement'].$data_this_time['detailed_msg']['unit_data'];
|
||
|
||
$temporary_arr_c['all_times'] = count($all_time_title);
|
||
foreach ($all_time_title as $k1 => $v1) {
|
||
$temporary_arr_c['all_time_value'] = $temporary_arr_c['all_time_value']+$v1['achievement'];
|
||
if($v1['r_t'] == $today_time){
|
||
$temporary_arr_c['today_times'] = $temporary_arr_c['today_times']+1;
|
||
$temporary_arr_c['today_time_value'] = $temporary_arr_c['today_time_value']+$v1['achievement'];
|
||
}
|
||
}
|
||
$temporary_arr_c['today_time_value'] = $temporary_arr_c['today_time_value'].$data_this_time['detailed_msg']['unit_data'];
|
||
|
||
$temporary_arr_c['all_time_value'] = bcdiv($temporary_arr_c['all_time_value'],$temporary_arr_c['all_times'],1).$data_this_time['detailed_msg']['unit_data'];
|
||
}
|
||
$temporary_arr_c['today_times'] = $temporary_arr_c['today_times'].'次';
|
||
$temporary_arr_c['all_times'] = $temporary_arr_c['all_times'].'次';
|
||
|
||
}
|
||
array_push($return_data['label_data'],$temporary_arr_c);
|
||
}
|
||
return $this->msg($return_data);
|
||
}
|
||
##################################################data_save##################################################
|
||
public function data_save_action($data){
|
||
|
||
// 查找用户是存在
|
||
$user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find();
|
||
if(!$user_data){
|
||
return $this->msg(10004);
|
||
}
|
||
// 查找项目是否存在,以及获取项目信息
|
||
$card_data_sub_item_data = Db::table($this->cardpublic_use_db_name['2'])->where("name = '".$data['name']."' and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit,acd_id')->find();
|
||
if(!$card_data_sub_item_data){
|
||
return $this->msg(10004);
|
||
}
|
||
// 如果项目数据类型为分秒格式
|
||
if($card_data_sub_item_data['type'] == 1){
|
||
// 判断是否为整型,或者字符串类型的整型数字
|
||
if(!$this->isValidInteger($data['data'])){
|
||
return $this->msg(10005);
|
||
}
|
||
}else if($card_data_sub_item_data['type'] == 4){
|
||
// 检查字符串格式是否为“数字”+“:”+“数字”的格式,且冒号后的数字小于等于59
|
||
if(!$this->isValidFormatWithLimit($data['data'])){
|
||
return $this->msg(10005);
|
||
}
|
||
}else if($card_data_sub_item_data['type'] == 2){
|
||
// 判断一个字符串是否为两位以内小数
|
||
// dump($this->isTwoDecimalOrLess($data['data']));
|
||
if(!$this->isTwoDecimalOrLess($data['data'])){
|
||
return $this->msg(10005);
|
||
}
|
||
}
|
||
$score_all_data = $this->calculation_score($user_data['gender'],$data,$card_data_sub_item_data['type']);
|
||
$save_data = [
|
||
'acd_id' => $card_data_sub_item_data['acd_id'],
|
||
'acdsi_id' => $card_data_sub_item_data['id'],
|
||
'aud_id' => $data['aud_id'],
|
||
'achievement' => $data['data'],
|
||
'record_time' => $data['record_time'].date(' H:i:s'),
|
||
'create_time' => date('Y-m-d H:i:s'),
|
||
'unit' => $card_data_sub_item_data['unit'],
|
||
'score' => $score_all_data['score'],
|
||
'detailed_msg' => json_encode($score_all_data),
|
||
];
|
||
|
||
$result = Db::table($this->cardpublic_use_db_name['3'])->insert($save_data);
|
||
// $result = true;
|
||
if($result){
|
||
if($save_data['unit'] == '分/秒'){
|
||
list($minutes, $seconds) = explode(':', $data['data']);
|
||
$score_all_data['this_time_value'] = $minutes . '分' . sprintf('%02d', $seconds) . '秒';
|
||
}else{
|
||
$score_all_data['this_time_value'] = $data['data'].$save_data['unit'];
|
||
}
|
||
|
||
return $this->msg($score_all_data);
|
||
}else{
|
||
return $this->msg(10002);
|
||
}
|
||
}
|
||
##################################################get_label_list##################################################
|
||
public function get_label_list_action($data){
|
||
// 查找用户是存在
|
||
$user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,gender')->find();
|
||
if(!$user_data){
|
||
return $this->msg(10004);
|
||
}
|
||
$label_data = Db::table($this->cardpublic_use_db_name['2'])->where("is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,acd_id,name,unit,type')->select();
|
||
if(count($label_data)<=0){
|
||
return $this->msg(10004);
|
||
}
|
||
|
||
$return_data = [];
|
||
$temporary_arr = [];
|
||
foreach ($label_data as $key => $value) {
|
||
if(!array_key_exists($value['acd_id'], $temporary_arr)){
|
||
$temporary_arr[$value['acd_id']] = [$value['name']];
|
||
}else{
|
||
array_push($temporary_arr[$value['acd_id']],$value['name']);
|
||
}
|
||
}
|
||
foreach ($temporary_arr as $key => $value) {
|
||
array_push($return_data,[
|
||
'acd_id'=>$key,
|
||
'list'=>$value,
|
||
]);
|
||
}
|
||
return $this->msg($return_data);
|
||
}
|
||
|
||
##################################################card_motion_curve##################################################
|
||
public function card_motion_curve_action($data){
|
||
$user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,gender')->find();
|
||
if(!$user_data){
|
||
return $this->msg(10004);
|
||
}
|
||
$card_sub_item_data = Db::table($this->cardpublic_use_db_name['3'])->where(['acd_id'=>$data['acd_id'],'aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc')->field('id,acdsi_id,score,LEFT(record_time,10) as record_time')->select();
|
||
$card_sub_item_type = Db::table($this->cardpublic_use_db_name['2'])->where("acd_id = ".$data['acd_id']." and is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,name,unit')->select();
|
||
$temporary_arr = [];
|
||
$return_data = [];
|
||
// 处理一个临时数据
|
||
foreach ($card_sub_item_type as $key => $value) {
|
||
$temporary_arr[$value['id']] = ['name'=>$value['name'],'unit'=>$value['unit'],'time'=>[],'data'=>[]];
|
||
}
|
||
// 往临时数组内填入数据
|
||
foreach ($card_sub_item_data as $key => $value) {
|
||
// dump($value);
|
||
array_push($temporary_arr[$value['acdsi_id']]['time'],$value['record_time']);
|
||
array_push($temporary_arr[$value['acdsi_id']]['data'],$value['score']);
|
||
}
|
||
$num = 0;
|
||
foreach ($temporary_arr as $key => $value) {
|
||
if(($num+1) > count($this->curve_color)){
|
||
$num = 0;
|
||
}
|
||
array_push($return_data,[
|
||
'title'=>$value['name'],
|
||
'key'=>$value['name'],
|
||
'line'=>[
|
||
'categories'=>$value['time'],
|
||
'series'=>[
|
||
[
|
||
'color'=>$this->curve_color[$num],
|
||
'name'=>$value['name'],
|
||
'data'=>$value['data'],
|
||
]
|
||
],
|
||
],
|
||
]);
|
||
$num = $num+1;
|
||
}
|
||
return $this->msg($return_data);
|
||
}
|
||
##################################################data_contrast_obtain_data##################################################
|
||
public function data_contrast_obtain_data_action($data){
|
||
// dump($data);
|
||
// $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find();
|
||
$card_data = Db::table($this->cardpublic_use_db_name['2'])->where(['acd_id'=>$data['acd_id'],'name'=>$data['name'],'is_del'=>0])->find();
|
||
|
||
$result_data = Db::table($this->cardpublic_use_db_name['3'])
|
||
->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$card_data['id'],'is_del'=>0])
|
||
->whereTime('record_time', 'between', [$data['s_time'], $data['e_time']])
|
||
->field('id,achievement,score,unit,record_time')
|
||
->order('record_time desc')
|
||
->select();
|
||
|
||
// dump($result_data);
|
||
$return_data = [];
|
||
foreach ($result_data as $key => $value) {
|
||
if($value['unit'] == '分/秒'){
|
||
$temporary_arr_e1 = explode(':', $value['achievement']);
|
||
$temporary_arr_e2 = explode('/', $value['unit']);
|
||
}
|
||
$temporary_arr = [
|
||
"id"=> $value['id'],
|
||
// "v1"=> $value['achievement'].$value['unit'],
|
||
"v1"=> $value['unit'] == '分/秒'?$temporary_arr_e1[0].$temporary_arr_e2[0].$temporary_arr_e1[1].$temporary_arr_e2[1]:$value['achievement'].$value['unit'],
|
||
"v2"=> $value['score'].'分',
|
||
"v1_name"=> "成绩",
|
||
"v2_name"=> "得分",
|
||
"r_t"=> substr($value['record_time'], 0, 10)
|
||
];
|
||
array_push($return_data,$temporary_arr);
|
||
}
|
||
// dump($user_data);
|
||
// dump($card_data);
|
||
// dump($result_data);
|
||
// dump($return_data);
|
||
return $this->msg($return_data);
|
||
}
|
||
##################################################data_contrast_contrast_data##################################################
|
||
public function data_contrast_contrast_data_action($data){
|
||
|
||
$tj = "id IN (".$data['before_id'].",".$data['after_id'].")";
|
||
|
||
$card_data = Db::table($this->cardpublic_use_db_name['3'])->where($tj)->select();
|
||
if(count($card_data)<2){
|
||
return $this->msg(10004);
|
||
}
|
||
if($card_data[0]['acdsi_id'] != $card_data[1]['acdsi_id']){
|
||
return $this->msg(10003);
|
||
}
|
||
|
||
dump($card_data);
|
||
}
|
||
##################################################obtain_history_record##################################################
|
||
public function obtain_history_record_action($data){
|
||
$card_data = Db::table($this->cardpublic_use_db_name['2'])->where(['acd_id'=>$data['acd_id'],'name'=>$data['name'],'is_del'=>0])->find();
|
||
$result_count = Db::table($this->cardpublic_use_db_name['3'])
|
||
->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$card_data['id'],'is_del'=>0])
|
||
->count();
|
||
$result_data = Db::table($this->cardpublic_use_db_name['3'])
|
||
->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$card_data['id'],'is_del'=>0])
|
||
->field('id,achievement,score,unit,record_time')
|
||
->order('record_time desc')
|
||
->page($data['page'].",10")
|
||
->select();
|
||
|
||
$return_data = [
|
||
'totalrows'=>$result_count,
|
||
'rows'=>[],
|
||
'pagenow'=>$data['page'],
|
||
'pagesize'=>10,
|
||
'totalpage'=>ceil($result_count/10),
|
||
];
|
||
foreach ($result_data as $key => $value) {
|
||
$temporary_arr = [];
|
||
if($value['unit'] == '分/秒'){
|
||
$temporary_arr_e1 = explode(':', $value['achievement']);
|
||
$temporary_arr_e2 = explode('/', $value['unit']);
|
||
}
|
||
$temporary_arr = [
|
||
"id"=> $value['id'],
|
||
// "v1"=> $value['achievement'].$value['unit'],
|
||
"v1"=> $value['unit'] == '分/秒'?$temporary_arr_e1[0].$temporary_arr_e2[0].$temporary_arr_e1[1].$temporary_arr_e2[1]:$value['achievement'].$value['unit'],
|
||
"v2"=> $value['score'].'分',
|
||
"v1_name"=> "成绩",
|
||
"v2_name"=> "得分",
|
||
"record_time"=> $value['record_time']
|
||
];
|
||
array_push($return_data['rows'],$temporary_arr);
|
||
}
|
||
|
||
return $this->msg($return_data);
|
||
}
|
||
##################################################history_record_del##################################################
|
||
public function history_record_del_action($data){
|
||
$result_count = Db::table($this->cardpublic_use_db_name['3'])
|
||
->where(['id'=>$data['id']])
|
||
->update(['is_del'=>1]);
|
||
if($result_count){
|
||
return $this->msg([]);
|
||
}else{
|
||
return $this->msg(10002);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
################################################################tool################################################################
|
||
################################################################tool################################################################
|
||
|
||
// 计算得分成绩以及线性进度
|
||
public function calculation_score($gender,$data,$type){
|
||
// $card_name['card_name'] = ;
|
||
$card_name['project_name'] = $data['name'];
|
||
$card_name['score'] = 0;
|
||
$card_name['offset'] = 0;
|
||
$describe_list = $this->level_data;
|
||
$card_name['rule'] = [];
|
||
|
||
// 计算得分
|
||
// 获取评分细则
|
||
$estimate = Db::table($this->cardpublic_use_db_name['4'])->where(['type'=>3])->find();
|
||
$estimate = json_decode($estimate['content'],true);
|
||
|
||
// 根据男女循环出项目细则
|
||
foreach ($estimate[$gender]['公共考核标准'] as $key => $value) {
|
||
if(count($card_name['rule']) > 0){
|
||
break;
|
||
}
|
||
foreach ($value['list'] as $k => $v) {
|
||
if($k == $data['name']){
|
||
$card_name['rule'] = $v;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
foreach ($card_name['rule']['content'] as $key => $value) {
|
||
if($type == '分/秒'){
|
||
$rule_result = $this->convertMinutesSecondsToStringSeconds($value[0]);
|
||
$data_result = $this->convertMinutesSecondsToStringSeconds($data['data']);
|
||
}else{
|
||
$rule_result = $value[0];
|
||
$data_result = $data['data'];
|
||
}
|
||
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){
|
||
$card_name['score'] = $value[2];
|
||
if($value[2] < 100){
|
||
$card_name['offset'] = $value[2];
|
||
}else{
|
||
$card_name['offset'] = 100;
|
||
}
|
||
|
||
// $card_name['offset'] = bcdiv($value[2],$card_name['diagram'][count($card_name['diagram'])-1]['max_val'],0);
|
||
break;
|
||
}
|
||
}
|
||
|
||
foreach ($describe_list as $key => $value) {
|
||
if($card_name['score'] >= $value['min_val'] && $card_name['score'] <= $value['max_val']){
|
||
$card_name['standard'] = $value['text'];
|
||
$card_name['color'] = $value['color'];
|
||
break;
|
||
}
|
||
}
|
||
$card_name['max_score'] = $card_name['rule']['content'][0][2];
|
||
$card_name['describe'] = $card_name['rule']['describe'];
|
||
$card_name['unit_data'] = $card_name['rule']['unit_data'];
|
||
// $card_name['default_data_format'] = $card_name['rule']['value'];
|
||
// $card_name['default_data_type'] = $card_name['rule']['type'];
|
||
// $card_name['list'] = $describe_list;
|
||
unset($card_name['rule']);
|
||
return $card_name;
|
||
}
|
||
|
||
|
||
// 获取标签列表,以及标签列表下数据
|
||
public function get_other_data(){
|
||
|
||
}
|
||
|
||
|
||
################################################################其他################################################################
|
||
################################################################其他################################################################
|
||
|
||
|
||
// 检查字符串格式是否为“数字”+“:”+“数字”的格式,且冒号后的数字小于等于59
|
||
public function isValidFormatWithLimit($str){
|
||
// 使用正则表达式匹配“数字:数字”的格式
|
||
if (preg_match('/^(\d+):(\d+)$/', $str, $matches)) {
|
||
// 提取冒号前后的数字
|
||
$firstNumber = $matches[1];
|
||
$secondNumber = $matches[2];
|
||
|
||
// 检查冒号后的数字是否小于等于60
|
||
if ($secondNumber <= 59) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// 两个时间相加4:20、5:15
|
||
function sumTimes($time1, $time2) {
|
||
// 将时间字符串拆分为分钟和秒
|
||
list($min1, $sec1) = explode(':', $time1);
|
||
list($min2, $sec2) = explode(':', $time2);
|
||
|
||
// 将分钟和秒转换为整数
|
||
$totalMin = (int)$min1 + (int)$min2;
|
||
$totalSec = (int)$sec1 + (int)$sec2;
|
||
|
||
// 如果秒数超过或等于60,则进位到分钟
|
||
if ($totalSec >= 60) {
|
||
$totalMin += floor($totalSec / 60);
|
||
$totalSec = $totalSec % 60;
|
||
}
|
||
// 格式化总时间为"分:秒"
|
||
// $totalTime = sprintf('%d分%02d秒', $totalMin, $totalSec);
|
||
$totalTime = $totalMin.":".$totalSec;
|
||
// 返回结果
|
||
return $totalTime;
|
||
}
|
||
|
||
|
||
// 处理平均时间
|
||
function averageTime($timeStr, $divisor) {
|
||
// 步骤1: 拆分时间字符串
|
||
list($minutes, $seconds) = explode(':', $timeStr);
|
||
|
||
// 步骤2: 转换为总秒数
|
||
$totalSeconds = ($minutes * 60) + $seconds;
|
||
|
||
// 步骤3: 除以参数
|
||
$averageSeconds = $totalSeconds / $divisor;
|
||
|
||
// 步骤4: 转换回分钟和秒
|
||
$averageMinutes = floor($averageSeconds / 60);
|
||
$remainingSeconds = round($averageSeconds % 60); // 使用round来处理小数秒,如果需要更精确的四舍五入
|
||
|
||
// 步骤5: 格式化结果为“分:秒”
|
||
$formattedTime = sprintf('%d分%02d秒', $averageMinutes, $remainingSeconds);
|
||
|
||
return $formattedTime;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |