771 lines
38 KiB
PHP
771 lines
38 KiB
PHP
<?php
|
||
|
||
namespace app\testapp\controller;
|
||
|
||
use think\Db;
|
||
use app\testapp\controller\Calculatebody;
|
||
use app\testapp\controller\Cardparts;
|
||
|
||
class Card extends Base{
|
||
|
||
protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6'];
|
||
protected $card_use_db_name = [
|
||
'1'=>'test_app_card_body_data',
|
||
'2'=>'test_app_user_data',
|
||
'3'=>'test_pc_bmistand',
|
||
'4'=>'test_pc_heightstand',
|
||
'5'=>'test_pc_weightstand',
|
||
'6'=>'test_pc_childrenprescription',
|
||
'7'=>'test_pc_childprescriptionbyage',
|
||
'8'=>'test_pc_heightstand',
|
||
'9'=>'test_pc_weightstand',
|
||
'10'=>'test_pc_bmistand',
|
||
];
|
||
protected $age_limit = 16;
|
||
protected $unit_symbol = ['score'=>'分','height'=>'CM','weight'=>'公斤','bmi'=>'','fat_r'=>'%','fat_w'=>'kg','muscle'=>'%','muscleval'=>'kg','water'=>'kg','bone'=>'kg','protein'=>'%','proteinval'=>'kg','kcal'=>'kcal','visceral'=>'','sfr'=>'%',];
|
||
protected $unit_name = ['score'=>'身体得分','height'=>'身高','weight'=>'体重','bmi'=>'BMI','fat_r'=>'脂肪率','fat_w'=>'脂肪量','muscle'=>'肌肉率','muscleval'=>'肌肉量','water'=>'水分','bone'=>'骨重','protein'=>'蛋白率','proteinval'=>'蛋白量','kcal'=>'基础代谢','visceral'=>'内脏指数','sfr'=>'皮下脂肪','body_level'=>'肥胖等级','body_type'=>'身体类型'];
|
||
protected $bhw_list = [
|
||
'bmi'=>[
|
||
['min_val'=>'0','max_val'=>'','text'=>'消瘦','color'=>'#FDDA6B'],
|
||
['min_val'=>'','max_val'=>'','text'=>'正常','color'=>'#59D06A'],
|
||
['min_val'=>'','max_val'=>'','text'=>'偏重','color'=>'#FDAA02'],
|
||
['min_val'=>'','max_val'=>'50','text'=>'肥胖','color'=>'#FB5755'],
|
||
],
|
||
'height'=>[
|
||
['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'],
|
||
],
|
||
'weight'=>[
|
||
['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'],
|
||
]
|
||
];
|
||
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','优'=>'#5ad06d'],
|
||
'visceral'=>['标准'=>'#55CF6C','警惕'=>'#FEAC00','危险'=>'#FB5A52'],
|
||
'sfr'=>['不足'=>'#FCDB68','标准'=>'#59D16F','偏高'=>'#FEAB03'],
|
||
];
|
||
protected $result_end_data_mould = [
|
||
'name'=>'',
|
||
'value'=>'',
|
||
'unit'=>'',
|
||
'standard'=>'',
|
||
'color'=>'',
|
||
'list'=>[]
|
||
];
|
||
// 曲线参数
|
||
protected $card_body_curve_arr = ['height','weight','bmi','fat_r'];
|
||
protected $card_body_curve_arr2 = ['身高','体重','BMI','脂肪率',];
|
||
protected $card_body_curve_arr3 = ['#f7b03e','#fb7b92','#ff9f40','#3fcba7',];
|
||
|
||
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]],
|
||
];
|
||
################################################################接口################################################################
|
||
################################################################接口################################################################
|
||
################################################################接口################################################################
|
||
|
||
|
||
// 详细卡片信息
|
||
// $data = ['id'=>'2']
|
||
public function card_data_detailed($data=['aud_id'=>'11','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->get_user_body_data($data);
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
|
||
// 曲线页面-曲线接口
|
||
public function card_curve_chart($data = ['aud_id'=>'11','s_time'=>'2024-04-01','e_time'=>'2024-10-25','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->curve_chart_action($data);
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
|
||
// 手动记录
|
||
// $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1']
|
||
public function card_manual_recording($data = ['aud_id'=>'11','time'=>'2024-10-12','height'=>'155.7','weight'=>'46.7','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}else{
|
||
$data['time'] = date('Y-m-d H:i:s');
|
||
}
|
||
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']);
|
||
$data['acd_id'] = '2';
|
||
$return_data = $this->set_user_body_data($data);
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
// 设备记录
|
||
// $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1']
|
||
public function card_manual_recording_device($data = ['aud_id'=>'58','height'=>'175','weight'=>'68','adc'=>'550','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}else{
|
||
$data['time'] = date('Y-m-d H:i:s');
|
||
}
|
||
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($data['adc'] == 0){
|
||
$data['adc'] = 550;
|
||
}
|
||
$data['time'] = date('Y-m-d H:i:s');
|
||
$data['acd_id'] = '2';
|
||
$return_data = $this->set_user_body_data($data);
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
|
||
// 修改初始体重/目标体重
|
||
public function card_modify_weight($data = ['aud_id'=>'25','weight'=>'25','type'=>1,'time'=>'','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!is_array($data)){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('weight', $data) || !array_key_exists('type', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->modify_weight_action($data);
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_data;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999,'接口错误');
|
||
}
|
||
|
||
}
|
||
|
||
################################################################业务接口################################################################
|
||
################################################################业务接口################################################################
|
||
|
||
################################################card_data_detailed
|
||
// 用户身体数据卡片获取
|
||
public function get_user_body_data($data){
|
||
$result = Db::query("
|
||
select
|
||
Top 1
|
||
acbd.id,
|
||
acbd.acd_id,
|
||
acbd.create_time,
|
||
acbd.last_update_time,
|
||
acbd.score,
|
||
acbd.fat_r,
|
||
acbd.fat_w,
|
||
acbd.muscle,
|
||
acbd.muscleval,
|
||
acbd.water,
|
||
acbd.proteinval,
|
||
acbd.bone,
|
||
acbd.protein,
|
||
acbd.kcal,
|
||
acbd.visceral,
|
||
acbd.sfr,
|
||
acbd.body_level,
|
||
acbd.aud_id,
|
||
acbd.record_time,
|
||
acbd.body_type,
|
||
acbd.age,
|
||
acbd.is_del,
|
||
acbd.height,
|
||
acbd.weight,
|
||
acbd.bmi,
|
||
acbd.body_age,
|
||
aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date
|
||
from ".$this->card_use_db_name['1']." as acbd
|
||
left join ".$this->card_use_db_name['2']." as aud on acbd.aud_id=aud.id
|
||
where acbd.aud_id='".$data['aud_id']."'
|
||
order by acbd.record_time desc
|
||
");
|
||
if(!$result){
|
||
return $this->msg(10004);
|
||
}else{
|
||
// $curve_bottom = $this->card_curve_target_action($result);
|
||
$result_end = $this->processing_return_data_new($result[0]);
|
||
$cardparts = new Cardparts;
|
||
$result_end['gender'] = $result[0]['gender'];
|
||
$result_end['record_time'] = $result[0]['record_time'];
|
||
$result_end['score'] = $result_end['score'];
|
||
$result_end['body_type'] = $result_end['body_type'];
|
||
$result_end = $cardparts->conversion_interval($result_end);
|
||
$result_end['cplist'] = $this->grow_up_recommendation([
|
||
'birthday'=>$result[0]['birthday'],
|
||
'body'=>[
|
||
'height'=>$result[0]['height'],
|
||
'weight'=>$result[0]['weight'],
|
||
'bmi'=>$result[0]['bmi']
|
||
],
|
||
]);
|
||
if(count($result_end['cplist']['nutritionlist']) <= 0){
|
||
// $result_end['cplist'] = [];
|
||
$result_end['literature'] = [];
|
||
}else{
|
||
$result_end['literature'] = [
|
||
'《中华人民共和国卫生行业标准WS 423-2013》',
|
||
'《中华人民共和国卫生行业标准WS/T 612-2018》',
|
||
'《中华人民共和国卫生行业标准WS/T1586-2018》',
|
||
'《WHO 5~19岁身高/体重判定标准》',
|
||
];
|
||
}
|
||
return $this->msg($result_end);
|
||
}
|
||
}
|
||
// 返回数据处理
|
||
public function processing_return_data_new($data){
|
||
$result_end_data = [];
|
||
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
|
||
$gender_val = $data['gender'];
|
||
foreach ($data as $key => $value) {
|
||
if($key != 'aud_id' && $key != 'id' && $key != 'create_time' && $key != 'last_update_time' && $key != 'acd_id' && $key != 'ROW_NUMBER' && $key != 'record_time' && $key != 'gender' && $key != 'birthday'){
|
||
// 设置单个数据格式
|
||
$result_end_data[$key] = $this->result_end_data_mould;
|
||
if(array_key_exists($key, $this->unit_name)){
|
||
$result_end_data[$key]['name'] = $this->unit_name[$key];
|
||
}
|
||
if(array_key_exists($key, $this->unit_symbol)){
|
||
$result_end_data[$key]['unit'] = $this->unit_symbol[$key];
|
||
}
|
||
$result_end_data[$key]['value'] = explode(',',$value)[0];
|
||
if(strpos($value, ',')){
|
||
$result_end_data[$key]['standard'] = explode(',',$value)[1];
|
||
}
|
||
if(array_key_exists($key, $this->standard_color)){
|
||
if($result_end_data[$key]['standard'] != '异常'){
|
||
$result_end_data[$key]['color'] = $this->standard_color[$key][$result_end_data[$key]['standard']];
|
||
}
|
||
}
|
||
// 如果小于16岁(儿童)
|
||
if($data['age'] < $this->age_limit){
|
||
if(array_key_exists($key, $this->bhw_list)){
|
||
$result_end_data[$key]['list'] = $this->bhw_list[$key];
|
||
if($key == 'bmi'){
|
||
$bhw_date = Db::table($this->card_use_db_name['3'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||
if($bhw_date){
|
||
$result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f1sd'];
|
||
$result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f1sd'];
|
||
$result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['z1sd'];
|
||
$result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['z1sd'];
|
||
$result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z2sd'];
|
||
$result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z2sd'];
|
||
}
|
||
}else if($key == 'height'){
|
||
$bhw_date = Db::table($this->card_use_db_name['4'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||
if($bhw_date){
|
||
$result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd'];
|
||
$result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd'];
|
||
$result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['f1sd'];
|
||
$result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['f1sd'];
|
||
$result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z1sd'];
|
||
$result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z1sd'];
|
||
$result_end_data[$key]['list'][3]['max_val'] = $bhw_date[0]['z2sd'];
|
||
$result_end_data[$key]['list'][4]['min_val'] = $bhw_date[0]['z2sd'];
|
||
$result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd'];
|
||
}
|
||
}else if($key == 'weight'){
|
||
$bhw_date = Db::table($this->card_use_db_name['5'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||
if($bhw_date){
|
||
$result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd'];
|
||
$result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd'];
|
||
$result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['f1sd'];
|
||
$result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['f1sd'];
|
||
$result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z1sd'];
|
||
$result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z1sd'];
|
||
$result_end_data[$key]['list'][3]['max_val'] = $bhw_date[0]['z2sd'];
|
||
$result_end_data[$key]['list'][4]['min_val'] = $bhw_date[0]['z2sd'];
|
||
$result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return $result_end_data;
|
||
}
|
||
|
||
public function grow_up_recommendation($data){
|
||
// card_body_level
|
||
// die;
|
||
// $result = [
|
||
// ['name'=>'营养','key'=>'nutrition','content'=>''],
|
||
// ['name'=>'睡眠','key'=>'sleep','content'=>''],
|
||
// ['name'=>'运动','key'=>'motion','content'=>''],
|
||
// ['name'=>'情绪','key'=>'emotion','content'=>'']
|
||
// ];
|
||
$result = [
|
||
'nutritionlist'=>[],//营养
|
||
'sportlist'=>[],//运动
|
||
'sleeplist'=>[],//睡眠
|
||
'moodlist'=>[],//情绪
|
||
];
|
||
|
||
$temporary_arr = [];
|
||
foreach ($data['body'] as $key => $value) {
|
||
if(explode(',',$value)[1] == '无'){
|
||
$result = [
|
||
'nutritionlist'=>[],//营养
|
||
'sportlist'=>[],//运动
|
||
'sleeplist'=>[],//睡眠
|
||
'moodlist'=>[],//情绪
|
||
];
|
||
return $result;
|
||
}
|
||
$temporary_arr[$key] = $this->card_body_level[$key]['list'][explode(',',$value)[1]];
|
||
}
|
||
$min_value = min($temporary_arr);
|
||
$min_key = array_search($min_value,$temporary_arr);
|
||
$type_num = $this->card_body_level[$min_key]['value'];
|
||
$temporary_arr2 = Db::table($this->card_use_db_name['6'])->where(['Type'=>$type_num,'Level'=>$min_value,'IsDeleted'=>0])->field('Nutrition,Sport')->find();
|
||
array_push($result['nutritionlist'],$temporary_arr2['Nutrition']);
|
||
array_push($result['sportlist'],$temporary_arr2['Sport']);
|
||
// $result['nutritionlist'] = $temporary_arr2['Nutrition'];
|
||
// $result['sportlist'] = $temporary_arr2['Sport'];
|
||
|
||
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
|
||
$temporary_arr2 = Db::table($this->card_use_db_name['7'])->where(['IsDeleted'=>0])->field('MinAge,MaxAge,Type,Content')->select();
|
||
$default_sleep = '';
|
||
$default_emotion = '';
|
||
foreach ($temporary_arr2 as $key => $value) {
|
||
if($value['MinAge'] == -1 && $value['Type'] == 2){
|
||
$default_sleep = $value['Content'];
|
||
}
|
||
if($value['MinAge'] == -1 && $value['Type'] == 3){
|
||
$default_emotion = $value['Content'];
|
||
}
|
||
if($month_num>=$value['MinAge'] && $month_num<=$value['MaxAge']){
|
||
if($value['Type'] == 1){
|
||
array_push($result['sportlist'],$value['Content']);
|
||
// $result['sportlist'] = $result['sportlist'].$value['Content'];
|
||
}else if($value['Type'] == 2){
|
||
array_push($result['sleeplist'],$value['Content']);
|
||
// $result['sleeplist'] = $result['sleeplist'].$value['Content'];
|
||
}else if($value['Type'] == 3){
|
||
array_push($result['moodlist'],$value['Content']);
|
||
// $result['moodlist'] = $result['moodlist'].$value['Content'];
|
||
}
|
||
}
|
||
}
|
||
|
||
$result['sleeplist'] = count($result['sleeplist']) <= 0?array_push($result['sportlist'],$default_sleep):$result['sleeplist'];
|
||
$result['moodlist'] = count($result['moodlist']) <= 0?array_push($result['moodlist'],$default_sleep):$result['moodlist'];
|
||
|
||
return $result;
|
||
}
|
||
|
||
########################################################card_curve_chart
|
||
|
||
// 曲线图动作函数
|
||
public function curve_chart_action($data){
|
||
$card_body_curve_arr = implode(',',$this->card_body_curve_arr);
|
||
|
||
$data['s_time'] = $data['s_time'].' 00:00:00';
|
||
$data['e_time'] = $data['e_time'].' 23:59:59';
|
||
|
||
$user_data_list = Db::table($this->card_use_db_name['1'])
|
||
->where('aud_id', $data['aud_id'])
|
||
->whereTime('record_time', 'between', [$data['s_time'], $data['e_time']])
|
||
->field("record_time,REPLACE(CONVERT(varchar(10), record_time, 23), '-', '-') AS b_time,$card_body_curve_arr")
|
||
// ->field("record_time,REPLACE(CONVERT(varchar(10), record_time, 23), '-', '/') AS b_time,$card_body_curve_arr")
|
||
->order('record_time desc')
|
||
->select();
|
||
|
||
// 下面业务逻辑是取每天的,最近后一次记录成绩
|
||
$data_arr = [];
|
||
$record_arr1 = [];
|
||
$record_arr2 = [];
|
||
// 如果有数据
|
||
if(count($user_data_list)>0){
|
||
// 循环数据
|
||
foreach ($user_data_list as $key => $value) {
|
||
// 如果数据中的时间不存在临时数组中
|
||
if(!in_array($value['b_time'],$record_arr1)){
|
||
array_push($record_arr1,$value['b_time']);
|
||
foreach ($this->card_body_curve_arr as $k => $v) {
|
||
$user_data_list[$key][$v] = explode(',',$user_data_list[$key][$v])[0];
|
||
}
|
||
array_push($record_arr2,$user_data_list[$key]);
|
||
}
|
||
}
|
||
foreach ($this->card_body_curve_arr as $key => $value) {
|
||
$temporary_arr = [];
|
||
$temporary_arr['title'] = $this->card_body_curve_arr2[$key];
|
||
$temporary_arr['key'] = $value;
|
||
$temporary_arr['line']['categories'] = [];
|
||
$temporary_arr['line']['series'][0]['color'] = $this->card_body_curve_arr3[$key];
|
||
$temporary_arr['line']['series'][0]['data'] = [];
|
||
foreach ($record_arr2 as $k => $v) {
|
||
array_push($temporary_arr['line']['categories'],$record_arr2[$k]['b_time']);
|
||
array_push($temporary_arr['line']['series'][0]['data'],$record_arr2[$k][$value]);
|
||
}
|
||
array_push($data_arr,$temporary_arr);
|
||
}
|
||
}
|
||
return $this->msg($data_arr);
|
||
}
|
||
|
||
################################################card_manual_recording
|
||
// 用户身体数据卡片记录
|
||
public function set_user_body_data($data){
|
||
|
||
$data['type'] = 1;
|
||
$user_data = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->field('birthday,gender,target_weight,initial_weight,initial_date')->find();
|
||
if(!$user_data){
|
||
return $this->msg(10003);
|
||
}
|
||
if($user_data['initial_date'] == null){
|
||
Db::table($this->card_use_db_name['2'])->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'];
|
||
if(array_key_exists('adc', $data)){
|
||
$result_data['adc'] = $data['adc'];
|
||
}
|
||
$calculate_body_formula = new Calculatebody();
|
||
|
||
// 计算身体数据
|
||
$get_body_value = $calculate_body_formula->calculate_body_data_result($result_data);
|
||
// dump($get_body_value);
|
||
// die;
|
||
$get_body_value['gender'] = $user_data['gender'];
|
||
$get_body_value['birthday'] = $user_data['birthday'];
|
||
// 添加身高体重bmi的标尺标准
|
||
$get_body_value = $this->hwb_standard($get_body_value);
|
||
// dump($get_body_value);
|
||
// die;
|
||
$set_data = [
|
||
'acd_id'=>$data['acd_id'],
|
||
'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['身体年龄']
|
||
];
|
||
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']);
|
||
}
|
||
|
||
$set_user_data = Db::table($this->card_use_db_name['1'])->insert($set_data);
|
||
if($set_user_data){
|
||
// 返回简要数据
|
||
if($data['type'] == 1){
|
||
return $this->msg([
|
||
'acd_id'=>2,
|
||
'height'=>$get_body_value['身高'].',CM',
|
||
'weight'=>$get_body_value['体重'].',公斤',
|
||
'bmi'=>$get_body_value['BMI'],
|
||
'target_current'=>$target_current,
|
||
]);
|
||
}
|
||
|
||
}else{
|
||
return $this->msg(10002);
|
||
}
|
||
}
|
||
|
||
// 添加身高体重bmi的标准
|
||
public function hwb_standard($data){
|
||
// dump($data);
|
||
// die;
|
||
$linshi_data = [];
|
||
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
|
||
// dump($month_num);
|
||
$gender_val = $data['gender'];
|
||
if($data['age'] < $this->age_limit){
|
||
foreach ($data as $key => $value) {
|
||
if($key =='身高'){
|
||
$linshi_data['身高'] = $this->bhw_list['height'];
|
||
$bhw_date = Db::table($this->card_use_db_name['8'])->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 =='体重'){
|
||
$linshi_data['体重'] = $this->bhw_list['weight'];
|
||
$bhw_date = Db::table($this->card_use_db_name['9'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||
// dump($data['体重']);
|
||
// dump($bhw_date);
|
||
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->bhw_list['bmi'];
|
||
$bhw_date = Db::table($this->card_use_db_name['10'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
|
||
// dump($bhw_date);
|
||
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'];
|
||
}
|
||
}
|
||
}
|
||
// dump($linshi_data);
|
||
// die;
|
||
foreach ($linshi_data as $key => $value) {
|
||
// dump($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'];
|
||
}
|
||
}
|
||
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'].',无,无';
|
||
}
|
||
// dump($data);
|
||
// die;
|
||
return $data;
|
||
// dump($data);
|
||
}
|
||
|
||
|
||
################################################card_modify_weight
|
||
public function modify_weight_action($data){
|
||
// $data['aud_id'] = 26;
|
||
// $data['weight'] = 60;
|
||
// dump($data);
|
||
// die;
|
||
|
||
$result = Db::query("
|
||
select
|
||
TOP 1
|
||
acbd.weight,
|
||
aud.target_weight,
|
||
aud.initial_weight,
|
||
aud.initial_date
|
||
from ".$this->card_use_db_name['1']." as acbd
|
||
left join ".$this->card_use_db_name['2']." as aud on acbd.aud_id = aud.id
|
||
where acbd.aud_id = ".$data['aud_id']."
|
||
order by acbd.record_time desc
|
||
");
|
||
if($data['type'] == 1){
|
||
// 修改目标体重
|
||
$bhw_date = ['target_weight'=>$data['weight']];
|
||
}else if($data['type'] == 2){
|
||
// 修改原始体重
|
||
$bhw_date = ['initial_weight'=>$data['weight'],'initial_date' => $data['time']];
|
||
}else{
|
||
return $this->msg(10005);
|
||
}
|
||
$result_update = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->update($bhw_date);
|
||
// dump($result_update);
|
||
// dump($result[0]['weight']);
|
||
// dump($result);
|
||
|
||
if($result_update){
|
||
$target_current = $this->base_target_initial_cumulative_weight([
|
||
'weight'=>$result[0]['weight'],
|
||
'target_weight'=>$data['type'] == 1?$data['weight']:$result[0]['target_weight'],
|
||
'initial_weight'=>$data['type'] == 1?$result[0]['initial_weight']:$data['weight'],
|
||
'initial_date'=>$data['type'] == 1?$result[0]['initial_date']:$data['time'],
|
||
]);
|
||
// die;
|
||
// dump($target_current);
|
||
return $this->msg($target_current);
|
||
}else{
|
||
return $this->msg(10002);
|
||
}
|
||
|
||
}
|
||
|
||
################################################card_record_detailed_information
|
||
|
||
|
||
################################################################其他接口################################################################
|
||
################################################################其他接口################################################################
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |