2026-02-03 18:56:47 +08:00
< ? 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' ,
2026-03-07 15:06:35 +08:00
'body_data_new' => 'app_card_body_data_new' ,
2026-02-03 18:56:47 +08:00
'bmi' => 'pc_bmistand' ,
2026-03-09 08:35:43 +08:00
'height' => 'pc_heightstand' ,
'weight' => 'pc_weightstand' ,
// 'chufang1'=>'pc_childrenprescription',
// 'chufang2'=>'pc_childprescriptionbyage',
2026-02-03 18:56:47 +08:00
];
protected $age_limit = 16 ;
protected $pagesize = 15 ;
2026-03-06 18:02:49 +08:00
protected $detailed_model_1 = [ //详情里面的数据模板
" name " => " " , //名称
" value " => " 0 " , //值
" unit " => " " , // 单位
" desc " => '' , // 描述
" standard " => " " , //标准值
" standard_color " => " #000000 " , //标准颜色
" list " => [], //标准列表
" key_name " => '' , //标准列表
" offset " => 0 , //标准列表
" tip " => '' , //小妙招
];
2026-02-03 18:56:47 +08:00
protected $merged_data = [
'score' => [
'name' => '身体得分' ,
'unit' => '分' ,
2026-03-09 08:35:43 +08:00
" description " => " " ,
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/score.png " ,
2026-03-06 18:02:49 +08:00
'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' ],
2026-03-09 08:35:43 +08:00
],
'key_name' => 'score' ,
2026-02-03 18:56:47 +08:00
],
'height' => [
'name' => '身高' ,
'unit' => 'cm' ,
2026-03-06 18:02:49 +08:00
" description " => " 人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-16 19:29:36 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/height.png " ,
2026-03-06 18:02:49 +08:00
'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' ],
2026-03-09 08:35:43 +08:00
],
'key_name' => 'height' ,
2026-02-03 18:56:47 +08:00
],
'weight' => [
'name' => '体重' ,
'unit' => 'kg' ,
2026-03-06 18:02:49 +08:00
" description " => " 体重指人体的重量,通常用斤、公斤或磅作为单位来衡量。体重是人体健康的重要指标,但需要结合身高、体型和体脂率等因素来综合评估。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " 保持均衡营养的饮食,摄入足够的碳水化合物、蛋白质、脂肪等。适度进行运动,保持良好的生活习惯。 " ,
2026-03-16 19:29:36 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/weight.png " ,
2026-03-06 18:02:49 +08:00
'standard_list' => [
2026-03-09 08:35:43 +08:00
[ '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' ,
2026-02-03 18:56:47 +08:00
],
'bmi' => [
'name' => 'BMI' ,
'unit' => '' ,
2026-03-11 18:45:25 +08:00
" description " => " BMI是身体质量指数(BodyMasslndex)的缩写,是一种常用的衡量人体肥胖程度的指标 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-16 19:29:36 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/bmi10.png " ,
2026-03-06 18:02:49 +08:00
'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' ],
2026-03-09 08:35:43 +08:00
],
'key_name' => 'bmi' ,
2026-02-03 18:56:47 +08:00
],
'fat_r' => [
'name' => '脂肪率' ,
'unit' => '%' ,
2026-03-11 18:45:25 +08:00
" description " => " 体脂率指人体中脂肪组织所占的百分比。体脂率是评估一个人身体脂肪含量和肥胖程度的指标。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/fat_r.png " ,
2026-02-03 18:56:47 +08:00
'list' => [
'偏低' => '#FCDB67' ,
'标准' => '#58D268' ,
'偏高' => '#FCAA00' ,
'高' => '#FD5752'
2026-03-06 18:02:49 +08:00
],
'standard_list' => [
2026-03-09 08:35:43 +08:00
'1' => [
2026-03-06 18:02:49 +08:00
'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' ],
],
],
2026-03-09 08:35:43 +08:00
'2' => [
2026-03-06 18:02:49 +08:00
'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' ],
]
]
2026-03-09 08:35:43 +08:00
],
'key_name' => 'fat_r' ,
2026-02-03 18:56:47 +08:00
],
'fat_w' => [
'name' => '脂肪量' ,
'unit' => 'kg' ,
2026-03-11 18:45:25 +08:00
" description " => " 脂肪量指人体含有脂肪的总量。脂肪在身体中起着能量储存、保护内脏器官和维持体温等重要作用。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/fat_w.png " ,
2026-02-03 18:56:47 +08:00
'list' => [
'偏低' => '#FCDB67' ,
'标准' => '#58D268' ,
'偏高' => '#FCAA00' ,
'高' => '#FD5752'
2026-03-06 18:02:49 +08:00
],
'standard_list' => [
2026-03-09 08:35:43 +08:00
'1' => [
2026-03-06 18:02:49 +08:00
'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' ],
],
],
2026-03-09 08:35:43 +08:00
'2' => [
2026-03-06 18:02:49 +08:00
'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' ],
]
]
2026-03-09 08:35:43 +08:00
],
'key_name' => 'fat_w' ,
2026-02-03 18:56:47 +08:00
],
'muscle' => [
'name' => '肌肉率' ,
'unit' => '%' ,
2026-03-11 18:45:25 +08:00
" description " => " 肌肉率指人体成分中肌肉占体重的百分比。肌肉率越高, BMR越大, 消耗的热量越多, 就不容易发胖。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/muscle.png " ,
2026-02-03 18:56:47 +08:00
'list' => [
'不足' => '#FFDA68' ,
'标准' => '#59CD6F' ,
'优' => '#3C64D4'
2026-03-06 18:02:49 +08:00
],
'standard_list' => [
2026-03-09 08:35:43 +08:00
'1' => [
2026-03-06 18:02:49 +08:00
[ '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' ],
],
2026-03-09 08:35:43 +08:00
'2' => [
2026-03-06 18:02:49 +08:00
[ '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' ],
]
2026-03-09 08:35:43 +08:00
],
'key_name' => 'muscle' ,
2026-02-03 18:56:47 +08:00
],
'muscleval' => [
'name' => '肌肉量' ,
'unit' => 'kg' ,
2026-03-11 18:45:25 +08:00
" description " => " 肌肉量指人体所有肌肉的含量,包括水分量、骨骼肌、心肌和平滑肌等。肌肉是人体内的主要代谢组织之一,具有维持基础代谢率、提高身体稳定性、促进脂肪分解等重要作用。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/muscleval.png " ,
2026-02-03 18:56:47 +08:00
'list' => [
'不足' => '#FFDA68' ,
'标准' => '#59CD6F' ,
'优' => '#3C64D4'
2026-03-06 18:02:49 +08:00
],
'standard_list' => [
2026-03-09 08:35:43 +08:00
'1' => [
2026-03-06 18:02:49 +08:00
[ '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' ],
],
2026-03-09 08:35:43 +08:00
'2' => [
2026-03-06 18:02:49 +08:00
[ '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' ],
]
2026-03-09 08:35:43 +08:00
],
'key_name' => 'muscleval' ,
2026-02-03 18:56:47 +08:00
],
'water' => [
'name' => '水分' ,
2026-03-11 18:45:25 +08:00
'unit' => '%' ,
" description " => " 体水分率指人体组织中的水分占总体重的百分比,也称为身体水分含量。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/water.png " ,
2026-02-03 18:56:47 +08:00
'list' => [
'不足' => '#FED966' ,
'标准' => '#58CF6B' ,
'优' => '#3A68D7'
2026-03-06 18:02:49 +08:00
],
'standard_list' => [
2026-03-09 08:35:43 +08:00
'1' => [
2026-03-06 18:02:49 +08:00
[ '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' ],
],
2026-03-09 08:35:43 +08:00
'2' => [
2026-03-06 18:02:49 +08:00
[ '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' ],
]
2026-03-09 08:35:43 +08:00
],
'key_name' => 'water' ,
2026-02-03 18:56:47 +08:00
],
'bone' => [
'name' => '骨重' ,
'unit' => 'kg' ,
2026-03-11 18:45:25 +08:00
" description " => " 身体骨量指人体骨骼所含的骨基质和矿物质的质量。骨量的大小直接影响骨骼健康,对身体的稳定性和功能起着至关重要的作用。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/bone.png " ,
2026-02-03 18:56:47 +08:00
'list' => [
'不足' => '#FED966' ,
'标准' => '#58CF6F' ,
'优' => '#3A68D7'
2026-03-06 18:02:49 +08:00
],
'standard_list' => [
2026-03-09 08:35:43 +08:00
'1' => [
2026-03-06 18:02:49 +08:00
'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' ],
],
],
2026-03-09 08:35:43 +08:00
'2' => [
2026-03-06 18:02:49 +08:00
'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' ],
],
]
2026-03-09 08:35:43 +08:00
],
'key_name' => 'bone' ,
2026-02-03 18:56:47 +08:00
],
'protein' => [
'name' => '蛋白率' ,
'unit' => '%' ,
2026-03-11 18:45:25 +08:00
" description " => " 蛋白质率指人体组织中蛋白质含量占总体重的百分比。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/protein.png " ,
2026-02-03 18:56:47 +08:00
'list' => [
'不足' => '#FED966' ,
'标准' => '#58CF6F' ,
'优' => '#3A68D7'
2026-03-06 18:02:49 +08:00
],
'standard_list' => [
2026-03-09 08:35:43 +08:00
'1' => [
2026-03-06 18:02:49 +08:00
[ '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' ], //蓝
],
2026-03-09 08:35:43 +08:00
'2' => [
2026-03-06 18:02:49 +08:00
[ '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' ],
]
2026-03-09 08:35:43 +08:00
],
'key_name' => 'protein' ,
2026-02-03 18:56:47 +08:00
],
'proteinval' => [
'name' => '蛋白量' ,
'unit' => 'kg' ,
2026-03-06 18:02:49 +08:00
" description " => " " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/proteinval.png " ,
2026-02-03 18:56:47 +08:00
'list' => [
'不足' => '#FED966' ,
'标准' => '#58CF6F' ,
'优' => '#3A68D7'
2026-03-06 18:02:49 +08:00
],
'standard_list' => [
2026-03-09 08:35:43 +08:00
'1' => [
2026-03-06 18:02:49 +08:00
[ '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' ], //蓝
],
2026-03-09 08:35:43 +08:00
'2' => [
2026-03-06 18:02:49 +08:00
[ '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' ],
]
],
2026-03-09 08:35:43 +08:00
'key_name' => 'proteinval' ,
2026-02-03 18:56:47 +08:00
],
'visceral' => [
'name' => '内脏指数' ,
'unit' => '' ,
2026-03-11 18:45:25 +08:00
" description " => " 内脏脂肪指围绕脏器的脂肪组织,主要分布于腹腔内,包括肝脏、心脏、肾脏、胰腺等器官周围的脂肪。身体内脏脂肪的增加会导致慢性代谢性疾病的风险增加。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/visceral.png " ,
2026-02-03 18:56:47 +08:00
'list' => [
'标准' => '#55CF6C' ,
'警惕' => '#FEAC00' ,
'危险' => '#FB5A52'
2026-03-06 18:02:49 +08:00
],
'standard_list' => [
2026-03-09 08:35:43 +08:00
'1' => [
2026-03-06 18:02:49 +08:00
[ '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' ], //红
],
2026-03-09 08:35:43 +08:00
'2' => [
2026-03-06 18:02:49 +08:00
[ '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' ], //红
]
2026-03-09 08:35:43 +08:00
],
'key_name' => 'visceral' ,
2026-02-03 18:56:47 +08:00
],
'sfr' => [
'name' => '皮下脂肪' ,
'unit' => '%' ,
2026-03-11 18:45:25 +08:00
" description " => " 皮下脂肪率指身体内皮下脂肪组织占身体总重量的百分比。皮下脂肪适量时对身体有益,但过量会使身体处于肥胖状态,并可能导致多种健康问题。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/sfr.png " ,
2026-02-03 18:56:47 +08:00
'list' => [
'不足' => '#FCDB68' ,
'标准' => '#59D16F' ,
'偏高' => '#FEAB03'
2026-03-06 18:02:49 +08:00
],
'standard_list' => [
2026-03-09 08:35:43 +08:00
'1' => [
2026-03-06 18:02:49 +08:00
[ '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' ], //橙
],
2026-03-09 08:35:43 +08:00
'2' => [
2026-03-06 18:02:49 +08:00
[ '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' ],
]
2026-03-09 08:35:43 +08:00
],
'key_name' => 'sfr' ,
2026-02-03 18:56:47 +08:00
],
'body_level' => [
'name' => '肥胖等级' ,
'unit' => '' ,
2026-03-06 18:02:49 +08:00
" description " => " 肥胖等级指根据个体BMI来评估一个人是否超重或肥胖的指标。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/body_level.png " ,
2026-03-06 18:02:49 +08:00
'list' => [],
2026-03-09 08:35:43 +08:00
'standard_list' => [],
'key_name' => 'body_level' ,
2026-02-03 18:56:47 +08:00
],
'body_type' => [
'name' => '身体类型' ,
'unit' => '' ,
2026-03-06 18:02:49 +08:00
" description " => " 身体类型是对人体外形的总体描述和评定 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/body_type.png " ,
2026-03-06 18:02:49 +08:00
'list' => [],
2026-03-09 08:35:43 +08:00
'standard_list' => [],
'key_name' => 'body_type' ,
2026-02-03 18:56:47 +08:00
],
'body_age' => [
'name' => '身体年龄' ,
'unit' => '岁' ,
2026-03-06 18:02:49 +08:00
" description " => " 身体年龄指衡量身体健康状况的指标, 它反映了一个人的生理状态相对于实际年龄的健康程度。相关模型主要与BMI有关。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/body_age.png " ,
2026-03-06 18:02:49 +08:00
'list' => [],
2026-03-09 08:35:43 +08:00
'standard_list' => [],
'key_name' => 'body_age' ,
],
'head_circumference' => [
'name' => '头围' ,
'unit' => 'cm' ,
" description " => " " ,
" smart_tip_description " => " " ,
2026-03-16 19:29:36 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/head_circumference.png " ,
2026-03-09 08:35:43 +08:00
'standard_list' => [],
'key_name' => 'head_circumference' ,
],
'heart_rate' => [
'name' => '心率' ,
'unit' => '跳/分钟' ,
2026-03-11 18:45:25 +08:00
" description " => " 心率指正常人安静状态下每分钟心跳的次数,可因年龄、性别或其他生理因素产生个体差异。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " 注意减少压力和焦虑,适度锻炼,保持良好的睡眠质量,避免过度用力或剧烈运动。 " ,
2026-03-16 19:29:36 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/heart_rate10.png " ,
2026-03-09 08:35:43 +08:00
'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' ,
2026-03-11 18:45:25 +08:00
" description " => " 理想体重是反映和衡量一个人健康状况的重要标志之一。 " ,
2026-03-09 08:35:43 +08:00
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/ideal_weight.png " ,
2026-03-09 08:35:43 +08:00
'standard_list' => [],
'key_name' => 'ideal_weight' ,
],
'ideal_height' => [
'name' => '理想身高' ,
'unit' => 'cm' ,
" description " => " " ,
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/ideal_height.png " ,
2026-03-09 08:35:43 +08:00
'standard_list' => [],
'key_name' => 'ideal_height' ,
],
'ideal_bmi' => [
'name' => '理想BMI' ,
'unit' => '' ,
" description " => " " ,
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/ideal_bmi.png " ,
2026-03-09 08:35:43 +08:00
'standard_list' => [],
'key_name' => 'ideal_bmi' ,
],
'kcal' => [
'name' => 'BMR' ,
'unit' => 'kcal' ,
" description " => " BMR是基础代谢率(BasalMetabolicRate)的缩写,指人体在安静状态下,维持基本生命活动所需的最低能量消耗率。 " ,
" smart_tip_description " => " " ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/ideal_bmi.png " ,
2026-03-09 08:35:43 +08:00
'list' => [
'偏低' => '#FF5656' ,
'优' => '#3A68D4'
],
'standard_list' => [
[ 'min_val' => '0' , 'max_val' => '' , 'text' => '偏低' , 'color' => '#ff5656' ],
[ 'min_val' => '' , 'max_val' => '9999' , 'text' => '优' , 'color' => '#3C66D2' ],
],
'key_name' => 'kcal' ,
2026-03-07 15:06:35 +08:00
],
2026-02-03 18:56:47 +08:00
];
2026-03-07 15:06:35 +08:00
protected $heart_rate = [
[
'age' => [ 'min' => '0' , 'max' => '1' ],
2026-03-09 08:35:43 +08:00
'1' => [ 'min' => '70' , 'max' => '190' ],
'2' => [ 'min' => '70' , 'max' => '190' ]
2026-03-07 15:06:35 +08:00
],
[
'age' => [ 'min' => '1' , 'max' => '12' ],
2026-03-09 08:35:43 +08:00
'1' => [ 'min' => '80' , 'max' => '160' ],
'2' => [ 'min' => '80' , 'max' => '160' ]
2026-03-07 15:06:35 +08:00
],
[
'age' => [ 'min' => '12' , 'max' => '36' ],
2026-03-09 08:35:43 +08:00
'1' => [ 'min' => '80' , 'max' => '130' ],
'2' => [ 'min' => '80' , 'max' => '130' ]
2026-03-07 15:06:35 +08:00
],
[
'age' => [ 'min' => '36' , 'max' => '60' ],
2026-03-09 08:35:43 +08:00
'1' => [ 'min' => '80' , 'max' => '120' ],
'2' => [ 'min' => '80' , 'max' => '120' ]
2026-03-07 15:06:35 +08:00
],
[
'age' => [ 'min' => '60' , 'max' => '120' ],
2026-03-09 08:35:43 +08:00
'1' => [ 'min' => '70' , 'max' => '110' ],
'2' => [ 'min' => '70' , 'max' => '110' ]
2026-03-07 15:06:35 +08:00
],
[
'age' => [ 'min' => '120' , 'max' => '204' ],
2026-03-09 08:35:43 +08:00
'1' => [ 'min' => '60' , 'max' => '100' ],
'2' => [ 'min' => '60' , 'max' => '100' ]
2026-03-07 15:06:35 +08:00
],
[
'age' => [ 'min' => '204' , 'max' => '480' ],
2026-03-09 08:35:43 +08:00
'1' => [ 'min' => '60' , 'max' => '100' ],
'2' => [ 'min' => '60' , 'max' => '100' ]
2026-03-07 15:06:35 +08:00
],
[
'age' => [ 'min' => '480' , 'max' => '720' ],
2026-03-09 08:35:43 +08:00
'1' => [ 'min' => '60' , 'max' => '100' ],
'2' => [ 'min' => '60' , 'max' => '100' ]
2026-03-07 15:06:35 +08:00
],
[
'age' => [ 'min' => '720' , 'max' => '9999' ], // 61岁+, 9999作为最大值占位
2026-03-09 08:35:43 +08:00
'1' => [ 'min' => '60' , 'max' => '100' ],
'2' => [ 'min' => '60' , 'max' => '100' ]
2026-03-07 15:06:35 +08:00
]
2026-02-03 18:56:47 +08:00
];
2026-03-09 08:35:43 +08:00
2026-02-03 18:56:47 +08:00
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
2026-03-06 18:02:49 +08:00
// 手动记录
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.' );
2026-03-07 15:06:35 +08:00
// try {
2026-03-06 18:02:49 +08:00
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' );
2026-03-07 15:06:35 +08:00
// } 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 );
2026-03-06 18:02:49 +08:00
} catch ( \Exception $e ) {
// 捕获异常
$logContent [ " flie " ] = $e -> getFile ();
$logContent [ " line " ] = $e -> getLine ();
$logContent [ 'all_content' ] = " 异常信息: \n " ;
2026-03-07 15:06:35 +08:00
$logContent [ 'all_content' ] .= " 函数: body_report_brief " . " \n " ;
2026-03-06 18:02:49 +08:00
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
}
}
2026-03-07 15:06:35 +08:00
// 获取角色报告(详细)
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 );
}
}
2026-03-09 08:35:43 +08:00
// 获取角色报告(深度)
public function body_report_depth (){
$data = input ( 'post.' );
2026-03-12 07:40:45 +08:00
try {
2026-03-09 08:35:43 +08:00
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 );
2026-03-12 07:40:45 +08:00
} 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 );
}
2026-03-09 08:35:43 +08:00
}
2026-03-06 18:02:49 +08:00
// 修改目标体重
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 " ;
2026-02-03 18:56:47 +08:00
$logContent [ 'all_content' ] .= " 消息: " . $e -> getMessage () . " \n " ;
$logContent [ 'all_content' ] .= " 代码: " . $e -> getCode () . " \n " ;
$logContent [ 'all_content' ] .= " 文件: " . $e -> getFile () . " \n " ;
$logContent [ 'all_content' ] .= " 行号: " . $e -> getLine () . " \n " ;
$logContent [ 'all_content' ] .= " 跟踪信息: \n " . $e -> getTraceAsString () . " \n " ;
$this -> record_api_log ( $data , $logContent , null );
return $this -> msg ( 99999 );
}
}
2026-03-12 07:40:45 +08:00
// 修改初始体重
public function set_initial_weight (){
$data = input ( 'post.' );
try {
2026-03-16 19:29:36 +08:00
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'weight' , $data ) || ! array_key_exists ( 'time' , $data ) || ! array_key_exists ( 'token' , $data )){
2026-03-12 07:40:45 +08:00
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' );
}
2026-03-16 19:29:36 +08:00
if ( ! $this -> verify_data_is_ok ( $data [ 'time' ], 'datetime' )){
return $this -> msg ( 10005 , 'time type error' );
}
2026-03-12 07:40:45 +08:00
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 (){
2026-03-16 19:29:36 +08:00
$data = input ( 'post.' );
2026-03-12 07:40:45 +08:00
try {
2026-03-16 19:29:36 +08:00
2026-03-12 07:40:45 +08:00
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 (){
2026-03-16 19:29:36 +08:00
$data = input ( 'post.' );
2026-03-12 07:40:45 +08:00
try {
2026-03-16 19:29:36 +08:00
2026-03-12 07:40:45 +08:00
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 (){
2026-03-16 19:29:36 +08:00
$data = input ( 'post.' );
2026-03-12 07:40:45 +08:00
try {
2026-03-16 19:29:36 +08:00
2026-03-12 07:40:45 +08:00
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 );
}
}
2026-03-16 19:29:36 +08:00
// 曲线详情
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 );
}
}
2026-02-03 18:56:47 +08:00
################################################################action################################################################
################################################################action################################################################
2026-03-07 15:06:35 +08:00
// 用户身体数据卡片记录
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 );
}
2026-03-09 08:35:43 +08:00
2026-03-07 15:06:35 +08:00
// 开始设置数据
$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 = [];
2026-03-09 08:35:43 +08:00
2026-03-07 15:06:35 +08:00
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' ]);
2026-03-16 19:29:36 +08:00
$db_data [ 'head_circumference_val' ] = $db_data [ 'head_circumference' ];
2026-03-09 08:35:43 +08:00
$db_data [ 'head_circumference' ] = json_encode ( $standardlist );
2026-03-07 15:06:35 +08:00
}
} else {
if ( array_key_exists ( 'standardlist' , $get_body_value )){
unset ( $get_body_value [ 'standardlist' ]);
}
}
// 如果年纪小于三岁, 处理头围数据end
2026-03-09 08:35:43 +08:00
2026-03-07 15:06:35 +08:00
} 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' ;
}
}
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' );
2026-03-09 08:35:43 +08:00
// 开始设置数据
$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 );
2026-03-07 15:06:35 +08:00
} else {
// 发送请求获取照良那边的身体数据
$get_body_value = $this -> send_body_data ( $send_data , '4_electrode' );
2026-03-09 08:35:43 +08:00
// 开始设置数据
$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 );
2026-03-07 15:06:35 +08:00
}
if ( $get_body_value === false ){
return $this -> msg ( 10002 );
}
2026-03-09 08:35:43 +08:00
// dump($get_body_value);
2026-03-07 15:06:35 +08:00
// 处理心率start
if ( array_key_exists ( 'heart_rate' , $data )){
if ( ! $this -> verify_data_is_ok ( $data [ 'heart_rate' ], 'num' )){
2026-03-09 08:35:43 +08:00
return $this -> msg ( 10005 , '心率数据格式错误' );
2026-03-07 15:06:35 +08:00
}
$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 = [
2026-03-09 08:35:43 +08:00
'height' => $db_data [ 'height' ],
'weight' => $db_data [ 'weight' ]
2026-03-07 15:06:35 +08:00
];
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 );
}
}
2026-02-03 18:56:47 +08:00
public function body_report_brief_action ( $data ){
$result_return = [
2026-03-06 18:02:49 +08:00
'top_list' => [
[
2026-03-09 08:35:43 +08:00
" name " => $this -> merged_data [ 'weight' ][ 'name' ],
2026-03-06 18:02:49 +08:00
'time' => '' ,
" value " => " 0 " ,
2026-03-09 08:35:43 +08:00
" unit " => $this -> merged_data [ 'weight' ][ 'unit' ],
2026-03-06 18:02:49 +08:00
" standard " => " " ,
2026-03-09 08:35:43 +08:00
" standard_color " => " #000000 " ,
2026-03-06 18:02:49 +08:00
'target_weight' => '0' ,
2026-03-11 18:45:25 +08:00
'target_weight_unit' => 'kg' ,
'bk_color' => '#fffae4' ,
'curve_list' => [
'title' => '体重' ,
'key' => 'weight' ,
'line' => [ 'categories' => [], 'series' => [[ 'color' => '#f78814' , 'data' => []]]],
],
'ideal_weight' => '' ,
2026-03-06 18:02:49 +08:00
],
[
2026-03-09 08:35:43 +08:00
" name " => $this -> merged_data [ 'height' ][ 'name' ],
2026-03-06 18:02:49 +08:00
'time' => '' ,
" value " => " 0 " ,
2026-03-09 08:35:43 +08:00
" unit " => $this -> merged_data [ 'height' ][ 'unit' ],
2026-03-06 18:02:49 +08:00
" standard " => " " ,
2026-03-09 08:35:43 +08:00
" standard_color " => " #000000 " ,
2026-03-11 18:45:25 +08:00
'bk_color' => '#f6eefd' ,
'curve_list' => [
'title' => '身高' ,
'key' => 'height' ,
'line' => [ 'categories' => [], 'series' => [[ 'color' => '#dab8f4' , 'data' => []]]],
],
'ideal_height' => '' ,
2026-03-06 18:02:49 +08:00
],
[
2026-03-09 08:35:43 +08:00
" name " => $this -> merged_data [ 'bmi' ][ 'name' ],
2026-03-06 18:02:49 +08:00
'time' => '' ,
" value " => " 0 " ,
2026-03-09 08:35:43 +08:00
" unit " => $this -> merged_data [ 'bmi' ][ 'unit' ],
2026-03-06 18:02:49 +08:00
" standard " => " " ,
2026-03-09 08:35:43 +08:00
" standard_color " => " #000000 " ,
2026-03-11 18:45:25 +08:00
'bk_color' => '#edf8fe' ,
'curve_list' => [
'title' => 'BMI' ,
'key' => 'bmi' ,
'line' => [ 'categories' => [], 'series' => [[ 'color' => '#a8def6' , 'data' => []]]],
],
'ideal_bmi' => '' ,
2026-03-06 18:02:49 +08:00
],
2026-02-03 18:56:47 +08:00
],
'card_list' => [
],
];
2026-03-09 08:35:43 +08:00
$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 );
2026-02-03 18:56:47 +08:00
}
2026-03-09 08:35:43 +08:00
$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 ();
2026-02-03 18:56:47 +08:00
2026-03-09 08:35:43 +08:00
if ( ! $body_last_data ){
return $this -> msg ( $result_return );
}
2026-03-11 18:45:25 +08:00
$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 ();
2026-03-09 08:35:43 +08:00
$record_time = substr ( $body_last_data [ 'record_time' ], 11 , 5 );
2026-02-03 18:56:47 +08:00
// 处理体重
2026-03-06 18:02:49 +08:00
$result_return [ 'top_list' ][ 0 ][ 'time' ] = $record_time ;
2026-03-09 08:35:43 +08:00
$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' ];
2026-03-06 18:02:49 +08:00
$result_return [ 'top_list' ][ 0 ][ 'key_name' ] = 'weight' ;
2026-03-11 18:45:25 +08:00
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' ]);
}
2026-03-09 08:35:43 +08:00
$user_data [ 'weight' ] = $result_return [ 'top_list' ][ 0 ][ 'value' ];
2026-02-03 18:56:47 +08:00
// 处理身高
2026-03-06 18:02:49 +08:00
$result_return [ 'top_list' ][ 1 ][ 'time' ] = $record_time ;
2026-03-09 08:35:43 +08:00
$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 ];
2026-03-06 18:02:49 +08:00
$result_return [ 'top_list' ][ 1 ][ 'key_name' ] = 'height' ;
2026-03-11 18:45:25 +08:00
2026-02-03 18:56:47 +08:00
// 处理BMI
2026-03-06 18:02:49 +08:00
$result_return [ 'top_list' ][ 2 ][ 'time' ] = $record_time ;
2026-03-09 08:35:43 +08:00
$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 ];
2026-03-06 18:02:49 +08:00
$result_return [ 'top_list' ][ 2 ][ 'key_name' ] = 'bmi' ;
// 如果有头围
2026-03-09 08:35:43 +08:00
if ( $body_last_data [ 'head_circumference' ]){
$temporary_head_circumference = json_decode ( $body_last_data [ 'head_circumference' ], true );
2026-03-11 18:45:25 +08:00
$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' ]);
}
2026-03-09 08:35:43 +08:00
$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 ,
2026-03-11 18:45:25 +08:00
'bk_color' => '#ddfaef' ,
'curve_list' => $head_circumference_curve_list ,
'ideal_head_circumference' => '' ,
2026-03-09 08:35:43 +08:00
];
}
// 如果有心率
if ( $body_last_data [ 'heart_rate' ]){
$temporary_standard_color = $this -> judgment_standard_color ( floatval ( $body_last_data [ 'heart_rate' ]), 'heart_rate' , $user_data );
2026-03-11 18:45:25 +08:00
$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' ]);
}
2026-03-09 08:35:43 +08:00
$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' ,
2026-03-11 18:45:25 +08:00
'bk_color' => '#fbeeee' ,
'curve_list' => $heart_rate_curve_list ,
'ideal_heart_rate' => $temporary_standard_color [ 3 ],
2026-03-09 08:35:43 +08:00
];
2026-03-07 15:06:35 +08:00
}
2026-03-11 18:45:25 +08:00
// 设置卡片顺序
$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' , //身体年龄☆
];
2026-02-03 18:56:47 +08:00
// 处理卡片数据
2026-03-09 08:35:43 +08:00
if ( $body_last_data [ 'record_type' ] == 'by_hand_means' ){
2026-03-11 18:45:25 +08:00
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 ,
];
}
2026-02-03 18:56:47 +08:00
return $this -> msg ( $result_return );
} else {
// 设置卡片顺序
2026-03-11 18:45:25 +08:00
// $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', //身体年龄☆
// ];
2026-03-09 08:35:43 +08:00
$temporary_three = [];
2026-02-03 18:56:47 +08:00
foreach ( $set_order as $key => $value ) {
2026-03-09 08:35:43 +08:00
if ( $value == 'body_level' || $value == 'body_type' || $value == 'body_age' ){
2026-02-03 18:56:47 +08:00
// 如果是特殊数据
$result_return [ 'card_list' ][] = [
'name' => $this -> merged_data [ $value ][ 'name' ],
2026-03-09 08:35:43 +08:00
'icon' => $this -> merged_data [ $value ][ 'icon' ],
'value' => $value == 'body_age' ? floatval ( $body_last_data [ $value ]) : $body_last_data [ $value ],
2026-02-03 18:56:47 +08:00
'unit' => $this -> merged_data [ $value ][ 'unit' ],
'standard' => '' ,
'standard_color' => '' ,
2026-03-06 18:02:49 +08:00
'key_name' => $value ,
2026-02-03 18:56:47 +08:00
];
} else {
2026-03-09 08:35:43 +08:00
if ( $value == 'ideal_weight' || $value == 'ideal_height' || $value == 'ideal_bmi' ){
$temporary_standard_color = $this -> judgment_standard_color ( 'none' , $value , $user_data );
2026-03-11 18:45:25 +08:00
// dump($temporary_standard_color);
2026-03-09 08:35:43 +08:00
if ( $temporary_standard_color ){
2026-03-11 18:45:25 +08:00
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 ;
}
2026-03-09 08:35:43 +08:00
}
2026-03-11 18:45:25 +08:00
2026-03-09 08:35:43 +08:00
} 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 );
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 ]],
];
}
}
}
2026-02-03 18:56:47 +08:00
}
2026-03-09 08:35:43 +08:00
2026-02-03 18:56:47 +08:00
}
}
}
return $this -> msg ( $result_return );
}
public function body_report_detailed_action ( $data ){
2026-03-09 08:35:43 +08:00
2026-03-06 18:02:49 +08:00
$result_return = [];
2026-03-09 08:35:43 +08:00
$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 ();
2026-03-06 18:02:49 +08:00
2026-03-09 08:35:43 +08:00
if ( ! $body_last_data ){
2026-02-03 18:56:47 +08:00
return $this -> msg ( $result_return );
}
2026-03-09 08:35:43 +08:00
$user_data [ 'weight' ] = $body_last_data [ 'weight' ];
2026-02-03 18:56:47 +08:00
$set_order = [
'weight' , //体重
2026-03-06 18:02:49 +08:00
'height' , //身高
2026-03-09 08:35:43 +08:00
'heart_rate' , //心率
'head_circumference' , //头围
'kcal' , //BMR 静态基础代谢
2026-03-06 18:02:49 +08:00
'bmi' , //BMI
2026-02-03 18:56:47 +08:00
'fat_r' , //体脂率
'fat_w' , //脂肪量
'muscle' , //肌肉率
'muscleval' , //肌肉量
'protein' , //蛋白率
'proteinval' , //蛋白量
'water' , //水分
'sfr' , //皮下脂肪
2026-03-09 08:35:43 +08:00
// '', //骨骼肌率
// '', //骨路肌量
2026-02-03 18:56:47 +08:00
'visceral' , //内脏指数
2026-03-09 08:35:43 +08:00
// '', //肌肉控制量
// '', //脂筋控制量
'ideal_weight' , //理想体重
'ideal_height' , //理想身高
'ideal_bmi' , //理想bmi
// '', //去脂体重
// '', //控制体量
2026-02-03 18:56:47 +08:00
'bone' , //骨重
'body_type' , //身体类型☆
'body_level' , //肥胖等级☆
2026-03-09 08:35:43 +08:00
// '', //健康评价
2026-02-03 18:56:47 +08:00
'body_age' , //身体年龄☆
'score' , //身体得分☆
];
2026-03-06 18:02:49 +08:00
foreach ( $set_order as $key => $value ) {
2026-03-09 08:35:43 +08:00
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 {
2026-03-16 19:29:36 +08:00
// $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 ;
}
}
2026-03-09 08:35:43 +08:00
}
2026-03-06 18:02:49 +08:00
} else {
2026-03-09 08:35:43 +08:00
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 ;
}
2026-03-11 18:45:25 +08:00
} 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 ;
}
2026-03-09 08:35:43 +08:00
} 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 ;
2026-03-06 18:02:49 +08:00
}
2026-03-09 08:35:43 +08:00
}
}
}
2026-03-11 18:45:25 +08:00
//身体
2026-03-09 08:35:43 +08:00
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 );
}
$user_data [ 'weight' ] = $body_last_data [ 'weight' ];
$temporary_data_list = $this -> judgment_standard_color_detailed ( $body_last_data [ 'score' ], 'score' , $user_data );
2026-03-11 18:45:25 +08:00
$result_return [ 'user_data' ] = [
// 'title_key'=>'user_data',
2026-03-09 08:35:43 +08:00
'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' => $body_last_data [ 'height' ],
2026-03-11 18:45:25 +08:00
'weight' => $body_last_data [ 'weight' ],
2026-03-09 08:35:43 +08:00
'score' => $temporary_data_list ? $temporary_data_list [ 'value' ] : 0 ,
];
// 如果有心率
if ( $body_last_data [ 'heart_rate' ]){
$temporary_data_list = $this -> judgment_standard_color_detailed ( $body_last_data [ 'heart_rate' ], 'heart_rate' , $user_data );
2026-03-11 18:45:25 +08:00
$result_return [ 'heart_rate' ] = [
// 'title_key'=>'heart_rate',
2026-03-09 08:35:43 +08:00
'title_name' => '心脏健康' ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/heart_rate.png " ,
2026-03-09 08:35:43 +08:00
'value' => " 心率 " . $temporary_data_list [ 'value' ],
'unit' => $temporary_data_list [ 'unit' ],
'standard' => $temporary_data_list [ 'standard' ],
'standard_color' => $temporary_data_list [ 'standard_color' ],
'standard_list' => $temporary_data_list [ 'standard_list' ],
'offset' => $temporary_data_list [ 'offset' ],
];
2026-03-11 18:45:25 +08:00
} else {
$result_return [ 'heart_rate' ] = [];
2026-03-09 08:35:43 +08:00
}
$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 [ 'muscleval' ] = $this -> judgment_standard_color_detailed ( $body_last_data [ 'muscleval' ], 'muscleval' , $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 );
$temporary_data_list [ 'bone' ] = $this -> judgment_standard_color_detailed ( $body_last_data [ 'bone' ], 'bone' , $user_data );
// 体重
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' ]){
2026-03-11 18:45:25 +08:00
$temporary_body_data [ 'weight' ][ 0 ] = $value [ 'min_val' ] . " ~ " . $value [ 'max_val' ] . " ) " ;
2026-03-09 08:35:43 +08:00
$temporary_body_data [ 'weight' ][ 1 ] = '' ;
}
}
} else {
$temporary_body_data [ 'weight' ][ 0 ] = '' ;
$temporary_body_data [ 'weight' ][ 1 ] = '' ;
}
// 脂肪量
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' ][ 0 ] = " ( " . $value [ 'min_val' ] . " ~ " . $value [ 'max_val' ] . " ) " ;
$temporary_body_data [ 'fat_w' ][ 1 ] = bcdiv ( $body_last_data [ 'fat_w' ], $body_last_data [ 'weight' ], 2 );
}
}
} else {
$temporary_body_data [ 'fat_w' ][ 0 ] = '' ;
$temporary_body_data [ 'fat_w' ][ 1 ] = bcdiv ( $body_last_data [ 'fat_w' ], $body_last_data [ 'weight' ], 2 );
}
// 肌肉量
2026-03-11 18:45:25 +08:00
// if(count($temporary_data_list['muscleval']['standard_list'])){
// foreach ($temporary_data_list['muscleval']['standard_list'] as $key => $value) {
// if($value['text'] == $temporary_data_list['muscleval']['standard']){
// $temporary_body_data['muscleval'][0] = "(".$value['min_val']."~".$value['max_val'].")";
// $temporary_body_data['muscleval'][1] = bcdiv($body_last_data['muscleval'],$body_last_data['weight'],2);
// }
// }
// }else{
// $temporary_body_data['muscleval'][0] = '';
// $temporary_body_data['muscleval'][1] = bcdiv($body_last_data['muscleval'],$body_last_data['weight'],2);
// }
2026-03-09 08:35:43 +08:00
// 蛋白量
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' ][ 0 ] = " ( " . $value [ 'min_val' ] . " ~ " . $value [ 'max_val' ] . " ) " ;
$temporary_body_data [ 'proteinval' ][ 1 ] = bcdiv ( $body_last_data [ 'proteinval' ], $body_last_data [ 'weight' ], 2 );
}
}
} else {
$temporary_body_data [ 'proteinval' ][ 0 ] = '' ;
$temporary_body_data [ 'proteinval' ][ 1 ] = 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' ][ 0 ] = " ( " . $value [ 'min_val' ] . " ~ " . $value [ 'max_val' ] . " ) " ;
$temporary_body_data [ 'water' ][ 1 ] = bcdiv ( $body_last_data [ 'water' ], $body_last_data [ 'weight' ], 2 );
}
}
} else {
$temporary_body_data [ 'water' ][ 0 ] = '' ;
$temporary_body_data [ 'water' ][ 1 ] = bcdiv ( $body_last_data [ 'water' ], $body_last_data [ 'weight' ], 2 );
}
// 骨重
2026-03-11 18:45:25 +08:00
// if(count($temporary_data_list['bone']['standard_list'])){
// foreach ($temporary_data_list['bone']['standard_list'] as $key => $value) {
// if($value['text'] == $temporary_data_list['bone']['standard']){
// $temporary_body_data['bone'][0] = "(".$value['min_val']."~".$value['max_val'].")";
// $temporary_body_data['bone'][1] = bcdiv($body_last_data['bone'],$body_last_data['weight'],2);
// }
// }
// }else{
// $temporary_body_data['bone'][0] = '';
// $temporary_body_data['bone'][1] = bcdiv($body_last_data['bone'],$body_last_data['weight'],2);
// }
2026-03-09 08:35:43 +08:00
// 加 bcadd(,,20)
2026-03-11 18:45:25 +08:00
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
$result_return [ 'body_data' ] = [
// 'title_key'=>'body_data',
2026-03-09 08:35:43 +08:00
'title_name' => '身体成分分析' ,
2026-03-11 18:45:25 +08:00
" icon " => " https://tc.pcxbc.com/new_reedaw/icon/body_data.png " ,
" title " => " 体重( " . $temporary_body_data [ 'weight' ][ 0 ] . " " ,
'standard' => $temporary_data_list [ 'weight' ][ 'standard' ] == '' ? '' : $temporary_data_list [ 'weight' ][ 'standard' ],
" description " => " *总体重=体水分量+蛋白质量+脂肪量+其他 " ,
2026-03-09 08:35:43 +08:00
'list' => [
[ 'color' => '#3E7AF6' , 'name' => '体水分量' , 'scope' => $temporary_body_data [ 'water' ][ 0 ], 'value' => $body_last_data [ 'water' ], 'offset' => $temporary_body_data [ 'water' ][ 1 ]],
[ 'color' => '#FFB119' , 'name' => '蛋白质量' , 'scope' => $temporary_body_data [ 'proteinval' ][ 0 ], 'value' => $body_last_data [ 'proteinval' ], 'offset' => $temporary_body_data [ 'proteinval' ][ 1 ]],
[ 'color' => '#31D4F5' , 'name' => '脂肪量' , 'scope' => $temporary_body_data [ 'fat_w' ][ 0 ], 'value' => $body_last_data [ 'fat_w' ], 'offset' => $temporary_body_data [ 'fat_w' ][ 1 ]],
2026-03-11 18:45:25 +08:00
// ['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]],
2026-03-09 08:35:43 +08:00
[
'color' => '#999999' ,
'name' => '其他' ,
'scope' => " " ,
'value' => '' ,
'offset' => '' ,
],
],
'value' => $body_last_data [ 'weight' ],
2026-03-11 18:45:25 +08:00
'unit' => $temporary_data_list [ 'weight' ][ 'unit' ],
];
//肌肉脂肪分析
$result_return [ 'muscle_fat' ] = [
// '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' ,
]
],
2026-03-09 08:35:43 +08:00
];
2026-03-11 18:45:25 +08:00
// 节段脂肪分析
$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' => '1' ,
'unit' => 'kg' ,
],
[
'name' => 'R:' ,
'value' => '1' ,
'unit' => 'kg' ,
],
[
'name' => 'B:' ,
'value' => '1' ,
'unit' => 'kg' ,
],
[
'name' => 'L:' ,
'value' => '1' ,
'unit' => 'kg' ,
],
[
'name' => 'R:' ,
'value' => '1' ,
'unit' => 'kg' ,
],
],
];
// 肌肉平衡
$result_return [ 'segment_muscle' ] = [
// 'title_key'=>'segment_muscle',
'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' => '1' ,
'unit' => 'kg' ,
],
[
'name' => 'R:' ,
'value' => '1' ,
'unit' => 'kg' ,
],
[
'name' => 'B:' ,
'value' => '1' ,
'unit' => 'kg' ,
],
[
'name' => 'L:' ,
'value' => '1' ,
'unit' => 'kg' ,
],
[
'name' => 'R:' ,
'value' => '1' ,
'unit' => 'kg' ,
],
],
];
2026-03-09 08:35:43 +08:00
2026-03-11 18:45:25 +08:00
//肥胖分析
$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' => [
[
'name' => 'BMI' ,
'unit' => 'kg/m²' ,
'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' ,
],
[
'name' => '体脂率' ,
'unit' => '%' ,
'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' => '肥胖水平' ,
'unit' => '' ,
'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' => 9 ,
'standard' => '低' ,
'standard_color' => '#F8595D' ,
'offset' => '9' ,
]
],
];
//体重控制
$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' => '62kg' ],
[ 'name' => '控制体重' , 'value' => '-3.5kg' ],
[ 'name' => 'BMR' , 'value' => '1500kcal' ],
],
];
//身体类型
$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' => '浮肿肥胖型' ,
2026-03-09 08:35:43 +08:00
];
2026-03-11 18:45:25 +08:00
//其他指标
$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' => '47.6kg' ],
[ 'name' => '皮下脂肪量' , 'value' => '15.2kg' ],
[ 'name' => '身体年龄' , 'value' => '33' ],
[ 'name' => '内脏脂肪' , 'value' => '9' ],
],
];
2026-03-06 18:02:49 +08:00
return $this -> msg ( $result_return );
2026-02-03 18:56:47 +08:00
}
2026-03-06 18:02:49 +08:00
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 );
}
}
2026-03-12 07:40:45 +08:00
public function set_initial_weight_action ( $data ){
2026-03-16 19:29:36 +08:00
$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' ]]);
2026-03-12 07:40:45 +08:00
if ( $user_data ){
return $this -> msg ([]);
2026-03-06 18:02:49 +08:00
} else {
2026-03-12 07:40:45 +08:00
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' ],
]);
2026-03-06 18:02:49 +08:00
}
2026-03-12 07:40:45 +08:00
return $this -> msg ( $return_result );
2026-03-06 18:02:49 +08:00
}
2026-03-12 07:40:45 +08:00
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 ) {
2026-03-06 18:02:49 +08:00
2026-03-12 07:40:45 +08:00
$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 ;
2026-03-06 18:02:49 +08:00
} else {
2026-03-12 07:40:45 +08:00
$temporary_arr [ 'value' ] = $result [ $key ];
2026-03-06 18:02:49 +08:00
}
} else {
2026-03-12 07:40:45 +08:00
if ( $key == 'un_fat_w_weight' ){
$temporary_arr [ 'value' ] = bcsub ( $result [ 'weight' ], $result [ 'fat_w' ], 2 );
2026-03-06 18:02:49 +08:00
} else {
2026-03-12 07:40:45 +08:00
if ( array_key_exists ( $key , $result )){
$temporary_arr [ 'value' ] = $result [ $key ];
}
2026-03-06 18:02:49 +08:00
}
}
2026-03-12 07:40:45 +08:00
$temporary_arr [ 'unit' ] = $value [ 1 ];
array_push ( $result_data , $temporary_arr );
2026-03-06 18:02:49 +08:00
}
2026-03-12 07:40:45 +08:00
//
// 添加头围详细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 );
2026-03-06 18:02:49 +08:00
}
2026-03-12 07:40:45 +08:00
2026-03-06 18:02:49 +08:00
}
2026-03-12 07:40:45 +08:00
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 );
}
2026-03-16 19:29:36 +08:00
}
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 );
2026-03-12 07:40:45 +08:00
}
################################################################工具################################################################
################################################################工具################################################################
// // 处理身高体重BMI的标准
// public function process_hwb_standard_action($birthday,$key_name,$age,$gender_val){
// $month_num = $this->calculateAgeInMonthsWithPrecision($birthday);
// if($age < $this->age_limit){
// $result_data = $this->merged_data[$key_name]['standard_list'];
// if($key_name == 'bmi'){
// $bhw_date = Db::table($this->body_db_name['bmi'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
// if($bhw_date){
// $result_data[0]['max_val'] = $bhw_date[0]['f1sd'];
// $result_data[0]['max_val'] = $bhw_date[0]['f1sd'];
// $result_data[1]['min_val'] = $bhw_date[0]['f1sd'];
// $result_data[1]['max_val'] = $bhw_date[0]['z1sd'];
// $result_data[2]['min_val'] = $bhw_date[0]['z1sd'];
// $result_data[2]['max_val'] = $bhw_date[0]['z2sd'];
// $result_data[3]['min_val'] = $bhw_date[0]['z2sd'];
// }
// }else if($key_name == 'height'){
// $bhw_date = Db::table($this->body_db_name['heigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
// if($bhw_date){
// $result_data[0]['max_val'] = $bhw_date[0]['f2sd'];
// $result_data[1]['min_val'] = $bhw_date[0]['f2sd'];
// $result_data[1]['max_val'] = $bhw_date[0]['f1sd'];
// $result_data[2]['min_val'] = $bhw_date[0]['f1sd'];
// $result_data[2]['max_val'] = $bhw_date[0]['z1sd'];
// $result_data[3]['min_val'] = $bhw_date[0]['z1sd'];
// $result_data[3]['max_val'] = $bhw_date[0]['z2sd'];
// $result_data[4]['min_val'] = $bhw_date[0]['z2sd'];
// $result_data[4]['max_val'] = $bhw_date[0]['z3sd'];
// }
// }else if($key_name == 'weight'){
// $bhw_date = Db::table($this->body_db_name['weigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
// // dump($bhw_date);
// if($bhw_date){
// $result_data[0]['max_val'] = $bhw_date[0]['f2sd'];
// $result_data[1]['min_val'] = $bhw_date[0]['f2sd'];
// $result_data[1]['max_val'] = $bhw_date[0]['f1sd'];
// $result_data[2]['min_val'] = $bhw_date[0]['f1sd'];
// $result_data[2]['max_val'] = $bhw_date[0]['z1sd'];
// $result_data[3]['min_val'] = $bhw_date[0]['z1sd'];
// $result_data[3]['max_val'] = $bhw_date[0]['z2sd'];
// $result_data[4]['min_val'] = $bhw_date[0]['z2sd'];
// $result_data[4]['max_val'] = $bhw_date[0]['z3sd'];
// }
// }
// }else{
// $result_data = [];
// }
// return $result_data;
// }
// // 处理其他的标注列表
// public function process_other_standard_action($data,$key_name){
// if($key_name == 'body_age'){
// $result_data = [
// ['min_val'=>'0','max_val'=>$data['age'],'text'=>'年轻','color'=>'#14CBAD'], //淡黄
// ['min_val'=>$data['age'],'max_val'=>bcadd(bcsub($data['age'],0,2),$data['age'],2),'text'=>'偏大','color'=>'#F53F31'], //绿
// ];
// }else if($key_name == 'score'){
// $result_data = $this->merged_data['score']['standard_list'];
// }else{
// $gender_val = $data['gender'] == 2?'woman':'man';
// if($key_name == 'fat_r'){
// if($data['age'] < 30){
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['29'];
// }else{
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['30'];
// }
// }else if($key_name == 'fat_w'){
// if($data['age'] < 30){
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['29'];
// }else{
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['30'];
// }
// $result_data = $this->calculate_new_standard($result_data,$data['weight_val'],$key_name,$data['age'],$gender_val);
// }else if($key_name == 'muscle' || $key_name == 'protein' || $key_name == 'water' || $key_name == 'sfr' || $key_name == 'visceral'){
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val];
// }else if($key_name == 'muscleval' || $key_name == 'proteinval'){
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val];
// $result_data = $this->calculate_new_standard($result_data,$data['weight_val'],$key_name,$data['age'],$gender_val);
// }else if($key_name == 'bone'){
// if($gender_val == 'man'){
// if($data['weight_val'] < 60){
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['60'];
// }else if($data['weight_val'] >= 60 && $data['weight_val'] < 75){
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['60_75'];
// }else{
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['75'];
// }
// }else{
// if($data['weight_val'] < 45){
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['45'];
// }else if($data['weight_val'] >= 45 && $data['weight_val'] < 60){
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['45_60'];
// }else{
// $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['60'];
// }
// }
// }
// }
// return $result_data;
// }
2026-03-06 18:02:49 +08:00
2026-03-09 08:35:43 +08:00
2026-03-06 18:02:49 +08:00
2026-03-12 07:40:45 +08:00
// // 处理特殊落点下的标准值
// public function process_special_offset_action($val, $list) {
// $return_data['standard'] = '';
// $return_data['standard_color'] = '#000000';
// if($val<$list[0]['min_val']){
// $return_data['standard'] = $list[0]['text'];
// $return_data['standard_color'] = $list[0]['color'];
// return $return_data;
// }
2026-03-06 18:02:49 +08:00
2026-03-12 07:40:45 +08:00
// if($val>$list[count($list)-1]['max_val']){
// $return_data['standard'] = $list[count($list)-1]['text'];
// $return_data['standard_color'] = $list[count($list)-1]['color'];
// return $return_data;
// }
// foreach ($list as $key => $value) {
// if($val >= $value['min_val'] && $val <= $value['max_val']){
// $return_data['standard'] = $value['text'];
// $return_data['standard_color'] = $value['color'];
// break;
// }
// }
// return $return_data;
// }
2026-03-06 18:02:49 +08:00
// 计算新标准
public function calculate_new_standard ( $data , $w , $k , $age = 0 , $gender = 'man' ){
$temporary_arr = [];
if ( $k != 'kcal' ){
foreach ( $data as $key => $value ) {
array_push ( $temporary_arr ,[
'min_val' => bcmul ( $w , bcdiv ( $value [ 'min_val' ], 100 , 2 ), 2 ),
'max_val' => bcmul ( $w , bcdiv ( $value [ 'max_val' ], 100 , 2 ), 2 ),
'text' => $value [ 'text' ],
'color' => $value [ 'color' ]
]);
}
} else {
// 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 == 'man' ){
$vv_val = bcsub ( bcmul ( 60.9 , $w , 2 ), 54 , 2 );
} else {
$vv_val = bcsub ( bcmul ( 61.0 , $w , 2 ), 51 , 2 );
}
} else if ( $age >= 3 && $age < 10 ){
if ( $gender == 'man' ){
$vv_val = bcadd ( bcmul ( 22.7 , $w , 2 ), 495 , 2 );
} else {
$vv_val = bcadd ( bcmul ( 22.5 , $w , 2 ), 499 , 2 );
}
} else if ( $age >= 10 && $age < 18 ){
if ( $gender == 'man' ){
$vv_val = bcadd ( bcmul ( 17.5 , $w , 2 ), 651 , 2 );
} else {
$vv_val = bcadd ( bcmul ( 12.2 , $w , 2 ), 746 , 2 );
}
} else if ( $age >= 18 && $age < 30 ){
if ( $gender == 'man' ){
$vv_val = bcadd ( bcmul ( 15.3 , $w , 2 ), 679 , 2 );
} else {
$vv_val = bcadd ( bcmul ( 14.7 , $w , 2 ), 496 , 2 );
}
} else {
if ( $gender == 'man' ){
$vv_val = bcadd ( bcmul ( 11.6 , $w , 2 ), 879 , 2 );
} else {
$vv_val = bcadd ( bcmul ( 8.7 , $w , 2 ), 820 , 2 );
}
}
$data [ 0 ][ 'max_val' ] = $vv_val ;
$data [ 1 ][ 'min_val' ] = $vv_val ;
$temporary_arr = $data ;
}
return $temporary_arr ;
}
//
2026-03-12 07:40:45 +08:00
// public function hwb_standard($data){
// $linshi_data = [];
// $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
// $gender_val = $data['gender'];
// if($data['age'] < $this->age_limit){
// foreach ($data as $key => $value) {
// if($key =='身高'){
// $linshi_data['身高'] = $this->merged_data['height']['standard_list'];
// $bhw_date = Db::table($this->body_db_name['heigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
2026-03-06 18:02:49 +08:00
2026-03-12 07:40:45 +08:00
// if($bhw_date){
// $linshi_data['身高'][0]['max_val'] = $bhw_date[0]['f2sd'];
// $linshi_data['身高'][1]['min_val'] = $bhw_date[0]['f2sd'];
// $linshi_data['身高'][1]['max_val'] = $bhw_date[0]['f1sd'];
// $linshi_data['身高'][2]['min_val'] = $bhw_date[0]['f1sd'];
// $linshi_data['身高'][2]['max_val'] = $bhw_date[0]['z1sd'];
// $linshi_data['身高'][3]['min_val'] = $bhw_date[0]['z1sd'];
// $linshi_data['身高'][3]['max_val'] = $bhw_date[0]['z2sd'];
// $linshi_data['身高'][4]['min_val'] = $bhw_date[0]['z2sd'];
// $linshi_data['身高'][4]['max_val'] = $bhw_date[0]['z3sd'];
// }
2026-03-06 18:02:49 +08:00
2026-03-12 07:40:45 +08:00
// }else if($key =='体重'){
// $linshi_data['体重'] = $this->merged_data['weight']['standard_list'];
// $bhw_date = Db::table($this->body_db_name['weigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
// if($bhw_date){
// $linshi_data['体重'][0]['max_val'] = $bhw_date[0]['f2sd'];
// $linshi_data['体重'][1]['min_val'] = $bhw_date[0]['f2sd'];
// $linshi_data['体重'][1]['max_val'] = $bhw_date[0]['f1sd'];
// $linshi_data['体重'][2]['min_val'] = $bhw_date[0]['f1sd'];
// $linshi_data['体重'][2]['max_val'] = $bhw_date[0]['z1sd'];
// $linshi_data['体重'][3]['min_val'] = $bhw_date[0]['z1sd'];
// $linshi_data['体重'][3]['max_val'] = $bhw_date[0]['z2sd'];
// $linshi_data['体重'][4]['min_val'] = $bhw_date[0]['z2sd'];
// $linshi_data['体重'][4]['max_val'] = $bhw_date[0]['z3sd'];
// }
// }else if($key =='BMI'){
// $linshi_data['BMI'] = $this->merged_data['bmi']['standard_list'];
// $bhw_date = Db::table($this->body_db_name['bmi'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
// if($bhw_date){
// $linshi_data['BMI'][0]['max_val'] = $bhw_date[0]['f1sd'];
// $linshi_data['BMI'][1]['min_val'] = $bhw_date[0]['f1sd'];
// $linshi_data['BMI'][1]['max_val'] = $bhw_date[0]['z1sd'];
// $linshi_data['BMI'][2]['min_val'] = $bhw_date[0]['z1sd'];
// $linshi_data['BMI'][2]['max_val'] = $bhw_date[0]['z2sd'];
// $linshi_data['BMI'][3]['min_val'] = $bhw_date[0]['z2sd'];
// }
// }
// }
// foreach ($linshi_data as $key => $value) {
// foreach ($value as $k => $v) {
// if($data[$key] >= $v['min_val'] && $data[$key] < $v['max_val']){
// // 如果落在区间内
// $data[$key.'2'] = $data[$key].','.$v['text'].','.$v['color'];
// break;
// }
// }
// // 如果$key.'2'没有被设置
// if(!array_key_exists($key.'2', $data)){
// if($data[$key] < $value[0]['min_val']){
// // 如果小于最小值
// $data[$key.'2'] = $data[$key].','.$value[0]['text'].','.$value[0]['color'];
// }else if($data[$key] >= $value[count($value)-1]['max_val']){
// // 如果大于最大值
// $data[$key.'2'] = $data[$key].','.$value[count($value)-1]['text'].','.$value[count($value)-1]['color'];
// }
// }
// }
// // die;
// }else{
// $data['身高2'] = $data['身高'].',无,无';
// $data['体重2'] = $data['体重'].',无,无';
// $data['BMI2'] = $data['BMI'].',无,无';
// }
// return $data;
// }
2026-02-03 18:56:47 +08:00
2026-03-12 07:40:45 +08:00
// // 处理异常
// public function handling_exceptions($data){
// for ($i=0; $i < count($data['list']); $i++) {
// if($data['value']>=$data['list'][$i]['min_val'] && $data['value']<$data['list'][$i]['max_val']){
// $data['standard'] = $data['list'][$i]['text'];
// $data['color'] = $data['list'][$i]['color'];
// break;
// }
// }
// if($data['standard'] == '异常'){
// if($data['value'] <= $data['list'][0]['min_val']){
// $data['standard'] = $data['list'][0]['text'];
// $data['color'] = $data['list'][0]['color'];
// }else if($data['value'] >= $data['list'][count($data['list'])-1]['max_val']){
// $data['standard'] = $data['list'][count($data['list'])-1]['text'];
// $data['color'] = $data['list'][count($data['list'])-1]['color'];
// }
// }
// return $data;
// }
2026-02-03 18:56:47 +08:00
2026-03-09 08:35:43 +08:00
// 处理一般落点
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 ;
}
2026-03-07 15:06:35 +08:00
// 发送信息获取身体数据
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' ];
}
}
2026-03-09 08:35:43 +08:00
//简要身体数据标准和颜色
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' ];
2026-03-11 18:45:25 +08:00
$return_data [] = bcdiv ( bcadd ( $linshi_data [ 'standard_list' ][ 1 ][ 'min_val' ], $linshi_data [ 'standard_list' ][ 1 ][ 'max_val' ], 20 ), 2 , 0 );
2026-03-09 08:35:43 +08:00
}
}
if ( count ( $return_data ) <= 1 ){
$return_data [] = '异常' ;
$return_data [] = '#000000' ;
2026-03-11 18:45:25 +08:00
$return_data [] = 0 ;
2026-03-09 08:35:43 +08:00
}
return $return_data ;
} else if ( $type == 'ideal_weight' ){
2026-03-11 18:45:25 +08:00
$bhw_date = Db :: table ( $this -> body_db_name [ 'weight' ]) -> where ( " Month >= $month_num and Sex = ' $gender_val ' " ) -> order ( 'Month' ) -> limit ( 1 ) -> cache ( 86400 ) -> select ();
2026-03-09 08:35:43 +08:00
if ( $bhw_date ){
return $bhw_date [ 0 ][ 'median' ];
} else {
return false ;
}
} else if ( $type == 'ideal_height' ){
2026-03-11 18:45:25 +08:00
$bhw_date = Db :: table ( $this -> body_db_name [ 'height' ]) -> where ( " Month >= $month_num and Sex = ' $gender_val ' " ) -> order ( 'Month' ) -> limit ( 1 ) -> cache ( 86400 ) -> select ();
2026-03-09 08:35:43 +08:00
if ( $bhw_date ){
return $bhw_date [ 0 ][ 'median' ];
} else {
return false ;
}
} else if ( $type == 'ideal_bmi' ){
2026-03-11 18:45:25 +08:00
$bhw_date = Db :: table ( $this -> body_db_name [ 'bmi' ]) -> where ( " Month >= $month_num and Sex = ' $gender_val ' " ) -> order ( 'Month' ) -> limit ( 1 ) -> cache ( 86400 ) -> select ();
2026-03-09 08:35:43 +08:00
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 ;
}
}
2026-03-07 15:06:35 +08:00
2026-02-03 18:56:47 +08:00
}