2025-11-21 19:13:01 +08:00
< ? php
namespace app\NewReedaw\controller\app ;
use think\Db ;
2026-03-06 18:02:49 +08:00
2025-11-21 19:13:01 +08:00
class Card extends Base {
protected $card_db_name = [
'zhanghao' => 'app_account_number' ,
'juese' => 'app_user_data' ,
2026-03-06 18:02:49 +08:00
'card' => 'app_card_data' ,
'skip' => 'app_card_skip_data' ,
'vitalcapacity' => 'app_card_vitalcapacity_data' ,
'zhongzhao' => 'app_sportstesting_data' ,
2026-03-18 18:24:07 +08:00
'body_data_new' => 'app_card_body_data_new' ,
'vitalcapacity_biaozhun' => 'pc_vitalcapacity_standard' ,
'card_bz' => 'app_card_data_sub_item' ,
2026-03-06 18:02:49 +08:00
];
2026-03-18 18:24:07 +08:00
protected $vitalcapacity_color = [ '无效' => '#FF5656' , '不及格' => '#FF5656' , '及格' => '#FFAB00' , '良好' => '#5AD06D' , '优秀' => '#6492F6' , '牛逼' => '#3967D6' ];
protected $curve_data_format_skip = [ 'jump_num' => [ '跳绳个数' , '个' , '#009DFF' ], 'jump_time' => [ '跳绳时长' , '分钟' , '#009DFF' ], 'jump_kcal' => [ '消耗卡路里' , 'kcal' , '#009DFF' ]];
protected $curve_data_format_vitalcapacity = [ 'one_val' => [ '第一次' , '容积/ml' , '#009DFF' ], 'two_val' => [ '第二次' , '容积/ml' , '#009DFF' ], 'three_val' => [ '第三次' , '容积/ml' , '#009DFF' ], 'average_val' => [ '平均' , '容积/ml' , '#009DFF' ]];
2026-03-06 18:02:49 +08:00
protected $card_standard_arr_data = [
'id' => '' ,
'name' => '' ,
'content' => '' ,
'page_url_report' => '' ,
'is_sub_item' => '' ,
'background_color' => '' ,
'background_pic' => '' ,
'key_word' => '' ,
'data' => [],
2025-11-21 19:13:01 +08:00
];
2026-03-18 18:24:07 +08:00
protected $pagesize = 15 ;
2025-11-21 19:13:01 +08:00
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 卡片列表信息
2026-03-06 18:02:49 +08:00
public function card_list_all (){
$data = input ( 'post.' );
2025-11-21 19:13:01 +08:00
try {
// 你的业务逻辑
if ( ! array_key_exists ( 'token' , $data ) || ! array_key_exists ( 'aud_id' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 , 'token type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 , 'aud_id type error' );
}
2026-03-06 18:02:49 +08:00
return $this -> card_list_all_action ( $data );
2025-11-21 19:13:01 +08:00
} 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 );
}
}
2026-03-06 18:02:49 +08:00
// 保存用户所选的卡片列表
public function save_card_list (){
$data = input ( 'post.' );
2025-11-21 19:13:01 +08:00
try {
// 你的业务逻辑
2026-03-06 18:02:49 +08:00
if ( ! array_key_exists ( 'token' , $data ) || ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'card_list' , $data )){
2025-11-21 19:13:01 +08:00
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 , 'token type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 , 'aud_id type error' );
}
2026-03-18 18:24:07 +08:00
2026-03-06 18:02:49 +08:00
return $this -> save_card_list_action ( $data );
2025-11-21 19:13:01 +08:00
} 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 );
}
}
2026-03-06 18:02:49 +08:00
// 角色卡片列表信息
public function user_card_list (){
$data = input ( 'post.' );
try {
// 你的业务逻辑
if ( ! array_key_exists ( 'token' , $data ) || ! array_key_exists ( 'aud_id' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 , 'token type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 , 'aud_id type error' );
}
return $this -> user_card_list_action ( $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 );
}
}
// BMI测评
public function bmi_evaluation (){
$cbe_data = input ( 'post.' );
try {
if ( ! is_array ( $cbe_data )){
return $this -> msg ( 10005 );
}
if ( ! array_key_exists ( 'height' , $cbe_data ) || ! array_key_exists ( 'weight' , $cbe_data ) || ! array_key_exists ( 'birthday' , $cbe_data ) || ! array_key_exists ( 'sex' , $cbe_data )){
return $this -> msg ( 10001 );
}
unset ( $cbe_data [ 'token' ]);
if ( ! $this -> verify_data_is_ok ( $cbe_data [ 'birthday' ], 'datetime' )){
return $this -> msg ( 10005 , 'birthday type error' );
}
if ( ! $this -> verify_data_is_ok ( $cbe_data [ 'height' ], 'num' )){
return $this -> msg ( 10005 , 'height type error' );
}
if ( ! $this -> verify_data_is_ok ( $cbe_data [ 'weight' ], 'num' )){
return $this -> msg ( 10005 , 'weight type error' );
}
if ( ! $this -> verify_data_is_ok ( $cbe_data [ 'sex' ], 'intnum' )){
return $this -> msg ( 10005 , 'sex type error' );
}
// 直接开始业务, 请求外部接口start
$url = 'http://ybdevice.pcxbc.com/api/result/calcbmi' ;
$temporary_parameter = [
'height' => $cbe_data [ 'height' ],
'weight' => $cbe_data [ 'weight' ],
'birthday' => $cbe_data [ 'birthday' ],
'sex' => $cbe_data [ 'sex' ],
];
$request_result = $this -> postRequest ( $url , $temporary_parameter , array ( 'Content-Type:application/json' , 'Origin:http://ybdevice.pcxbc.com' ));
// 直接开始业务, 请求外部接口end
// 处理进度点
$request_result = $this -> bmi_evaluation_action ( $request_result );
return $request_result ;
} 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 ( $cbe_data , $logContent , null );
return $this -> msg ( 99999 );
}
}
// 身高预测
public function genetic_height (){
$data = input ( 'post.' );
try {
if ( ! array_key_exists ( 'dadHeight' , $data ) || ! array_key_exists ( 'momHeight' , $data ) || ! array_key_exists ( 'birthday' , $data ) || ! array_key_exists ( 'sex' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'birthday' ], 'datetime' )){
return $this -> msg ( 10005 , 'birthday type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'dadHeight' ], 'num' )){
return $this -> msg ( 10005 , 'dadHeight type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'momHeight' ], 'num' )){
return $this -> msg ( 10005 , 'momHeight type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'sex' ], 'intnum' )){
return $this -> msg ( 10005 , 'sex type error' );
}
// 直接开始业务, 请求外部接口start
$url = 'https://ybapi.pcxbc.com/api/child/predictheight' ;
$temporary_parameter = [
'dadHeight' => $data [ 'dadHeight' ],
'momHeight' => $data [ 'momHeight' ],
'birthday' => $data [ 'birthday' ],
'sex' => $data [ 'sex' ],
];
$request_result = $this -> postRequest ( $url , $temporary_parameter , array ( 'Content-Type:application/json' , 'Origin:http://ybdevice.pcxbc.com' ));
return json ( $request_result );
} 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 );
}
}
2026-03-18 18:24:07 +08:00
// 获取手动记录内容
public function obtain_manual_record_content (){
$data = input ( 'post.' );
try {
if ( ! array_key_exists ( 'aud_id' , $data )){
return $this -> msg ( 10001 );
}
type类型 :
// 数字输入框: number
// 文本输入框: text
// 日期下拉框: date Y-m-d
// 时间下拉框: multiSelector His或者is
// 带小数点的数字键盘: digit
$card_data = [
[
'id' => 6 ,
'name' => '跳绳' ,
'key_word' => 'skip' ,
'list' => [
[ 'name' => '日期' , 'key_word' => 'r_time' , 'type' => 'date' , 'unit' => '' , 'value' => '' ],
[ 'name' => '时长' , 'key_word' => 'time_m_s' , 'type' => 'multiSelector' , 'unit' => '' , 'value' => '' ],
[ 'name' => '数量' , 'key_word' => 'num' , 'type' => 'number' , 'unit' => '个' , 'value' => '' ],
]
],
[
'id' => 8 ,
'name' => '肺活训练' ,
'key_word' => 'vitalcapacity' ,
'list' => [
[ 'name' => '日期' , 'key_word' => 'r_time' , 'type' => 'date' , 'unit' => '' , 'value' => '' ],
[ 'name' => '第一次' , 'key_word' => 'one' , 'type' => 'number' , 'unit' => 'ml' , 'value' => '' ],
[ 'name' => '第二次' , 'key_word' => 'two' , 'type' => 'number' , 'unit' => 'ml' , 'value' => '' ],
[ 'name' => '第三次' , 'key_word' => 'three' , 'type' => 'number' , 'unit' => 'ml' , 'value' => '' ],
]
]
];
// if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
// return $this->msg(10005);
// }
// $user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,gender')->find();
// if(!$user_data){
// return $this->msg(10004);
// }
// $card_data_c = Db::table($this->card_db_name['card_bz'])
// ->where(['is_del'=>0])
// ->field('id,name,type,unit,unit2,suit_gender,acd_id')
// ->select();
// $card_data_c2 = [];
// foreach ($card_data_c as $key => $value) {
// $temporary_arr = [];
// $temporary_arr['id'] = $value['acd_id'];
// $temporary_arr['height'] = false;
// $temporary_arr['weight'] = false;
// $temporary_arr['number'] = false;
// $temporary_arr['time'] = false;
// $temporary_arr['list'] = [];
// $card_data_c2[$value['acd_id']] = $temporary_arr;
// }
// foreach ($card_data_c as $key => $value) {
// if(in_array($user_data['gender'], explode(",", $value['suit_gender']))){
// $temporary_arr = [];
// $temporary_arr['id'] = $value['id'];
// $temporary_arr['name'] = $value['name'];
// $temporary_arr['number'] = $value['unit2'] == '时长'?false:true;
// $temporary_arr['type'] = $value['type'];
// $temporary_arr['time'] = $value['unit2'] == '时长'?true:false;
// $temporary_arr['describe'] = $value['unit2'];
// $temporary_arr['unit'] = $value['unit'] == "分/秒"?'': $value['unit'];
// array_push($card_data_c2[$value['acd_id']]['list'],$temporary_arr);
// }else{
// continue;
// }
// }
// $card_data = [
// ['id'=>'2','height'=>true,'weight'=>true,'number'=>false,'time'=>false,'list'=>[]],
// ['id'=>'6','height'=>false,'weight'=>false,'number'=>true,'time'=>true,'list'=>[]],
// ];
// foreach ($card_data_c2 as $key => $value) {
// array_push($card_data,$value);
// }
// 成功
return $this -> msg ( $card_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 manual_record (){
$data = input ( 'post.' );
try {
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'token' , $data ) || ! array_key_exists ( 'type' , $data ) || ! array_key_exists ( 'data' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 , 'aud_id type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'type' ], 'str' )){
return $this -> msg ( 10005 , 'type type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 , 'token type error' );
}
if ( ! is_array ( $data [ 'data' ])) {
return $this -> msg ( 10005 , 'data type error' );
}
// $data = [
// 'aud_id' => '61',
// 'type' => 'skip',
// 'data' => [
// [
// 'name' => '日期',
// 'key_word' => 'r_time',
// 'type' => 'date',
// 'unit' => '',
// 'value' => '2026-03-18',
// ],
// [
// 'name' => '时长',
// 'key_word' => 'time_m_s',
// 'type' => 'multiSelector',
// 'unit' => '',
// 'value' => '01:00',
// ],
// [
// 'name' => '数量',
// 'key_word' => 'num',
// 'type' => 'number',
// 'unit' => '个',
// 'value' => '258',
// ],
// ],
// 'token' => 'caadd1be045a65f30b92aa805f1de54a',
// 'aan_id' => '100',
// ];
if ( $data [ 'type' ] == 'skip' ){ //跳绳
return $this -> manual_record_skip_action ( $data );
} else if ( $data [ 'type' ] == 'vitalcapacity' ){ //肺活
return $this -> manual_record_vitalcapacity_action ( $data );
} else {
return $this -> msg ( 10005 , 'type data error' );
}
} 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 curve_chart (){
$data = input ( 'post.' );
try {
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'token' , $data ) || ! array_key_exists ( 'type' , $data ) || ! array_key_exists ( 'time' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 , 'aud_id type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'time' ], 'datetime' )){
return $this -> msg ( 10005 , 'time type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'type' ], 'str' )){
return $this -> msg ( 10005 , 'type type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 , 'token type error' );
}
if ( $data [ 'type' ] == 'skip' ){ //跳绳
return $this -> curve_chart_skip_action ( $data );
} else if ( $data [ 'type' ] == 'vitalcapacity' ){ //肺活
return $this -> curve_chart_vitalcapacity_action ( $data );
} else {
return $this -> msg ( 10005 , 'type data error' );
}
} 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 record_list_group (){
$data = input ( 'post.' );
try {
if ( ! array_key_exists ( 'token' , $data ) || ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 's_time' , $data ) || ! array_key_exists ( 'e_time' , $data ) || ! array_key_exists ( 'type' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 , 'token type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 , 'aud_id type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 's_time' ], 'datetime' )){
return $this -> msg ( 10005 , 'page type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'e_time' ], 'datetime' )){
return $this -> msg ( 10005 , 'page type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'type' ], 'str' )){
return $this -> msg ( 10005 , 'type type error' );
}
if ( $data [ 'type' ] == 'skip' ){ //跳绳
return $this -> record_list_group_skip_action ( $data , 'group' );
} else if ( $data [ 'type' ] == 'vitalcapacity' ){ //肺活
return $this -> record_list_group_vitalcapacity_action ( $data , 'group' );
} else {
return $this -> msg ( 10005 , 'type data error' );
}
} 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_compare (){
$data = input ( 'post.' );
try {
if ( ! array_key_exists ( 'token' , $data ) || ! array_key_exists ( 'before_id' , $data ) || ! array_key_exists ( 'after_id' , $data ) || ! array_key_exists ( 'type' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 , 'token type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'before_id' ], 'intnum' )){
return $this -> msg ( 10005 , 'before_id type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'after_id' ], 'intnum' )){
return $this -> msg ( 10005 , 'after_id type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'type' ], 'str' )){
return $this -> msg ( 10005 , 'type type error' );
}
if ( $data [ 'type' ] == 'skip' ){ //跳绳
return $this -> data_compare_skip_action ( $data );
} else if ( $data [ 'type' ] == 'vitalcapacity' ){ //肺活
return $this -> data_compare_vitalcapacity_action ( $data );
} else {
return $this -> msg ( 10005 , 'type data error' );
}
} 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 record_list_page (){
$data = input ( 'post.' );
try {
if ( ! array_key_exists ( 'token' , $data ) || ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'page' , $data ) || ! array_key_exists ( 'type' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 , 'token type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'aud_id' ], 'intnum' )){
return $this -> msg ( 10005 , 'aud_id type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'page' ], 'intnum' )){
return $this -> msg ( 10005 , 'page type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'type' ], 'str' )){
return $this -> msg ( 10005 , 'type type error' );
}
if ( $data [ 'type' ] == 'skip' ){ //跳绳
return $this -> record_list_group_skip_action ( $data , 'page' );
} else if ( $data [ 'type' ] == 'vitalcapacity' ){ //肺活
return $this -> record_list_group_vitalcapacity_action ( $data , 'page' );
} else {
return $this -> msg ( 10005 , 'type data error' );
}
} 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 detailed_record (){
$data = input ( 'post.' );
try {
if ( ! array_key_exists ( 'token' , $data ) || ! array_key_exists ( 'id' , $data ) || ! array_key_exists ( 'type' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 , 'token type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'id' ], 'intnum' )){
return $this -> msg ( 10005 , 'id type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'type' ], 'str' )){
return $this -> msg ( 10005 , 'type type error' );
}
if ( $data [ 'type' ] == 'vitalcapacity' ){ //肺活
return $this -> detailed_record_vitalcapacity_action ( $data );
} else {
return $this -> msg ( 10005 , 'type data error' );
}
} 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 del_record (){
try {
$data = input ( 'post.' );
if ( ! array_key_exists ( 'id' , $data ) || ! array_key_exists ( 'token' , $data ) || ! array_key_exists ( 'type' , $data )){
return $this -> msg ( 10001 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'type' ], 'str' )){
return $this -> msg ( 10005 , 'type type error' );
}
unset ( $data [ 'token' ]);
if ( $data [ 'type' ] == 'skip' ){ //跳绳
$user_data = Db :: table ( $this -> card_db_name [ 'skip' ]) -> where ([ 'id' => $data [ 'id' ]]) -> update ([ 'is_del' => 1 ]);
if ( $user_data ){
return $this -> msg ([]);
} else {
return $this -> msg ( 10002 );
}
} else if ( $data [ 'type' ] == 'vitalcapacity' ){ //肺活
$user_data = Db :: table ( $this -> card_db_name [ 'vitalcapacity' ]) -> where ([ 'id' => $data [ 'id' ]]) -> update ([ 'is_del' => 1 ]);
if ( $user_data ){
return $this -> msg ([]);
} else {
return $this -> msg ( 10002 );
}
} else {
return $this -> msg ( 10005 , 'type data error' );
}
} 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 );
}
}
2026-03-06 18:02:49 +08:00
2025-11-21 19:13:01 +08:00
################################################################action################################################################
################################################################action################################################################
2026-03-06 18:02:49 +08:00
public function card_list_all_action ( $data ){
2025-11-21 19:13:01 +08:00
// 检查角色
$user_data = Db :: table ( $this -> card_db_name [ 'juese' ]) -> where ([ 'id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> field ( 'id,card_order' ) -> find ();
if ( ! $user_data ){
return $this -> msg ( 10003 , '未核实到角色信息' );
}
// 获取卡片信息
2026-03-18 18:24:07 +08:00
$card_data = Db :: table ( $this -> card_db_name [ 'card' ]) -> where ([ 'is_del' => 0 ]) -> field ( 'id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word' ) -> select ();
// $card_data = Db::table($this->card_db_name['card'])->where(['is_del'=>0])->field('id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word')->cache(10)->select();
// dump($card_data);
// die;
2025-11-21 19:13:01 +08:00
// 根据用户处理卡片信息
2026-03-18 18:24:07 +08:00
$return_data_title = [
[ 'name' => '对比' , 'icon' => '' , 'page_jump' => " " ],
[ 'name' => '曲线' , 'icon' => '' , 'page_jump' => " " ],
[ 'name' => '添加' , 'icon' => '' , 'page_jump' => " " ],
[ 'name' => '历史' , 'icon' => '' , 'page_jump' => " " ]
];
2025-11-21 19:13:01 +08:00
$return_data = [
2026-03-18 18:24:07 +08:00
'title' => [],
2026-03-16 20:02:09 +08:00
'chosen_fixed' => [
2026-03-18 18:24:07 +08:00
[ 'id' => '20' , 'name' => '中招估分' , 'key_word' => " zz_score " , 'background_color' => '' , 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/report.png' , 'page_jump' => '/pageTwo/score/score' ],
[ 'id' => '21' , 'name' => 'BMI测评' , 'key_word' => " bmi " , 'background_color' => '' , 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/bmi.png' , 'page_jump' => '/pageTwo/bmi/bmi' ],
[ 'id' => '22' , 'name' => '遗传身高' , 'key_word' => " heredity " , 'background_color' => '' , 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/inheritHeighet.png' , 'page_jump' => '/pageTwo/inheritHeighet/inheritHeighet' ],
2026-03-16 20:02:09 +08:00
],
2025-11-21 19:13:01 +08:00
'chosen_yes' => [],
'chosen_no' => [],
];
if ( $user_data [ 'card_order' ] != '' ){
2026-03-06 18:02:49 +08:00
// 如果有设置过
2025-11-21 19:13:01 +08:00
$user_data [ 'card_order' ] = explode ( ',' , $user_data [ 'card_order' ]);
} else {
$user_data [ 'card_order' ] = [];
}
2026-03-18 18:24:07 +08:00
// dump($user_data['card_order']);
// die;
2026-03-06 18:02:49 +08:00
// 对照处理用户的卡片信息
foreach ( $user_data [ 'card_order' ] as $key => $value ) {
foreach ( $card_data as $k => $v ) {
if ( in_array ( $v [ 'id' ], $user_data [ 'card_order' ]) && $v [ 'id' ] == $value ){
2026-03-16 20:02:09 +08:00
if ( $v [ 'id' ] == 20 || $v [ 'id' ] == 21 || $v [ 'id' ] == 22 ){
continue ;
} else {
$return_data [ 'chosen_yes' ][] = $v ;
unset ( $card_data [ $k ]);
}
2026-03-06 18:02:49 +08:00
}
}
}
foreach ( $card_data as $key => $value ) {
$return_data [ 'chosen_no' ][] = $value ;
}
// 剔除不必要的数据
foreach ( $return_data as $key => $value ) {
2026-03-18 18:24:07 +08:00
if ( $key == 'chosen_yes' || $key == 'chosen_no' ){
foreach ( $value as $k => $v ) {
$return_data [ $key ][ $k ][ 'icon' ] = $return_data [ $key ][ $k ][ 'background_pic' ];
unset ( $return_data [ $key ][ $k ][ 'background_pic' ]);
$return_data [ $key ][ $k ][ 'page_jump' ] = $return_data [ $key ][ $k ][ 'page_url_report' ];
unset ( $return_data [ $key ][ $k ][ 'page_url_report' ]);
unset ( $return_data [ $key ][ $k ][ 'content' ]);
unset ( $return_data [ $key ][ $k ][ 'is_sub_item' ]);
unset ( $return_data [ $key ][ $k ][ 'ROW_NUMBER' ]);
}
}
}
foreach ( $return_data [ 'chosen_yes' ] as $key => $value ) {
if ( in_array ( $value [ 'id' ],[ 6 , 8 ])){
$return_data [ 'title' ] = $return_data_title ;
break ;
2025-11-21 19:13:01 +08:00
}
}
2026-03-18 18:24:07 +08:00
2025-11-21 19:13:01 +08:00
return $this -> msg ( $return_data );
}
2026-03-06 18:02:49 +08:00
public function save_card_list_action ( $data ){
// 检查角色
$user_data = Db :: table ( $this -> card_db_name [ 'juese' ]) -> where ([ 'id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> field ( 'id,card_order' ) -> find ();
if ( ! $user_data ){
return $this -> msg ( 10003 , '未核实到角色信息' );
2025-11-21 19:13:01 +08:00
}
2026-03-16 20:02:09 +08:00
2026-03-18 18:24:07 +08:00
if ( $data [ 'card_list' ]){
if ( ! $this -> verify_data_is_ok ( explode ( ',' , $data [ 'card_list' ]), 'arr_intnum' )){
return $this -> msg ( 10005 , 'card_list type error' );
}
// 查一下卡片数据
$card_data = Db :: table ( $this -> card_db_name [ 'card' ]) -> where ( " id in ( " . $data [ 'card_list' ] . " ) " ) -> field ( 'id' ) -> select ();
if ( count ( explode ( ',' , $data [ 'card_list' ])) == count ( $card_data )){
$result = Db :: table ( $this -> card_db_name [ 'juese' ]) -> where ([ 'id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> update ([
'card_order' => $data [ 'card_list' ]
]);
if ( $result ){
return $this -> msg ([]);
} else {
return $this -> msg ( 10002 );
}
} else {
return $this -> msg ( 10003 , '卡片数据错误' );
}
} else {
$result = Db :: table ( $this -> card_db_name [ 'juese' ]) -> where ([ 'id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> update ([ 'card_order' => " " ]);
2026-03-06 18:02:49 +08:00
if ( $result ){
return $this -> msg ([]);
} else {
return $this -> msg ( 10002 );
2025-11-21 19:13:01 +08:00
}
}
2026-03-18 18:24:07 +08:00
2026-03-06 18:02:49 +08:00
}
public function user_card_list_action ( $data ){
// 检查角色
$user_data = Db :: table ( $this -> card_db_name [ 'juese' ]) -> where ([ 'id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> field ( 'id,card_order' ) -> find ();
if ( ! $user_data ){
2025-11-21 19:13:01 +08:00
return $this -> msg ( 10003 , '未核实到角色信息' );
}
2026-03-06 18:02:49 +08:00
if ( $user_data [ 'card_order' ] == '' || $user_data [ 'card_order' ] == '2' ){
// == 2是为了兼容老数据
2025-11-21 19:13:01 +08:00
return $this -> msg ([]);
2026-03-06 18:02:49 +08:00
}
$card_data = Db :: table ( $this -> card_db_name [ 'card' ]) -> where ([ 'is_del' => 0 ]) -> field ( 'id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word' ) -> cache ( 86400 ) -> select ();
// 处理卡片映射
$card_data_map = [];
foreach ( $card_data as $key => $value ) {
$card_data_map [ $value [ 'key_word' ]] = $value ;
}
// 开始处理列表数据
$user_card_list = explode ( ',' , $user_data [ 'card_order' ]);
$return_data = [];
// dump($card_data_map);
// die;
foreach ( $user_card_list as $key => $value ) {
// dump('本次card_id:'.$value);
$temporary_data = $this -> little_tool_one ( $card_data_map , $data [ 'aud_id' ], $value );
// dump('最终结果如下');
// dump($temporary_data);
if ( count ( $temporary_data ) > 0 ){
$return_data [] = $temporary_data ;
}
}
return $this -> msg ( $return_data );
}
public function bmi_evaluation_action ( $data ){
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
if ( ! array_key_exists ( 'code' , $data ) || ! array_key_exists ( 'data' , $data )){
return $this -> msg ( 99999 , '网络异常, 请稍后重试1' );
}
if ( $data [ 'code' ] != 0 ){
return $this -> msg ( 99999 , '网络异常, 请稍后重试2' );
}
if ( ! is_array ( $data [ 'data' ])){
return $this -> msg ( 99999 , '网络异常, 请稍后重试3' );
}
if ( ! array_key_exists ( 'bmi' , $data [ 'data' ]) || ! array_key_exists ( 'bmilevel' , $data [ 'data' ]) || ! array_key_exists ( 'bmilevelcolor' , $data [ 'data' ]) || ! array_key_exists ( 'bmilevellist' , $data [ 'data' ])){
return $this -> msg ( 99999 , '网络异常, 请稍后重试4' );
}
if ( ! is_array ( $data [ 'data' ][ 'bmilevellist' ])){
return $this -> msg ( 99999 , '网络异常, 请稍后重试5' );
}
$num = 0 ;
$subsection_val = 0 ;
$temporary_subsection_val = null ;
foreach ( $data [ 'data' ][ 'bmilevellist' ] as $key => $value ) {
if ( ! array_key_exists ( 'maxvalue' , $value ) || ! array_key_exists ( 'minvalue' , $value )){
return $this -> msg ( 99999 , '网络异常, 请稍后重试6' );
}
// 判断是否可以进行比较,规则是否正确
if ( is_numeric ( $value [ 'maxvalue' ]) && is_numeric ( $value [ 'minvalue' ])){
if ( $data [ 'data' ][ 'bmi' ] >= $value [ 'minvalue' ] && $data [ 'data' ][ 'bmi' ] < $value [ 'maxvalue' ]){
// 在落点内
$subsection_val = bcsub ( $value [ 'maxvalue' ], $value [ 'minvalue' ], 1 ); //获取最大最小值差
$temporary_subsection_val = bcsub ( $data [ 'data' ][ 'bmi' ], $value [ 'minvalue' ], 1 ); //获取当前值与最小值差
$temporary_subsection_val = bcdiv ( $temporary_subsection_val , $subsection_val , 1 ); //获取当前值与最小值差与最大最小值差之比
$subsection_val = bcdiv ( 100 , count ( $data [ 'data' ][ 'bmilevellist' ]), 1 ); //每段应该的百分比
$temporary_subsection_val = bcmul ( $subsection_val , $temporary_subsection_val , 1 ); //获取当前值与最小值差与最大最小值差之比与总段数之比
$temporary_subsection_val = bcadd ( $temporary_subsection_val , bcmul ( $subsection_val , $num , 1 ), 1 );
} else {
$num = $num + 1 ;
}
}
}
if ( $temporary_subsection_val === null ){
if ( $data [ 'data' ][ 'bmi' ] >= $data [ 'data' ][ 'bmilevellist' ][ count ( $data [ 'data' ][ 'bmilevellist' ]) - 1 ][ 'maxvalue' ]){
$temporary_subsection_val = 100 ;
} else {
return $this -> msg ( 99999 , '网络异常, 请稍后重试7' );
}
}
$data [ 'data' ][ 'offset' ] = $temporary_subsection_val ;
$data = $data [ 'data' ];
// 处理key名称一致start
foreach ( $data [ 'bmilevellist' ] as $key => $value ) {
$data [ 'bmilevellist' ][ $key ][ 'max_val' ] = $value [ 'maxvalue' ];
$data [ 'bmilevellist' ][ $key ][ 'min_val' ] = $value [ 'minvalue' ];
unset ( $data [ 'bmilevellist' ][ $key ][ 'minvalue' ]);
unset ( $data [ 'bmilevellist' ][ $key ][ 'maxvalue' ]);
}
// 处理key名称一致end
return $this -> msg ( $data );
}
2026-03-18 18:24:07 +08:00
// 跳绳手动记录
public function manual_record_skip_action ( $data ){
// ['name'=>'日期','key_word'=>'r_time','type'=>'date','unit'=>'','value'=>''],
// ['name'=>'时长','key_word'=>'time_m_s','type'=>'multiSelector','unit'=>'','value'=>''],
// ['name'=>'数量','key_word'=>'num','type'=>'number','unit'=>'个','value'=>''],
$temporary_data = [];
foreach ( $data [ 'data' ] as $key => $value ) {
$temporary_data [ $value [ 'key_word' ]] = $value [ 'value' ];
}
if ( ! array_key_exists ( 'num' , $temporary_data ) || ! array_key_exists ( 'r_time' , $temporary_data ) || ! array_key_exists ( 'time_m_s' , $temporary_data )){
return $this -> msg ( 10001 );
}
$temporary_data [ 'time_m_s' ] = explode ( ':' , $temporary_data [ 'time_m_s' ]);
$data [ 'time_m' ] = ( int ) $temporary_data [ 'time_m_s' ][ 0 ];
$data [ 'time_s' ] = ( int ) $temporary_data [ 'time_m_s' ][ 1 ];
$data [ 'num' ] = ( int ) $temporary_data [ 'num' ];
$data [ 'r_time' ] = $temporary_data [ 'r_time' ];
if ( ! $this -> verify_data_is_ok ( $data [ 'num' ], 'intnum' ) || ! $this -> verify_data_is_ok ( $data [ 'time_m' ], 'intnum_0' ) || ! $this -> verify_data_is_ok ( $data [ 'time_s' ], 'intnum_0' )){
return $this -> msg ( 10005 , '跳绳数量或者分钟、秒钟值必须为整数' );
}
if ( $data [ 'num' ] <= 0 ){
return $this -> msg ( 10005 , '跳绳数不能小于等于0' );
}
if ( abs ( $data [ 'time_m' ]) >= 60 ){
return $this -> msg ( 10005 , '分钟值不能大于60' );
}
if ( abs ( $data [ 'time_s' ]) >= 60 ){
return $this -> msg ( 10005 , '秒钟值不能大于60' );
}
if ( strlen ( $data [ 'r_time' ]) <= 12 ){
// 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
$data [ 'r_time' ] = $this -> addCurrentTimeToDateString ( $data [ 'r_time' ]);
}
// 分秒转换为秒
$data [ 'time' ] = abs ( $data [ 'time_m' ]) * 60 + abs ( $data [ 'time_s' ]);
$user_msg_content = Db :: table ( $this -> card_db_name [ 'juese' ]) -> where ([ 'id' => $data [ 'aud_id' ]]) -> count ();
if ( $user_msg_content <= 0 ){
return $this -> msg ( 10004 );
}
if ( ! array_key_exists ( 'kcal' , $data )){
$last_data_body = Db :: table ( $this -> card_db_name [ 'body_data_new' ]) -> where ([ 'aud_id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> order ( 'record_time desc,id desc' ) -> field ( 'id,weight,record_time' ) -> find ();
if ( ! $last_data_body ){
$last_data_body = Db :: table ( $this -> card_db_name [ 'juese' ]) -> where ([ 'id' => $data [ 'aud_id' ]]) -> field ( 'id,weight' ) -> find ();
if ( ! $last_data_body ){
return $this -> msg ( 10004 );
}
}
$kcal_data = $this -> skip_kcal_calculate ( $data [ 'num' ], $data [ 'time' ], $last_data_body [ 'weight' ]);
} else {
// 将时间从秒转换为分钟
$minutes = bcdiv ( $data [ 'time' ], 60 , 20 );
// 计算每分钟的跳绳次数
$jumpsPerMinute = bcdiv ( $data [ 'num' ], $minutes , 2 );
$kcal_data [ 'totalCalories' ] = $data [ 'kcal' ];
$kcal_data [ 'averageAchievement' ] = $jumpsPerMinute ;
$kcal_data [ 'caloriesPerMinute' ] = bcdiv ( $kcal_data [ 'totalCalories' ], $minutes , 2 );
}
$data_set = [
'create_time' => date ( 'Y-m-d H:i:s' ),
'last_update_time' => date ( 'Y-m-d H:i:s' ),
'jump_num' => $data [ 'num' ],
'jump_time' => $data [ 'time' ],
'jump_kcal' => $kcal_data [ 'totalCalories' ],
'average_num' => $kcal_data [ 'averageAchievement' ],
'average_kcal' => $kcal_data [ 'caloriesPerMinute' ],
'aud_id' => $data [ 'aud_id' ],
'record_time' => array_key_exists ( 'r_time' , $data ) ? $data [ 'r_time' ] : date ( 'Y-m-d H:i:s' ),
'jump_type' => $data [ 'type' ]
];
if ( strlen ( $data_set [ 'record_time' ]) <= 12 ){
$data_set [ 'record_time' ] = $this -> addCurrentTimeToDateString ( $data_set [ 'record_time' ]);
}
$last_data_body = Db :: table ( $this -> card_db_name [ 'skip' ]) -> insert ( $data_set );
$result = [
'today_jump_num' => 0 ,
'today_jump_time' => 0 ,
'today_jump_kcal' => 0 ,
];
$all_data = Db :: table ( $this -> card_db_name [ 'skip' ]) -> where ([ 'aud_id' => $data [ 'aud_id' ]]) -> whereTime ( 'record_time' , 'today' ) -> field ( 'jump_num,jump_time,jump_kcal' ) -> select ();
foreach ( $all_data as $key => $value ) {
$result [ 'today_jump_num' ] = $result [ 'today_jump_num' ] + $value [ 'jump_num' ];
$result [ 'today_jump_time' ] = $result [ 'today_jump_time' ] + $value [ 'jump_time' ];
$result [ 'today_jump_kcal' ] = bcadd ( $result [ 'today_jump_kcal' ], $value [ 'jump_kcal' ], 2 );
}
$result [ 'last_jump_num' ] = $data [ 'num' ];
$result [ 'last_jump_time' ] = $data [ 'time' ];
$result [ 'last_jump_kcal' ] = $data_set [ 'jump_kcal' ];
// $result['last_record_time'] = str_replace('-', '/', $data_set['record_time']);
$result [ 'last_record_time' ] = $data_set [ 'record_time' ];
$time_conversion = $this -> handle_hour_branch_second ( $result [ 'today_jump_time' ]);
$result [ 'today_jump_time' ] = $time_conversion [ 'h' ] . ':' . $time_conversion [ 'm' ] . ':' . $time_conversion [ 's' ];
$time_conversion = $this -> handle_hour_branch_second ( $result [ 'last_jump_time' ]);
$result [ 'last_jump_time' ] = $time_conversion [ 'h' ] . ':' . $time_conversion [ 'm' ] . ':' . $time_conversion [ 's' ];
return $this -> msg ( $result );
}
// 肺活量手动记录
public function manual_record_vitalcapacity_action ( $data ){
$temporary_data = [];
foreach ( $data [ 'data' ] as $key => $value ) {
$temporary_data [ $value [ 'key_word' ]] = $value [ 'value' ];
}
if ( ! array_key_exists ( 'one' , $temporary_data ) || ! array_key_exists ( 'two' , $temporary_data ) || ! array_key_exists ( 'three' , $temporary_data ) || ! array_key_exists ( 'r_time' , $temporary_data )){
return $this -> msg ( 10001 );
}
$data [ 'one' ] = $temporary_data [ 'one' ];
$data [ 'two' ] = $temporary_data [ 'two' ];
$data [ 'three' ] = $temporary_data [ 'three' ];
$data [ 'r_time' ] = $temporary_data [ 'r_time' ];
if ( ! $this -> verify_data_is_ok ( $data [ 'one' ], 'intnum' )){
return $this -> msg ( 10005 , 'one type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'two' ], 'intnum' )){
return $this -> msg ( 10005 , 'two type error' );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'three' ], 'intnum' )){
return $this -> msg ( 10005 , 'three type error' );
}
if ( strlen ( $data [ 'r_time' ]) <= 12 ){
// 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
$data [ 'r_time' ] = $this -> addCurrentTimeToDateString ( $data [ 'r_time' ]);
}
$temporary_arr [ 'aud_id' ] = $data [ 'aud_id' ];
$temporary_arr [ 'record_time' ] = $data [ 'r_time' ];
$temporary_arr [ 'one' ] = $data [ 'one' ];
$temporary_arr [ 'two' ] = $data [ 'two' ];
$temporary_arr [ 'three' ] = $data [ 'three' ];
$temporary_arr [ 'average' ] = bcdiv ( bcadd ( bcadd ( $data [ 'one' ], $data [ 'two' ], 2 ), $data [ 'three' ], 2 ), 3 , 2 );
$temporary_arr [ 'create_time' ] = date ( 'Y-m-d H:i:s' );
$temporary_arr [ 'one_val' ] = $data [ 'one' ];
$temporary_arr [ 'two_val' ] = $data [ 'two' ];
$temporary_arr [ 'three_val' ] = $data [ 'three' ];
$temporary_arr [ 'average_val' ] = $temporary_arr [ 'average' ];
$temporary_arr [ 'flow_val' ] = '0.00' ; //流速
$temporary_arr [ 'record_type' ] = 'by_hand_means' ;
// die;
// 处理记录时间
$user_msg = Db :: name ( $this -> card_db_name [ 'juese' ]) -> where ([ 'id' => $data [ 'aud_id' ]]) -> field ( 'id,grade,gender,birthday' ) -> find ();
// die;
if ( $user_msg ){
// 根据性别&年级&年龄查规则
if ( $user_msg [ 'grade' ] == 'nothing' ){
// 计算年龄判断是属于哪个年级
$user_age = $this -> calculate_age ( $user_msg [ 'birthday' ]);
if ( $user_age <= 7 ){
$user_msg [ 'grade' ] = 'grade_s_1' ;
} else if ( $user_age == 8 ){
$user_msg [ 'grade' ] = 'grade_s_2' ;
} else if ( $user_age == 9 ){
$user_msg [ 'grade' ] = 'grade_s_3' ;
} else if ( $user_age == 10 ){
$user_msg [ 'grade' ] = 'grade_s_4' ;
} else if ( $user_age == 11 ){
$user_msg [ 'grade' ] = 'grade_s_5' ;
} else if ( $user_age == 12 ){
$user_msg [ 'grade' ] = 'grade_s_6' ;
} else if ( $user_age == 13 ){
$user_msg [ 'grade' ] = 'grade_m_1' ;
} else if ( $user_age == 14 ){
$user_msg [ 'grade' ] = 'grade_m_2' ;
} else if ( $user_age == 15 ){
$user_msg [ 'grade' ] = 'grade_m_3' ;
} else if ( $user_age == 16 ){
$user_msg [ 'grade' ] = 'grade_h_1' ;
} else if ( $user_age == 17 ){
$user_msg [ 'grade' ] = 'grade_h_2' ;
} else if ( $user_age == 18 ){
$user_msg [ 'grade' ] = 'grade_h_3' ;
} else if ( $user_age == 19 || $user_age == 20 ){
$user_msg [ 'grade' ] = 'grade_u_12' ;
} else if ( $user_age >= 21 ){
$user_msg [ 'grade' ] = 'grade_u_34' ;
}
}
$sql_str = " sex = " . $user_msg [ 'gender' ] . " and " . $user_msg [ 'grade' ] . " <= " . $temporary_arr [ 'average_val' ];
$user_achievement = Db :: name ( $this -> card_db_name [ 'vitalcapacity_biaozhun' ]) -> where ( $sql_str ) -> order ( $user_msg [ 'grade' ] . ' desc' ) -> field ( 'level,score,' . $user_msg [ 'grade' ]) -> limit ( 1 ) -> cache ( 86400 ) -> select ();
if ( count ( $user_achievement ) <= 0 ){
$user_achievement [ 0 ] = [ 'level' => '无效' , 'score' => '0' ];
}
$temporary_arr [ 'score' ] = $user_achievement [ 0 ][ 'score' ] . ',' . $user_achievement [ 0 ][ 'level' ] . ',' . $this -> vitalcapacity_color [ $user_achievement [ 0 ][ 'level' ]];
$temporary_arr [ 'score_val' ] = $user_achievement [ 0 ][ 'score' ];
} else {
return $this -> msg ( 10004 , '未找到有效数据' );
}
$standard_data = $this -> get_vitalcapacity_data ( $data [ 'aud_id' ]);
$temporary_arr [ 'standard_data' ] = json_encode ( $standard_data );
$result = Db :: table ( $this -> card_db_name [ 'vitalcapacity' ]) -> insert ( $temporary_arr );
if ( $result ){
$time = $result [ 0 ][ 'record_time' ];
$time = strtotime ( $time );
$time = date ( 'Y年m月d日 H:i:s' , $time );
return $this -> msg ([
'average' => $temporary_arr [ 'average' ] . 'ml' ,
'level' => $user_achievement [ 0 ][ 'level' ],
'time' => $time ,
'flow_val' => $temporary_arr [ 'flow_val' ],
'list' => $standard_data ,
'offset' => $this -> vitalcapacity_standard_interval ( $temporary_arr [ 'average' ], $standard_data )
]);
} else {
return $this -> msg ( 10002 );
}
}
// 跳绳曲线
public function curve_chart_skip_action ( $data ){
$audid = $data [ 'aud_id' ];
$timeData = explode ( '-' , $data [ 'time' ]);
// 根据$timeData的长度构建不同的查询条件
$map = [ 'aud_id' => $audid , 'is_del' => 0 ];
switch ( count ( $timeData )) {
case 3 : // 年月日
$map [ 'record_time' ] = [ 'between' , [ date ( 'Y-m-d 00:00:00' , strtotime ( $timeData [ 0 ] . '-' . $timeData [ 1 ] . '-' . $timeData [ 2 ])), date ( 'Y-m-d 23:59:59' , strtotime ( $timeData [ 0 ] . '-' . $timeData [ 1 ] . '-' . $timeData [ 2 ]))]];
break ;
case 2 : // 年月
$map [ 'record_time' ] = [ 'between' , [ date ( 'Y-m-01 00:00:00' , strtotime ( $timeData [ 0 ] . '-' . $timeData [ 1 ])), date ( 'Y-m-t 23:59:59' , strtotime ( $timeData [ 0 ] . '-' . $timeData [ 1 ]))]];
break ;
case 1 : // 年
$map [ 'record_time' ] = [ 'between' , [ date ( 'Y-01-01 00:00:00' , strtotime ( $timeData [ 0 ])), date ( 'Y-12-31 23:59:59' , strtotime ( $timeData [ 0 ]))]];
break ;
default :
return $this -> msg ( 10005 ); // 无效的时间数据格式
}
// 使用查询构造器进行查询
$result = Db :: name ( $this -> card_db_name [ 'skip' ]) -> where ( $map ) -> field ( 'jump_num,jump_time,jump_kcal,aud_id,record_time,jump_type,DATEPART(hour, record_time) AS hour,DATEPART(minute, record_time) AS minute,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month' ) -> order ( 'record_time' ) -> select ();
$return_data = [];
if ( count ( $timeData ) == 3 ){
$key_condition = 'hour' ;
} else if ( count ( $timeData ) == 2 ){
$key_condition = 'day' ;
} else if ( count ( $timeData ) == 1 ){
$key_condition = 'month' ;
}
foreach ( $this -> curve_data_format_skip as $key => $value ) {
$temporary_arr [ 'title' ] = $value [ 0 ] . '(' . $value [ 1 ] . ')' ;
$temporary_arr [ 'key' ] = $key ;
$temporary_arr [ 'line' ][ 'categories' ] = [];
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'color' ] = $value [ 2 ];
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'name' ] = $value [ 0 ] . '(' . $value [ 1 ] . ')' ;
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ] = [];
foreach ( $result as $k => $v ) {
if ( $key_condition == 'hour' ){
// 每一次的记录都添加进去
array_push ( $temporary_arr [ 'line' ][ 'categories' ], $result [ $k ][ 'hour' ] . ':' . $result [ $k ][ 'minute' ]);
array_push ( $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ], $result [ $k ][ $key ]);
} else if ( $key_condition == 'day' ){
// 根据天分组
if ( in_array ( $result [ $k ][ 'month' ] . '/' . $result [ $k ][ $key_condition ], $temporary_arr [ 'line' ][ 'categories' ])){
$num = array_search ( $result [ $k ][ 'month' ] . '/' . $result [ $k ][ $key_condition ], $temporary_arr [ 'line' ][ 'categories' ]);
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] = bcadd ( $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ], $result [ $k ][ $key ], 2 );
} else {
array_push ( $temporary_arr [ 'line' ][ 'categories' ], $result [ $k ][ 'month' ] . '/' . $result [ $k ][ $key_condition ]);
array_push ( $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ], $result [ $k ][ $key ]);
}
} else {
// 根据年分组
if ( in_array ( $result [ $k ][ 'month' ] . '月' , $temporary_arr [ 'line' ][ 'categories' ])){
$num = array_search ( $result [ $k ][ 'month' ] . '月' , $temporary_arr [ 'line' ][ 'categories' ]);
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] = bcadd ( $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ], $result [ $k ][ $key ], 2 );
} else {
array_push ( $temporary_arr [ 'line' ][ 'categories' ], $result [ $k ][ 'month' ] . '月' );
array_push ( $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ], $result [ $k ][ $key ]);
}
}
}
array_push ( $return_data , $temporary_arr );
}
foreach ( $return_data [ 1 ][ 'line' ][ 'series' ][ 0 ][ 'data' ] as $key => $value ) {
$return_data [ 1 ][ 'line' ][ 'series' ][ 0 ][ 'data' ][ $key ] = bcdiv ( $return_data [ 1 ][ 'line' ][ 'series' ][ 0 ][ 'data' ][ $key ], 60 , 2 );
}
return $this -> msg ( $return_data );
}
// 肺活曲线
public function curve_chart_vitalcapacity_action ( $data ){
$audid = $data [ 'aud_id' ];
$timeData = explode ( '-' , $data [ 'time' ]);
// 根据$timeData的长度构建不同的查询条件
$map = [ 'aud_id' => $audid ];
switch ( count ( $timeData )) {
case 3 : // 年月日
$map [ 'record_time' ] = [ 'between' , [ date ( 'Y-m-d 00:00:00' , strtotime ( $timeData [ 0 ] . '-' . $timeData [ 1 ] . '-' . $timeData [ 2 ])), date ( 'Y-m-d 23:59:59' , strtotime ( $timeData [ 0 ] . '-' . $timeData [ 1 ] . '-' . $timeData [ 2 ]))]];
break ;
case 2 : // 年月
$map [ 'record_time' ] = [ 'between' , [ date ( 'Y-m-01 00:00:00' , strtotime ( $timeData [ 0 ] . '-' . $timeData [ 1 ])), date ( 'Y-m-t 23:59:59' , strtotime ( $timeData [ 0 ] . '-' . $timeData [ 1 ]))]];
break ;
case 1 : // 年
$map [ 'record_time' ] = [ 'between' , [ date ( 'Y-01-01 00:00:00' , strtotime ( $timeData [ 0 ])), date ( 'Y-12-31 23:59:59' , strtotime ( $timeData [ 0 ]))]];
break ;
default :
return $this -> msg ( 10005 ); // 无效的时间数据格式
}
// 使用查询构造器进行查询
$result = Db :: name ( $this -> card_db_name [ 'vitalcapacity' ]) -> where ( $map ) -> field ( 'id,one_val,two_val,three_val,average_val,score_val,aud_id,record_time,DATEPART(hour, record_time) AS hour,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month' ) -> order ( 'record_time' ) -> select ();
$return_data = [];
if ( count ( $timeData ) == 3 ){
$key_condition = 'hour' ;
} else if ( count ( $timeData ) == 2 ){
$key_condition = 'day' ;
} else if ( count ( $timeData ) == 1 ){
$key_condition = 'month' ;
}
foreach ( $this -> curve_data_format_vitalcapacity as $key => $value ) {
$temporary_arr [ 'title' ] = $value [ 0 ] . '(' . $value [ 1 ] . ')' ;
$temporary_arr [ 'key' ] = $key ;
$temporary_arr [ 'line' ][ 'categories' ] = [];
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'color' ] = $value [ 2 ];
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'name' ] = $value [ 0 ] . '(' . $value [ 1 ] . ')' ;
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ] = [];
foreach ( $result as $k => $v ) {
if ( $key_condition == 'hour' ){
if ( in_array ( $result [ $k ][ $key_condition ] . '时' , $temporary_arr [ 'line' ][ 'categories' ])){
$num = array_search ( $result [ $k ][ $key_condition ] . '时' , $temporary_arr [ 'line' ][ 'categories' ]);
// $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] = $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] >= $result [ $k ][ $key ] ? $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] : $result [ $k ][ $key ];
} else {
array_push ( $temporary_arr [ 'line' ][ 'categories' ], $result [ $k ][ $key_condition ] . '时' );
array_push ( $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ], $result [ $k ][ $key ]);
}
} else if ( $key_condition == 'day' ){
if ( in_array ( $result [ $k ][ 'month' ] . '-' . $result [ $k ][ $key_condition ], $temporary_arr [ 'line' ][ 'categories' ])){
$num = array_search ( $result [ $k ][ 'month' ] . '-' . $result [ $k ][ $key_condition ], $temporary_arr [ 'line' ][ 'categories' ]);
// $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] = $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] >= $result [ $k ][ $key ] ? $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] : $result [ $k ][ $key ];
} else {
array_push ( $temporary_arr [ 'line' ][ 'categories' ], $result [ $k ][ 'month' ] . '-' . $result [ $k ][ $key_condition ]);
array_push ( $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ], $result [ $k ][ $key ]);
}
} else {
if ( in_array ( $result [ $k ][ 'month' ] . '月' , $temporary_arr [ 'line' ][ 'categories' ])){
$num = array_search ( $result [ $k ][ 'month' ] . '月' , $temporary_arr [ 'line' ][ 'categories' ]);
// $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] = $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] >= $result [ $k ][ $key ] ? $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ][ $num ] : $result [ $k ][ $key ];
} else {
array_push ( $temporary_arr [ 'line' ][ 'categories' ], $result [ $k ][ 'month' ] . '月' );
array_push ( $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ], $result [ $k ][ $key ]);
}
}
}
array_push ( $return_data , $temporary_arr );
}
return $this -> msg ( $return_data );
}
// 跳绳历史
public function record_list_group_skip_action ( $data , $type ){
$return_result = [];
if ( $type == 'group' ){
$data [ 's_time' ] = $data [ 's_time' ] . ' 00:00:00' ;
$data [ 'e_time' ] = $data [ 'e_time' ] . ' 23:59:59' ;
$result = Db :: query ( "
select
id ,
CONVERT ( varchar ( 10 ), record_time , 120 ) AS r_t ,
CONVERT ( varchar ( 19 ), record_time , 120 ) AS record_time ,
jump_num as v1 ,
jump_time as v2 ,
jump_kcal as v3
from " . $this->card_db_name ['skip']. "
where aud_id = '".$data[' aud_id ']."'
and record_time between '".$data[' s_time ']."' and '".$data[' e_time ']."'
and is_del = 0
order by record_time desc " );
foreach ( $result as $key => $value ) {
$time_t = $this -> handle_hour_branch_second ( $value [ 'v2' ]);
array_push ( $return_result , [
'id' => $value [ 'id' ],
'v1' => $value [ 'v1' ],
'v2' => $time_t [ 'h' ] . ':' . $time_t [ 'm' ] . ':' . $time_t [ 's' ],
'v3' => $value [ 'v3' ],
'v1_name' => '个数' ,
'v2_name' => '时长' ,
'v3_name' => '卡路里' ,
// 'r_t'=>str_replace('-', '/', $value['r_t'])
'r_t' => $value [ 'r_t' ]
]);
}
} else {
$result = Db :: table ( $this -> card_db_name [ 'skip' ]) -> where ([ 'aud_id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> field ( " id,record_time,REPLACE(record_time, '-', '-') AS b_time,jump_num,jump_time,jump_kcal " ) -> order ( 'record_time desc' ) -> page ( $data [ 'page' ], $this -> pagesize ) -> select ();
$return_result [ 'totalrows' ] = Db :: table ( $this -> card_db_name [ 'skip' ]) -> where ([ 'aud_id' => $data [ 'aud_id' ]]) -> count ();
$return_result [ 'rows' ] = [];
$return_result [ 'pageno' ] = $data [ 'page' ];
$return_result [ 'pagesize' ] = $this -> pagesize ;
$return_result [ 'totalpage' ] = ceil ( $return_result [ 'totalrows' ] / $this -> pagesize );
foreach ( $result as $key => $value ) {
$time_t = $this -> handle_hour_branch_second ( $value [ 'jump_time' ]);
array_push ( $return_result [ 'rows' ],[
'id' => $value [ 'id' ],
'v1' => $value [ 'jump_num' ],
'v2' => $time_t [ 'h' ] . ':' . $time_t [ 'm' ] . ':' . $time_t [ 's' ],
'v3' => $value [ 'jump_kcal' ],
'v1_name' => '个数' ,
'v2_name' => '时长' ,
'v3_name' => '卡路里' ,
'record_time' => $value [ 'b_time' ],
2026-03-25 17:46:32 +08:00
'is_have_details' => 'no'
2026-03-18 18:24:07 +08:00
]);
}
}
return $this -> msg ( $return_result );
}
// 肺活历史
public function record_list_group_vitalcapacity_action ( $data , $type ){
$return_result = [];
if ( $type == 'group' ){
$data [ 's_time' ] = $data [ 's_time' ] . ' 00:00:00' ;
$data [ 'e_time' ] = $data [ 'e_time' ] . ' 23:59:59' ;
$result = Db :: query ( "
select
id ,
CONVERT ( varchar ( 10 ), record_time , 120 ) AS r_t ,
CONVERT ( varchar ( 19 ), record_time , 120 ) AS record_time ,
one_val as v1 ,
two_val as v2 ,
three_val as v3 ,
average_val as v4 ,
score as v5
from " . $this->card_db_name ['vitalcapacity']. "
where aud_id = '".$data[' aud_id ']."'
and record_time between '".$data[' s_time ']."' and '".$data[' e_time ']."'
and is_del = 0
order by record_time desc " );
foreach ( $result as $key => $value ) {
// $time_t = $this->handle_hour_branch_second($value['v2']);
array_push ( $return_result , [
'id' => $value [ 'id' ],
'v1' => $value [ 'v1' ] == '.00' ? '0' : $value [ 'v1' ],
'v2' => $value [ 'v2' ] == '.00' ? '0' : $value [ 'v2' ],
'v3' => $value [ 'v3' ] == '.00' ? '0' : $value [ 'v3' ],
'v4' => $value [ 'v4' ] == '.00' ? '0' : $value [ 'v4' ],
'v5' => explode ( ',' , $value [ 'v5' ])[ 0 ],
'v1_name' => '第一次' ,
'v2_name' => '第二次' ,
'v3_name' => '第三次' ,
'v4_name' => '平均' ,
'v5_name' => '成绩' ,
// 'r_t'=>str_replace('-', '/', $value['r_t'])
'r_t' => $value [ 'r_t' ]
]);
}
} else {
$result = Db :: table ( $this -> card_db_name [ 'vitalcapacity' ]) -> where ([ 'aud_id' => $data [ 'aud_id' ], 'is_del' => 0 ]) -> field ( " id,record_time,REPLACE(record_time, '-', '-') AS b_time,one_val,two_val,three_val,average_val,score " ) -> order ( 'record_time desc' ) -> page ( $data [ 'page' ], $this -> pagesize ) -> select ();
$return_result [ 'totalrows' ] = Db :: table ( $this -> card_db_name [ 'vitalcapacity' ]) -> where ([ 'aud_id' => $data [ 'aud_id' ]]) -> count ();
$return_result [ 'rows' ] = [];
$return_result [ 'pageno' ] = $data [ 'page' ];
$return_result [ 'pagesize' ] = $this -> pagesize ;
$return_result [ 'totalpage' ] = ceil ( $return_result [ 'totalrows' ] / $this -> pagesize );
foreach ( $result as $key => $value ) {
// $time_t = $this->handle_hour_branch_second($value['jump_time']);
array_push ( $return_result [ 'rows' ],[
'id' => $value [ 'id' ],
'v1' => $value [ 'one_val' ] == '.00' ? '0' : $value [ 'one_val' ],
'v2' => $value [ 'two_val' ] == '.00' ? '0' : $value [ 'two_val' ],
'v3' => $value [ 'three_val' ] == '.00' ? '0' : $value [ 'three_val' ],
'v4' => $value [ 'average_val' ] == '.00' ? '0' : $value [ 'average_val' ],
'v5' => explode ( ',' , $value [ 'score' ])[ 0 ],
'v1_name' => '第一次' ,
'v2_name' => '第二次' ,
'v3_name' => '第三次' ,
'v4_name' => '平均' ,
'v5_name' => '成绩' ,
2026-03-25 17:46:32 +08:00
'record_time' => $value [ 'b_time' ],
'is_have_details' => 'yes'
2026-03-18 18:24:07 +08:00
]);
}
}
return $this -> msg ( $return_result );
}
// 数据对比
public function data_compare_skip_action ( $data ){
$data2 = [ $data [ 'before_id' ], $data [ 'after_id' ]];
$data3 = implode ( ',' , $data2 );
$calculate_arr = [];
$result = Db :: query ( "
select
acsd . id ,
acsd . jump_num ,
acsd . jump_time ,
acsd . jump_kcal ,
acsd . record_time ,
REPLACE ( CONVERT ( varchar ( 10 ), acsd . record_time , 23 ), '-' , '-' ) AS b_time ,
aud . nickname ,
aud . gender ,
aud . birthday ,
aud . head_pic
from " . $this->card_db_name ['skip']. " as acsd
left join " . $this->card_db_name ['juese']. " as aud on acsd . aud_id = aud . id
where acsd . id in ( $data3 )
and acsd . is_del = 0
" );
if ( ! $result || count ( $result ) < 2 ){
return $this -> msg ( 10004 );
}
// 调整顺序
foreach ( $result as $key => $value ) {
if ( $value [ 'id' ] == $data2 [ 0 ]){
$calculate_arr [ 'before' ] = $value ;
} else {
$calculate_arr [ 'after' ] = $value ;
}
}
$return_data [ 'time' ] = $calculate_arr [ 'before' ][ 'b_time' ] . '-' . $calculate_arr [ 'after' ][ 'b_time' ];
$return_data [ 'headimg' ] = $calculate_arr [ 'before' ][ 'head_pic' ];
$return_data [ 'name' ] = $calculate_arr [ 'before' ][ 'nickname' ];
$return_data [ 'gender' ] = $calculate_arr [ 'before' ][ 'gender' ];
$return_data [ 'age' ] = $this -> calculate_age ( $calculate_arr [ 'before' ][ 'birthday' ]);
$return_data [ 'day' ] = abs ( $this -> daysSince ( $calculate_arr [ 'before' ][ 'record_time' ], $calculate_arr [ 'after' ][ 'record_time' ]));
$return_data [ 'list' ] = [];
$request_result = [ 'jump_num' => [ '个数' , '' ], 'jump_time' => [ '时长' , '' ], 'jump_kcal' => [ '卡路里' , 'kcal' ]];
foreach ( $calculate_arr [ 'before' ] as $key => $value ) {
if ( in_array ( $key , [ 'jump_num' , 'jump_time' , 'jump_kcal' ])){
$before_arr = $value ;
$after_arr = $calculate_arr [ 'after' ][ $key ];
$temporary_arr = [
'firstresult' => [
'color' => '' ,
'level' => '' ,
'value' => $key == 'jump_time' ? implode ( ':' , $this -> handle_hour_branch_second ( $before_arr )) : $before_arr ,
'title' => $request_result [ $key ][ 0 ],
'unit' => $request_result [ $key ][ 1 ],
'name' => $key ,
],
'secondresult' => [
'color' => '' ,
'level' => '' ,
'value' => $key == 'jump_time' ? implode ( ':' , $this -> handle_hour_branch_second ( $after_arr )) : $after_arr ,
'title' => $request_result [ $key ][ 0 ],
'unit' => $request_result [ $key ][ 1 ],
'name' => $key ,
],
'diffval' => bcsub ( $after_arr , $before_arr , 2 )
];
if ( $key == 'jump_time' ){
$temporary_arr [ 'diffval' ] = $temporary_arr [ 'diffval' ] >= 0 ? implode ( ':' , $this -> handle_hour_branch_second ( $temporary_arr [ 'diffval' ])) : '-' . implode ( ':' , $this -> handle_hour_branch_second ( $temporary_arr [ 'diffval' ]));
}
array_push ( $return_data [ 'list' ], $temporary_arr );
}
}
return $this -> msg ( $return_data );
}
// 数据对比
public function data_compare_vitalcapacity_action ( $data ){
$data2 = [ $data [ 'before_id' ], $data [ 'after_id' ]];
$data3 = implode ( ',' , $data2 );
$calculate_arr = [];
$result = Db :: query ( "
select
acsd . id ,
acsd . one_val ,
acsd . two_val ,
acsd . three_val ,
acsd . average_val ,
acsd . score_val as score ,
acsd . record_time ,
REPLACE ( CONVERT ( varchar ( 10 ), acsd . record_time , 23 ), '-' , '-' ) AS b_time ,
aud . nickname ,
aud . gender ,
aud . birthday ,
aud . head_pic
from " . $this->card_db_name ['vitalcapacity']. " as acsd
left join " . $this->card_db_name ['juese']. " as aud on acsd . aud_id = aud . id
where acsd . id in ( $data3 )
and acsd . is_del = 0
" );
if ( ! $result || count ( $result ) < 2 ){
return $this -> msg ( 10004 );
}
// 调整顺序
foreach ( $result as $key => $value ) {
if ( $value [ 'id' ] == $data2 [ 0 ]){
$calculate_arr [ 'before' ] = $value ;
} else {
$calculate_arr [ 'after' ] = $value ;
}
}
$return_data [ 'time' ] = $calculate_arr [ 'before' ][ 'b_time' ] . '-' . $calculate_arr [ 'after' ][ 'b_time' ];
$return_data [ 'headimg' ] = $calculate_arr [ 'before' ][ 'head_pic' ];
$return_data [ 'name' ] = $calculate_arr [ 'before' ][ 'nickname' ];
$return_data [ 'gender' ] = $calculate_arr [ 'before' ][ 'gender' ];
$return_data [ 'age' ] = $this -> calculate_age ( $calculate_arr [ 'before' ][ 'birthday' ]);
$return_data [ 'day' ] = abs ( $this -> daysSince ( $calculate_arr [ 'before' ][ 'record_time' ], $calculate_arr [ 'after' ][ 'record_time' ]));
$return_data [ 'list' ] = [];
$request_result = [ 'one_val' => [ '第一次' , 'ml' ], 'two_val' => [ '第二次' , 'ml' ], 'three_val' => [ '第三次' , 'ml' ], 'average_val' => [ '三次平均' , 'ml' ], 'score' => [ '最后成绩' , '分' ]];
foreach ( $calculate_arr [ 'before' ] as $key => $value ) {
if ( in_array ( $key , [ 'one_val' , 'two_val' , 'three_val' , 'average_val' , 'score_val' ])){
$before_arr = $value ;
$after_arr = $calculate_arr [ 'after' ][ $key ];
$temporary_arr = [
'firstresult' => [
'color' => '' ,
'level' => '' ,
'value' => $before_arr ,
'title' => $request_result [ $key ][ 0 ],
'unit' => $request_result [ $key ][ 1 ],
'name' => $key ,
],
'secondresult' => [
'color' => '' ,
'level' => '' ,
'value' => $after_arr ,
'title' => $request_result [ $key ][ 0 ],
'unit' => $request_result [ $key ][ 1 ],
'name' => $key ,
],
'diffval' => bcsub ( $after_arr , $before_arr , 2 )
];
array_push ( $return_data [ 'list' ], $temporary_arr );
}
}
return $this -> msg ( $return_data );
}
// 历史详情(肺活)
public function detailed_record_vitalcapacity_action ( $data ){
$result = $result = Db :: table ( $this -> card_db_name [ 'vitalcapacity' ]) -> where ([ 'id' => $data [ 'id' ], 'is_del' => 0 ]) -> find ();
$for_data_arr = [ 'one_val' => [ '第一次' , 'ml' ], 'two_val' => [ '第二次' , 'ml' ], 'three_val' => [ '第三次' , 'ml' ], 'average_val' => [ '三次平均' , 'ml' ], 'score' => [ '最后成绩' , '分' ]];
if ( $result ){
$result_data = [];
foreach ( $for_data_arr as $key => $value ) {
$temporary_arr [ 'key_name' ] = $key ;
$temporary_arr [ 'name' ] = $value [ 0 ];
$temporary_arr [ 'value' ] = explode ( ',' , $result [ $key ])[ 0 ];
$temporary_arr [ 'unit' ] = $value [ 1 ];
array_push ( $result_data , $temporary_arr );
}
return $this -> msg ( $result_data );
} else {
return $this -> msg ( 10002 );
}
}
2026-03-06 18:02:49 +08:00
################################################################小工具################################################################
################################################################小工具################################################################
public function little_tool_one ( $data , $aud_id , $type ){
$result = $this -> card_standard_arr_data ;
if ( $type == 6 ){
if ( ! array_key_exists ( 'skip' , $data )){
// 如果系统已经停用了跳绳
return [];
}
$temporary_data = $data [ 'skip' ];
$all_data = Db :: table ( $this -> card_db_name [ 'skip' ]) -> where ([ 'aud_id' => $aud_id , 'is_del' => 0 ]) -> order ( 'id desc' ) -> field ( 'id,jump_kcal as val_data' ) -> find ();
$result [ 'data' ][ 'unit' ] = 'kcal' ;
} else if ( $type == 8 ){
if ( ! array_key_exists ( 'vitalcapacity' , $data )){
// 如果系统已经停用了肺活
return [];
}
$temporary_data = $data [ 'skip' ];
$all_data = Db :: table ( $this -> card_db_name [ 'vitalcapacity' ]) -> where ([ 'aud_id' => $aud_id , 'is_del' => 0 ]) -> order ( 'id desc' ) -> field ( 'id,score_val as val_data' ) -> find ();
$result [ 'data' ][ 'unit' ] = '分' ;
} else if ( $type == 20 ){
if ( ! array_key_exists ( 'zz_score' , $data )){
// 如果系统已经停用了中招估分
return [];
}
$temporary_data = $data [ 'skip' ];
$all_data = Db :: table ( $this -> card_db_name [ 'zhongzhao' ]) -> where ([ 'aud_id' => $aud_id , 'is_del' => 0 ]) -> order ( 'id desc' ) -> field ( 'id,score as val_data' ) -> find ();
$result [ 'data' ][ 'unit' ] = '分' ;
} else if ( $type == 21 || $type == 22 || $type == 25 || $type == 26 ){
if ( ! array_key_exists ( 'bmi' , $data ) || ! array_key_exists ( 'heredity' , $data ) || ! array_key_exists ( 'fat_loss' , $data ) || ! array_key_exists ( 'target' , $data )){
// 如果系统已经停用了BMI测评、遗传身高、减脂对比、曲线/目标、
return [];
}
$map = [ '21' => 'bmi' , '22' => 'heredity' , '25' => 'fat_loss' , '26' => 'target' ];
$temporary_data = $data [ $map [ $type ]];
$all_data = [ 'val_data' => '' ];
$result [ 'data' ][ 'unit' ] = '' ;
2025-11-21 19:13:01 +08:00
} else {
2026-03-06 18:02:49 +08:00
return [];
2025-11-21 19:13:01 +08:00
}
2026-03-06 18:02:49 +08:00
if ( $all_data ){
$result [ 'id' ] = $temporary_data [ 'id' ];
$result [ 'name' ] = $temporary_data [ 'name' ];
$result [ 'content' ] = $temporary_data [ 'content' ];
$result [ 'page_url_report' ] = $temporary_data [ 'page_url_report' ];
$result [ 'is_sub_item' ] = $temporary_data [ 'is_sub_item' ];
$result [ 'background_color' ] = $temporary_data [ 'background_color' ];
$result [ 'background_pic' ] = $temporary_data [ 'background_pic' ];
$result [ 'key_word' ] = $temporary_data [ 'key_word' ];
2025-11-21 19:13:01 +08:00
2026-03-06 18:02:49 +08:00
$result [ 'data' ][ 'value' ] = $all_data [ 'val_data' ];
return $result ;
} else {
return [];
}
2025-11-21 19:13:01 +08:00
}
2026-03-18 18:24:07 +08:00
// 跳绳卡路里计算
public function skip_kcal_calculate ( $num = 143 , $time = 222 , $weight = 70 ) {
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 将时间从秒转换为分钟
$minutes = bcdiv ( $time , 60 , 20 );
// 计算每分钟的跳绳次数
$jumpsPerMinute = bcdiv ( $num , $minutes , 2 );
// 根据跳绳次数确定MET值
// $met = 11.8;
if ( $jumpsPerMinute < 100 ) {
$met = 8.8 ;
} else if ( $jumpsPerMinute >= 100 && $jumpsPerMinute < 120 ) {
$met = 11.8 ;
} else {
$met = 12.3 ;
}
// 计算每分钟燃烧的卡路里
$caloriesPerMinute = bcdiv ( bcmul ( bcmul ( $met , $weight , 20 ), 3.5 , 20 ), 200 , 2 );
// 计算总卡路里消耗
$totalCalories = bcmul ( $caloriesPerMinute , $minutes , 2 );
// 返回结果
return [
'averageAchievement' => $jumpsPerMinute ,
'caloriesPerMinute' => $caloriesPerMinute ,
'totalCalories' => $totalCalories
];
}
// 肺活量判断区间
public function vitalcapacity_standard_interval ( $val , $data ){
// 缓存一周
$result = '' ;
if ( ! $data || count ( $data ) <= 0 ){
return $result ;
}
$temporary_qj = $data ;
$max = 0 ;
$min = 0 ;
$num = 0 ;
foreach ( $temporary_qj as $key => $value ) {
if ( $val >= $value [ 'min_val' ] && $val <= $value [ 'max_val' ]){
$max = $value [ 'max_val' ];
$min = $value [ 'min_val' ];
$num = $key ;
break ;
}
}
$num = count ( $temporary_qj ) - 1 - $num ;
if ( $max == 0 ){
if ( $val >= $temporary_qj [ 0 ][ 'max_val' ]){
$result = 100 ;
}
} else {
$temporary_num = bcmul ( bcdiv ( bcsub ( $val , $min , 20 ), bcsub ( $max , $min , 20 ), 2 ), bcdiv ( 100 , count ( $temporary_qj ), 2 ), 2 );
$result = bcadd ( bcmul ( bcdiv ( 100 , count ( $temporary_qj ), 2 ), $num , 2 ), $temporary_num , 2 );
}
return $result ;
}
2025-11-21 19:13:01 +08:00
2026-03-06 18:02:49 +08:00
2025-11-21 19:13:01 +08:00
}