2025-10-11 18:11:41 +08:00
< ? php
namespace app\NewReedaw\controller\app ;
2025-11-21 19:13:01 +08:00
2025-10-11 18:11:41 +08:00
use think\Db ;
use think\Cache ;
use think\Log ;
use PHPMailer\PHPMailer\PHPMailer ;
use app\NewReedaw\controller\app\Role ;
2025-11-21 19:13:01 +08:00
use app\app\controller\Language ;
2025-10-11 18:11:41 +08:00
class Index extends Base {
protected $index_db_name = [
'zhanghao' => 'app_account_number' ,
'juese' => 'app_user_data' ,
'body_data' => 'app_card_body_data' ,
2025-11-21 19:13:01 +08:00
'banben' => 'app_version_log' ,
'shangwuhezuo' => 'admin_business_cooperation' ,
'diqu' => 'admin_estimate' ,
'banner' => 'admin_notice_banner' ,
'skip' => 'app_card_skip_data' ,
'vitalcapacity' => 'app_card_vitalcapacity_data' ,
];
protected $request_result = [
'2' => [ 'height' => [ '身高' , 'cm' ], 'weight' => [ '体重' , 'kg' ], 'age' => [ '年龄' , '岁' ], 'bmi' => [ 'BMI' , '' ], 'head' => [ '头围' , '' ], 'fat_w' => [ '脂肪量' , 'kg' ], 'fat_r' => [ '脂肪率' , '%' ], 'muscleval' => [ '肌肉量' , 'kg' ], 'muscle' => [ '肌肉率' , '%' ], 'proteinval' => [ '蛋白量' , 'kg' ], 'protein' => [ '蛋白率' , '%' ], 'water' => [ '水分' , '' ], 'bone' => [ '骨重' , 'kg' ], 'visceral' => [ '内脏指数' , '' ], 'sfr' => [ '皮下脂肪' , '%' ], 'kcal' => [ '基础代谢' , 'kcal' ], 'un_fat_w_weight' => [ '去脂体重' , 'kg' ], 'body_age' => [ '体龄' , '' ], 'body_level' => [ '肥胖等级' , '' ], 'body_type' => [ '体型' , '' ]],
'6' => [ 'jump_num' => [ '个数' , '' ], 'jump_time' => [ '时长' , '' ], 'jump_kcal' => [ '卡路里' , 'kcal' ]],
'8' => [ 'one_val' => [ '第一次' , 'ml' ], 'two_val' => [ '第二次' , 'ml' ], 'three_val' => [ '第三次' , 'ml' ], 'average_val' => [ '三次平均' , 'ml' ], 'score' => [ '最后成绩' , '分' ]]
];
protected $identity_list = [ 'P0' => '陌生人' , 'P1' => '爸爸' , 'P2' => '妈妈' , 'P3' => '大宝' , 'P4' => '二宝' , 'P5' => '三宝' , 'P6' => '四宝' , 'P7' => '爷爷' , 'P8' => '奶奶' ];
protected $grade_list = [
[ 'id' => 'nothing' , 'name' => '无' ],
[ 'id' => 'grade_s_1' , 'name' => '小学一年级' ],
[ 'id' => 'grade_s_2' , 'name' => '小学二年级' ],
[ 'id' => 'grade_s_3' , 'name' => '小学三年级' ],
[ 'id' => 'grade_s_4' , 'name' => '小学四年级' ],
[ 'id' => 'grade_s_5' , 'name' => '小学五年级' ],
[ 'id' => 'grade_s_6' , 'name' => '小学六年级' ],
[ 'id' => 'grade_m_1' , 'name' => '初中一年级' ],
[ 'id' => 'grade_m_2' , 'name' => '初中二年级' ],
[ 'id' => 'grade_m_3' , 'name' => '初中三年级' ],
[ 'id' => 'grade_h_1' , 'name' => '高中一年级' ],
[ 'id' => 'grade_h_2' , 'name' => '高中二年级' ],
[ 'id' => 'grade_h_3' , 'name' => '高中三年级' ],
[ 'id' => 'grade_u_12' , 'name' => '大学一、二年级' ],
[ 'id' => 'grade_u_34' , 'name' => '大学三、四年级' ]
];
protected $language_country = [
'en' => 'English' , // 英语(通用)★
'zh-Hans' => '中文' , // 中文(简体)★
// 'es' => 'Español', // 西班牙语(西班牙)★
// 'fr' => 'Français', // 法语(法国)★
// 'pt' => 'Português', // 葡萄牙语(巴西)★
// 'ar' => 'العربية', // 阿拉伯语(标准)★
// 'ru' => 'Русский', // 俄语(俄罗斯)★
// 'de' => 'Deutsch', // 德语(德国)★
// 'ja' => '日本語', // 日语
// 'ko' => '한국어', // 韩语
// 'it' => 'Italiano', // 意大利语
// 'nl' => 'Nederlands', // 荷兰语
// 'hi' => 'हिन्दी', // 印地语
// 'tr' => 'Türkçe', // 土耳其语
// 'vi' => 'Tiếng Việt', // 越南语
// 'th' => 'ไทย', // 泰语
// 'pl' => 'Polski', // 波兰语
// 'sv' => 'Svenska', // 瑞典语
// 'fi' => 'Suomi', // 芬兰语
// 'da' => 'Dansk', // 丹麦语
// 'no' => 'Norsk', // 挪威语
// 'he' => 'עברית', // 希伯来语
// 'id' => 'Bahasa Indonesia', // 印尼语
// 'ms' => 'Bahasa Melayu', // 马来语
// 'cs' => 'Čeština', // 捷克语
// 'hu' => 'Magyar', // 匈牙利语
// 'el' => 'Ελληνικά', // 希腊语
// 'ro' => 'Română', // 罗马尼亚语
// 'sk' => 'Slovenčina', // 斯洛伐克语
// 'uk' => 'Українська', // 乌克兰语
2025-10-11 18:11:41 +08:00
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 配置信息
public function config ( $data = [ 'token' => 'caadd1be045a65f30b92aa805f1de54a' ]){
try {
2025-11-21 19:13:01 +08:00
$data = input ( 'post.' );
2025-10-11 18:11:41 +08:00
return $this -> config_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 );
}
}
2025-11-21 19:13:01 +08:00
// 身高预测
2025-10-13 03:35:56 +08:00
public function genetic_height (){
try {
$data = input ( 'post.' );
2025-11-21 19:13:01 +08:00
if ( ! is_array ( $data )){
return $this -> msg ( 10005 );
}
2025-10-13 03:35:56 +08:00
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 );
}
unset ( $data [ 'token' ]);
if ( ! $this -> verify_data_is_ok ( $data [ 'birthday' ], 'datetime' )){
2025-11-21 19:13:01 +08:00
return $this -> msg ( 10005 , 'birthday type error' );
2025-10-13 03:35:56 +08:00
}
if ( ! $this -> verify_data_is_ok ( $data [ 'dadHeight' ], 'num' )){
2025-11-21 19:13:01 +08:00
return $this -> msg ( 10005 , 'dadHeight type error' );
2025-10-13 03:35:56 +08:00
}
if ( ! $this -> verify_data_is_ok ( $data [ 'momHeight' ], 'num' )){
2025-11-21 19:13:01 +08:00
return $this -> msg ( 10005 , 'momHeight type error' );
2025-10-13 03:35:56 +08:00
}
if ( ! $this -> verify_data_is_ok ( $data [ 'sex' ], 'intnum' )){
2025-11-21 19:13:01 +08:00
return $this -> msg ( 10005 , 'sex type error' );
2025-10-13 03:35:56 +08:00
}
// 直接开始业务, 请求外部接口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 );
}
}
2025-11-21 19:13:01 +08:00
2025-10-13 03:35:56 +08:00
// BMI测评
public function bmi_evaluation (){
try {
2025-11-21 19:13:01 +08:00
$cbe_data = input ( 'post.' );
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 )){
2025-10-13 03:35:56 +08:00
return $this -> msg ( 10001 );
}
2025-11-21 19:13:01 +08:00
unset ( $cbe_data [ 'token' ]);
if ( ! $this -> verify_data_is_ok ( $cbe_data [ 'birthday' ], 'datetime' )){
return $this -> msg ( 10005 , 'birthday type error' );
2025-10-13 03:35:56 +08:00
}
2025-11-21 19:13:01 +08:00
if ( ! $this -> verify_data_is_ok ( $cbe_data [ 'height' ], 'num' )){
return $this -> msg ( 10005 , 'height type error' );
2025-10-13 03:35:56 +08:00
}
2025-11-21 19:13:01 +08:00
if ( ! $this -> verify_data_is_ok ( $cbe_data [ 'weight' ], 'num' )){
return $this -> msg ( 10005 , 'weight type error' );
2025-10-13 03:35:56 +08:00
}
2025-11-21 19:13:01 +08:00
if ( ! $this -> verify_data_is_ok ( $cbe_data [ 'sex' ], 'intnum' )){
return $this -> msg ( 10005 , 'sex type error' );
2025-10-13 03:35:56 +08:00
}
// 直接开始业务, 请求外部接口start
$url = 'http://ybdevice.pcxbc.com/api/result/calcbmi' ;
$temporary_parameter = [
2025-11-21 19:13:01 +08:00
'height' => $cbe_data [ 'height' ],
'weight' => $cbe_data [ 'weight' ],
'birthday' => $cbe_data [ 'birthday' ],
'sex' => $cbe_data [ 'sex' ],
2025-10-13 03:35:56 +08:00
];
$request_result = $this -> postRequest ( $url , $temporary_parameter , array ( 'Content-Type:application/json' , 'Origin:http://ybdevice.pcxbc.com' ));
// 直接开始业务, 请求外部接口end
// 处理进度点
2025-11-21 19:13:01 +08:00
$request_result = $this -> bmi_evaluation_action ( $request_result );
return $request_result ;
2025-10-13 03:35:56 +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 " ;
2025-11-21 19:13:01 +08:00
$this -> record_api_log ( $cbe_data , $logContent , null );
2025-10-13 03:35:56 +08:00
return $this -> msg ( 99999 );
}
}
2025-11-21 19:13:01 +08:00
// 数据对比(包含身体、跳绳、肺活量)
public function all_data_contrast ( $data = [ 'before_id' => '171' , 'after_id' => '174' , 'type' => '2' , 'token' => 'caadd1be045a65f30b92aa805f1de54a' ]){
2025-10-11 18:11:41 +08:00
try {
$data = input ( 'post.' );
2025-11-21 19:13:01 +08:00
if ( ! array_key_exists ( 'before_id' , $data ) || ! array_key_exists ( 'after_id' , $data ) || ! array_key_exists ( 'type' , $data ) || ! array_key_exists ( 'token' , $data )){
2025-10-11 18:11:41 +08:00
return $this -> msg ( 10001 );
}
2025-11-21 19:13:01 +08:00
if ( ! $this -> verify_data_is_ok ( $data [ 'before_id' ], 'intnum' )){
return $this -> msg ( 10005 );
2025-10-11 18:11:41 +08:00
}
2025-11-21 19:13:01 +08:00
if ( ! $this -> verify_data_is_ok ( $data [ 'after_id' ], 'intnum' )){
return $this -> msg ( 10005 );
}
if ( ! $this -> verify_data_is_ok ( $data [ 'type' ], 'intnum' )){
return $this -> msg ( 10005 );
}
unset ( $data [ 'token' ]);
if ( $data [ 'type' ] == '2' ){
return $this -> get_body_data_contrast ( $data );
} else if ( $data [ 'type' ] == '6' ){
return $this -> get_skip_data_contrast ( $data );
} else if ( $data [ 'type' ] == '8' ){
return $this -> get_vitalcapacity_data_contrast ( $data );
2025-10-11 18:11:41 +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 );
}
2025-11-21 19:13:01 +08:00
2025-10-11 18:11:41 +08:00
}
2025-11-21 19:13:01 +08:00
// // 获取首页角色信息
// public function get_user_data_information(){
// try {
// $data = input('post.');
// 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->get_user_data_information_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);
// }
// }
2025-10-11 18:11:41 +08:00
################################################################action################################################################
################################################################action################################################################
public function config_action ( $data ){
$return_data = [
'literature' => [
'index' => [
'*数据参考:' ,
'《中华人民共和国卫生行业标准WS/T 423-2022》' ,
'《中华人民共和国卫生行业标准WS/T 612-2018》' ,
'《中华人民共和国卫生行业标准WS/T 586-2018》' ,
'《WHO 5~19岁身高/体重判定标准》' ,
],
'bmi_evaluation' => [
'*数据参考:' ,
'《WHO 5~19岁身高/体重判定标准》'
],
'height_prediction' => [
'*数据参考:' ,
'Khamis-Roche方法' ,
'北京积水潭医院儿科临床参考公式' ,
'《中国妇幼保健》等相关学术期刊文献' ,
],
'warning' => [
'此测量数据仅供参考,不可替代医学专业测试!'
]
],
'king_kong_region' => [
2025-11-21 19:13:01 +08:00
[ 'title' => '减值对比' , 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/contrast.png' , 'jump' => '/pageTwo/compk/contrast' ],
[ 'title' => '中招估分' , 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/report.png' , 'jump' => '/pageTwo/score/report' ],
[ 'title' => '遗传身高' , 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/inheritHeighet.png' , 'jump' => '/pageTwo/home/inheritHeighet' ],
[ 'title' => 'BMI测评' , 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/bmi.png' , 'jump' => '/pageTwo/home/bmi' ],
2025-10-11 18:11:41 +08:00
],
2025-11-21 19:13:01 +08:00
'version_msg' => [],
'login_status' => [],
'business_cooperation_url' => [],
'area_list' => [],
'identity_list' => [],
'grade_list' => [],
'banner' => [],
2025-10-11 18:11:41 +08:00
];
2025-11-21 19:13:01 +08:00
$temporary = $this -> login_invalid_version ( $data );
$return_data [ 'version_msg' ] = $temporary [ 1 ];
$return_data [ 'login_status' ] = $temporary [ 0 ];
$return_data [ 'business_cooperation_url' ] = Db :: table ( $this -> index_db_name [ 'shangwuhezuo' ]) -> where ([ 'is_del' => 0 ]) -> field ( 'title,data_url as url' ) -> select ();
$address_data = Db :: table ( $this -> index_db_name [ 'diqu' ]) -> where ([ 'type' => '2' ]) -> cache ( 86400 ) -> field ( 'id,content,city,area' ) -> find ();
$return_data [ 'area_list' ] = json_decode ( $address_data [ 'content' ], true );
$return_data [ 'identity_list' ] = [];
foreach ( $this -> identity_list as $key => $value ) {
array_push ( $return_data [ 'identity_list' ],[ 'id' => $key , 'name' => $value ]);
}
$return_data [ 'grade_list' ] = $this -> grade_list ;
$return_data [ 'banner' ] = Db :: table ( $this -> index_db_name [ 'banner' ]) -> where ([ 'scene_data' => '3' , 'is_del' => 0 ]) -> cache ( 3600 ) -> order ( 'sort_num desc' ) -> field ( 'id,type,pic,jump_url,parameter_data,sort_num' ) -> select ();
for ( $i = 0 ; $i < count ( $return_data [ 'banner' ]); $i ++ ) {
if ( $return_data [ 'banner' ][ $i ][ 'type' ] != 1 ){
$return_data [ 'banner' ][ $i ][ 'parameter_data' ] = '' ;
}
unset ( $return_data [ 'banner' ][ $i ][ 'sort_num' ]);
unset ( $return_data [ 'banner' ][ $i ][ 'ROW_NUMBER' ]);
}
2025-10-11 18:11:41 +08:00
return $this -> msg ( $return_data );
}
2025-10-13 03:35:56 +08:00
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 );
}
2025-11-21 19:13:01 +08:00
// 数据对比(身体)
public function get_body_data_contrast ( $data ){
$data2 = [ $data [ 'before_id' ], $data [ 'after_id' ]];
$data3 = implode ( ',' , $data2 );
$calculate_arr = [];
$result = Db :: query ( "
select
acbd . id ,
acbd . height ,
acbd . weight ,
acbd . bmi ,
acbd . fat_r ,
acbd . fat_w ,
acbd . muscle ,
acbd . muscleval ,
acbd . water ,
acbd . proteinval ,
acbd . bone ,
acbd . protein ,
acbd . kcal ,
acbd . visceral ,
acbd . sfr ,
acbd . record_time ,
acbd . record_type ,
acbd . head_circumference ,
REPLACE ( CONVERT ( varchar ( 10 ), acbd . record_time , 23 ), '-' , '-' ) AS b_time ,
aud . nickname ,
aud . gender ,
aud . birthday ,
aud . head_pic
from " . $this->index_db_name ['body_data']. " as acbd
left join " . $this->index_db_name ['juese']. " as aud on acbd . aud_id = aud . id
where acbd . id in ( $data3 )
and acbd . is_del = 0
" );
2025-10-11 18:11:41 +08:00
2025-11-21 19:13:01 +08:00
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 ;
}
}
2025-10-11 18:11:41 +08:00
2025-11-21 19:13:01 +08:00
$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' ] = [];
// 处理如果没有阻抗的数据为0, 显示异常start;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息
if ( $calculate_arr [ 'before' ][ 'record_type' ] != 'by_device_adc' && $calculate_arr [ 'after' ][ 'record_type' ] != 'by_device_adc' ){
foreach ( $calculate_arr [ 'before' ] as $key => $value ) {
if ( ! in_array ( $key , [ 'height' , 'weight' , 'bmi' , 'head_circumference' ])){
unset ( $calculate_arr [ 'before' ][ $key ]);
unset ( $calculate_arr [ 'after' ][ $key ]);
}
}
if ( $return_data [ 'age' ] >= 3 ){
unset ( $calculate_arr [ 'before' ][ 'head_circumference' ]);
unset ( $calculate_arr [ 'after' ][ 'head_circumference' ]);
} else {
$calculate_arr [ 'before' ][ 'head_circumference' ] = json_decode ( $calculate_arr [ 'before' ][ 'head_circumference' ], true );
$calculate_arr [ 'after' ][ 'head_circumference' ] = json_decode ( $calculate_arr [ 'after' ][ 'head_circumference' ], true );
foreach ( $calculate_arr as $key => $value ) {
if ( array_key_exists ( 'value' , $value [ 'head_circumference' ])){
$calculate_arr [ $key ][ 'head' ][ 0 ] = $value [ 'head_circumference' ][ 'value' ];
} else {
$calculate_arr [ $key ][ 'head' ][ 0 ] = 0 ;
}
if ( array_key_exists ( 'level' , $value [ 'head_circumference' ])){
$calculate_arr [ $key ][ 'head' ][ 1 ] = $value [ 'head_circumference' ][ 'level' ];
} else {
$calculate_arr [ $key ][ 'head' ][ 1 ] = '异常' ;
}
if ( array_key_exists ( 'color' , $value [ 'head_circumference' ])){
$calculate_arr [ $key ][ 'head' ][ 2 ] = $value [ 'head_circumference' ][ 'color' ];
} else {
$calculate_arr [ $key ][ 'head' ][ 2 ] = '' ;
}
$calculate_arr [ $key ][ 'head' ] = implode ( ',' , $calculate_arr [ $key ][ 'head' ]);
unset ( $calculate_arr [ 'before' ][ 'head_circumference' ]);
unset ( $calculate_arr [ 'after' ][ 'head_circumference' ]);
}
}
} else {
foreach ( $calculate_arr as $key => $value ) {
if ( $value [ 'record_type' ] != 'by_device_adc' ){
$calculate_arr [ $key ][ 'fat_r' ] = " 0,异常 " ;
$calculate_arr [ $key ][ 'fat_w' ] = " 0,异常 " ;
$calculate_arr [ $key ][ 'muscle' ] = " 0,异常 " ;
$calculate_arr [ $key ][ 'muscleval' ] = " 0,异常 " ;
$calculate_arr [ $key ][ 'water' ] = " 0,异常 " ;
$calculate_arr [ $key ][ 'proteinval' ] = " 0,异常 " ;
$calculate_arr [ $key ][ 'bone' ] = " 0,异常 " ;
$calculate_arr [ $key ][ 'protein' ] = " 0,异常 " ;
$calculate_arr [ $key ][ 'kcal' ] = " 0,异常 " ;
$calculate_arr [ $key ][ 'visceral' ] = " 0,异常 " ;
$calculate_arr [ $key ][ 'sfr' ] = " 0,异常 " ;
}
}
}
// 处理如果没有阻抗的数据为0, 显示异常end; 同步处理, 如果两个对比数据, 都没有阻抗数据, 则只显示基础信息
foreach ( $calculate_arr [ 'before' ] as $key => $value ) {
if ( in_array ( $key , [ 'height' , 'weight' , 'bmi' , 'head' , 'fat_r' , 'fat_w' , 'muscle' , 'muscleval' , 'water' , 'proteinval' , 'bone' , 'protein' , 'kcal' , 'visceral' , 'sfr' ])){
$before_arr = explode ( ',' , $value );
$after_arr = explode ( ',' , $calculate_arr [ 'after' ][ $key ]);
array_push ( $return_data [ 'list' ], [
'firstresult' => [
'color' => '' ,
'level' => $before_arr [ 1 ],
'value' => $before_arr [ 0 ],
'title' => $this -> request_result [ '2' ][ $key ][ 0 ],
'unit' => $this -> request_result [ '2' ][ $key ][ 1 ],
'name' => $key ,
],
'secondresult' => [
'color' => '' ,
'level' => $after_arr [ 1 ],
'value' => $after_arr [ 0 ],
'title' => $this -> request_result [ '2' ][ $key ][ 0 ],
'unit' => $this -> request_result [ '2' ][ $key ][ 1 ],
'name' => $key ,
],
'diffval' => bcsub ( $after_arr [ 0 ], $before_arr [ 0 ], 2 ),
]);
}
}
// 添加头围数据( 如果需要的话) end
return $this -> msg ( $return_data );
}
// 数据对比(跳绳)
public function get_skip_data_contrast ( $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->index_db_name ['skip']. " as acsd
left join " . $this->index_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' ] = [];
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' => $this -> request_result [ '6' ][ $key ][ 0 ],
'unit' => $this -> request_result [ '6' ][ $key ][ 1 ],
'name' => $key ,
],
'secondresult' => [
'color' => '' ,
'level' => '' ,
'value' => $key == 'jump_time' ? implode ( ':' , $this -> handle_hour_branch_second ( $after_arr )) : $after_arr ,
'title' => $this -> request_result [ '6' ][ $key ][ 0 ],
'unit' => $this -> request_result [ '6' ][ $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 get_vitalcapacity_data_contrast ( $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->index_db_name ['vitalcapacity']. " as acsd
left join " . $this->index_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' ] = [];
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' => $this -> request_result [ '8' ][ $key ][ 0 ],
'unit' => $this -> request_result [ '8' ][ $key ][ 1 ],
'name' => $key ,
],
'secondresult' => [
'color' => '' ,
'level' => '' ,
'value' => $after_arr ,
'title' => $this -> request_result [ '8' ][ $key ][ 0 ],
'unit' => $this -> request_result [ '8' ][ $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 login_invalid_version ( $data ){
// 获取客户端IP
$ip = request () -> ip ();
// 调用IP识别方法
$region = $this -> getIpInfo ( $ip );
// 解析地区信息
$regionParts = explode ( '|' , $region );
$country = $regionParts [ 0 ] ? ? '' ;
// 判断国家是否在支持的语言列表中
$language = '' ;
if ( $country && $country !== '0' ) {
$languageMap = [
'中国' => 'zh-Hans' ,
'美国' => 'en' ,
'英国' => 'en' ,
'西班牙' => 'es' ,
'法国' => 'fr' ,
'葡萄牙' => 'pt' ,
'阿拉伯联合酋长国' => 'ar' ,
'俄罗斯' => 'ru' ,
'德国' => 'de'
];
$language = $languageMap [ $country ] ? ? '' ;
}
// 检查语言是否在支持列表中
$language_all = new Language ();
$isSupportedLanguage = array_key_exists ( $language , $language_all -> getSupportedLanguages ());
$result = Db :: table ( $this -> index_db_name [ 'banben' ]) -> order ( 'is_del,id desc' ) -> find ();
if ( $result ){
$version = $result [ 'version_num_original' ];
$url = $result [ 'download_url' ];
} else {
$version = '' ;
$url = '' ;
}
if ( ! array_key_exists ( 'token' , $data )){
return [[ 'code' =>- 1 , 'description' => '已过期' ],[ 'version' => $version , 'url' => $url , 'language' => 'zh-Hans' , 'language_arr' => $this -> process_Language ()]];
} else {
if ( ! $this -> verify_data_is_ok ( $data [ 'token' ], 'str' )){
return $this -> msg ( 10005 );
}
$user_token_state = $this -> token_time_validate ( $data [ 'token' ]);
$language_data = $this -> pd_language ( $user_token_state [ 'language' ], $isSupportedLanguage , $language );
if ( $user_token_state [ 'state' ] === false ){
return [[ 'code' =>- 1 , 'description' => '已过期' ],[ 'version' => $version , 'url' => $url , 'language' => $language_data , 'language_arr' => $this -> process_Language ()]];
} else {
return [[ 'code' => 0 , 'description' => '未过期' ],[ 'version' => $version , 'url' => $url , 'language' => $language_data , 'language_arr' => $this -> process_Language ()]];
}
}
2025-10-11 18:11:41 +08:00
}
2025-11-21 19:13:01 +08:00
// 添加IP信息获取方法
protected function getIpInfo ( $ip ) {
// 默认IP
$ip = $ip ? : request () -> ip ();
try {
$ip2region = new \Ip2Region ();
$info = $ip2region -> memorySearch ( $ip );
// 返回国家信息
return $info [ 'region' ] ? : '未知' ;
} catch ( \Exception $e ) {
return '未知' ;
}
}
public function pd_language ( $user_language , $isSupportedLanguage , $language ){
if ( ! $user_language ){
if ( $isSupportedLanguage ){
$result = $language ;
} else {
$result = 'zh-Hans' ; // 默认语言为中文
}
} else {
$result = $user_language ;
}
return $result ;
}
// 处理返回的语言数组
protected function process_Language (){
$temporary_arr = [];
foreach ( $this -> language_country as $key => $value ) {
array_push ( $temporary_arr ,[ 'key' => $key , 'value' => $value ]);
}
return $temporary_arr ;
}
// public function get_user_data_information_action($data){
// $return_result = [
// 'body_data'=>[],
// 'kcal_data'=>[],
// 'card_data'=>[]
// ];
// $aud_data = Db::table($this->index_db_name['juese'])->where(['id'=>$data['aud_id']])->find();
// $body_data = Db::table($this->index_db_name['body_data'])->where(['id'=>$data['aud_id']])->find();
// }
2025-10-11 18:11:41 +08:00
}