260307部分测试
This commit is contained in:
parent
6f8fe55e03
commit
cf5ab31231
|
|
@ -634,8 +634,5 @@ class Calculatebody extends Base{
|
|||
|
||||
|
||||
|
||||
public function msg($code,$msg='',$data=[]){
|
||||
return json(['code'=>$code,'msg'=>$msg,'data'=>$data]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ class Userbody extends Base{
|
|||
'zhanghao'=>'app_account_number',
|
||||
'juese'=>'app_user_data',
|
||||
'body_data'=>'app_card_body_data',
|
||||
'body_data_new'=>'app_card_body_data_new',
|
||||
'bmi'=>'pc_bmistand',
|
||||
'heigh'=>'pc_heightstand',
|
||||
'weigh'=>'pc_weightstand',
|
||||
|
|
@ -420,27 +421,102 @@ class Userbody extends Base{
|
|||
"description"=>"身体年龄指衡量身体健康状况的指标,它反映了一个人的生理状态相对于实际年龄的健康程度。相关模型主要与BMI有关。",
|
||||
'list' => [],
|
||||
'standard_list' => []
|
||||
]
|
||||
],
|
||||
// 'heart_rate' => [
|
||||
// 'name' => '心率',
|
||||
// 'unit' => '跳/分钟',
|
||||
// "description"=>"",
|
||||
// 'list' => [
|
||||
// '低' => '#FCDB67',
|
||||
// '标准' => '#58D268',
|
||||
// '高' => '#FD5752'
|
||||
// ],
|
||||
// 'standard_list' => [
|
||||
// 'man'=>[
|
||||
// '1'=>[
|
||||
// ['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'],
|
||||
// ],
|
||||
// ],
|
||||
// 'woman'=>[
|
||||
// '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'],
|
||||
// ],
|
||||
// ]
|
||||
// ]
|
||||
// ],
|
||||
|
||||
];
|
||||
protected $standard_color = [
|
||||
'fat_r'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'],
|
||||
'fat_w'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'],
|
||||
'muscle'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'],
|
||||
'muscleval'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'],
|
||||
'water'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
'proteinval'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
'bone'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
'protein'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
'kcal'=>['偏低'=>'#FF5656','优'=>'#3A68D4'],
|
||||
'visceral'=>['标准'=>'#55CF6C','警惕'=>'#FEAC00','危险'=>'#FB5A52'],
|
||||
'sfr'=>['不足'=>'#FCDB68','标准'=>'#59D16F','偏高'=>'#FEAB03'],
|
||||
];
|
||||
protected $card_body_level = [
|
||||
'height'=>['value'=>1,'list'=>['矮'=>2,'偏矮'=>3,'标准'=>4,'偏高'=>5,'高'=>5]],
|
||||
'weight'=>['value'=>3,'list'=>['低'=>1,'偏低'=>1,'标准'=>2,'偏高'=>3,'高'=>3]],
|
||||
'bmi'=>['value'=>2,'list'=>['消瘦'=>1,'正常'=>2,'偏重'=>3,'肥胖'=>4]],
|
||||
protected $heart_rate = [
|
||||
[
|
||||
'age' => ['min' => '0', 'max' => '1'],
|
||||
'male' => ['min' => '70', 'max' => '190'],
|
||||
'female' => ['min' => '70', 'max' => '190']
|
||||
],
|
||||
[
|
||||
'age' => ['min' => '1', 'max' => '12'],
|
||||
'male' => ['min' => '80', 'max' => '160'],
|
||||
'female' => ['min' => '80', 'max' => '160']
|
||||
],
|
||||
[
|
||||
'age' => ['min' => '12', 'max' => '36'],
|
||||
'male' => ['min' => '80', 'max' => '130'],
|
||||
'female' => ['min' => '80', 'max' => '130']
|
||||
],
|
||||
[
|
||||
'age' => ['min' => '36', 'max' => '60'],
|
||||
'male' => ['min' => '80', 'max' => '120'],
|
||||
'female' => ['min' => '80', 'max' => '120']
|
||||
],
|
||||
[
|
||||
'age' => ['min' => '60', 'max' => '120'],
|
||||
'male' => ['min' => '70', 'max' => '110'],
|
||||
'female' => ['min' => '70', 'max' => '110']
|
||||
],
|
||||
[
|
||||
'age' => ['min' => '120', 'max' => '204'],
|
||||
'male' => ['min' => '60', 'max' => '100'],
|
||||
'female' => ['min' => '60', 'max' => '100']
|
||||
],
|
||||
[
|
||||
'age' => ['min' => '204', 'max' => '480'],
|
||||
'male' => ['min' => '60', 'max' => '100'],
|
||||
'female' => ['min' => '60', 'max' => '100']
|
||||
],
|
||||
[
|
||||
'age' => ['min' => '480', 'max' => '720'],
|
||||
'male' => ['min' => '60', 'max' => '100'],
|
||||
'female' => ['min' => '60', 'max' => '100']
|
||||
],
|
||||
[
|
||||
'age' => ['min' => '720', 'max' => '9999'], // 61岁+,9999作为最大值占位
|
||||
'male' => ['min' => '60', 'max' => '100'],
|
||||
'female' => ['min' => '60', 'max' => '100']
|
||||
]
|
||||
];
|
||||
// protected $standard_color = [
|
||||
// 'fat_r'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'],
|
||||
// 'fat_w'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'],
|
||||
// 'muscle'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'],
|
||||
// 'muscleval'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'],
|
||||
// 'water'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
// 'proteinval'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
// 'bone'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
// 'protein'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'],
|
||||
// 'kcal'=>['偏低'=>'#FF5656','优'=>'#3A68D4'],
|
||||
// 'visceral'=>['标准'=>'#55CF6C','警惕'=>'#FEAC00','危险'=>'#FB5A52'],
|
||||
// 'sfr'=>['不足'=>'#FCDB68','标准'=>'#59D16F','偏高'=>'#FEAB03'],
|
||||
// ];
|
||||
// protected $card_body_level = [
|
||||
// 'height'=>['value'=>1,'list'=>['矮'=>2,'偏矮'=>3,'标准'=>4,'偏高'=>5,'高'=>5]],
|
||||
// 'weight'=>['value'=>3,'list'=>['低'=>1,'偏低'=>1,'标准'=>2,'偏高'=>3,'高'=>3]],
|
||||
// 'bmi'=>['value'=>2,'list'=>['消瘦'=>1,'正常'=>2,'偏重'=>3,'肥胖'=>4]],
|
||||
// ];
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
|
|
@ -450,6 +526,106 @@ class Userbody extends Base{
|
|||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
################################################################接口################################################################
|
||||
// 手动记录
|
||||
public function manual_record(){
|
||||
$data = input('post.');
|
||||
try {
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['time'],'datetime')){
|
||||
return $this->msg(10005,'time type error');
|
||||
}
|
||||
$temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
|
||||
if($temporary_data['height_in_cm'] == false){
|
||||
return $this->msg(10005,'身高单位错误');
|
||||
}
|
||||
if($temporary_data['weight_in_kg'] == false){
|
||||
return $this->msg(10005,'体重单位错误');
|
||||
}
|
||||
$data['height'] = $temporary_data['height_in_cm'];
|
||||
$data['weight'] = $temporary_data['weight_in_kg'];
|
||||
if(strlen($data['time']) <= 12){
|
||||
// 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
|
||||
$data['time'] = $this->addCurrentTimeToDateString($data['time']);
|
||||
}
|
||||
|
||||
return $this->set_user_body_data($data,'by_hand_means');
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常
|
||||
$logContent["flie"] = $e->getFile();
|
||||
$logContent["line"] = $e->getLine();
|
||||
$logContent['all_content'] = "异常信息:\n";
|
||||
$logContent['all_content'] .= "函数: manual_record" . "\n";
|
||||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||
$this->record_api_log($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
}
|
||||
|
||||
// 设备记录
|
||||
public function device_record(){
|
||||
$data = input('post.');
|
||||
// try {
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['adc'],'num')){
|
||||
return $this->msg(10005,'adc type error');
|
||||
}
|
||||
$temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
|
||||
if($temporary_data['height_in_cm'] == false){
|
||||
return $this->msg(10005,'身高单位错误');
|
||||
}
|
||||
if($temporary_data['weight_in_kg'] == false){
|
||||
return $this->msg(10005,'体重单位错误');
|
||||
}
|
||||
// 检测设备传过来的info信息
|
||||
if(array_key_exists('info', $data)){
|
||||
if (!is_array($data['info'])) {
|
||||
return $this->msg(10005,'info参数格式错误');
|
||||
}else{
|
||||
$info_data_arr =['bodyage','fat_r','muscle','kcal','visceral','sfr','water','bone','fatlevlval','protein','bmi'];
|
||||
foreach ($data['info'] as $key => $value) {
|
||||
if (!in_array($key, $info_data_arr)) {
|
||||
return $this->msg(10005,'info参数格式错误-2');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$data['height'] = $temporary_data['height_in_cm'];
|
||||
$data['weight'] = $temporary_data['weight_in_kg'];
|
||||
$data['time'] = date('Y-m-d H:i:s');
|
||||
return $this->set_user_body_data($data,'by_device');
|
||||
// } catch (\Exception $e) {
|
||||
// // 捕获异常
|
||||
// $logContent["flie"] = $e->getFile();
|
||||
// $logContent["line"] = $e->getLine();
|
||||
// $logContent['all_content'] = "异常信息:\n";
|
||||
// $logContent['all_content'] .= "函数: device_record" . "\n";
|
||||
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||
// $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||
// $this->record_api_log($data, $logContent, null);
|
||||
// return $this->msg(99999);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 获取角色报告(简要)
|
||||
public function body_report_brief(){
|
||||
$data = input('post.');
|
||||
|
|
@ -509,102 +685,8 @@ class Userbody extends Base{
|
|||
}
|
||||
}
|
||||
|
||||
// 手动记录
|
||||
public function manual_record(){
|
||||
$data = input('post.');
|
||||
try {
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
unset($data['token']);
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['time'],'datetime')){
|
||||
return $this->msg(10005,'time type error');
|
||||
}
|
||||
$temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
|
||||
if($temporary_data['height_in_cm'] == false){
|
||||
return $this->msg(10005,'身高单位错误');
|
||||
}
|
||||
if($temporary_data['weight_in_kg'] == false){
|
||||
return $this->msg(10005,'体重单位错误');
|
||||
}
|
||||
$data['height'] = $temporary_data['height_in_cm'];
|
||||
$data['weight'] = $temporary_data['weight_in_kg'];
|
||||
if(strlen($data['time']) <= 12){
|
||||
// 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
|
||||
$data['time'] = $this->addCurrentTimeToDateString($data['time']);
|
||||
}
|
||||
|
||||
return $this->set_user_body_data($data,'by_hand_means');
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常
|
||||
$logContent["flie"] = $e->getFile();
|
||||
$logContent["line"] = $e->getLine();
|
||||
$logContent['all_content'] = "异常信息:\n";
|
||||
$logContent['all_content'] .= "函数: manual_record" . "\n";
|
||||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||
$this->record_api_log($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
}
|
||||
// 设备记录
|
||||
public function device_record(){
|
||||
$data = input('post.');
|
||||
try {
|
||||
if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['adc'],'num')){
|
||||
return $this->msg(10005,'adc type error');
|
||||
}
|
||||
$temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
|
||||
if($temporary_data['height_in_cm'] == false){
|
||||
return $this->msg(10005,'身高单位错误');
|
||||
}
|
||||
if($temporary_data['weight_in_kg'] == false){
|
||||
return $this->msg(10005,'体重单位错误');
|
||||
}
|
||||
// 检测设备传过来的info信息
|
||||
if(array_key_exists('info', $data)){
|
||||
if (!is_array($data['info'])) {
|
||||
return $this->msg(10005,'info参数格式错误');
|
||||
}else{
|
||||
$info_data_arr =['bodyage','fat_r','muscle','kcal','visceral','sfr','water','bone','fatlevlval','protein','bmi'];
|
||||
foreach ($data['info'] as $key => $value) {
|
||||
if (!in_array($key, $info_data_arr)) {
|
||||
return $this->msg(10005,'info参数格式错误-2');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$data['height'] = $temporary_data['height_in_cm'];
|
||||
$data['weight'] = $temporary_data['weight_in_kg'];
|
||||
$data['time'] = date('Y-m-d H:i:s');
|
||||
return $this->set_user_body_data($data,'by_device');
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常
|
||||
$logContent["flie"] = $e->getFile();
|
||||
$logContent["line"] = $e->getLine();
|
||||
$logContent['all_content'] = "异常信息:\n";
|
||||
$logContent['all_content'] .= "函数: device_record" . "\n";
|
||||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||
$this->record_api_log($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 修改目标体重
|
||||
public function set_target_weight(){
|
||||
|
|
@ -645,6 +727,191 @@ class Userbody extends Base{
|
|||
|
||||
################################################################action################################################################
|
||||
################################################################action################################################################
|
||||
|
||||
// 用户身体数据卡片记录
|
||||
public function set_user_body_data($data,$type){
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
|
||||
$db_data = [];
|
||||
$db_data['create_time'] = date('Y-m-d H:i:s');
|
||||
$db_data['aud_id'] = $data['aud_id'];
|
||||
$db_data['record_time'] = $data['time'];
|
||||
$db_data['height'] = $data['height'];
|
||||
$db_data['weight'] = $data['weight'];
|
||||
|
||||
$db_data['create_time'] = date('Y-m-d H:i:s');
|
||||
// 查询用户信息
|
||||
$user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('birthday,gender,target_weight,initial_weight,initial_date')->find();
|
||||
if(!$user_data){
|
||||
return $this->msg(10003);
|
||||
}
|
||||
// 如果最初体重设置为null
|
||||
if($user_data['initial_date'] == null){
|
||||
Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]);
|
||||
}
|
||||
$db_data['age'] = $this->calculate_age($user_data['birthday']);
|
||||
|
||||
// 设置发送数据:身高、体重、年龄、性别、头围、生日、阻抗
|
||||
$send_data['height'] = $data['height'];
|
||||
$send_data['weight'] = $data['weight'];
|
||||
$send_data['age'] = $db_data['age'];
|
||||
$send_data['gender'] = $user_data['gender'];
|
||||
$send_data['birthDay'] = $user_data['birthday'];
|
||||
|
||||
|
||||
// 1、手动记录还是设备记录
|
||||
if($type == 'by_hand_means'){
|
||||
$db_data['record_type'] = 'by_hand_means';
|
||||
// 判断头围数据是否存在是否合理
|
||||
if(array_key_exists('head_data', $data)){
|
||||
if(!$this->verify_data_is_ok($data['head_data'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$db_data['head_circumference'] = $data['head_data'];
|
||||
}
|
||||
|
||||
$send_data['adc'] = 550;
|
||||
$send_data['head'] = $data['head_data'];
|
||||
|
||||
// 发送请求获取照良那边的身体数据
|
||||
$get_body_value = $this->send_body_data($send_data,'4_electrode');
|
||||
if($get_body_value === false){
|
||||
return $this->msg(10002);
|
||||
}
|
||||
// 开始设置数据
|
||||
$db_data['bmi'] = $get_body_value['bmi'];
|
||||
$db_data['score'] = $get_body_value['cmi'];
|
||||
$db_data['fat_r'] = $get_body_value['bfr'];
|
||||
$db_data['fat_w'] = $get_body_value['bfrval'];
|
||||
$db_data['muscle'] = $get_body_value['rom'];
|
||||
$db_data['muscleval'] = $get_body_value['romval'];
|
||||
$db_data['water'] = $get_body_value['vwc'];
|
||||
$db_data['protein'] = $get_body_value['pp'];
|
||||
$db_data['proteinval'] = $get_body_value['ppval'];
|
||||
$db_data['bone'] = $get_body_value['bm'];
|
||||
$db_data['kcal'] = $get_body_value['bmr'];
|
||||
$db_data['visceral'] = $get_body_value['uvi'];
|
||||
$db_data['sfr'] = $get_body_value['sfr'];
|
||||
$db_data['body_level'] = $get_body_value['fatlevelname'];//肥胖等级
|
||||
$db_data['body_type'] = $get_body_value['body'];//身体类型
|
||||
$db_data['body_age'] = $get_body_value['bodyage'];
|
||||
// 如果年纪小于三岁,处理头围数据star
|
||||
$standardlist = [];
|
||||
if($send_data['age'] < 3){
|
||||
if(array_key_exists('standardlist',$get_body_value)){
|
||||
$standardlist = $get_body_value['standardlist'];
|
||||
foreach ($standardlist as $key => $value) {
|
||||
if($value['name'] == 'head' && count($value['list'] ) > 0){
|
||||
$standardlist = $value;
|
||||
}
|
||||
}
|
||||
$standardlist['list2'] = [];
|
||||
foreach ($standardlist['list'] as $key => $value) {
|
||||
array_push($standardlist['list2'],[
|
||||
'min_val'=>$value['minvalue'],
|
||||
'max_val'=>$value['maxvalue'],
|
||||
'text'=>$value['text'],
|
||||
'color'=>$value['color']
|
||||
]);
|
||||
}
|
||||
unset($standardlist['list']);
|
||||
unset($get_body_value['standardlist']);
|
||||
}
|
||||
}else{
|
||||
if(array_key_exists('standardlist',$get_body_value)){
|
||||
unset($get_body_value['standardlist']);
|
||||
}
|
||||
}
|
||||
// 如果年纪小于三岁,处理头围数据end
|
||||
$db_data['head_circumference'] = json_encode($standardlist);
|
||||
}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');
|
||||
}else{
|
||||
// 发送请求获取照良那边的身体数据
|
||||
$get_body_value = $this->send_body_data($send_data,'4_electrode');
|
||||
}
|
||||
if($get_body_value === false){
|
||||
return $this->msg(10002);
|
||||
}
|
||||
// 开始设置数据
|
||||
$db_data['bmi'] = $get_body_value['bmi'];
|
||||
$db_data['score'] = $get_body_value['cmi'];
|
||||
$db_data['fat_r'] = $get_body_value['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['fatlevelname'];//肥胖等级
|
||||
$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['bodyage']);
|
||||
|
||||
// 处理心率start
|
||||
if(array_key_exists('heart_rate', $data)){
|
||||
if(!$this->verify_data_is_ok($data['heart_rate'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$db_data['heart_rate'] = $data['heart_rate'];
|
||||
}
|
||||
// 处理心率end
|
||||
}
|
||||
|
||||
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try{
|
||||
Db::table($this->body_db_name['body_data_new'])->insert($db_data);
|
||||
$update_arr = [
|
||||
'height'=>$get_body_value['身高'],
|
||||
'weight'=>$get_body_value['体重']
|
||||
];
|
||||
if($data['head_circumference']>0){
|
||||
$update_arr['head_data'] = $data['head_circumference'];
|
||||
}
|
||||
Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update($update_arr);
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return $this->msg([]);
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $this->msg(10002);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function body_report_brief_action($data){
|
||||
$result_return = [
|
||||
'top_list'=>[
|
||||
|
|
@ -716,6 +983,7 @@ class Userbody extends Base{
|
|||
acbd.bmi,
|
||||
acbd.body_age,
|
||||
acbd.head_circumference,
|
||||
acbd.heart_rate,
|
||||
aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date
|
||||
from ".$this->body_db_name['body_data']." as acbd
|
||||
left join ".$this->body_db_name['juese']." as aud on acbd.aud_id=aud.id
|
||||
|
|
@ -738,7 +1006,6 @@ class Userbody extends Base{
|
|||
$result_return['top_list'][0]['standard_color'] = $temporary_weight[2] == '无'?'':$temporary_weight[2];
|
||||
$result_return['top_list'][0]['target_weight'] = $body_last_data[0]['target_weight'];
|
||||
$result_return['top_list'][0]['key_name'] = 'weight';
|
||||
|
||||
// 处理身高
|
||||
$temporary_height = explode(',',$body_last_data[0]['height']);
|
||||
$result_return['top_list'][1]['time'] = $record_time;
|
||||
|
|
@ -746,7 +1013,6 @@ class Userbody extends Base{
|
|||
$result_return['top_list'][1]['standard'] = $temporary_height[1] == '无'?'':$temporary_height[1];
|
||||
$result_return['top_list'][1]['standard_color'] = $temporary_height[2] == '无'?'':$temporary_height[2];
|
||||
$result_return['top_list'][1]['key_name'] = 'height';
|
||||
|
||||
// 处理BMI
|
||||
$temporary_bmi = explode(',',$body_last_data[0]['bmi']);
|
||||
$result_return['top_list'][2]['time'] = $record_time;
|
||||
|
|
@ -756,8 +1022,23 @@ class Userbody extends Base{
|
|||
$result_return['top_list'][2]['key_name'] = 'bmi';
|
||||
|
||||
// 如果有心率
|
||||
|
||||
if($body_last_data[0]['heart_rate']){
|
||||
$temporary_heart_rate = explode(',',$body_last_data[0]['heart_rate']);
|
||||
$result_return['top_list'][2]['time'] = $record_time;
|
||||
$result_return['top_list'][2]['value'] = $temporary_heart_rate[0];
|
||||
$result_return['top_list'][2]['standard'] = $temporary_heart_rate[1] == '无'?'':$temporary_heart_rate[1];
|
||||
$result_return['top_list'][2]['standard_color'] = $temporary_heart_rate[2] == '无'?'':$temporary_heart_rate[2];
|
||||
$result_return['top_list'][2]['key_name'] = 'heart_rate';
|
||||
}
|
||||
// 如果有头围
|
||||
if($body_last_data[0]['head_circumference']){
|
||||
$temporary_head_circumference = explode(',',$body_last_data[0]['head_circumference']);
|
||||
$result_return['top_list'][2]['time'] = $record_time;
|
||||
$result_return['top_list'][2]['value'] = $temporary_head_circumference[0];
|
||||
$result_return['top_list'][2]['standard'] = $temporary_head_circumference[1] == '无'?'':$temporary_head_circumference[1];
|
||||
$result_return['top_list'][2]['standard_color'] = $temporary_head_circumference[2] == '无'?'':$temporary_head_circumference[2];
|
||||
$result_return['top_list'][2]['key_name'] = 'head_circumference';
|
||||
}
|
||||
|
||||
// 处理卡片数据
|
||||
if($body_last_data[0]['record_type'] == 'by_hand_means'){
|
||||
|
|
@ -852,6 +1133,7 @@ class Userbody extends Base{
|
|||
acbd.bmi,
|
||||
acbd.body_age,
|
||||
acbd.head_circumference,
|
||||
acbd.heart_rate,
|
||||
aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date
|
||||
from ".$this->body_db_name['body_data']." as acbd
|
||||
left join ".$this->body_db_name['juese']." as aud on acbd.aud_id=aud.id
|
||||
|
|
@ -959,214 +1241,8 @@ class Userbody extends Base{
|
|||
return $this->msg($result_return);
|
||||
|
||||
}
|
||||
// 用户身体数据卡片记录
|
||||
public function set_user_body_data($data,$type){
|
||||
// 加 bcadd(,,20)
|
||||
// 减 bcsub(,,20)
|
||||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
|
||||
// 判断头围数据是否存在是否合理
|
||||
if(array_key_exists('head_data', $data)){
|
||||
if(!$this->verify_data_is_ok($data['head_data'],'num')){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$data['head_circumference'] = $data['head_data'];
|
||||
}else{
|
||||
$data['head_circumference'] = 0;
|
||||
}
|
||||
// 查询用户信息
|
||||
$user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->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']]);
|
||||
// $target_current = $this->base_target_initial_cumulative_weight([
|
||||
// 'weight'=>$data['weight'],
|
||||
// 'target_weight'=>$user_data['target_weight'],
|
||||
// 'initial_weight'=>$data['weight'],
|
||||
// 'initial_date'=>$data['time'],
|
||||
// ]);
|
||||
}else{
|
||||
// $target_current = $this->base_target_initial_cumulative_weight([
|
||||
// 'weight'=>$data['weight'],
|
||||
// 'target_weight'=>$user_data['target_weight'],
|
||||
// 'initial_weight'=>$user_data['initial_weight'],
|
||||
// 'initial_date'=>$user_data['initial_date'],
|
||||
// ]);
|
||||
}
|
||||
|
||||
// 设置身高、体重、年龄、性别、阶段称谓、头围、生日、阻抗
|
||||
$result_data['height'] = $data['height'];
|
||||
$result_data['weight'] = $data['weight'];
|
||||
$result_data['age'] = $this->calculate_age($user_data['birthday']);
|
||||
$result_data['gender'] = $user_data['gender'];
|
||||
$result_data['head_circumference'] = $data['head_circumference'];
|
||||
$result_data['birthday'] = $user_data['birthday'];
|
||||
|
||||
// 如果原始数据存在阻抗
|
||||
if(array_key_exists('adc', $data)){
|
||||
if($data['adc'] > 0){
|
||||
// 如果阻抗大于0,那就使用传过来的阻抗
|
||||
$result_data['adc'] = $data['adc'];
|
||||
$type = "by_device_adc";
|
||||
}else{
|
||||
$result_data['adc'] = 550;
|
||||
$type = "by_device";
|
||||
}
|
||||
}
|
||||
$calculate_body_formula = new Calculatebody();
|
||||
|
||||
// 计算身体数据
|
||||
$get_body_value = $calculate_body_formula->calculate_body_data_result($result_data);
|
||||
|
||||
if($get_body_value === false){
|
||||
return $this->msg(10002);
|
||||
}
|
||||
|
||||
// 如果年纪小于三岁,处理头围数据star
|
||||
$standardlist = [];
|
||||
if($result_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']);
|
||||
}
|
||||
}else{
|
||||
if(array_key_exists('standardlist',$get_body_value)){
|
||||
unset($get_body_value['standardlist']);
|
||||
}
|
||||
}
|
||||
// 如果年纪小于三岁,处理头围数据end
|
||||
$get_body_value['gender'] = $user_data['gender'];
|
||||
$get_body_value['birthday'] = $user_data['birthday'];
|
||||
// 添加身高、体重、bmi、头围(如果有)的标尺标准
|
||||
$get_body_value = $this->hwb_standard($get_body_value);
|
||||
|
||||
|
||||
$enumeration_data = [
|
||||
'fat_r'=>'脂肪率',
|
||||
'muscle'=>'肌肉率',
|
||||
'kcal'=>'基础代谢',
|
||||
'visceral'=>'内脏指数',
|
||||
'sfr'=>'皮下脂肪',
|
||||
'water'=>'水分',
|
||||
'bone'=>'骨重',
|
||||
'protein'=>'蛋白率',
|
||||
'bodyage'=>'身体年龄'
|
||||
];
|
||||
|
||||
|
||||
// 根据秤传过来的数据,去处理要存的结果
|
||||
if(array_key_exists('info', $data)){
|
||||
|
||||
|
||||
foreach ($data['info'] as $key => $value) {
|
||||
if($key == 'bmi'){
|
||||
if($value > 0){
|
||||
$get_body_value['BMI'] = $value;
|
||||
$get_body_value['BMI2'] = explode(',',$get_body_value['BMI2']);
|
||||
$get_body_value['BMI2'][0] = $value;
|
||||
$get_body_value['BMI2'] = implode(',',$get_body_value['BMI2']);
|
||||
}
|
||||
}else if($key == 'bodyage'){
|
||||
$get_body_value[$enumeration_data[$key]] = $value;
|
||||
}else if($key == 'fatlevlval'){
|
||||
continue;
|
||||
}else{
|
||||
if($value > 0){
|
||||
$get_body_value[$enumeration_data[$key]][0] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$set_data = [
|
||||
'acd_id'=>2,
|
||||
'aud_id'=>$data['aud_id'],
|
||||
'record_time'=>array_key_exists('time', $data)?$data['time']:date('Y-m-d H:i:s'),
|
||||
'create_time'=>date('Y-m-d H:i:s'),
|
||||
'last_update_time'=>date('Y-m-d H:i:s'),
|
||||
'age'=>$get_body_value['age'],
|
||||
'height'=>$get_body_value['身高2'],
|
||||
'height_val'=>$get_body_value['身高'],
|
||||
'weight'=>$get_body_value['体重2'],
|
||||
'weight_val'=>$get_body_value['体重'],
|
||||
'bmi'=>$get_body_value['BMI2'],
|
||||
'bmi_val'=>$get_body_value['BMI'],
|
||||
'score'=>$get_body_value['身体得分'],
|
||||
'fat_r'=> implode(',',$get_body_value['脂肪率']),
|
||||
'fat_w'=>implode(',',$get_body_value['脂肪量']),
|
||||
'muscle'=>implode(',',$get_body_value['肌肉率']),
|
||||
'muscleval'=>implode(',',$get_body_value['肌肉量']),
|
||||
'water'=>implode(',',$get_body_value['水分']),
|
||||
'proteinval'=>implode(',',$get_body_value['蛋白量']),
|
||||
'bone'=>implode(',',$get_body_value['骨重']),
|
||||
'protein'=>implode(',',$get_body_value['蛋白率']),
|
||||
'kcal'=>implode(',',$get_body_value['基础代谢']),
|
||||
'visceral'=>implode(',',$get_body_value['内脏指数']),
|
||||
'sfr'=>implode(',',$get_body_value['皮下脂肪']),
|
||||
'body_level'=>$get_body_value['肥胖等级'],
|
||||
'body_type'=>$get_body_value['身体类型'],
|
||||
'body_age'=>$get_body_value['身体年龄'],
|
||||
'record_type' => $type,
|
||||
'head_circumference' => $result_data['age'] < 3?json_encode($standardlist):"",
|
||||
];
|
||||
if(strlen($set_data['record_time']) <= 12){
|
||||
// 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
|
||||
$set_data['record_time'] = $this->addCurrentTimeToDateString($set_data['record_time']);
|
||||
}
|
||||
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try{
|
||||
$set_user_data = Db::table($this->body_db_name['body_data'])->insert($set_data);
|
||||
$update_arr = [
|
||||
'height'=>$get_body_value['身高'],
|
||||
'weight'=>$get_body_value['体重']
|
||||
];
|
||||
if($data['head_circumference']>0){
|
||||
$update_arr['head_data'] = $data['head_circumference'];
|
||||
}
|
||||
$update_user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update($update_arr);
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return $this->msg([]);
|
||||
// return $this->msg([
|
||||
// 'acd_id'=>2,
|
||||
// 'height'=>$get_body_value['身高'].',CM',
|
||||
// 'weight'=>$get_body_value['体重'].',公斤',
|
||||
// 'bmi'=>$get_body_value['BMI'],
|
||||
// 'target_current'=>$target_current,
|
||||
// ]);
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
// 用户身体数据卡片记录
|
||||
// 设置理想体重
|
||||
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){
|
||||
|
|
@ -1547,6 +1623,43 @@ class Userbody extends Base{
|
|||
return $data;
|
||||
}
|
||||
|
||||
// 发送信息获取身体数据
|
||||
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']);
|
||||
// dump($data);
|
||||
// die;
|
||||
$request_result = $this->postRequest($url,$data);
|
||||
}
|
||||
|
||||
// dump($request_result);
|
||||
if($request_result['code'] != 0){
|
||||
return false;
|
||||
}else{
|
||||
return $request_result['data'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue