3380 lines
160 KiB
PHP
3380 lines
160 KiB
PHP
<?php
|
||
|
||
namespace app\NewReedaw\controller\app;
|
||
|
||
use think\Db;
|
||
use app\NewReedaw\controller\app\Cardparts;
|
||
use app\NewReedaw\controller\app\Calculatebody;
|
||
|
||
class Userbody extends Base{
|
||
|
||
protected $body_db_name = [
|
||
'zhanghao'=>'app_account_number',
|
||
'juese'=>'app_user_data',
|
||
'body_data'=>'app_card_body_data',
|
||
'body_data_new'=>'app_card_body_data_new',
|
||
'bmi'=>'pc_bmistand',
|
||
'height'=>'pc_heightstand',
|
||
'weight'=>'pc_weightstand',
|
||
// 'chufang1'=>'pc_childrenprescription',
|
||
// 'chufang2'=>'pc_childprescriptionbyage',
|
||
];
|
||
protected $age_limit = 16;
|
||
protected $pagesize = 15;
|
||
protected $detailed_model_1 = [ //详情里面的数据模板
|
||
"name"=>"", //名称
|
||
"value"=>"0", //值
|
||
"unit"=>"", // 单位
|
||
"desc"=>'',// 描述
|
||
"standard"=>"", //标准值
|
||
"standard_color"=>"#000000", //标准颜色
|
||
"list"=>[], //标准列表
|
||
"key_name"=>'', //标准列表
|
||
"offset"=>0, //标准列表
|
||
"tip"=>'', //小妙招
|
||
];
|
||
protected $merged_data = [
|
||
'score' => [
|
||
'name' => '身体得分',
|
||
'unit' => '分',
|
||
"description"=>"",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/score.png",
|
||
'standard_list' => [
|
||
['min_val'=>'0','max_val'=>'70','text'=>'较差','color'=>'#C2831C'],
|
||
['min_val'=>'71','max_val'=>'80','text'=>'一般','color'=>'#F5A623'],
|
||
['min_val'=>'81','max_val'=>'90','text'=>'良好','color'=>'#14CBAD'],
|
||
['min_val'=>'91','max_val'=>'100','text'=>'很棒','color'=>'#0F9982'],
|
||
],
|
||
'key_name'=>'score',
|
||
],
|
||
'height' => [
|
||
'name' => '身高',
|
||
'unit' => 'cm',
|
||
"description"=>"人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/height.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'矮' => '#FD5759',
|
||
'偏矮' => '#FAAD01',
|
||
'标准' => '#5BD068',
|
||
'偏高' => '#6793F4',
|
||
'高' => '#3D67D3'
|
||
],
|
||
'standard_list' => [
|
||
['min_val'=>'0','max_val'=>'','text'=>'矮','color'=>'#FD5759'],
|
||
['min_val'=>'','max_val'=>'','text'=>'偏矮','color'=>'#FAAD01'],
|
||
['min_val'=>'','max_val'=>'','text'=>'标准','color'=>'#5BD068'],
|
||
['min_val'=>'','max_val'=>'','text'=>'偏高','color'=>'#6793F4'],
|
||
['min_val'=>'','max_val'=>'','text'=>'高','color'=>'#3D67D3'],
|
||
],
|
||
'key_name'=>'height',
|
||
],
|
||
'weight' => [
|
||
'name' => '体重',
|
||
'unit' => 'kg',
|
||
"description"=>"体重指人体的重量,通常用斤、公斤或磅作为单位来衡量。体重是人体健康的重要指标,但需要结合身高、体型和体脂率等因素来综合评估。",
|
||
"smart_tip_description"=>"保持均衡营养的饮食,摄入足够的碳水化合物、蛋白质、脂肪等。适度进行运动,保持良好的生活习惯。",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/weight.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'低' => '#F8595D',
|
||
'偏低' => '#FFAF04',
|
||
'标准' => '#59D168',
|
||
'偏高' => '#FFAF04',
|
||
'高' => '#F8595D'
|
||
],
|
||
'standard_list' => [
|
||
['min_val'=>'0','max_val'=>'','text'=>'低','color'=>'#F8595D'],
|
||
['min_val'=>'','max_val'=>'','text'=>'偏低','color'=>'#FFAF04'],
|
||
['min_val'=>'','max_val'=>'','text'=>'标准','color'=>'#59D168'],
|
||
['min_val'=>'','max_val'=>'','text'=>'偏高','color'=>'#FFAF04'],
|
||
['min_val'=>'','max_val'=>'','text'=>'高','color'=>'#F8595D'],
|
||
],
|
||
'key_name'=>'weight',
|
||
],
|
||
'bmi' => [
|
||
'name' => 'BMI',
|
||
'unit' => '',
|
||
"description"=>"BMI是身体质量指数(BodyMasslndex)的缩写,是一种常用的衡量人体肥胖程度的指标",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/bmi10.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'消瘦' => '#FDDA6B',
|
||
'正常' => '#5BD068',
|
||
'偏重' => '#FAAD01',
|
||
'肥胖' => '#FD5759'
|
||
],
|
||
'standard_list' => [
|
||
['min_val'=>'0','max_val'=>'','text'=>'消瘦','color'=>'#FDDA6B'],
|
||
['min_val'=>'','max_val'=>'','text'=>'正常','color'=>'#5BD068'],
|
||
['min_val'=>'','max_val'=>'','text'=>'偏重','color'=>'#FAAD01'],
|
||
['min_val'=>'','max_val'=>'50','text'=>'肥胖','color'=>'#FD5759'],
|
||
],
|
||
'key_name'=>'bmi',
|
||
],
|
||
'fat_r' => [
|
||
'name' => '脂肪率',
|
||
'unit' => '%',
|
||
"description"=>"体脂率指人体中脂肪组织所占的百分比。体脂率是评估一个人身体脂肪含量和肥胖程度的指标。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/fat_r.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'偏低' => '#FCDB67',
|
||
'标准' => '#58D268',
|
||
'偏高' => '#FCAA00',
|
||
'高' => '#FD5752'
|
||
],
|
||
'standard_list' => [
|
||
'1'=>[
|
||
'29'=>[
|
||
['min_val'=>'0','max_val'=>'10','text'=>'偏低','color'=>'#FCDB67'],
|
||
['min_val'=>'10','max_val'=>'21','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'21','max_val'=>'26','text'=>'偏高','color'=>'#FAB000'],
|
||
['min_val'=>'26','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
|
||
],
|
||
'30'=>[
|
||
['min_val'=>'0','max_val'=>'11','text'=>'偏低','color'=>'#FCDB67'],
|
||
['min_val'=>'11','max_val'=>'22','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'22','max_val'=>'27','text'=>'偏高','color'=>'#FAB000'],
|
||
['min_val'=>'27','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
|
||
],
|
||
],
|
||
'2'=>[
|
||
'29'=>[
|
||
['min_val'=>'0','max_val'=>'20','text'=>'偏低','color'=>'#FCDB67'],
|
||
['min_val'=>'20','max_val'=>'31','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'31','max_val'=>'38','text'=>'偏高','color'=>'#FAB000'],
|
||
['min_val'=>'38','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
|
||
],
|
||
'30'=>[
|
||
['min_val'=>'0','max_val'=>'21','text'=>'偏低','color'=>'#FCDB67'],
|
||
['min_val'=>'21','max_val'=>'32','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'32','max_val'=>'39','text'=>'偏高','color'=>'#FAB000'],
|
||
['min_val'=>'39','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
|
||
]
|
||
]
|
||
],
|
||
'key_name'=>'fat_r',
|
||
],
|
||
'fat_w' => [
|
||
'name' => '脂肪量',
|
||
'unit' => 'kg',
|
||
"description"=>"脂肪量指人体含有脂肪的总量。脂肪在身体中起着能量储存、保护内脏器官和维持体温等重要作用。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/fat_w.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'偏低' => '#FCDB67',
|
||
'标准' => '#58D268',
|
||
'偏高' => '#FCAA00',
|
||
'高' => '#FD5752'
|
||
],
|
||
'standard_list' => [
|
||
'1'=>[
|
||
'29'=>[
|
||
['min_val'=>'0','max_val'=>'10','text'=>'偏低','color'=>'#FCDB67'],
|
||
['min_val'=>'10','max_val'=>'21','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'21','max_val'=>'26','text'=>'偏高','color'=>'#FAB000'],
|
||
['min_val'=>'26','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
|
||
],
|
||
'30'=>[
|
||
['min_val'=>'0','max_val'=>'11','text'=>'偏低','color'=>'#FCDB67'],
|
||
['min_val'=>'11','max_val'=>'22','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'22','max_val'=>'27','text'=>'偏高','color'=>'#FAB000'],
|
||
['min_val'=>'27','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
|
||
],
|
||
],
|
||
'2'=>[
|
||
'29'=>[
|
||
['min_val'=>'0','max_val'=>'20','text'=>'偏低','color'=>'#FCDB67'],
|
||
['min_val'=>'20','max_val'=>'31','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'31','max_val'=>'38','text'=>'偏高','color'=>'#FAB000'],
|
||
['min_val'=>'38','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
|
||
],
|
||
'30'=>[
|
||
['min_val'=>'0','max_val'=>'21','text'=>'偏低','color'=>'#FCDB67'],
|
||
['min_val'=>'21','max_val'=>'32','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'32','max_val'=>'39','text'=>'偏高','color'=>'#FAB000'],
|
||
['min_val'=>'39','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
|
||
]
|
||
]
|
||
],
|
||
'key_name'=>'fat_w',
|
||
],
|
||
'muscle' => [
|
||
'name' => '肌肉率',
|
||
'unit' => '%',
|
||
"description"=>"肌肉率指人体成分中肌肉占体重的百分比。肌肉率越高,BMR越大,消耗的热量越多,就不容易发胖。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/muscle.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'不足' => '#FFDA68',
|
||
'标准' => '#59CD6F',
|
||
'优' => '#3C64D4'
|
||
],
|
||
'standard_list' => [
|
||
'1'=>[
|
||
['min_val'=>'0','max_val'=>'40','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'60','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
|
||
],
|
||
'2'=>[
|
||
['min_val'=>'0','max_val'=>'30','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'30','max_val'=>'50','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'50','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
|
||
]
|
||
],
|
||
'key_name'=>'muscle',
|
||
],
|
||
'muscleval' => [
|
||
'name' => '肌肉量',
|
||
'unit' => 'kg',
|
||
"description"=>"肌肉量指人体所有肌肉的含量,包括水分量、骨骼肌、心肌和平滑肌等。肌肉是人体内的主要代谢组织之一,具有维持基础代谢率、提高身体稳定性、促进脂肪分解等重要作用。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/muscleval.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'不足' => '#FFDA68',
|
||
'标准' => '#59CD6F',
|
||
'优' => '#3C64D4'
|
||
],
|
||
'standard_list' => [
|
||
'1'=>[
|
||
['min_val'=>'0','max_val'=>'40','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'60','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
|
||
],
|
||
'2'=>[
|
||
['min_val'=>'0','max_val'=>'30','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'30','max_val'=>'50','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'50','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
|
||
]
|
||
],
|
||
'key_name'=>'muscleval',
|
||
],
|
||
'water' => [
|
||
'name' => '水分',
|
||
'unit' => '%',
|
||
"description"=>"体水分率指人体组织中的水分占总体重的百分比,也称为身体水分含量。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/water.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'不足' => '#FED966',
|
||
'标准' => '#58CF6B',
|
||
'优' => '#3A68D7'
|
||
],
|
||
'standard_list' => [
|
||
'1'=>[
|
||
['min_val'=>'0','max_val'=>'55','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'55','max_val'=>'65','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'65','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
|
||
],
|
||
'2'=>[
|
||
['min_val'=>'0','max_val'=>'45','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'45','max_val'=>'60','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'60','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
|
||
]
|
||
],
|
||
'key_name'=>'water',
|
||
],
|
||
'bone' => [
|
||
'name' => '骨重',
|
||
'unit' => 'kg',
|
||
"description"=>"身体骨量指人体骨骼所含的骨基质和矿物质的质量。骨量的大小直接影响骨骼健康,对身体的稳定性和功能起着至关重要的作用。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/bone.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'不足' => '#FED966',
|
||
'标准' => '#58CF6F',
|
||
'优' => '#3A68D7'
|
||
],
|
||
'standard_list' => [
|
||
'1'=>[
|
||
'60'=>[
|
||
['min_val'=>'0','max_val'=>'2.4','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'2.4','max_val'=>'2.6','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'2.6','max_val'=>'6','text'=>'优','color'=>'#3C66D2'],
|
||
],
|
||
'60_75'=>[
|
||
['min_val'=>'0','max_val'=>'2.8','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'2.8','max_val'=>'3','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'3','max_val'=>'6','text'=>'优','color'=>'#3C66D2'],
|
||
],
|
||
'75'=>[
|
||
['min_val'=>'0','max_val'=>'3.1','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'3.1','max_val'=>'3.3','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'3.3','max_val'=>'7','text'=>'优','color'=>'#3C66D2'],
|
||
],
|
||
],
|
||
'2'=>[
|
||
'45'=>[
|
||
['min_val'=>'0','max_val'=>'1.7','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'1.7','max_val'=>'1.9','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'1.9','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
|
||
],
|
||
'45_60'=>[
|
||
['min_val'=>'0','max_val'=>'2.1','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'2.1','max_val'=>'2.3','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'2.3','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
|
||
],
|
||
'60'=>[
|
||
['min_val'=>'0','max_val'=>'2.4','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'2.4','max_val'=>'2.6','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'2.6','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
|
||
],
|
||
]
|
||
],
|
||
'key_name'=>'bone',
|
||
],
|
||
'protein' => [
|
||
'name' => '蛋白率',
|
||
'unit' => '%',
|
||
"description"=>"蛋白质率指人体组织中蛋白质含量占总体重的百分比。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/protein.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'不足' => '#FED966',
|
||
'标准' => '#58CF6F',
|
||
'优' => '#3A68D7'
|
||
],
|
||
'standard_list' => [
|
||
'1'=>[
|
||
['min_val'=>'0','max_val'=>'16','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'16','max_val'=>'18','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'18','max_val'=>'50','text'=>'优','color'=>'#3C66D2'], //蓝
|
||
],
|
||
'2'=>[
|
||
['min_val'=>'0','max_val'=>'14','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'14','max_val'=>'16','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'16','max_val'=>'50','text'=>'优','color'=>'#3C66D2'],
|
||
]
|
||
],
|
||
'key_name'=>'protein',
|
||
],
|
||
'proteinval' => [
|
||
'name' => '蛋白量',
|
||
'unit' => 'kg',
|
||
"description"=>"",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/proteinval.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'不足' => '#FED966',
|
||
'标准' => '#58CF6F',
|
||
'优' => '#3A68D7'
|
||
],
|
||
'standard_list' => [
|
||
'1'=>[
|
||
['min_val'=>'0','max_val'=>'16','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'16','max_val'=>'18','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'18','max_val'=>'50','text'=>'优','color'=>'#3C66D2'], //蓝
|
||
],
|
||
'2'=>[
|
||
['min_val'=>'0','max_val'=>'14','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'14','max_val'=>'16','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'16','max_val'=>'50','text'=>'优','color'=>'#3C66D2'],
|
||
]
|
||
],
|
||
'key_name'=>'proteinval',
|
||
],
|
||
'visceral' => [
|
||
'name' => '内脏指数',
|
||
'unit' => '',
|
||
"description"=>"内脏脂肪指围绕脏器的脂肪组织,主要分布于腹腔内,包括肝脏、心脏、肾脏、胰腺等器官周围的脂肪。身体内脏脂肪的增加会导致慢性代谢性疾病的风险增加。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/visceral.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'标准' => '#55CF6C',
|
||
'警惕' => '#FEAC00',
|
||
'危险' => '#FB5A52'
|
||
],
|
||
'standard_list' => [
|
||
'1'=>[
|
||
['min_val'=>'0','max_val'=>'9','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'9','max_val'=>'14','text'=>'警惕','color'=>'#FAB000'],
|
||
['min_val'=>'14','max_val'=>'50','text'=>'危险','color'=>'#FA5951'], //红
|
||
],
|
||
'2'=>[
|
||
['min_val'=>'0','max_val'=>'9','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'9','max_val'=>'14','text'=>'警惕','color'=>'#FAB000'],
|
||
['min_val'=>'14','max_val'=>'50','text'=>'危险','color'=>'#FA5951'], //红
|
||
]
|
||
],
|
||
'key_name'=>'visceral',
|
||
],
|
||
'sfr' => [
|
||
'name' => '皮下脂肪',
|
||
'unit' => '%',
|
||
"description"=>"皮下脂肪率指身体内皮下脂肪组织占身体总重量的百分比。皮下脂肪适量时对身体有益,但过量会使身体处于肥胖状态,并可能导致多种健康问题。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/sfr.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'不足' => '#FCDB68',
|
||
'标准' => '#59D16F',
|
||
'偏高' => '#FEAB03'
|
||
],
|
||
'standard_list' => [
|
||
'1'=>[
|
||
['min_val'=>'0','max_val'=>'7','text'=>'不足','color'=>'#FCDB67'], //淡黄
|
||
['min_val'=>'7','max_val'=>'15','text'=>'标准','color'=>'#59D16D'], //绿
|
||
['min_val'=>'15','max_val'=>'50','text'=>'偏高','color'=>'#FAB000'], //橙
|
||
],
|
||
'2'=>[
|
||
['min_val'=>'0','max_val'=>'11','text'=>'不足','color'=>'#FCDB67'],
|
||
['min_val'=>'11','max_val'=>'17','text'=>'标准','color'=>'#59D16D'],
|
||
['min_val'=>'17','max_val'=>'50','text'=>'偏高','color'=>'#FAB000'],
|
||
]
|
||
],
|
||
'key_name'=>'sfr',
|
||
],
|
||
'body_level' => [
|
||
'name' => '肥胖等级',
|
||
'unit' => '',
|
||
"description"=>"肥胖等级指根据个体BMI来评估一个人是否超重或肥胖的指标。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_level.png",
|
||
'list' => [],
|
||
'standard_list' => [],
|
||
'key_name'=>'body_level',
|
||
],
|
||
'body_type' => [
|
||
'name' => '身体类型',
|
||
'unit' => '',
|
||
"description"=>"身体类型是对人体外形的总体描述和评定",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_type.png",
|
||
'list' => [],
|
||
'standard_list' => [],
|
||
'key_name'=>'body_type',
|
||
],
|
||
'body_age' => [
|
||
'name' => '身体年龄',
|
||
'unit' => '岁',
|
||
"description"=>"身体年龄指衡量身体健康状况的指标,它反映了一个人的生理状态相对于实际年龄的健康程度。相关模型主要与BMI有关。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_age.png",
|
||
'list' => [],
|
||
'standard_list' => [],
|
||
'key_name'=>'body_age',
|
||
],
|
||
'head_circumference' => [
|
||
'name' => '头围',
|
||
'unit' => 'cm',
|
||
"description"=>"",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/head_circumference.png",
|
||
'standard_list' => [],
|
||
'key_name'=>'head_circumference',
|
||
],
|
||
'heart_rate' => [
|
||
'name' => '心率',
|
||
'unit' => '跳/分钟',
|
||
"description"=>"心率指正常人安静状态下每分钟心跳的次数,可因年龄、性别或其他生理因素产生个体差异。",
|
||
"smart_tip_description"=>"注意减少压力和焦虑,适度锻炼,保持良好的睡眠质量,避免过度用力或剧烈运动。",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/heart_rate10.png",
|
||
'standard_list' => [
|
||
['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#FCDB67'],
|
||
['min_val'=>'','max_val'=>'','text'=>'标准','color'=>'#58D268'],
|
||
['min_val'=>'','max_val'=>'9999','text'=>'偏高','color'=>'#FD5752'],
|
||
],
|
||
'key_name'=>'heart_rate',
|
||
],
|
||
'ideal_weight' => [
|
||
'name' => '理想体重',
|
||
'unit' => 'kg',
|
||
"description"=>"理想体重是反映和衡量一个人健康状况的重要标志之一。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/ideal_weight.png",
|
||
'standard_list' => [],
|
||
'key_name'=>'ideal_weight',
|
||
],
|
||
'ideal_height' => [
|
||
'name' => '理想身高',
|
||
'unit' => 'cm',
|
||
"description"=>"",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/ideal_height.png",
|
||
'standard_list' => [],
|
||
'key_name'=>'ideal_height',
|
||
],
|
||
'ideal_bmi' => [
|
||
'name' => '理想BMI',
|
||
'unit' => '',
|
||
"description"=>"",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/ideal_bmi.png",
|
||
'standard_list' => [],
|
||
'key_name'=>'ideal_bmi',
|
||
],
|
||
'kcal' => [
|
||
'name' => 'BMR',
|
||
'unit' => 'kcal',
|
||
"description"=>"BMR是基础代谢率(BasalMetabolicRate)的缩写,指人体在安静状态下,维持基本生命活动所需的最低能量消耗率。",
|
||
"smart_tip_description"=>"",
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/ideal_bmi.png",
|
||
'list' => [
|
||
'异常' => '#ff0004',
|
||
'偏低' => '#FF5656',
|
||
'优' => '#3A68D4'
|
||
],
|
||
'standard_list' => [
|
||
['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'],
|
||
['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#3C66D2'],
|
||
],
|
||
'key_name'=>'kcal',
|
||
],
|
||
];
|
||
protected $heart_rate = [
|
||
[
|
||
'age' => ['min' => '0', 'max' => '1'],
|
||
'1' => ['min' => '70', 'max' => '190'],
|
||
'2' => ['min' => '70', 'max' => '190']
|
||
],
|
||
[
|
||
'age' => ['min' => '1', 'max' => '12'],
|
||
'1' => ['min' => '80', 'max' => '160'],
|
||
'2' => ['min' => '80', 'max' => '160']
|
||
],
|
||
[
|
||
'age' => ['min' => '12', 'max' => '36'],
|
||
'1' => ['min' => '80', 'max' => '130'],
|
||
'2' => ['min' => '80', 'max' => '130']
|
||
],
|
||
[
|
||
'age' => ['min' => '36', 'max' => '60'],
|
||
'1' => ['min' => '80', 'max' => '120'],
|
||
'2' => ['min' => '80', 'max' => '120']
|
||
],
|
||
[
|
||
'age' => ['min' => '60', 'max' => '120'],
|
||
'1' => ['min' => '70', 'max' => '110'],
|
||
'2' => ['min' => '70', 'max' => '110']
|
||
],
|
||
[
|
||
'age' => ['min' => '120', 'max' => '204'],
|
||
'1' => ['min' => '60', 'max' => '100'],
|
||
'2' => ['min' => '60', 'max' => '100']
|
||
],
|
||
[
|
||
'age' => ['min' => '204', 'max' => '480'],
|
||
'1' => ['min' => '60', 'max' => '100'],
|
||
'2' => ['min' => '60', 'max' => '100']
|
||
],
|
||
[
|
||
'age' => ['min' => '480', 'max' => '720'],
|
||
'1' => ['min' => '60', 'max' => '100'],
|
||
'2' => ['min' => '60', 'max' => '100']
|
||
],
|
||
[
|
||
'age' => ['min' => '720', 'max' => '9999'], // 61岁+,9999作为最大值占位
|
||
'1' => ['min' => '60', 'max' => '100'],
|
||
'2' => ['min' => '60', 'max' => '100']
|
||
]
|
||
];
|
||
|
||
// 加 bcadd(,,20)
|
||
// 减 bcsub(,,20)
|
||
// 乘 bcmul(,,20)
|
||
// 除 bcdiv(,,20)
|
||
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
|
||
|
||
################################################################接口################################################################
|
||
################################################################接口################################################################
|
||
################################################################接口################################################################
|
||
// 手动记录
|
||
public function manual_record(){
|
||
$data = input('post.');
|
||
try {
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
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');
|
||
}
|
||
$temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
|
||
if($temporary_data['height_in_cm'] == false){
|
||
return $this->msg(10005,'身高单位错误');
|
||
}
|
||
if($temporary_data['weight_in_kg'] == false){
|
||
return $this->msg(10005,'体重单位错误');
|
||
}
|
||
$data['height'] = $temporary_data['height_in_cm'];
|
||
$data['weight'] = $temporary_data['weight_in_kg'];
|
||
if(strlen($data['time']) <= 12){
|
||
// 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
|
||
$data['time'] = $this->addCurrentTimeToDateString($data['time']);
|
||
}
|
||
return $this->set_user_body_data($data,'by_hand_means');
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "函数: manual_record" . "\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 device_record(){
|
||
$data = input('post.');
|
||
// try {
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $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['adc'],'num')){
|
||
return $this->msg(10005,'adc type error');
|
||
}
|
||
$temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
|
||
if($temporary_data['height_in_cm'] == false){
|
||
return $this->msg(10005,'身高单位错误');
|
||
}
|
||
if($temporary_data['weight_in_kg'] == false){
|
||
return $this->msg(10005,'体重单位错误');
|
||
}
|
||
// 检测设备传过来的info信息
|
||
if(array_key_exists('info', $data)){
|
||
if (!is_array($data['info'])) {
|
||
return $this->msg(10005,'info参数格式错误');
|
||
}else{
|
||
$info_data_arr =['bodyage','fat_r','muscle','kcal','visceral','sfr','water','bone','fatlevlval','protein','bmi'];
|
||
foreach ($data['info'] as $key => $value) {
|
||
if (!in_array($key, $info_data_arr)) {
|
||
return $this->msg(10005,'info参数格式错误-2');
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$data['height'] = $temporary_data['height_in_cm'];
|
||
$data['weight'] = $temporary_data['weight_in_kg'];
|
||
$data['time'] = date('Y-m-d H:i:s');
|
||
return $this->set_user_body_data($data,'by_device');
|
||
// } catch (\Exception $e) {
|
||
// // 捕获异常
|
||
// $logContent["flie"] = $e->getFile();
|
||
// $logContent["line"] = $e->getLine();
|
||
// $logContent['all_content'] = "异常信息:\n";
|
||
// $logContent['all_content'] .= "函数: device_record" . "\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 body_report_brief(){
|
||
$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->body_report_brief_action($data);
|
||
// } catch (\Exception $e) {
|
||
// // 捕获异常
|
||
// $logContent["flie"] = $e->getFile();
|
||
// $logContent["line"] = $e->getLine();
|
||
// $logContent['all_content'] = "异常信息:\n";
|
||
// $logContent['all_content'] .= "函数: body_report_brief" . "\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 body_report_detailed(){
|
||
$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->body_report_detailed_action($data);
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "函数: body_report_detailed" . "\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 body_report_depth(){
|
||
$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->body_report_depth_action($data);
|
||
// } catch (\Exception $e) {
|
||
// // 捕获异常
|
||
// $logContent["flie"] = $e->getFile();
|
||
// $logContent["line"] = $e->getLine();
|
||
// $logContent['all_content'] = "异常信息:\n";
|
||
// $logContent['all_content'] .= "函数: body_report_detailed" . "\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 set_target_weight(){
|
||
$data = input('post.');
|
||
try {
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $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['weight'],'num')){
|
||
return $this->msg(10005,'weight type error');
|
||
}
|
||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||
return $this->msg(10005,'token type error');
|
||
}
|
||
|
||
$data['time'] = date('Y-m-d H:i:s');
|
||
return $this->set_target_weight_action($data);
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "函数: set_target_weight" . "\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 set_initial_weight(){
|
||
$data = input('post.');
|
||
try {
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('weight', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $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['weight'],'num')){
|
||
return $this->msg(10005,'weight 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['token'],'str')){
|
||
return $this->msg(10005,'token type error');
|
||
}
|
||
return $this->set_initial_weight_action($data);
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "函数: set_initial_weight" . "\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999);
|
||
}
|
||
}
|
||
// 获取历史列表(分页)
|
||
public function history_list_page(){
|
||
$data = input('post.');
|
||
try {
|
||
|
||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $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');
|
||
}
|
||
return $this->history_list_page_action($data,'page');
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999);
|
||
}
|
||
}
|
||
// 历史记录(详细)
|
||
public function history_detailed(){
|
||
$data = input('post.');
|
||
try {
|
||
|
||
if(!array_key_exists('token', $data) || !array_key_exists('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['id'],'intnum')){
|
||
return $this->msg(10005,'id type error');
|
||
}
|
||
return $this->history_detailed_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);
|
||
}
|
||
}
|
||
// 历史记录删除
|
||
public function history_del(){
|
||
$data = input('post.');
|
||
try {
|
||
|
||
if(!array_key_exists('token', $data) || !array_key_exists('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['id'],'intnum')){
|
||
return $this->msg(10005,'id type error');
|
||
}
|
||
return $this->history_del_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);
|
||
}
|
||
}
|
||
// 曲线详情
|
||
public function curve_detailed(){
|
||
$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)){
|
||
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,'s_time type error');
|
||
}
|
||
if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
|
||
return $this->msg(10005,'e_time type error');
|
||
}
|
||
return $this->curve_detailed_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);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
################################################################action################################################################
|
||
################################################################action################################################################
|
||
|
||
// 用户身体数据卡片记录
|
||
public function set_user_body_data($data,$type){
|
||
// 加 bcadd(,,20)
|
||
// 减 bcsub(,,20)
|
||
// 乘 bcmul(,,20)
|
||
// 除 bcdiv(,,20)
|
||
|
||
$db_data = [];
|
||
$db_data['create_time'] = date('Y-m-d H:i:s');
|
||
$db_data['aud_id'] = $data['aud_id'];
|
||
$db_data['record_time'] = $data['time'];
|
||
$db_data['height'] = $data['height'];
|
||
$db_data['weight'] = $data['weight'];
|
||
|
||
$db_data['create_time'] = date('Y-m-d H:i:s');
|
||
// 查询用户信息
|
||
$user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('birthday,gender,target_weight,initial_weight,initial_date')->find();
|
||
if(!$user_data){
|
||
return $this->msg(10003);
|
||
}
|
||
// 如果最初体重设置为null
|
||
if($user_data['initial_date'] == null){
|
||
Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]);
|
||
}
|
||
$db_data['age'] = $this->calculate_age($user_data['birthday']);
|
||
|
||
// 设置发送数据:身高、体重、年龄、性别、头围、生日、阻抗
|
||
$send_data['height'] = $data['height'];
|
||
$send_data['weight'] = $data['weight'];
|
||
$send_data['age'] = $db_data['age'];
|
||
$send_data['gender'] = $user_data['gender'];
|
||
$send_data['birthDay'] = $user_data['birthday'];
|
||
|
||
|
||
// 1、手动记录还是设备记录
|
||
if($type == 'by_hand_means'){
|
||
$db_data['record_type'] = 'by_hand_means';
|
||
// 判断头围数据是否存在是否合理
|
||
if(array_key_exists('head_data', $data)){
|
||
if(!$this->verify_data_is_ok($data['head_data'],'num')){
|
||
return $this->msg(10005);
|
||
}
|
||
$db_data['head_circumference'] = $data['head_data'];
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
$send_data['adc'] = 550;
|
||
$send_data['head'] = $data['head_data'];
|
||
|
||
// 发送请求获取照良那边的身体数据
|
||
$get_body_value = $this->send_body_data($send_data,'4_electrode');
|
||
if($get_body_value === false){
|
||
return $this->msg(10002);
|
||
}
|
||
|
||
// 开始设置数据
|
||
$db_data['bmi'] = $get_body_value['bmi'];
|
||
$db_data['score'] = $get_body_value['cmi'];
|
||
$db_data['fat_r'] = $get_body_value['bfr'];
|
||
$db_data['fat_w'] = $get_body_value['bfrval'];
|
||
$db_data['muscle'] = $get_body_value['rom'];
|
||
$db_data['muscleval'] = $get_body_value['romval'];
|
||
$db_data['water'] = $get_body_value['vwc'];
|
||
$db_data['protein'] = $get_body_value['pp'];
|
||
$db_data['proteinval'] = $get_body_value['ppval'];
|
||
$db_data['bone'] = $get_body_value['bm'];
|
||
$db_data['kcal'] = $get_body_value['bmr'];
|
||
$db_data['visceral'] = $get_body_value['uvi'];
|
||
$db_data['sfr'] = $get_body_value['sfr'];
|
||
$db_data['body_level'] = $get_body_value['fatlevelname'];//肥胖等级
|
||
$db_data['body_type'] = $get_body_value['body'];//身体类型
|
||
$db_data['body_age'] = $get_body_value['bodyage'];
|
||
// 如果年纪小于三岁,处理头围数据star
|
||
$standardlist = [];
|
||
|
||
if($send_data['age'] < 3){
|
||
if(array_key_exists('standardlist',$get_body_value)){
|
||
$standardlist = $get_body_value['standardlist'];
|
||
foreach ($standardlist as $key => $value) {
|
||
if($value['name'] == 'head' && count($value['list'] ) > 0){
|
||
$standardlist = $value;
|
||
}
|
||
}
|
||
$standardlist['list2'] = [];
|
||
foreach ($standardlist['list'] as $key => $value) {
|
||
array_push($standardlist['list2'],[
|
||
'min_val'=>$value['minvalue'],
|
||
'max_val'=>$value['maxvalue'],
|
||
'text'=>$value['text'],
|
||
'color'=>$value['color']
|
||
]);
|
||
}
|
||
unset($standardlist['list']);
|
||
unset($get_body_value['standardlist']);
|
||
$db_data['head_circumference_val'] = $db_data['head_circumference'];
|
||
$db_data['head_circumference'] = json_encode($standardlist);
|
||
}
|
||
}else{
|
||
if(array_key_exists('standardlist',$get_body_value)){
|
||
unset($get_body_value['standardlist']);
|
||
}
|
||
}
|
||
// 如果年纪小于三岁,处理头围数据end
|
||
|
||
}else{
|
||
// 如果原始数据存在阻抗
|
||
if(array_key_exists('adc', $data)){
|
||
if(!$this->verify_data_is_ok($data['adc'],'num')){
|
||
return $this->msg(10005);
|
||
}
|
||
if($data['adc'] > 0){
|
||
// 如果阻抗大于0,那就使用传过来的阻抗
|
||
$send_data['adc'] = $data['adc'];
|
||
$db_data['record_type'] = 'by_device_adc';
|
||
}else{
|
||
$send_data['adc'] = 550;
|
||
$db_data['record_type'] = 'by_device';
|
||
}
|
||
}else{
|
||
return $this->msg(10001);
|
||
}
|
||
if(array_key_exists('lefthand', $data) && array_key_exists('righthand', $data) && array_key_exists('leftfoot', $data) && array_key_exists('rightfoot', $data)){
|
||
// 发送请求获取照良那边的身体数据
|
||
$send_data['lefthand'] = $data['lefthand'];
|
||
$send_data['righthand'] = $data['righthand'];
|
||
$send_data['leftfoot'] = $data['leftfoot'];
|
||
$send_data['rightfoot'] = $data['rightfoot'];
|
||
$get_body_value = $this->send_body_data($send_data,'8_electrode');
|
||
// 开始设置数据
|
||
$db_data['bmi'] = $get_body_value['bmi'];
|
||
$db_data['score'] = $get_body_value['cmi'];
|
||
$db_data['fat_r'] = $get_body_value['fat_r'];
|
||
$db_data['fat_w'] = $get_body_value['fat_w'];
|
||
$db_data['muscle'] = $get_body_value['muscle'];
|
||
$db_data['muscleval'] = $get_body_value['muscleval'];
|
||
$db_data['water'] = $get_body_value['water'];
|
||
$db_data['protein'] = $get_body_value['protein'];
|
||
$db_data['proteinval'] = $get_body_value['proteinval'];
|
||
$db_data['bone'] = $get_body_value['bone'];
|
||
$db_data['kcal'] = $get_body_value['kcal'];
|
||
$db_data['visceral'] = $get_body_value['visceral'];
|
||
$db_data['sfr'] = $get_body_value['sfr'];
|
||
$db_data['body_level'] = $get_body_value['fatlevel'];//肥胖等级
|
||
$db_data['body_type'] = $get_body_value['body'];//身体类型
|
||
$db_data['body_age'] = $get_body_value['bodyage'];
|
||
$db_data['8_electrode_data'] = json_encode($get_body_value);
|
||
}else{
|
||
// 判断头围数据是否存在是否合理
|
||
if(array_key_exists('head_data', $data)){
|
||
if(!$this->verify_data_is_ok($data['head_data'],'num')){
|
||
return $this->msg(10005);
|
||
}
|
||
$db_data['head_circumference'] = $data['head_data'];
|
||
}
|
||
$send_data['head'] = $data['head_data'];
|
||
|
||
// 发送请求获取照良那边的身体数据
|
||
$get_body_value = $this->send_body_data($send_data,'4_electrode');
|
||
// 开始设置数据
|
||
$db_data['bmi'] = $get_body_value['bmi'];
|
||
$db_data['score'] = $get_body_value['cmi'];
|
||
$db_data['fat_r'] = $get_body_value['bfr'];
|
||
$db_data['fat_w'] = $get_body_value['bfrval'];
|
||
$db_data['muscle'] = $get_body_value['rom'];
|
||
$db_data['muscleval'] = $get_body_value['romval'];
|
||
$db_data['water'] = $get_body_value['vwc'];
|
||
$db_data['protein'] = $get_body_value['pp'];
|
||
$db_data['proteinval'] = $get_body_value['ppval'];
|
||
$db_data['bone'] = $get_body_value['bm'];
|
||
$db_data['kcal'] = $get_body_value['bmr'];
|
||
$db_data['visceral'] = $get_body_value['uvi'];
|
||
$db_data['sfr'] = $get_body_value['sfr'];
|
||
$db_data['body_level'] = $get_body_value['fatlevelname'];//肥胖等级
|
||
$db_data['body_type'] = $get_body_value['body'];//身体类型
|
||
$db_data['body_age'] = $get_body_value['bodyage'];
|
||
$db_data['4_electrode_data'] = json_encode($get_body_value);
|
||
|
||
// 如果年纪小于三岁,处理头围数据star
|
||
$standardlist = [];
|
||
|
||
if($send_data['age'] < 3){
|
||
if(array_key_exists('standardlist',$get_body_value)){
|
||
$standardlist = $get_body_value['standardlist'];
|
||
foreach ($standardlist as $key => $value) {
|
||
if($value['name'] == 'head' && count($value['list'] ) > 0){
|
||
$standardlist = $value;
|
||
}
|
||
}
|
||
$standardlist['list2'] = [];
|
||
foreach ($standardlist['list'] as $key => $value) {
|
||
array_push($standardlist['list2'],[
|
||
'min_val'=>$value['minvalue'],
|
||
'max_val'=>$value['maxvalue'],
|
||
'text'=>$value['text'],
|
||
'color'=>$value['color']
|
||
]);
|
||
}
|
||
unset($standardlist['list']);
|
||
unset($get_body_value['standardlist']);
|
||
$db_data['head_circumference_val'] = $db_data['head_circumference'];
|
||
$db_data['head_circumference'] = json_encode($standardlist);
|
||
}
|
||
}else{
|
||
if(array_key_exists('standardlist',$get_body_value)){
|
||
unset($get_body_value['standardlist']);
|
||
}
|
||
}
|
||
// 如果年纪小于三岁,处理头围数据end
|
||
|
||
}
|
||
if($get_body_value === false){
|
||
return $this->msg(10002);
|
||
}
|
||
// dump($get_body_value);
|
||
|
||
|
||
// 处理心率start
|
||
if(array_key_exists('heart_rate', $data)){
|
||
if(!$this->verify_data_is_ok($data['heart_rate'],'num')){
|
||
return $this->msg(10005,'心率数据格式错误');
|
||
}
|
||
$db_data['heart_rate'] = $data['heart_rate'];
|
||
}
|
||
// 处理心率end
|
||
}
|
||
|
||
|
||
// 启动事务
|
||
Db::startTrans();
|
||
try{
|
||
Db::table($this->body_db_name['body_data_new'])->insert($db_data);
|
||
$update_arr = [
|
||
'height'=>$db_data['height'],
|
||
'weight'=>$db_data['weight']
|
||
];
|
||
Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update($update_arr);
|
||
// 提交事务
|
||
Db::commit();
|
||
return $this->msg([]);
|
||
} catch (\Exception $e) {
|
||
// 回滚事务
|
||
Db::rollback();
|
||
return $this->msg(10002);
|
||
}
|
||
|
||
|
||
|
||
}
|
||
public function body_report_brief_action($data){
|
||
$result_return = [
|
||
'top_list'=>[
|
||
[
|
||
"name"=>$this->merged_data['weight']['name'],
|
||
'time'=>'',
|
||
"value"=>"0",
|
||
"unit"=>$this->merged_data['weight']['unit'],
|
||
"standard"=>"",
|
||
"standard_color"=>"#000000",
|
||
'target_weight'=>'0',
|
||
'target_weight_unit'=>'kg',
|
||
'bk_color'=>'#fffae4',
|
||
'curve_list'=>[
|
||
'title'=>'体重',
|
||
'key'=>'weight',
|
||
'line'=>['categories'=>[],'series'=>[['color'=>'#f78814','data'=>[]]]],
|
||
],
|
||
'ideal_weight'=>'',
|
||
],
|
||
[
|
||
"name"=>$this->merged_data['height']['name'],
|
||
'time'=>'',
|
||
"value"=>"0",
|
||
"unit"=>$this->merged_data['height']['unit'],
|
||
"standard"=>"",
|
||
"standard_color"=>"#000000",
|
||
'bk_color'=>'#f6eefd',
|
||
'curve_list'=>[
|
||
'title'=>'身高',
|
||
'key'=>'height',
|
||
'line'=>['categories'=>[],'series'=>[['color'=>'#dab8f4','data'=>[]]]],
|
||
],
|
||
'ideal_height'=>'',
|
||
],
|
||
[
|
||
"name"=>$this->merged_data['bmi']['name'],
|
||
'time'=>'',
|
||
"value"=>"0",
|
||
"unit"=>$this->merged_data['bmi']['unit'],
|
||
"standard"=>"",
|
||
"standard_color"=>"#000000",
|
||
'bk_color'=>'#edf8fe',
|
||
'curve_list'=>[
|
||
'title'=>'BMI',
|
||
'key'=>'bmi',
|
||
'line'=>['categories'=>[],'series'=>[['color'=>'#a8def6','data'=>[]]]],
|
||
],
|
||
'ideal_bmi'=>'',
|
||
],
|
||
],
|
||
'card_list'=>[
|
||
],
|
||
];
|
||
|
||
$user_data = Db::table($this->body_db_name['juese'])
|
||
->where(['id'=>$data['aud_id'],'is_del'=>0])
|
||
->field('birthday,gender,target_weight,initial_weight,initial_date')
|
||
->find();
|
||
if(!$user_data){
|
||
return $this->msg(10003);
|
||
}
|
||
|
||
$body_last_data = Db::table($this->body_db_name['body_data_new'])
|
||
->where(['is_del'=>0,'aud_id'=>$data['aud_id']])
|
||
->order('record_time desc,id desc')
|
||
->find();
|
||
|
||
|
||
if(!$body_last_data){
|
||
return $this->msg($result_return);
|
||
}
|
||
|
||
$body_last_data_3_list = Db::table($this->body_db_name['body_data_new'])
|
||
->where(['is_del'=>0,'aud_id'=>$data['aud_id']])
|
||
->order('record_time desc,id desc')
|
||
->field('id,weight,height,bmi,record_time')
|
||
->page('1,5')
|
||
->select();
|
||
|
||
|
||
|
||
|
||
$record_time = substr($body_last_data['record_time'], 11, 5);
|
||
// 处理体重
|
||
$result_return['top_list'][0]['time'] = $record_time;
|
||
$result_return['top_list'][0]['value'] = floatval($body_last_data['weight']);
|
||
$temporary_standard_color = $this->judgment_standard_color($result_return['top_list'][0]['value'],'weight',$user_data);
|
||
$result_return['top_list'][0]['standard'] = $temporary_standard_color[1];
|
||
$result_return['top_list'][0]['standard_color'] = $temporary_standard_color[2];
|
||
$result_return['top_list'][0]['target_weight'] = $user_data['target_weight'];
|
||
$result_return['top_list'][0]['key_name'] = 'weight';
|
||
foreach ($body_last_data_3_list as $key => $value) {
|
||
$result_return['top_list'][0]['curve_list']['line']['categories'][] = $value['record_time'];
|
||
$result_return['top_list'][0]['curve_list']['line']['series'][0]['data'][] = floatval($value['weight']);
|
||
$result_return['top_list'][1]['curve_list']['line']['categories'][] = $value['record_time'];
|
||
$result_return['top_list'][1]['curve_list']['line']['series'][0]['data'][] = floatval($value['height']);
|
||
$result_return['top_list'][2]['curve_list']['line']['categories'][] = $value['record_time'];
|
||
$result_return['top_list'][2]['curve_list']['line']['series'][0]['data'][] = floatval($value['bmi']);
|
||
}
|
||
$user_data['weight'] = $result_return['top_list'][0]['value'];
|
||
// 处理身高
|
||
$result_return['top_list'][1]['time'] = $record_time;
|
||
$result_return['top_list'][1]['value'] = floatval($body_last_data['height']);
|
||
$temporary_standard_color = $this->judgment_standard_color($result_return['top_list'][0]['value'],'height',$user_data);
|
||
$result_return['top_list'][1]['standard'] = $temporary_standard_color[1];
|
||
$result_return['top_list'][1]['standard_color'] = $temporary_standard_color[2];
|
||
$result_return['top_list'][1]['key_name'] = 'height';
|
||
|
||
// 处理BMI
|
||
$result_return['top_list'][2]['time'] = $record_time;
|
||
$result_return['top_list'][2]['value'] = floatval($body_last_data['bmi']);
|
||
$temporary_standard_color = $this->judgment_standard_color($result_return['top_list'][0]['value'],'bmi',$user_data);
|
||
$result_return['top_list'][2]['standard'] = $temporary_standard_color[1];
|
||
$result_return['top_list'][2]['standard_color'] = $temporary_standard_color[2];
|
||
$result_return['top_list'][2]['key_name'] = 'bmi';
|
||
// 如果有头围
|
||
if($body_last_data['head_circumference']){
|
||
$temporary_head_circumference = json_decode($body_last_data['head_circumference'],true);
|
||
$body_last_data_head_circumference_list = Db::table($this->body_db_name['body_data_new'])
|
||
->where("is_del = 0 AND aud_id = ".$data['aud_id']." AND head_circumference IS NOT NULL")
|
||
->order('record_time desc,id desc')
|
||
->field('id,head_circumference,record_time')
|
||
->page('1,5')
|
||
->select();
|
||
$head_circumference_curve_list = [
|
||
'title'=>'头围',
|
||
'key'=>'head_circumference',
|
||
'line'=>['categories'=>[],'series'=>[['color'=>'#55d87b','data'=>[]]]],
|
||
];
|
||
foreach ($body_last_data_head_circumference_list as $key => $value) {
|
||
$head_circumference_curve_list['line']['categories'][] = $value['record_time'];
|
||
$head_circumference_curve_list['line']['series'][0]['data'][] = floatval($value['head_circumference']);
|
||
}
|
||
$result_return['top_list'][] = [
|
||
"name"=>$this->merged_data['head_circumference']['name'],
|
||
'time' => $record_time,
|
||
'value' => $temporary_head_circumference['value']?$temporary_head_circumference['value']:0,
|
||
"unit"=>$this->merged_data['head_circumference']['unit'],
|
||
'standard' => $temporary_head_circumference['level']?$temporary_head_circumference['level']:0,
|
||
'standard_color' => $temporary_head_circumference['color']?$temporary_head_circumference['color']:0,
|
||
'bk_color'=>'#ddfaef',
|
||
'curve_list' => $head_circumference_curve_list,
|
||
'ideal_head_circumference' => '',
|
||
];
|
||
}
|
||
// 如果有心率
|
||
if($body_last_data['heart_rate']){
|
||
$temporary_standard_color = $this->judgment_standard_color(floatval($body_last_data['heart_rate']),'heart_rate',$user_data);
|
||
$body_last_data_heart_rate_list = Db::table($this->body_db_name['body_data_new'])
|
||
->where("is_del = 0 AND aud_id = ".$data['aud_id']." AND heart_rate IS NOT NULL")
|
||
->order('record_time desc,id desc')
|
||
->field('id,heart_rate,record_time')
|
||
->page('1,5')
|
||
->select();
|
||
$heart_rate_curve_list = [
|
||
'title'=>'心率',
|
||
'key'=>'heart_rate',
|
||
'line'=>['categories'=>[],'series'=>[['color'=>'#fb8587','data'=>[]]]],
|
||
];
|
||
foreach ($body_last_data_heart_rate_list as $key => $value) {
|
||
$heart_rate_curve_list['line']['categories'][] = $value['record_time'];
|
||
$heart_rate_curve_list['line']['series'][0]['data'][] = floatval($value['heart_rate']);
|
||
}
|
||
$result_return['top_list'][] = [
|
||
"name"=>$this->merged_data['heart_rate']['name'],
|
||
'time' => $record_time,
|
||
'value' => floatval($body_last_data['heart_rate']),
|
||
"unit"=>$this->merged_data['heart_rate']['unit'],
|
||
'standard' => $temporary_standard_color[1],
|
||
'standard_color' => $temporary_standard_color[2],
|
||
'key_name' => 'heart_rate',
|
||
'bk_color'=>'#fbeeee',
|
||
'curve_list' => $heart_rate_curve_list,
|
||
'ideal_heart_rate' => $temporary_standard_color[3],
|
||
];
|
||
}
|
||
// 设置卡片顺序
|
||
$set_order = [
|
||
// 'ideal_weight', //体脂率
|
||
// 'ideal_height', //体脂率
|
||
// 'ideal_bmi', //体脂率
|
||
'fat_r', //体脂率
|
||
'fat_w', //脂肪量
|
||
'muscle', //肌肉率
|
||
'muscleval', //肌肉量
|
||
'protein', //蛋白率
|
||
'proteinval', //蛋白量
|
||
'water', //水分
|
||
'sfr', //皮下脂肪
|
||
'body_level', //肥胖等级☆
|
||
'visceral', //内脏指数
|
||
'bone', //骨重
|
||
'body_type', //身体类型☆
|
||
'score', //身体得分☆
|
||
'body_age', //身体年龄☆
|
||
];
|
||
// 处理卡片数据
|
||
if($body_last_data['record_type'] == 'by_hand_means'){
|
||
foreach ($set_order as $key => $value) {
|
||
$result_return['card_list'][] = [
|
||
'name'=>$this->merged_data[$value]['name'],
|
||
'icon'=>$this->merged_data[$value]['icon'],
|
||
'value'=>'--',
|
||
'unit'=>$this->merged_data[$value]['unit'],
|
||
'standard'=>'',
|
||
'standard_color'=>'',
|
||
'key_name'=>$value,
|
||
];
|
||
}
|
||
return $this->msg($result_return);
|
||
}else{
|
||
// 设置卡片顺序
|
||
// $set_order = [
|
||
// 'ideal_weight', //体脂率
|
||
// 'ideal_height', //体脂率
|
||
// 'ideal_bmi', //体脂率
|
||
// 'fat_r', //体脂率
|
||
// 'fat_w', //脂肪量
|
||
// 'muscle', //肌肉率
|
||
// 'muscleval', //肌肉量
|
||
// 'protein', //蛋白率
|
||
// 'proteinval', //蛋白量
|
||
// 'water', //水分
|
||
// 'sfr', //皮下脂肪
|
||
// 'body_level', //肥胖等级☆
|
||
// 'visceral', //内脏指数
|
||
// 'bone', //骨重
|
||
// 'body_type', //身体类型☆
|
||
// 'score', //身体得分☆
|
||
// 'body_age', //身体年龄☆
|
||
// ];
|
||
$temporary_three = [];
|
||
foreach ($set_order as $key => $value) {
|
||
|
||
if($value == 'body_level' || $value == 'body_type' || $value == 'body_age'){
|
||
// 如果是特殊数据
|
||
$result_return['card_list'][] = [
|
||
'name'=>$this->merged_data[$value]['name'],
|
||
'icon'=>$this->merged_data[$value]['icon'],
|
||
'value'=>$value == 'body_age'?floatval($body_last_data[$value]):$body_last_data[$value],
|
||
'unit'=>$this->merged_data[$value]['unit'],
|
||
'standard'=>'',
|
||
'standard_color'=>'',
|
||
'key_name'=>$value,
|
||
];
|
||
}else{
|
||
if($value == 'ideal_weight' || $value == 'ideal_height' || $value == 'ideal_bmi'){
|
||
$temporary_standard_color = $this->judgment_standard_color('none',$value,$user_data);
|
||
// dump($temporary_standard_color);
|
||
if($temporary_standard_color){
|
||
|
||
if($value == 'ideal_weight'){
|
||
// dump($temporary_standard_color);
|
||
// die;
|
||
$result_return['top_list'][0]['ideal_weight'] = $temporary_standard_color;
|
||
$result_return['card_list'][] = [
|
||
'name'=>$this->merged_data[$value]['name'],
|
||
'icon'=>$this->merged_data[$value]['icon'],
|
||
'value'=>$temporary_standard_color,
|
||
'unit'=>$this->merged_data[$value]['unit'],
|
||
'standard'=>'',
|
||
'standard_color'=>'',
|
||
'key_name'=>$value,
|
||
];
|
||
}else if($value == 'ideal_height'){
|
||
$result_return['top_list'][1]['ideal_height'] = $temporary_standard_color;
|
||
}else if($value == 'ideal_bmi'){
|
||
$result_return['top_list'][2]['ideal_bmi'] = $temporary_standard_color;
|
||
}
|
||
}
|
||
|
||
}else{
|
||
|
||
if($value == 'fat_w' || $value == 'muscleval' || $value == 'proteinval'){
|
||
$result_return['card_list'][] = [
|
||
'name'=>$this->merged_data[$value]['name'],
|
||
'icon'=>$this->merged_data[$value]['icon'],
|
||
'value'=>floatval($body_last_data[$value]),
|
||
'unit'=>$this->merged_data[$value]['unit'],
|
||
'standard'=>$temporary_three[$value][0],
|
||
'standard_color'=>$temporary_three[$value][1],
|
||
'key_name'=>$value,
|
||
];
|
||
}else if($value == 'score'){
|
||
$temporary_standard_color = $this->judgment_standard_color($body_last_data[$value],$value,$user_data);
|
||
$result_return['card_list'][] = [
|
||
'name'=>$this->merged_data[$value]['name'],
|
||
'icon'=>$this->merged_data[$value]['icon'],
|
||
'value'=>floatval($temporary_standard_color[0]),
|
||
'unit'=>$this->merged_data[$value]['unit'],
|
||
'standard'=>$temporary_standard_color[1],
|
||
'standard_color'=>$temporary_standard_color[2],
|
||
'key_name'=>$value,
|
||
];
|
||
}else{
|
||
|
||
$temporary_standard_color = $this->judgment_standard_color($body_last_data[$value],$value,$user_data);
|
||
// dump($temporary_standard_color);
|
||
if($temporary_standard_color){
|
||
|
||
$result_return['card_list'][] = [
|
||
'name'=>$this->merged_data[$value]['name'],
|
||
'icon'=>$this->merged_data[$value]['icon'],
|
||
'value'=>floatval($temporary_standard_color[0]),
|
||
'unit'=>$this->merged_data[$value]['unit'],
|
||
'standard'=>$temporary_standard_color[1],
|
||
'standard_color'=>$this->merged_data[$value]['list'][$temporary_standard_color[1]],
|
||
'key_name'=>$value,
|
||
];
|
||
if($value == 'fat_r'){
|
||
$temporary_three['fat_w'] = [
|
||
$temporary_standard_color[1],
|
||
$this->merged_data[$value]['list'][$temporary_standard_color[1]],
|
||
];
|
||
}
|
||
if($value == 'muscle'){
|
||
$temporary_three['muscleval'] = [
|
||
$temporary_standard_color[1],
|
||
$this->merged_data[$value]['list'][$temporary_standard_color[1]],
|
||
];
|
||
}
|
||
if($value == 'protein'){
|
||
$temporary_three['proteinval'] = [
|
||
$temporary_standard_color[1],
|
||
$this->merged_data[$value]['list'][$temporary_standard_color[1]],
|
||
];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
return $this->msg($result_return);
|
||
}
|
||
public function body_report_detailed_action($data){
|
||
|
||
$result_return = [];
|
||
|
||
$user_data = Db::table($this->body_db_name['juese'])
|
||
->where(['id'=>$data['aud_id'],'is_del'=>0])
|
||
->field('birthday,gender,target_weight,initial_weight,initial_date')
|
||
->find();
|
||
if(!$user_data){
|
||
return $this->msg(10003);
|
||
}
|
||
|
||
$body_last_data = Db::table($this->body_db_name['body_data_new'])
|
||
->where(['is_del'=>0,'aud_id'=>$data['aud_id']])
|
||
->order('record_time desc,id desc')
|
||
->find();
|
||
|
||
if(!$body_last_data){
|
||
return $this->msg($result_return);
|
||
}
|
||
$user_data['weight'] = $body_last_data['weight'];
|
||
$set_order = [
|
||
'weight', //体重
|
||
'height', //身高
|
||
'heart_rate', //心率
|
||
'head_circumference', //头围
|
||
'kcal', //BMR 静态基础代谢
|
||
'bmi', //BMI
|
||
'fat_r', //体脂率
|
||
'fat_w', //脂肪量
|
||
'muscle', //肌肉率
|
||
'muscleval', //肌肉量
|
||
'protein', //蛋白率
|
||
'proteinval', //蛋白量
|
||
'water', //水分
|
||
'sfr', //皮下脂肪
|
||
// '', //骨骼肌率
|
||
// '', //骨路肌量
|
||
'visceral', //内脏指数
|
||
// '', //肌肉控制量
|
||
// '', //脂筋控制量
|
||
'ideal_weight', //理想体重
|
||
'ideal_height', //理想身高
|
||
'ideal_bmi', //理想bmi
|
||
// '', //去脂体重
|
||
// '', //控制体量
|
||
'bone', //骨重
|
||
'body_type', //身体类型☆
|
||
'body_level', //肥胖等级☆
|
||
// '', //健康评价
|
||
'body_age', //身体年龄☆
|
||
'score', //身体得分☆
|
||
];
|
||
|
||
foreach ($set_order as $key => $value) {
|
||
if($body_last_data['record_type'] == 'by_hand_means'){
|
||
if($value == 'weight' || $value == 'height' || $value == 'bmi' || $value == 'head_circumference'){
|
||
|
||
$temporary_data_list = $this->judgment_standard_color_detailed($body_last_data[$value],$value,$user_data);
|
||
if($temporary_data_list){
|
||
$result_return[] = $temporary_data_list;
|
||
}
|
||
}else{
|
||
// $temporary_data_list = $this->merged_data[$value];
|
||
// $temporary_data_list['list'] = [];
|
||
// $temporary_data_list['standard_list'] = [];
|
||
// $temporary_data_list['value'] = '--';
|
||
// $result_return[] = $temporary_data_list;
|
||
// continue;
|
||
if($value == 'ideal_weight' || $value == 'ideal_height' || $value == 'ideal_bmi'){
|
||
$temporary_data_list = $this->judgment_standard_color_detailed(null,$value,$user_data);
|
||
if($temporary_data_list){
|
||
$temporary_data_list['value'] = '--';
|
||
if(array_key_exists('offset',$temporary_data_list) && $temporary_data_list['offset']){
|
||
$temporary_data_list['offset'] = 0;
|
||
}
|
||
$result_return[] = $temporary_data_list;
|
||
}
|
||
}else if($value == 'body_type'){
|
||
$temporary_data_list = $this->judgment_standard_color_detailed($body_last_data[$value],$value,$user_data);
|
||
if($temporary_data_list){
|
||
$temporary_data_list['l_line_color'] = ['name'=>'体脂率','standard_list'=>[['name'=>'偏低','color'=>'#EAAE29'],['name'=>'标准、偏高','color'=>'#0AD2B0'],['name'=>'过高、超高','color'=>'#F83F29']]];
|
||
$temporary_data_list['r_line_color'] = ['name'=>'肌肉量','standard_list'=>[['name'=>'偏低','color'=>'#4db4ec'],['name'=>'标准','color'=>'#8bcc4c'],['name'=>'优秀','color'=>'#159383']]];
|
||
$temporary_data_list['box_list'] = ['浮肿肥胖型','偏胖肌肉型','肌肉型偏胖','缺乏运动型','标准型','标准肌肉型','偏瘦型','偏瘦肌肉型','肌肉发达型'];
|
||
$temporary_data_list['value'] = '--';
|
||
if(array_key_exists('offset',$temporary_data_list) && $temporary_data_list['offset']){
|
||
$temporary_data_list['offset'] = 0;
|
||
}
|
||
$result_return[] = $temporary_data_list;
|
||
}
|
||
}else{
|
||
$temporary_data_list = $this->judgment_standard_color_detailed($body_last_data[$value],$value,$user_data);
|
||
if($temporary_data_list){
|
||
$temporary_data_list['value'] = '--';
|
||
if(array_key_exists('offset',$temporary_data_list) && $temporary_data_list['offset']){
|
||
$temporary_data_list['offset'] = 0;
|
||
}
|
||
$result_return[] = $temporary_data_list;
|
||
}
|
||
}
|
||
}
|
||
}else{
|
||
if($value == 'ideal_weight' || $value == 'ideal_height' || $value == 'ideal_bmi'){
|
||
$temporary_data_list = $this->judgment_standard_color_detailed(null,$value,$user_data);
|
||
if($temporary_data_list){
|
||
$result_return[] = $temporary_data_list;
|
||
}
|
||
}else if($value == 'body_type'){
|
||
$temporary_data_list = $this->judgment_standard_color_detailed($body_last_data[$value],$value,$user_data);
|
||
if($temporary_data_list){
|
||
$temporary_data_list['l_line_color'] = ['name'=>'体脂率','standard_list'=>[['name'=>'偏低','color'=>'#EAAE29'],['name'=>'标准、偏高','color'=>'#0AD2B0'],['name'=>'过高、超高','color'=>'#F83F29']]];
|
||
$temporary_data_list['r_line_color'] = ['name'=>'肌肉量','standard_list'=>[['name'=>'偏低','color'=>'#4db4ec'],['name'=>'标准','color'=>'#8bcc4c'],['name'=>'优秀','color'=>'#159383']]];
|
||
$temporary_data_list['box_list'] = ['浮肿肥胖型','偏胖肌肉型','肌肉型偏胖','缺乏运动型','标准型','标准肌肉型','偏瘦型','偏瘦肌肉型','肌肉发达型'];
|
||
$result_return[] = $temporary_data_list;
|
||
}
|
||
}else{
|
||
$temporary_data_list = $this->judgment_standard_color_detailed($body_last_data[$value],$value,$user_data);
|
||
if($temporary_data_list){
|
||
$result_return[] = $temporary_data_list;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//身体
|
||
|
||
return $this->msg($result_return);
|
||
|
||
}
|
||
public function body_report_depth_action($data){
|
||
|
||
$result_return = [];
|
||
|
||
$user_data = Db::table($this->body_db_name['juese'])
|
||
->where(['id'=>$data['aud_id'],'is_del'=>0])
|
||
->field('nickname,head_pic,birthday,gender,target_weight,initial_weight,initial_date')
|
||
->find();
|
||
if(!$user_data){
|
||
return $this->msg(10003);
|
||
}
|
||
|
||
$body_last_data = Db::table($this->body_db_name['body_data_new'])
|
||
->where(['is_del'=>0,'aud_id'=>$data['aud_id']])
|
||
->order('record_time desc,id desc')
|
||
->find();
|
||
|
||
if(!$body_last_data){
|
||
return $this->msg($result_return);
|
||
}
|
||
if($body_last_data['8_electrode_data']){
|
||
$electrode_data_8 = json_decode($body_last_data['8_electrode_data'],true);
|
||
}else{
|
||
$electrode_data_8 = [];
|
||
}
|
||
|
||
$user_data['weight'] = $body_last_data['weight'];
|
||
|
||
$temporary_data_list_score = $this->judgment_standard_color_detailed($body_last_data['score'],'score',$user_data);
|
||
|
||
// 处理顶部用户信息板块
|
||
$result_return['user_data'] = [
|
||
// 'title_key'=>'user_data',
|
||
'title_name'=>'',
|
||
'nickname'=>$user_data['nickname'],
|
||
'head_pic'=>$user_data['head_pic'],
|
||
'gender'=>$user_data['gender'],
|
||
'record_time'=>$body_last_data['record_time'],
|
||
'age'=>$this->calculate_age($user_data['birthday']),
|
||
'height'=>(float)$body_last_data['height'],
|
||
'weight'=>(float)$body_last_data['weight'],
|
||
'score'=>(float)$temporary_data_list_score?$temporary_data_list_score['value']:0,
|
||
];
|
||
|
||
// 如果有心率处理心率板块
|
||
if($body_last_data['heart_rate']){
|
||
$temporary_data_list_heart_rate = $this->judgment_standard_color_detailed($body_last_data['heart_rate'],'heart_rate',$user_data);
|
||
$result_return['heart_rate'] = [
|
||
// 'title_key'=>'heart_rate',
|
||
'title_name'=>'心脏健康',
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/heart_rate.png",
|
||
'value'=>"心率 ".$temporary_data_list_heart_rate['value'],
|
||
'unit'=>$temporary_data_list_heart_rate['unit'],
|
||
'standard'=>$temporary_data_list_heart_rate['standard'],
|
||
'standard_color'=>$temporary_data_list_heart_rate['standard_color'],
|
||
'standard_list'=>$temporary_data_list_heart_rate['standard_list'],
|
||
'offset'=>$temporary_data_list_heart_rate['offset'],
|
||
];
|
||
}else{
|
||
$result_return['heart_rate'] = [];
|
||
}
|
||
|
||
// 处理身体成分分析板块
|
||
$temporary_data_list_weight = $this->judgment_standard_color_detailed($body_last_data['weight'],'weight',$user_data);
|
||
$temporary_data_list_fat_w = $this->judgment_standard_color_detailed($body_last_data['fat_w'],'fat_w',$user_data);
|
||
$temporary_data_list_proteinval = $this->judgment_standard_color_detailed($body_last_data['proteinval'],'proteinval',$user_data);
|
||
$temporary_data_list_water = $this->judgment_standard_color_detailed($body_last_data['water'],'water',$user_data);
|
||
// 加 bcadd(,,20)
|
||
// 减 bcsub(,,20)
|
||
// 乘 bcmul(,,20)
|
||
// 除 bcdiv(,,20)
|
||
// 设置临时身体成分数据变量
|
||
$temporary_data_list = [];
|
||
// 体重获取标准信息以及标准描述
|
||
if(count($temporary_data_list_weight['standard_list'])){
|
||
foreach ($temporary_data_list_weight['standard_list'] as $key => $value) {
|
||
if($value['text'] == $temporary_data_list_weight['standard']){
|
||
$temporary_body_data['weight']['standard_arr'] = "(".$value['min_val']."~".$value['max_val'].")";
|
||
$temporary_body_data['weight']['standard_str'] = $value['text'];
|
||
}
|
||
}
|
||
}else{
|
||
$temporary_body_data['weight']['standard_arr'] = '';
|
||
$temporary_body_data['weight']['standard_str'] = '';
|
||
}
|
||
// 脂肪量获取标准信息以及体重占比值
|
||
if(count($temporary_data_list_fat_w['standard_list'])){
|
||
foreach ($temporary_data_list_fat_w['standard_list'] as $key => $value) {
|
||
if($value['text'] == $temporary_data_list_fat_w['standard']){
|
||
$temporary_body_data['fat_w']['standard_arr'] = "(".$value['min_val']."~".$value['max_val'].")";
|
||
$temporary_body_data['fat_w']['standard_str'] = bcdiv($body_last_data['fat_w'],$body_last_data['weight'],2);
|
||
}
|
||
}
|
||
}else{
|
||
$temporary_body_data['fat_w']['standard_arr'] = '';
|
||
$temporary_body_data['fat_w']['standard_str'] = bcdiv($body_last_data['fat_w'],$body_last_data['weight'],2);
|
||
}
|
||
// 蛋白量获取标准信息以及体重占比值
|
||
if(count($temporary_data_list_proteinval['standard_list'])){
|
||
foreach ($temporary_data_list_proteinval['standard_list'] as $key => $value) {
|
||
if($value['text'] == $temporary_data_list_proteinval['standard']){
|
||
$temporary_body_data['proteinval']['standard_arr'] = "(".$value['min_val']."~".$value['max_val'].")";
|
||
$temporary_body_data['proteinval']['standard_str'] = bcdiv($body_last_data['proteinval'],$body_last_data['weight'],2);
|
||
}
|
||
}
|
||
}else{
|
||
$temporary_body_data['proteinval']['standard_arr'] = '';
|
||
$temporary_body_data['proteinval']['standard_str'] = bcdiv($body_last_data['proteinval'],$body_last_data['weight'],2);
|
||
}
|
||
// 水分获取标准信息以及体重占比值
|
||
if(count($temporary_data_list_water['standard_list'])){
|
||
foreach ($temporary_data_list_water['standard_list'] as $key => $value) {
|
||
if($value['text'] == $temporary_data_list_water['standard']){
|
||
$temporary_body_data['water']['standard_arr'] = "(".$value['min_val']."~".$value['max_val'].")";
|
||
$temporary_body_data['water']['standard_str'] = bcdiv($body_last_data['water'],$body_last_data['weight'],2);
|
||
}
|
||
}
|
||
}else{
|
||
$temporary_body_data['water']['standard_arr'] = '';
|
||
$temporary_body_data['water']['standard_str'] = bcdiv($body_last_data['water'],$body_last_data['weight'],2);
|
||
}
|
||
$result_return['body_data'] = [
|
||
'title_name'=>'身体成分分析',
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_data.png",
|
||
"title"=>"体重".$temporary_body_data['weight']['standard_arr'],
|
||
'standard'=>$temporary_body_data['weight']['standard_str'] == ''?'':$temporary_body_data['weight']['standard_str'],
|
||
"description"=>"*总体重=体水分量+蛋白质量+脂肪量+其他",
|
||
'list'=>[
|
||
['color'=>'#3E7AF6','name'=>'体水分量','scope'=>$temporary_body_data['water']['standard_arr'],'value'=>(float)$body_last_data['water'],'offset'=>$temporary_body_data['water']['standard_str']],
|
||
['color'=>'#FFB119','name'=>'蛋白质量','scope'=>$temporary_body_data['proteinval']['standard_arr'],'value'=>(float)$body_last_data['proteinval'],'offset'=>$temporary_body_data['proteinval']['standard_str']],
|
||
['color'=>'#31D4F5','name'=>'脂肪量','scope'=>$temporary_body_data['fat_w']['standard_arr'],'value'=>(float)$body_last_data['fat_w'],'offset'=>$temporary_body_data['fat_w']['standard_str']],
|
||
// ['color'=>'#E749F5','name'=>'肌肉量','scope'=>$temporary_body_data['muscleval'][0],'value'=>$body_last_data['muscleval'],'offset'=>$temporary_body_data['muscleval'][1]],
|
||
// ['color'=>'#1EA04A','name'=>'骨重','scope'=>$temporary_body_data['bone'][0],'value'=>$body_last_data['bone'],'offset'=>$temporary_body_data['bone'][1]],
|
||
['color'=>'#999999','name'=>'其他','scope'=>"",'value'=>'','offset'=>bcsub(bcsub(bcsub(100,$temporary_body_data['water']['standard_str'],20),$temporary_body_data['proteinval']['standard_str'],20),$temporary_body_data['fat_w']['standard_str'],2)],
|
||
],
|
||
'value'=>(float)$body_last_data['weight'],
|
||
'unit'=>$temporary_data_list_weight['unit'],
|
||
];
|
||
|
||
|
||
// 处理肌肉脂肪分析
|
||
$temporary_data_list_muscleval = $this->judgment_standard_color_detailed($body_last_data['muscleval'],'muscleval',$user_data);
|
||
$result_return['muscle_fat'] = [
|
||
'title_name'=>'肌肉脂肪分析',
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/muscle_fat.png",
|
||
'list'=>[],
|
||
];
|
||
$result_return['muscle_fat']['list'][] = $temporary_data_list_weight;
|
||
$result_return['muscle_fat']['list'][] = $temporary_data_list_muscleval;
|
||
$result_return['muscle_fat']['list'][] = $temporary_data_list_fat_w;
|
||
foreach ($result_return['muscle_fat']['list'] as $key => $value) {
|
||
$result_return['muscle_fat']['list'][$key]['list'] = $value['standard_list'];
|
||
}
|
||
//肌肉脂肪分析
|
||
// $ceshi = [
|
||
// // 'title_key'=>'muscle_fat',
|
||
// 'title_name'=>'肌肉脂肪分析',
|
||
// "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/muscle_fat.png",
|
||
// // "title"=>$temporary_body_data['weight'][0],
|
||
// 'list'=>[
|
||
// [
|
||
// 'name'=>'体重',
|
||
// 'unit'=>'kg',
|
||
// 'description'=>$this->merged_data['weight']['description'],
|
||
// 'smart_tip_description'=>'',
|
||
// 'icon'=>'',
|
||
// 'list'=>$this->merged_data['weight']['standard_list'],
|
||
// 'standard_list'=>[
|
||
// ['min_val'=>'0','max_val'=>'20','text'=>'低','color'=>'#F8595D'],
|
||
// ['min_val'=>'20','max_val'=>'40','text'=>'偏低','color'=>'#FFAF04'],
|
||
// ['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D168'],
|
||
// ['min_val'=>'60','max_val'=>'80','text'=>'偏高','color'=>'#FFAF04'],
|
||
// ['min_val'=>'80','max_val'=>'100','text'=>'高','color'=>'#F8595D'],
|
||
// ],
|
||
// 'key_name'=>'weight',
|
||
// 'value'=>50,
|
||
// 'standard'=>'标准',
|
||
// 'standard_color'=>'#59D168',
|
||
// 'offset'=>'50',
|
||
// ],
|
||
// [
|
||
// 'name'=>'骨骼肌量(kg)',
|
||
// 'unit'=>'kg',
|
||
// 'description'=>$this->merged_data['weight']['description'],
|
||
// 'smart_tip_description'=>'',
|
||
// 'icon'=>'',
|
||
// 'list'=>$this->merged_data['weight']['standard_list'],
|
||
// 'standard_list'=>[
|
||
// ['min_val'=>'0','max_val'=>'20','text'=>'低','color'=>'#F8595D'],
|
||
// ['min_val'=>'20','max_val'=>'40','text'=>'偏低','color'=>'#FFAF04'],
|
||
// ['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D168'],
|
||
// ['min_val'=>'60','max_val'=>'80','text'=>'偏高','color'=>'#FFAF04'],
|
||
// ['min_val'=>'80','max_val'=>'100','text'=>'高','color'=>'#F8595D'],
|
||
// ],
|
||
// 'key_name'=>'weight',
|
||
// 'value'=>45,
|
||
// 'standard'=>'标准',
|
||
// 'standard_color'=>'#59D168',
|
||
// 'offset'=>'45',
|
||
// ],
|
||
// [
|
||
// 'name'=>'脂肪量',
|
||
// 'unit'=>'kg',
|
||
// 'description'=>$this->merged_data['weight']['description'],
|
||
// 'smart_tip_description'=>'',
|
||
// 'icon'=>'',
|
||
// 'list'=>$this->merged_data['weight']['standard_list'],
|
||
// 'standard_list'=>[
|
||
// ['min_val'=>'0','max_val'=>'20','text'=>'低','color'=>'#F8595D'],
|
||
// ['min_val'=>'20','max_val'=>'40','text'=>'偏低','color'=>'#FFAF04'],
|
||
// ['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D168'],
|
||
// ['min_val'=>'60','max_val'=>'80','text'=>'偏高','color'=>'#FFAF04'],
|
||
// ['min_val'=>'80','max_val'=>'100','text'=>'高','color'=>'#F8595D'],
|
||
// ],
|
||
// 'key_name'=>'weight',
|
||
// 'value'=>70,
|
||
// 'standard'=>'偏高',
|
||
// 'standard_color'=>'#FFAF04',
|
||
// 'offset'=>'70',
|
||
// ]
|
||
// ],
|
||
// ];
|
||
|
||
// return $this->msg(['a'=>$result_return['muscle_fat'],'b'=>$ceshi]);
|
||
|
||
|
||
|
||
// 处理节段脂肪分析(如果是8电极才有)
|
||
// return $this->msg($electrode_data_8);
|
||
if(count($electrode_data_8) > 0){
|
||
$result_return['segment_fat'] = [
|
||
// 'title_key'=>'segment_fat',
|
||
'title_name'=>'节段脂肪分析',
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/segment_fat.png",
|
||
"bg_img"=>"https://tc.pcxbc.com/new_reedaw/icon/segment_fat".$user_data['gender'].".png",
|
||
'list'=>[
|
||
[
|
||
'name'=>'L:',
|
||
'value'=>$electrode_data_8['bodyfatkgleftarm'],//左手脂肪量,kg
|
||
'unit'=>'kg',
|
||
'value2'=>$electrode_data_8['bodyfatrateleftarm'],//左手脂肪率,%
|
||
'unit2'=>'%',
|
||
],
|
||
[
|
||
'name'=>'R:',
|
||
'value'=>$electrode_data_8['bodyfatkgrightarm'],//右手脂肪量,kg
|
||
'unit'=>'kg',
|
||
'value'=>$electrode_data_8['bodyfatraterightarm'],//右手脂肪率,%
|
||
'unit'=>'%',
|
||
],
|
||
[
|
||
'name'=>'B:',
|
||
'value'=>$electrode_data_8['bodyfatkgtrunk'],//躯干脂肪量,kg
|
||
'unit'=>'kg',
|
||
'value'=>$electrode_data_8['bodyfatraterunk'],//躯干脂肪率,%
|
||
'unit'=>'%',
|
||
],
|
||
[
|
||
'name'=>'L:',
|
||
'value'=>$electrode_data_8['bodyfatkgleftleg'],//左脚脂肪量,kg
|
||
'unit'=>'kg',
|
||
'value'=>$electrode_data_8['bodyfatrateleftleg'],//左脚脂肪率,%
|
||
'unit'=>'%',
|
||
],
|
||
[
|
||
'name'=>'R:',
|
||
'value'=>$electrode_data_8['bodyfatkgrightleg'],//右脚脂肪量,kg
|
||
'unit'=>'kg',
|
||
'value'=>$electrode_data_8['bodyfatraterightleg'],//右脚脂肪率,%
|
||
'unit'=>'%',
|
||
],
|
||
],
|
||
];
|
||
|
||
// 肌肉平衡
|
||
$result_return['segment_muscle'] = [
|
||
// 'title_key'=>'segment_muscle',
|
||
'title_name'=>'肌肉平衡',
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/segment_muscle.png",
|
||
"bg_img"=>"https://tc.pcxbc.com/new_reedaw/icon/segment_fat".$user_data['gender'].".png",
|
||
'list'=>[
|
||
[
|
||
'name'=>'L:',
|
||
'value'=>$electrode_data_8['musclekgleftarm'],//左手肌肉量,kg
|
||
'unit'=>'kg',
|
||
'value2'=>$electrode_data_8['musclerateleftarm'],//左手肌肉率,%
|
||
'unit2'=>'%',
|
||
],
|
||
[
|
||
'name'=>'R:',
|
||
'value'=>$electrode_data_8['musclekgrightarm'],//右手肌肉量,kg
|
||
'unit'=>'kg',
|
||
'value'=>$electrode_data_8['muscleraterightarm'],//右手肌肉率,%
|
||
'unit'=>'%',
|
||
],
|
||
[
|
||
'name'=>'B:',
|
||
'value'=>$electrode_data_8['musclekgtrunk'],//躯干肌肉量,kg
|
||
'unit'=>'kg',
|
||
'value'=>$electrode_data_8['muscleratetrunk'],//躯干肌肉率,%
|
||
'unit'=>'%',
|
||
],
|
||
[
|
||
'name'=>'L:',
|
||
'value'=>$electrode_data_8['musclekgleftleg'],//左脚肌肉量,kg
|
||
'unit'=>'kg',
|
||
'value'=>$electrode_data_8['musclerateleftleg'],//左脚肌肉率,%
|
||
'unit'=>'%',
|
||
],
|
||
[
|
||
'name'=>'R:',
|
||
'value'=>$electrode_data_8['musclekgrightleg'],//右脚肌肉量,kg
|
||
'unit'=>'kg',
|
||
'value'=>$electrode_data_8['muscleraterightleg'],//右脚肌肉率,%
|
||
'unit'=>'%',
|
||
],
|
||
],
|
||
];
|
||
}
|
||
|
||
|
||
|
||
//处理肥胖分析
|
||
$temporary_data_list_fat_r = $this->judgment_standard_color_detailed($body_last_data['fat_r'],'fat_r',$user_data);
|
||
$temporary_data_list_bmi = $this->judgment_standard_color_detailed($body_last_data['bmi'],'bmi',$user_data);
|
||
// $temporary_data_list_muscleval = $this->judgment_standard_color_detailed($body_last_data['fat_r'],'fat_r',$user_data);
|
||
$result_return['fat_analysis'] = [
|
||
// 'title_key'=>'fat_analysis',
|
||
'title_name'=>'肥胖分析',
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/fat_analysis.png",
|
||
// "title"=>$temporary_body_data['weight'][0],
|
||
'list'=>[],
|
||
];
|
||
$result_return['fat_analysis']['list'][] = $temporary_data_list_fat_r;
|
||
$result_return['fat_analysis']['list'][] = $temporary_data_list_bmi;
|
||
foreach ($result_return['fat_analysis']['list'] as $key => $value) {
|
||
$result_return['fat_analysis']['list'][$key]['list'] = $value['standard_list'];
|
||
}
|
||
|
||
|
||
//体重控制
|
||
if($body_last_data['age'] <= 18){
|
||
$month_num = $this->calculateAgeInMonthsWithPrecision($user_data['birthday']);
|
||
// dump($month_num);
|
||
$standard_weight = Db::table($this->body_db_name['weight'])
|
||
->where("Month <= $month_num AND Sex = ".$user_data['gender'])
|
||
->order('Month desc')
|
||
->field('id,median,Month')
|
||
->find();
|
||
$user_BMR = $this->calculateBMR_BC($body_last_data['age'],$body_last_data['weight'],$user_data['gender']);
|
||
$result_return['weight_controller'] = [
|
||
// 'title_key'=>'weight_controller',
|
||
'title_name'=>'体重控制',
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/weight_controller.png",
|
||
// "title"=>$temporary_body_data['weight'][0],
|
||
'list'=>[
|
||
['name'=>'数据','value'=>'测量值'],
|
||
['name'=>'标准体重','value'=>(float)$standard_weight.'kg'],
|
||
['name'=>'控制体重','value'=>bcsub($standard_weight['median'],$body_last_data['weight'],2).'kg'],
|
||
['name'=>'BMR','value'=>$user_BMR != false?$user_BMR:'异常'],
|
||
],
|
||
];
|
||
}else{
|
||
$standard_weight = $this->calculateStandardWeight($user_data['gender'],$body_last_data['age'],$body_last_data['height']);
|
||
$user_BMR = $this->calculateBMR_BC($body_last_data['age'],$body_last_data['weight'],$user_data['gender']);
|
||
$result_return['weight_controller'] = [
|
||
'title_name'=>'体重控制',
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/weight_controller.png",
|
||
// "title"=>$temporary_body_data['weight'][0],
|
||
'list'=>[
|
||
['name'=>'数据','value'=>'测量值'],
|
||
['name'=>'标准体重','value'=>(float)$standard_weight.'kg'],
|
||
['name'=>'控制体重','value'=>bcsub($standard_weight,$body_last_data['weight'],2).'kg'],
|
||
['name'=>'BMR','value'=>$user_BMR != false?$user_BMR:'异常'],
|
||
],
|
||
];
|
||
}
|
||
|
||
//身体类型(这还是假数据,需要根据接口确认正确的box_list以及value)
|
||
$result_return['body_type'] = [
|
||
// 'title_key'=>'body_type',
|
||
'title_name'=>'身体类型',
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_data.png",
|
||
// "title"=>$temporary_body_data['weight'][0],
|
||
'l_line_color'=>['name'=>'脂肪率','standard_list'=>[['name'=>'偏低','color'=>'#4db4ec'],['name'=>'标准','color'=>'#8bcc4c'],['name'=>'偏高','color'=>'#dc0225']]],
|
||
'r_line_color'=>['name'=>'肌肉量','standard_list'=>[['name'=>'偏低','color'=>'#4db4ec'],['name'=>'标准','color'=>'#8bcc4c'],['name'=>'优秀','color'=>'#299744']]],
|
||
'box_list'=>['浮肿肥胖型','偏胖肌肉型','肌肉型偏胖','缺乏运动型','标准型','标准肌肉型','偏瘦型','偏瘦肌肉型','肌肉发达型'],
|
||
'value'=>'浮肿肥胖型',
|
||
];
|
||
|
||
//其他指标
|
||
$result_return['other_data'] = [
|
||
// 'title_key'=>'other_data',
|
||
'title_name'=>'其他指标',
|
||
"icon"=>"https://tc.pcxbc.com/new_reedaw/icon/other_data.png",
|
||
// "title"=>$temporary_body_data['weight'][0],
|
||
'list'=>[
|
||
['name'=>'项目','value'=>'测量值'],
|
||
['name'=>'去脂体重','value'=>bcsub($body_last_data['weight'],$body_last_data['fat_w'],2).'kg'],
|
||
['name'=>'皮下脂肪量','value'=>$body_last_data['sfr'].'kg'],
|
||
['name'=>'身体年龄','value'=>$body_last_data['body_age']],
|
||
['name'=>'内脏脂肪','value'=>$body_last_data['visceral']],
|
||
],
|
||
];
|
||
|
||
|
||
return $this->msg($result_return);
|
||
}
|
||
public function set_target_weight_action($data){
|
||
$user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['target_weight'=>$data['weight']]);
|
||
if($user_data){
|
||
return $this->msg([]);
|
||
}else{
|
||
return $this->msg(10002);
|
||
}
|
||
}
|
||
public function set_initial_weight_action($data){
|
||
$data['time'] = $data['time'].' '.date('H:i:s');
|
||
$user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]);
|
||
if($user_data){
|
||
return $this->msg([]);
|
||
}else{
|
||
return $this->msg(10002);
|
||
}
|
||
}
|
||
public function history_list_page_action($data,$type){
|
||
$return_result = [];
|
||
$result = Db::table($this->body_db_name['body_data_new'])
|
||
->where(['aud_id'=>$data['aud_id'],'is_del'=>0])
|
||
->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,height,weight,bmi")
|
||
->order('record_time desc')
|
||
->page($data['page'],$this->pagesize)
|
||
->select();
|
||
$return_result['totalrows'] = Db::table($this->body_db_name['body_data_new'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->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) {
|
||
array_push($return_result['rows'],[
|
||
'id'=>$value['id'],
|
||
'v1'=>floatval($value['height']),
|
||
'v2'=>floatval($value['weight']),
|
||
'v3'=>floatval($value['bmi']),
|
||
'v1_name'=>'身高',
|
||
'v2_name'=>'体重',
|
||
'v3_name'=>'BMI',
|
||
'record_time'=>$value['b_time'],
|
||
]);
|
||
}
|
||
return $this->msg($return_result);
|
||
}
|
||
public function history_detailed_action($data){
|
||
// 加 bcadd(,,20)
|
||
// 减 bcsub(,,20)
|
||
// 乘 bcmul(,,20)
|
||
// 除 bcdiv(,,20)
|
||
// 设置排除在外的数据类型start
|
||
$exclude_data_arr = ['height','weight','age','bmi'];
|
||
// 设置排除在外的数据类型end
|
||
$result = Db::table($this->body_db_name['body_data_new'])->where(['id'=>$data['id']])->find();
|
||
$for_data_arr = ['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'=>['体型','']];
|
||
if($result){
|
||
$result_data = [];
|
||
foreach ($for_data_arr as $key => $value) {
|
||
|
||
$temporary_arr['key_name'] = $key;
|
||
$temporary_arr['name'] = $value[0];
|
||
// 身体数据处理,如果没有阻抗,则只显示四项$exclude_data_arr
|
||
if($result['record_type'] != 'by_device_adc'){
|
||
if(!in_array($key, $exclude_data_arr)){
|
||
continue;
|
||
}else{
|
||
$temporary_arr['value'] = $result[$key];
|
||
}
|
||
}else{
|
||
if($key == 'un_fat_w_weight'){
|
||
$temporary_arr['value'] = bcsub($result['weight'],$result['fat_w'],2);
|
||
}else{
|
||
if(array_key_exists($key,$result)){
|
||
$temporary_arr['value'] = $result[$key];
|
||
}
|
||
|
||
}
|
||
}
|
||
$temporary_arr['unit'] = $value[1];
|
||
array_push($result_data,$temporary_arr);
|
||
}
|
||
//
|
||
// 添加头围详细start
|
||
if($result['head_circumference']){
|
||
array_unshift($result_data,[
|
||
'key_name'=>'head_circumference',
|
||
'name'=>'头围',
|
||
'value'=>json_decode($result['head_circumference'],true)['value'] == 0?"0":json_decode($result['head_circumference'],true)['value'],
|
||
'unit'=>'cm',
|
||
]);
|
||
}
|
||
// 添加头围详细end
|
||
// 添加心率详细start
|
||
if($result['heart_rate']){
|
||
array_unshift($result_data,[
|
||
'key_name'=>'heart_rate',
|
||
'name'=>'心率',
|
||
'value'=>$result['heart_rate'],
|
||
'unit'=>'跳/分钟',
|
||
]);
|
||
}
|
||
// 添加心率详细end
|
||
return $this->msg($result_data);
|
||
}else{
|
||
return $this->msg(10004);
|
||
}
|
||
|
||
}
|
||
public function history_del_action($data){
|
||
|
||
$result = Db::table($this->body_db_name['body_data_new'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
|
||
if($result){
|
||
// 添加心率详细end
|
||
return $this->msg([]);
|
||
}else{
|
||
return $this->msg(10002);
|
||
}
|
||
|
||
}
|
||
public function curve_detailed_action($data){
|
||
|
||
$user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,target_weight,initial_weight,initial_date')->find();
|
||
if(!$user_data){
|
||
return $this->msg(10003);
|
||
}
|
||
|
||
|
||
$weight_result = null;
|
||
if($user_data['target_weight'] == null || $user_data['initial_weight'] == null){
|
||
$user_data['target_weight'] = $user_data['target_weight'] == null?0:$user_data['target_weight'];
|
||
$user_data['initial_weight'] = $user_data['initial_weight'] == null?0:$user_data['initial_weight'];
|
||
}else{
|
||
$weight_result = Db::table($this->body_db_name['body_data_new'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,weight,record_time')->find();
|
||
}
|
||
|
||
$return_data['target_weight'] = $user_data['target_weight'];
|
||
$return_data['initial_weight'] = $user_data['initial_weight'];
|
||
if($weight_result){
|
||
$return_data['calculate_time'] = $this->daysSince($user_data['initial_date']);
|
||
$return_data['calculate_val'] = bcsub($weight_result['weight'],$data['initial_weight'],2);
|
||
}else{
|
||
$return_data['calculate_time'] = 0;
|
||
$return_data['calculate_val'] = 0;
|
||
}
|
||
|
||
$db_type = [['weight','体重'],['height','身高'],['bmi','BMI'],['heart_rate','心率'],['head_circumference_val','头围']];
|
||
|
||
// foreach ($variable as $key => $value) {
|
||
// # code...
|
||
// }
|
||
|
||
$data['s_time'] = $data['s_time'].' 00:00:00';
|
||
$data['e_time'] = $data['e_time'].' 23:59:59';
|
||
|
||
$cha_data = Db::table($this->body_db_name['body_data_new'])
|
||
->where("aud_id = ".$data['aud_id']." AND is_del = 0 AND record_time >= '".$data['s_time']."' AND record_time <= '".$data['e_time']."'")
|
||
->order('record_time desc')
|
||
->field('id,weight,height,bmi,heart_rate,head_circumference_val,LEFT(record_time,10) as record_time')
|
||
->select();
|
||
|
||
$temporary_arr = [];
|
||
$return_data['curve_list'] = [];
|
||
foreach ($db_type as $key => $value) {
|
||
$temporary_arr = [];
|
||
// $temporary_arr['key'] = $value[0];
|
||
$temporary_arr['title'] = $value[1];
|
||
$temporary_arr['line'] = [
|
||
'categories' => [],
|
||
'series' => [
|
||
['color' => "#000000",'data' => []]
|
||
],
|
||
];
|
||
|
||
foreach ($cha_data as $k => $v) {
|
||
if($v[$value[0]]){
|
||
$temporary_arr['line']['categories'][] = $v['record_time'];
|
||
$temporary_arr['line']['series'][0]['data'][] = floatval($v[$value[0]]);
|
||
}
|
||
|
||
}
|
||
$return_data['curve_list'][] = $temporary_arr;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// if($data['type'] == 'heart_rate'){
|
||
// $where_str = "aud_id = ".$data['aud_id']." AND heart_rate is not null AND is_del = 0";
|
||
// $field_str = "id,record_time,heart_rate as val_data";
|
||
// }else if($data['type'] == 'head_circumference'){
|
||
// $where_str = "aud_id = ".$data['aud_id']." AND head_circumference_val is not null AND is_del = 0";
|
||
// $field_str = "id,record_time,head_circumference_val as val_data";
|
||
// }else{
|
||
// $where_str = "aud_id = ".$data['aud_id']." AND is_del = 0";
|
||
// $field_str = "id,record_time,".$data['type']." as val_data";
|
||
// }
|
||
|
||
|
||
// $return_data['curve_list'] = [
|
||
// 'key' => $data['type'],
|
||
// 'line' => [
|
||
// 'categories' => [],
|
||
// 'series' => [
|
||
// 'color' => "#000000",
|
||
// 'data' => [],
|
||
// ],
|
||
// ],
|
||
// ];
|
||
|
||
// foreach ($cha_data as $key => $value) {
|
||
// $return_data['curve_list']['line']['categories'][] = $value['record_time'];
|
||
// $return_data['curve_list']['line']['series']['data'][] = $value['val_data'];
|
||
// }
|
||
|
||
|
||
return $this->msg($return_data);
|
||
|
||
}
|
||
|
||
################################################################工具################################################################
|
||
################################################################工具################################################################
|
||
|
||
|
||
|
||
|
||
|
||
// 处理一般落点
|
||
public function process_offset_action($val, $list) {
|
||
|
||
$count = count($list);
|
||
if($count <= 0){
|
||
return 0;
|
||
}
|
||
// dump($val);
|
||
// dump($list);
|
||
// die;
|
||
// 边界检查:小于最小值
|
||
$firstMin = floatval($list[0]['min_val']);
|
||
if (floatval($val) < $firstMin) {
|
||
return '0';
|
||
}
|
||
|
||
// 边界检查:大于最大值
|
||
$lastMax = floatval($list[$count-1]['max_val']);
|
||
if (floatval($val) > $lastMax) {
|
||
return '100';
|
||
}
|
||
|
||
// 找到数值所在的区间
|
||
for ($i = 0; $i < $count; $i++) {
|
||
$item = $list[$i];
|
||
$valNum = floatval($val);
|
||
$minNum = floatval($item['min_val']);
|
||
$maxNum = floatval($item['max_val']);
|
||
|
||
// 如果是第一个区间,包含最小值
|
||
if ($i == 0 && $valNum <= $maxNum) {
|
||
$index = $i;
|
||
break;
|
||
}
|
||
// 如果是最后一个区间,包含最大值
|
||
elseif ($i == $count - 1 && $valNum >= $minNum) {
|
||
$index = $i;
|
||
break;
|
||
}
|
||
// 中间区间
|
||
elseif ($valNum >= $minNum && $valNum < $maxNum) {
|
||
$index = $i;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (!isset($index)) {
|
||
return '0';
|
||
}
|
||
|
||
// 计算基准值
|
||
$itemPercent = bcdiv('100', strval($count), 20);
|
||
$basePercent = bcmul(strval($index), $itemPercent, 20);
|
||
|
||
// 计算当前区间内的百分比
|
||
$item = $list[$index];
|
||
$minVal = $item['min_val'];
|
||
$maxVal = $item['max_val'];
|
||
|
||
$rangeWidth = bcsub($maxVal, $minVal, 20);
|
||
|
||
// 如果范围宽度为0,直接返回基准百分比
|
||
if (floatval($rangeWidth) == 0) {
|
||
$result = bcdiv($basePercent, '1', 1);
|
||
return $result;
|
||
}
|
||
|
||
$offset = bcsub($val, $minVal, 20);
|
||
$percentInRange = bcdiv($offset, $rangeWidth, 20);
|
||
$currentPercent = bcmul($percentInRange, $itemPercent, 20);
|
||
|
||
// 计算总百分比并格式化
|
||
$result = bcadd($basePercent, $currentPercent, 1);
|
||
// $result = bcdiv($totalPercent, '1', 1);
|
||
|
||
return $result;
|
||
}
|
||
// 发送信息获取身体数据
|
||
public function send_body_data($data,$type){
|
||
if($type == '4_electrode'){
|
||
// 使用接口调用照良那边的 进行计算start
|
||
$url = 'https://klcz.pcxbc.com/open-api/calc/healthcalc/bodyfat3';
|
||
if($data['age'] < '3'){
|
||
$data['hasStandardList'] = true;
|
||
}else{
|
||
unset($data['birthDay']);
|
||
unset($data['head']);
|
||
}
|
||
$request_result = $this->postRequest($url,$data);
|
||
}else{
|
||
// 使用接口调用照良那边的 进行计算start
|
||
$url = 'https://ybapi.ybhdmob.com/api/third/body120';
|
||
$data['body'] = $data['adc'];
|
||
$data['sex'] = $data['gender'];
|
||
unset($data['adc']);
|
||
unset($data['gender']);
|
||
unset($data['birthDay']);
|
||
$request_result = $this->postRequest($url,$data);
|
||
}
|
||
if($request_result['code'] != 0){
|
||
return false;
|
||
}else{
|
||
return $request_result['data'];
|
||
}
|
||
|
||
}
|
||
//简要身体数据标准和颜色
|
||
public function judgment_standard_color($data,$type,$user){
|
||
$linshi_data = [];
|
||
$month_num = $this->calculateAgeInMonthsWithPrecision($user['birthday']);
|
||
$age = $this->calculate_age($user['birthday']);
|
||
$gender_val = $user['gender'];
|
||
$return_data = [$data];
|
||
if($type == 'weight'){
|
||
|
||
$linshi_data = $this->merged_data['weight'];
|
||
$bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
$linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f2sd'];
|
||
$linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f2sd'];
|
||
$linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][3]['max_val'] = $bhw_date[0]['z2sd'];
|
||
$linshi_data['standard_list'][4]['min_val'] = $bhw_date[0]['z2sd'];
|
||
$linshi_data['standard_list'][4]['max_val'] = $bhw_date[0]['z3sd'];
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$return_data[] = $v['text'];
|
||
$return_data[] = $v['color'];
|
||
}
|
||
}
|
||
// dump($return_data);
|
||
if(count($return_data) <= 1){
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else{
|
||
|
||
$return_data[] = '';
|
||
$return_data[] = '';
|
||
return $return_data;
|
||
}
|
||
}else if($type == 'height'){
|
||
$linshi_data = $this->merged_data['height'];
|
||
$bhw_date = Db::table($this->body_db_name['height'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
$linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f2sd'];
|
||
$linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f2sd'];
|
||
$linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][3]['max_val'] = $bhw_date[0]['z2sd'];
|
||
$linshi_data['standard_list'][4]['min_val'] = $bhw_date[0]['z2sd'];
|
||
$linshi_data['standard_list'][4]['max_val'] = $bhw_date[0]['z3sd'];
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$return_data[] = $v['text'];
|
||
$return_data[] = $v['color'];
|
||
}
|
||
}
|
||
if(count($return_data) <= 1){
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else{
|
||
$return_data[] = '';
|
||
$return_data[] = '';
|
||
return $return_data;
|
||
}
|
||
}else if($type == 'bmi'){
|
||
$linshi_data = $this->merged_data['bmi'];
|
||
$bhw_date = Db::table($this->body_db_name['bmi'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
$linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z2sd'];
|
||
$linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z2sd'];
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$return_data[] = $v['text'];
|
||
$return_data[] = $v['color'];
|
||
}
|
||
}
|
||
if(count($return_data) <= 1){
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else{
|
||
$return_data[] = '';
|
||
$return_data[] = '';
|
||
return $return_data;
|
||
}
|
||
}else if($type == 'heart_rate'){
|
||
$linshi_data = $this->merged_data['heart_rate'];
|
||
foreach ($this->heart_rate as $key => $value) {
|
||
if($month_num > $value['age']['min'] && $month_num <= $value['age']['max']){
|
||
$linshi_data['standard_list'][0]['max_val'] = $value[$gender_val]['min'];
|
||
$linshi_data['standard_list'][1]['min_val'] = $value[$gender_val]['min'];
|
||
$linshi_data['standard_list'][1]['max_val'] = $value[$gender_val]['max'];
|
||
$linshi_data['standard_list'][2]['min_val'] = $value[$gender_val]['max'];
|
||
$linshi_data['standard_list'][2]['max_val'] = 300;
|
||
break;
|
||
}
|
||
}
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$return_data[] = $v['text'];
|
||
$return_data[] = $v['color'];
|
||
$return_data[] = bcdiv(bcadd($linshi_data['standard_list'][1]['min_val'],$linshi_data['standard_list'][1]['max_val'],20),2,0);
|
||
}
|
||
}
|
||
if(count($return_data) <= 1){
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
$return_data[] = 0;
|
||
}
|
||
return $return_data;
|
||
}else if($type == 'ideal_weight'){
|
||
$bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
return $bhw_date[0]['median'];
|
||
}else{
|
||
return false;
|
||
}
|
||
}else if($type == 'ideal_height'){
|
||
$bhw_date = Db::table($this->body_db_name['height'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
return $bhw_date[0]['median'];
|
||
}else{
|
||
return false;
|
||
}
|
||
}else if($type == 'ideal_bmi'){
|
||
$bhw_date = Db::table($this->body_db_name['bmi'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
return $bhw_date[0]['median'];
|
||
}else{
|
||
return false;
|
||
}
|
||
}else if($type == 'fat_r'){//'fat_w'同一标准
|
||
if(
|
||
($gender_val==1 && $age<30 && $data<10) ||
|
||
($gender_val==1 && $age>=30 && $data<11) ||
|
||
($gender_val==2 && $age<30 && $data<20) ||
|
||
($gender_val==2 && $age>=30 && $data<21)){
|
||
$return_data[] = '偏低';
|
||
$return_data[] = $this->merged_data[$type]['list']['偏低'];
|
||
}else if(
|
||
($gender_val==1 && $age<30 && $data>=10 && $data<21) ||
|
||
($gender_val==1 && $age>=30 && $data>=11 && $data<22) ||
|
||
($gender_val==2 && $age<30 && $data>=20 && $data<31) ||
|
||
($gender_val==2 && $age>=30 && $data>=21 && $data<32)){
|
||
$return_data[] = '标准';
|
||
$return_data[] = $this->merged_data[$type]['list']['标准'];
|
||
}else if(
|
||
($gender_val==1 && $age<30 && $data>=21 && $data<26) ||
|
||
($gender_val==1 && $age>=30 && $data>=22 && $data<27) ||
|
||
($gender_val==2 && $age<30 && $data>=31 && $data<38) ||
|
||
($gender_val==2 && $age>=30 && $data>=32 && $data<39)){
|
||
$return_data[] = '偏高';
|
||
$return_data[] = $this->merged_data[$type]['list']['偏高'];
|
||
}else if(
|
||
($gender_val==1 && $age<30 && $data>=26) ||
|
||
($gender_val==1 && $age>=30 && $data>=27) ||
|
||
($gender_val==2 && $age<30 && $data<38) ||
|
||
($gender_val==2 && $age>=30 && $data<39)){
|
||
$return_data[] = '高';
|
||
$return_data[] = $this->merged_data[$type]['list']['高'];
|
||
}else{
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else if($type == 'muscle'){//'muscleval'同一标准
|
||
if(
|
||
($gender_val==1 && $type<40) ||
|
||
($gender_val==2 && $type<30)){
|
||
$return_data[] = '不足';
|
||
$return_data[] = $this->merged_data[$type]['list']['不足'];
|
||
}else if(
|
||
($gender_val==1 && $type>=40 && $type<60) ||
|
||
($gender_val==2 && $type>=30 && $type<50)){
|
||
$return_data[] = '标准';
|
||
$return_data[] = $this->merged_data[$type]['list']['标准'];
|
||
}else if(
|
||
($gender_val==1 && $type>=60) ||
|
||
($gender_val==2 && $type>=50)){
|
||
$return_data[] = '优';
|
||
$return_data[] = $this->merged_data[$type]['list']['优'];
|
||
}else{
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else if($type == 'protein'){//'proteinval'同一标准
|
||
if(
|
||
($gender_val==1 && $data<16) ||
|
||
($gender_val==2 && $data<14)){
|
||
$return_data[] = '不足';
|
||
$return_data[] = $this->merged_data[$type]['list']['不足'];
|
||
}else if(
|
||
($gender_val==1 && $data>=16 && $data<18) ||
|
||
($gender_val==2 && $data>=14 && $data<16)){
|
||
$return_data[] = '标准';
|
||
$return_data[] = $this->merged_data[$type]['list']['标准'];
|
||
}else if(
|
||
($gender_val==1 && $data>18) ||
|
||
($gender_val==2 && $data>16)){
|
||
$return_data[] = '优';
|
||
$return_data[] = $this->merged_data[$type]['list']['优'];
|
||
}else{
|
||
$return_data['蛋白量'][1] = '异常';
|
||
$return_data['蛋白率'][1] = '异常';
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else if($type == 'water'){
|
||
if(
|
||
($gender_val==1 && $data<55) ||
|
||
($gender_val==2 && $data<45)){
|
||
$return_data[] = '不足';
|
||
$return_data[] = $this->merged_data[$type]['list']['不足'];
|
||
}else if(
|
||
($gender_val==1 && $data>=55 && $data<65) ||
|
||
($gender_val==2 && $data>=45 && $data<60)){
|
||
$return_data[] = '标准';
|
||
$return_data[] = $this->merged_data[$type]['list']['标准'];
|
||
}else if(
|
||
($gender_val==1 && $data>65) ||
|
||
($gender_val==2 && $data>60)){
|
||
$return_data[] = '优';
|
||
$return_data[] = $this->merged_data[$type]['list']['优'];
|
||
}else{
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else if($type == 'sfr'){
|
||
if(
|
||
($gender_val==1 && $data<7) ||
|
||
($gender_val==2 && $data<11)){
|
||
$return_data[] = '不足';
|
||
$return_data[] = $this->merged_data[$type]['list']['不足'];
|
||
}else if(
|
||
($gender_val==1 && $data>=7 && $data<15) ||
|
||
($gender_val==2 && $data>=11 && $data<17)){
|
||
$return_data[] = '标准';
|
||
$return_data[] = $this->merged_data[$type]['list']['标准'];
|
||
}else if(
|
||
($gender_val==1 && $data>=15) ||
|
||
($gender_val==2 && $data>=17)){
|
||
$return_data[] = '偏高';
|
||
$return_data[] = $this->merged_data[$type]['list']['偏高'];
|
||
}else{
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else if($type == 'visceral'){
|
||
if($data<9){
|
||
$return_data[] = '标准';
|
||
$return_data[] = $this->merged_data[$type]['list']['标准'];
|
||
}else if($data>=9 && $data<14){
|
||
$return_data[] = '警惕';
|
||
$return_data[] = $this->merged_data[$type]['list']['警惕'];
|
||
}else if($data>=14){
|
||
$return_data[] = '危险';
|
||
$return_data[] = $this->merged_data[$type]['list']['危险'];
|
||
}else{
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else if($type == 'bone'){
|
||
if(
|
||
($gender_val==1 && $user['weight']<60 && $data<2.4) ||
|
||
($gender_val==1 && $user['weight']>=60 && $user['weight']<75 && $data<2.8) ||
|
||
($gender_val==1 && $user['weight']>=75 && $data<3.1) ||
|
||
($gender_val==2 && $user['weight']<45 && $data<1.7) ||
|
||
($gender_val==2 && $user['weight']>=45 && $user['weight']<60 && $data<2.1) ||
|
||
($gender_val==2 && $user['weight']>=60 && $data<2.4)){
|
||
$return_data[] = '不足';
|
||
$return_data[] = $this->merged_data[$type]['list']['不足'];
|
||
}else if(
|
||
($gender_val==1 && $user['weight']<60 && $data>=2.4 && $data<=2.6) ||
|
||
($gender_val==1 && $user['weight']>=60 && $user['weight']<75 && $data>=2.8 && $data<=3) ||
|
||
($gender_val==1 && $user['weight']>=75 && $data>=3.1 && $data<=3.3) ||
|
||
($gender_val==2 && $user['weight']<45 && $data>=1.7 && $data<=1.9) ||
|
||
($gender_val==2 && $user['weight']>=45 && $user['weight']<60 && $data>=2.1 && $data<=2.3) ||
|
||
($gender_val==2 && $user['weight']>=60 && $data>=2.4 && $data<=2.6)){
|
||
$return_data[] = '标准';
|
||
$return_data[] = $this->merged_data[$type]['list']['标准'];
|
||
}else if(
|
||
($gender_val==1 && $user['weight']<60 && $data>2.6) ||
|
||
($gender_val==1 && $user['weight']>=60 && $user['weight']<75 && $data>3) ||
|
||
($gender_val==1 && $user['weight']>=75 && $data<3.3) ||
|
||
($gender_val==2 && $user['weight']<45 && $data>1.9) ||
|
||
($gender_val==2 && $user['weight']>=45 && $user['weight']<60 && $data>2.3) ||
|
||
($gender_val==2 && $user['weight']>=60 && $data>2.6)){
|
||
$return_data[] = '优';
|
||
$return_data[] = $this->merged_data[$type]['list']['优'];
|
||
}else{
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else if($type == 'score'){
|
||
$linshi_data = $this->merged_data['score'];
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$return_data[] = $v['text'];
|
||
$return_data[] = $v['color'];
|
||
}
|
||
}
|
||
if(count($return_data) <= 1){
|
||
$return_data[] = '异常';
|
||
$return_data[] = '#000000';
|
||
}
|
||
return $return_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
//详细身体数据
|
||
public function judgment_standard_color_detailed($data,$type,$user){
|
||
$linshi_data = [];
|
||
$month_num = $this->calculateAgeInMonthsWithPrecision($user['birthday']);
|
||
$age = $this->calculate_age($user['birthday']);
|
||
$gender_val = $user['gender'];
|
||
$return_data = [$data];
|
||
if($type == 'weight'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data['weight'];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
|
||
$bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
$linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f2sd'];
|
||
$linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f2sd'];
|
||
$linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][3]['max_val'] = $bhw_date[0]['z2sd'];
|
||
$linshi_data['standard_list'][4]['min_val'] = $bhw_date[0]['z2sd'];
|
||
$linshi_data['standard_list'][4]['max_val'] = $bhw_date[0]['z3sd'];
|
||
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$linshi_data['standard'] = $v['text'];
|
||
$linshi_data['standard_color'] = $v['color'];
|
||
}
|
||
}
|
||
if($linshi_data['standard'] == ''){
|
||
$linshi_data['standard'] = '异常';
|
||
$linshi_data['standard_color'] = '#000000';
|
||
}
|
||
|
||
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
|
||
|
||
}else{
|
||
$linshi_data['standard_list'] = [];
|
||
// $return_data[] = '异常';
|
||
// $return_data[] = '#000000';
|
||
// return $linshi_data;
|
||
}
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'height'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data['height'];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
$bhw_date = Db::table($this->body_db_name['height'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
$linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f2sd'];
|
||
$linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f2sd'];
|
||
$linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][3]['max_val'] = $bhw_date[0]['z2sd'];
|
||
$linshi_data['standard_list'][4]['min_val'] = $bhw_date[0]['z2sd'];
|
||
$linshi_data['standard_list'][4]['max_val'] = $bhw_date[0]['z3sd'];
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$linshi_data['standard'] = $v['text'];
|
||
$linshi_data['standard_color'] = $v['color'];
|
||
}
|
||
}
|
||
if($linshi_data['standard'] == ''){
|
||
$linshi_data['standard'] = '异常';
|
||
$linshi_data['standard_color'] = '#000000';
|
||
}
|
||
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
|
||
|
||
}else{
|
||
$linshi_data['standard_list'] = [];
|
||
// $return_data[] = '异常';
|
||
// $return_data[] = '#000000';
|
||
// return $return_data;
|
||
}
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'heart_rate'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data['heart_rate'];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
foreach ($this->heart_rate as $key => $value) {
|
||
if($month_num > $value['age']['min'] && $month_num <= $value['age']['max']){
|
||
$linshi_data['standard_list'][0]['max_val'] = $value[$gender_val]['min'];
|
||
$linshi_data['standard_list'][1]['min_val'] = $value[$gender_val]['min'];
|
||
$linshi_data['standard_list'][1]['max_val'] = $value[$gender_val]['max'];
|
||
$linshi_data['standard_list'][2]['min_val'] = $value[$gender_val]['max'];
|
||
$linshi_data['standard_list'][2]['max_val'] = 300;
|
||
break;
|
||
}
|
||
}
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$linshi_data['standard'] = $v['text'];
|
||
$linshi_data['standard_color'] = $v['color'];
|
||
}
|
||
}
|
||
if($linshi_data['standard'] == ''){
|
||
$linshi_data['standard'] = '异常';
|
||
$linshi_data['standard_color'] = '#000000';
|
||
}
|
||
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'head_circumference'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data['head_circumference'];
|
||
$bhw_date =json_decode($data,true);
|
||
$linshi_data['standard_list'] = $bhw_date['list2'];
|
||
$linshi_data['value'] = $bhw_date['value']?$bhw_date['value']:0;
|
||
$linshi_data['standard'] = $bhw_date['level']?$bhw_date['level']:'';
|
||
$linshi_data['standard_color'] = $bhw_date['color']?$bhw_date['color']:'#000000';
|
||
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
|
||
}
|
||
else if($type == 'kcal'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data['kcal'];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
// BMR标准值(男) BMR标准值(女)
|
||
// 60.9*体重(kg)-54 61.0*体重(kg)-51
|
||
// 22.7*体重(kg)+495 22.5*体重(kg)+499
|
||
// 17.5*体重(kg)+651 12.2*体重(kg)+746
|
||
// 15.3*体重(kg)+679 14.7*体重(kg)+496
|
||
// 11.6*体重(kg)+879 8.7*体重(kg)+820
|
||
$vv_val = 0;
|
||
if($age < 3){
|
||
if($gender_val == '1'){
|
||
$vv_val = bcsub(bcmul(60.9,$user['weight'],2),54,2);
|
||
}else{
|
||
$vv_val = bcsub(bcmul(61.0,$user['weight'],2),51,2);
|
||
}
|
||
}else if($age >= 3 && $age < 10){
|
||
if($gender_val == '1'){
|
||
$vv_val = bcadd(bcmul(22.7,$user['weight'],2),495,2);
|
||
}else{
|
||
$vv_val = bcadd(bcmul(22.5,$user['weight'],2),499,2);
|
||
}
|
||
}else if($age >= 10 && $age < 18){
|
||
if($gender_val == '1'){
|
||
$vv_val = bcadd(bcmul(17.5,$user['weight'],2),651,2);
|
||
}else{
|
||
$vv_val = bcadd(bcmul(12.2,$user['weight'],2),746,2);
|
||
}
|
||
}else if($age >= 18 && $age < 30){
|
||
if($gender_val == '1'){
|
||
$vv_val = bcadd(bcmul(15.3,$user['weight'],2),679,2);
|
||
}else{
|
||
$vv_val = bcadd(bcmul(14.7,$user['weight'],2),496,2);
|
||
}
|
||
}else{
|
||
if($gender_val == '1'){
|
||
$vv_val = bcadd(bcmul(11.6,$user['weight'],2),879,2);
|
||
}else{
|
||
$vv_val = bcadd(bcmul(8.7,$user['weight'],2),820,2);
|
||
}
|
||
}
|
||
// dump($linshi_data['standard_list']);
|
||
$linshi_data['standard_list'][0]['max_val'] = $vv_val;
|
||
$linshi_data['standard_list'][1]['min_val'] = $vv_val;
|
||
// dump($linshi_data['standard_list']);
|
||
// dump($data);
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$linshi_data['standard'] = $v['text'];
|
||
$linshi_data['standard_color'] = $v['color'];
|
||
}
|
||
}
|
||
if($linshi_data['standard'] == ''){
|
||
$linshi_data['standard'] = '异常';
|
||
$linshi_data['standard_color'] = '#000000';
|
||
}
|
||
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'bmi'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data['bmi'];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
|
||
$bhw_date = Db::table($this->body_db_name['bmi'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
|
||
// dump($month_num);
|
||
// dump($bhw_date);
|
||
if($bhw_date){
|
||
$linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f1sd'];
|
||
$linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['z1sd'];
|
||
$linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z2sd'];
|
||
$linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z2sd'];
|
||
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$linshi_data['standard'] = $v['text'];
|
||
$linshi_data['standard_color'] = $v['color'];
|
||
}
|
||
}
|
||
if($linshi_data['standard'] == ''){
|
||
$linshi_data['standard'] = '异常';
|
||
$linshi_data['standard_color'] = '#000000';
|
||
}
|
||
|
||
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
|
||
|
||
}else{
|
||
$linshi_data['standard_list'] = [];
|
||
// $return_data[] = '异常';
|
||
// $return_data[] = '#000000';
|
||
// return $linshi_data;
|
||
}
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'fat_r' || $type == 'fat_w'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data[$type];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
|
||
|
||
if($age < 30){
|
||
$linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['29'];
|
||
}else{
|
||
$linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['30'];
|
||
}
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$linshi_data['standard'] = $v['text'];
|
||
$linshi_data['standard_color'] = $v['color'];
|
||
}
|
||
}
|
||
if($linshi_data['standard'] == ''){
|
||
$linshi_data['standard'] = '异常';
|
||
$linshi_data['standard_color'] = '#000000';
|
||
}
|
||
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'muscle' || $type == 'muscleval' || $type == 'protein' || $type == 'proteinval' || $type == 'water' || $type == 'sfr' || $type == 'visceral'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data[$type];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
|
||
$linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val];
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$linshi_data['standard'] = $v['text'];
|
||
$linshi_data['standard_color'] = $v['color'];
|
||
}
|
||
}
|
||
if($linshi_data['standard'] == ''){
|
||
$linshi_data['standard'] = '异常';
|
||
$linshi_data['standard_color'] = '#000000';
|
||
}
|
||
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'ideal_weight'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data[$type];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
|
||
$bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
$linshi_data['value'] = $bhw_date[0]['median'];
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'ideal_height'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data[$type];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
|
||
$bhw_date = Db::table($this->body_db_name['height'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
$linshi_data['value'] = $bhw_date[0]['median'];
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'ideal_bmi'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data[$type];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
|
||
$bhw_date = Db::table($this->body_db_name['bmi'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
|
||
if($bhw_date){
|
||
$linshi_data['value'] = $bhw_date[0]['median'];
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'bone'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data[$type];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
|
||
|
||
if($gender_val == '1'){
|
||
if($user['weight'] < 60){
|
||
$linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60'];
|
||
}else if($user['weight'] >= 60 && $user['weight'] < 75){
|
||
$linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60_75'];
|
||
}else{
|
||
$linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['75'];
|
||
}
|
||
}else{
|
||
if($user['weight'] < 45){
|
||
$linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['45'];
|
||
}else if($user['weight'] >= 45 && $user['weight'] < 60){
|
||
$linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['45_60'];
|
||
}else{
|
||
$linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60'];
|
||
}
|
||
}
|
||
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$linshi_data['standard'] = $v['text'];
|
||
$linshi_data['standard_color'] = $v['color'];
|
||
}
|
||
}
|
||
if($linshi_data['standard'] == ''){
|
||
$linshi_data['standard'] = '异常';
|
||
$linshi_data['standard_color'] = '#000000';
|
||
}
|
||
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'body_type' || $type == 'body_level' || $type == 'body_age'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data[$type];
|
||
$linshi_data['value'] = $data;
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else if($type == 'score'){
|
||
if($data){
|
||
$linshi_data = $this->merged_data[$type];
|
||
$linshi_data['value'] = floatval($data);
|
||
$linshi_data['standard'] = '';
|
||
$linshi_data['standard_color'] = '';
|
||
$linshi_data['offset'] = 0;
|
||
|
||
foreach ($linshi_data['standard_list'] as $k => $v) {
|
||
if($data >= $v['min_val'] && $data < $v['max_val']){
|
||
// 如果落在区间内
|
||
$linshi_data['standard'] = $v['text'];
|
||
$linshi_data['standard_color'] = $v['color'];
|
||
}
|
||
}
|
||
if($linshi_data['standard'] == ''){
|
||
$linshi_data['standard'] = '异常';
|
||
$linshi_data['standard_color'] = '#000000';
|
||
}
|
||
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
|
||
return $linshi_data;
|
||
}else{
|
||
return false;
|
||
}
|
||
}
|
||
else{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 根据Broca改良公式计算标准体重参考值
|
||
* @param int $gender 性别: 1=男, 2=女
|
||
* @param int $age 年龄(周岁)
|
||
* @param float $height 身高(厘米)
|
||
* @return string 标准体重(kg),保留2位小数
|
||
* @throws InvalidArgumentException 当参数无效时抛出异常
|
||
*/
|
||
public function calculateStandardWeight($gender, $age, $height) {
|
||
// 1. 参数校验
|
||
if (!in_array($gender, [1, 2])) {
|
||
return false;
|
||
}
|
||
if ($age <= 0 || $age > 120) {
|
||
return false;
|
||
}
|
||
if ($height < 50 || $height > 250) {
|
||
return false;
|
||
}
|
||
|
||
// 2. 根据性别和年龄确定系数K
|
||
if ($age < 30) {
|
||
$k = ($gender === 1) ? '0.90' : '0.85'; // 1=男, 2=女
|
||
} elseif ($age <= 50) {
|
||
$k = ($gender === 1) ? '0.88' : '0.82';
|
||
} else { // age > 50
|
||
$k = ($gender === 1) ? '0.86' : '0.80';
|
||
}
|
||
|
||
// 3. 使用BC数学函数计算:标准体重 = (身高 - 100) × K
|
||
// 身高减去100
|
||
$heightMinus100 = bcsub((string)$height, '100', 20);
|
||
|
||
// 乘以系数K
|
||
$standardWeight = bcmul($heightMinus100, $k, 2);
|
||
|
||
// 4. 格式化为保留2位小数
|
||
return $standardWeight;
|
||
}
|
||
|
||
/**
|
||
* 使用BC数学函数的精确版本
|
||
* @param int $age 年龄(岁),数字类型
|
||
* @param float $weight 体重(kg),数字类型
|
||
* @param int $gender 性别: 1=男, 2=女
|
||
* @return string BMR值(千卡/天),保留2位小数
|
||
*/
|
||
function calculateBMR_BC($age, $weight, $gender) {
|
||
// 参数校验
|
||
if (!is_numeric($age) || $age < 0 || $age > 100) {
|
||
return false;
|
||
}
|
||
|
||
if (!is_numeric($weight) || $weight <= 0 || $weight > 300) {
|
||
return false;
|
||
}
|
||
|
||
if (!in_array($gender, [1, 2])) {
|
||
return false;
|
||
}
|
||
|
||
$isMale = ($gender === 1);
|
||
$weightStr = (string)$weight;
|
||
$bmr = '0';
|
||
|
||
// WHO/FAO/UNU公式分段计算(使用BC函数)
|
||
if ($age < 3) {
|
||
// 0-3岁婴儿
|
||
if ($isMale) {
|
||
$temp = bcmul('60.9', $weightStr, 4);
|
||
$bmr = bcsub($temp, '54', 2);
|
||
} else {
|
||
$temp = bcmul('61.0', $weightStr, 4);
|
||
$bmr = bcsub($temp, '51', 2);
|
||
}
|
||
} elseif ($age < 10) {
|
||
// 3-10岁儿童
|
||
if ($isMale) {
|
||
$temp = bcmul('22.7', $weightStr, 4);
|
||
$bmr = bcadd($temp, '495', 2);
|
||
} else {
|
||
$temp = bcmul('22.5', $weightStr, 4);
|
||
$bmr = bcadd($temp, '499', 2);
|
||
}
|
||
} elseif ($age < 18) {
|
||
// 10-18岁青少年
|
||
if ($isMale) {
|
||
$temp = bcmul('17.5', $weightStr, 4);
|
||
$bmr = bcadd($temp, '651', 2);
|
||
} else {
|
||
$temp = bcmul('12.2', $weightStr, 4);
|
||
$bmr = bcadd($temp, '746', 2);
|
||
}
|
||
} elseif ($age < 30) {
|
||
// 18-30岁成年人
|
||
if ($isMale) {
|
||
$temp = bcmul('15.3', $weightStr, 4);
|
||
$bmr = bcadd($temp, '679', 2);
|
||
} else {
|
||
$temp = bcmul('14.7', $weightStr, 4);
|
||
$bmr = bcadd($temp, '496', 2);
|
||
}
|
||
} elseif ($age < 60) {
|
||
// 30-60岁中年人
|
||
if ($isMale) {
|
||
$temp = bcmul('11.6', $weightStr, 4);
|
||
$bmr = bcadd($temp, '879', 2);
|
||
} else {
|
||
$temp = bcmul('8.7', $weightStr, 4);
|
||
$bmr = bcadd($temp, '820', 2);
|
||
}
|
||
} else {
|
||
// 60岁以上老年人
|
||
if ($isMale) {
|
||
$temp = bcmul('13.5', $weightStr, 4);
|
||
$bmr = bcadd($temp, '487', 2);
|
||
} else {
|
||
$temp = bcmul('10.5', $weightStr, 4);
|
||
$bmr = bcadd($temp, '596', 2);
|
||
}
|
||
}
|
||
|
||
// 确保BMR不为负值
|
||
if (bccomp($bmr, '0', 2) < 0) {
|
||
$bmr = '0.00';
|
||
}
|
||
|
||
return $bmr;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |