From 07aa97264f92083b5ddce5436f1d67b07033e942 Mon Sep 17 00:00:00 2001 From: tsf <460834639@qq.com> Date: Fri, 24 May 2024 18:45:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B00524=E6=B8=85=E7=90=86?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/app/controller/Calculatebody.php | 17 +- application/app/controller/Card.php | 262 ++++------------- application/app/controller/Cardparts.php | 271 +++++++++++++----- application/app/controller/Index.php | 6 +- application/app/controller/Pagingcontrast.php | 202 +++++++++++-- application/route.php | 9 +- 6 files changed, 467 insertions(+), 300 deletions(-) diff --git a/application/app/controller/Calculatebody.php b/application/app/controller/Calculatebody.php index b9cb4ba..d1d8eb0 100644 --- a/application/app/controller/Calculatebody.php +++ b/application/app/controller/Calculatebody.php @@ -144,7 +144,7 @@ class Calculatebody extends Controller{ // 肌肉率:不足 标准 优 - if($data['age']>=16){ + // if($data['age']>=16){ if($result['standard_level']<-0.2){ $return_data['肥胖等级'] = '体重不足'; }else if($result['standard_level']>=-0.2 && $result['standard_level']<-0.1){ @@ -158,12 +158,12 @@ class Calculatebody extends Controller{ }else{ $return_data['肥胖等级'] = '暂无数据'; } - }else{ - $return_data['肥胖等级'] = '儿童'; - } + // }else{ + // $return_data['肥胖等级'] = '儿童'; + // } - if($data['age']>=16){ + // if($data['age']>=16){ if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '不足'){ $return_data['身体类型'] = '隐形肥胖'; }else if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '标准'){ @@ -185,10 +185,11 @@ class Calculatebody extends Controller{ }else{ $return_data['身体类型'] = '暂无数据'; } - }else{ - $return_data['身体类型'] = '儿童'; - } + // }else{ + // $return_data['身体类型'] = '儿童'; + // } + $return_data['身体年龄'] = $result['bodyage']; // dump($return_data); // die; diff --git a/application/app/controller/Card.php b/application/app/controller/Card.php index ab5fb57..0e5a5d9 100644 --- a/application/app/controller/Card.php +++ b/application/app/controller/Card.php @@ -79,14 +79,11 @@ class Card extends Base{ // 详细卡片信息 // $data = ['id'=>'2'] - public function card_data_detailed($data=['aud_id'=>'25','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function card_data_detailed($data=['aud_id'=>'26','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ if(count(input('post.')) > 0){ $data = input('post.'); } - $bhw_date = Db::table('app_card_body_data')->where("height >= 170")->select(); - // cache($data['token']); - dump($bhw_date); - die; + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } @@ -101,7 +98,7 @@ class Card extends Base{ } // 曲线页面-曲线接口 - public function card_curve_chart($data = ['aud_id'=>'25','s_time'=>'2024-04-01 10:10:10','e_time'=>'2024-07-30 10:10:10','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function card_curve_chart($data = ['aud_id'=>'25','s_time'=>'2024-04-01','e_time'=>'2024-07-30','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ if(count(input('post.')) > 0){ $data = input('post.'); } @@ -112,7 +109,8 @@ class Card extends Base{ return $this->msg(20001); } unset($data['token']); - + $data['s_time'] = $data['s_time'].' 00:00:00'; + $data['e_time'] = $data['e_time'].' 23:59:59'; return $this->curve_chart_action($data); } @@ -155,40 +153,6 @@ class Card extends Base{ return $this->modify_weight_action($data); } - - // // 获取记录信息列表 - // public function get_card_record_data_group($data = ['aud_id'=>'25','s_time'=>'2024-04-01 10:10:10','e_time'=>'2024-06-12 10:10:10','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - // 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); - // } - // if($this->token_time_validate($data['token']) === false){ - // return $this->msg(20001); - // } - // unset($data['token']); - // $data['acd_id'] = '2'; - // return $this->get_all_record_data($data,'group'); - - // } - // // 获取记录信息列表 - // public function get_card_record_data_page($data = ['aud_id'=>'25','page'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - // if(count(input('post.')) > 0){ - // $data = input('post.'); - // } - - // if(!array_key_exists('aud_id', $data) || !array_key_exists('page', $data) || !array_key_exists('token', $data)){ - // return $this->msg(10001); - // } - // if($this->token_time_validate($data['token']) === false){ - // return $this->msg(20001); - // } - // unset($data['token']); - // $data['acd_id'] = '2'; - // return $this->get_all_record_data($data,'page'); - - // } // 删除历史数据 public function card_del_record_data($data = ['id'=>'16','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ if(count(input('post.')) > 0){ @@ -209,23 +173,24 @@ class Card extends Base{ } } - // 数据对比 - public function card_data_contrast($data = ['before_id'=>'24','after_id'=>'25','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // $data = explode(',',$data['id_arr']); - // dump($data); - // die; - return $this->body_data_contrast($data); - } + // // 数据对比 + // public function card_data_contrast($data = ['before_id'=>'24','after_id'=>'25','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + // if(count(input('post.')) > 0){ + // $data = input('post.'); + // } + // if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('token', $data)){ + // return $this->msg(10001); + // } + // if($this->token_time_validate($data['token']) === false){ + // return $this->msg(20001); + // } + // unset($data['token']); + // // $data = explode(',',$data['id_arr']); + // // dump($data); + // // die; + // return $this->body_data_contrast($data); + // } + ################################################################业务接口################################################################ ################################################################业务接口################################################################ @@ -243,7 +208,33 @@ class Card extends Base{ $result = Db::query(" select Top 1 - acbd.*,aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date + 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_data as height, + acbd.weight_data as weight, + acbd.bmi_data as bmi, + acbd.body_age, + aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date from app_card_body_data as acbd left join app_user_data as aud on acbd.aud_id=aud.id where acbd.aud_id='".$data['aud_id']."' @@ -257,11 +248,12 @@ class Card extends Base{ // $curve_bottom = $this->card_curve_target_action($result); $result_end = $this->processing_return_data_new($result[0]); $cardparts = new Cardparts; - // dump($result); + // dump($result_end); // die; $result_end['gender'] = $result[0]['gender']; $result_end = $cardparts->conversion_interval($result_end); - die; + // dump($result_end); + // die; return $this->msg($result_end); } } @@ -461,7 +453,8 @@ class Card extends Base{ 'visceral'=>implode(',',$get_body_value['内脏指数']), 'sfr'=>implode(',',$get_body_value['皮下脂肪']), 'body_level'=>$get_body_value['肥胖等级'], - 'body_type'=>$get_body_value['身体类型'] + 'body_type'=>$get_body_value['身体类型'], + 'body_age'=>$get_body_value['身体年龄'] ]); if($set_user_data){ // 返回简要数据 @@ -609,57 +602,7 @@ class Card extends Base{ } - ################################################get_card_record_data - // 获取历史数据记录信息列表 - // public function get_all_record_data($data,$type){ - // $return_result = []; - // if($type == 'group'){ - // $result = Db::query(" - // select - // id, - // CONVERT(varchar(10), record_time, 120) AS r_t, - // CONVERT(varchar(19), record_time, 120) AS record_time, - // height as v1, - // weight as v2, - // bmi as v3 - // from app_card_body_data - // where aud_id='".$data['aud_id']."' - // and record_time between '".$data['s_time']."' and '".$data['e_time']."' - // and is_del = 0 - // order by record_time desc"); - // foreach ($result as $key => $value) { - // if(array_key_exists($value['r_t'], $return_result)){ - // array_push($return_result[$value['r_t']], ['id'=>$value['id'],'v1'=>$value['v1'],'v2'=>$value['v2'],'v3'=>$value['v3'],'v1_name'=>'身高','v2_name'=>'体重','v3_name'=>'BMI']); - // }else{ - // $return_result[$value['r_t']] = [['id'=>$value['id'],'v1'=>$value['v1'],'v2'=>$value['v2'],'v3'=>$value['v3'],'v1_name'=>'身高','v2_name'=>'体重','v3_name'=>'BMI']]; - // } - // } - // }else{ - // $result = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->field('id,record_time,height,weight,bmi')->order('record_time desc')->page($data['page'],$this->pagesize)->select(); - // $return_result['totalrows'] = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->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_name'=>'身高', - // 'v1'=>$value['height'], - // 'v2_name'=>'体重', - // 'v2'=>$value['weight'], - // 'v3_name'=>'BMI', - // 'v3'=>$value['bmi'], - // ]); - // } - - - - // } - // return $this->msg($return_result); - // } + ################################################card_record_detailed_information ################################################################其他接口################################################################ @@ -671,98 +614,7 @@ class Card extends Base{ - // 身体数据对比 - public function body_data_contrast($data){ - // dump($data); - $data2 = [$data['before_id'],$data['after_id']]; - $data3 = implode(',',$data2); - // dump($data2); - // die; - $calculate_arr = []; - $result = Db::query(" - select - acbd.id, - acbd.height_data as height, - acbd.weight_data as weight, - acbd.bmi_data as bmi, - acbd.fat_r, - acbd.fat_w, - acbd.muscle, - acbd.muscleval, - acbd.water, - acbd.proteinval, - acbd.bone, - acbd.protein, - acbd.kcal, - acbd.visceral, - acbd.sfr, - acbd.record_time, - REPLACE(CONVERT(varchar(10), acbd.record_time, 23), '-', '/') AS b_time, - aud.nickname, - aud.gender, - aud.birthday, - aud.head_pic - from app_card_body_data as acbd - left join app_user_data as aud on acbd.aud_id=aud.id - where acbd.id in ($data3) - "); - // dump($result); - // die; - if(!$result || count($result)<2){ - return $this->msg(10004); - } - // 调整顺序 - foreach ($result as $key => $value) { - if($value['id'] == $data2[0]){ - $calculate_arr['before'] = $value; - }else{ - $calculate_arr['after'] = $value; - } - } - // dump($calculate_arr); - // die; - - $return_data['time'] = $calculate_arr['before']['b_time'].'-'.$calculate_arr['after']['b_time']; - $return_data['headimg'] = $calculate_arr['before']['head_pic']; - $return_data['name'] = $calculate_arr['before']['nickname']; - $return_data['gender'] = $calculate_arr['before']['gender']; - $return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']); - $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time'])); - - $return_data['list'] = []; - - foreach ($calculate_arr['before'] as $key => $value) { - if(in_array($key, ['height','weight','bmi','fat_r','fat_w','muscle','muscleval','water','proteinval','bone','protein','kcal','visceral','sfr'])){ - $before_arr = explode(',', $value); - $after_arr = explode(',', $calculate_arr['after'][$key]); - // $calculate_arr['before'][$key] = explode(',', $value); - - array_push($return_data['list'], [ - 'firstresult'=>[ - 'color'=>'', - 'level'=>$before_arr[1], - 'value'=>$before_arr[0], - 'title'=>$this->unit_name[$key], - 'unit'=>$this->unit_symbol[$key], - 'name'=>$key, - ], - 'secondresult'=>[ - 'color'=>'', - 'level'=>$after_arr[1], - 'value'=>$after_arr[0], - 'title'=>$this->unit_name[$key], - 'unit'=>$this->unit_symbol[$key], - 'name'=>$key, - ], - 'diffval'=>$before_arr[0]-$after_arr[0], - ]); - } - } - - // dump($return_data); - // die; - return $this->msg($return_data); - } + diff --git a/application/app/controller/Cardparts.php b/application/app/controller/Cardparts.php index 2afff83..0cff7a4 100644 --- a/application/app/controller/Cardparts.php +++ b/application/app/controller/Cardparts.php @@ -143,50 +143,8 @@ class Cardparts extends Base{ ]; // 基础代谢 protected $kcal = [ - 'man'=>[ - '3'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], - ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], - ], - '3_10'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], - ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], - ], - '10_18'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], - ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], - ], - '18_30'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], - ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], - ], - '30'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], - ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], - ], - ], - 'woman'=>[ - '3'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], - ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], - ], - '3_10'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], - ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], - ], - '10_18'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], - ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], - ], - '18_30'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], - ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], - ], - '30'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], - ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], - ], - ] + ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], + ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#5ad06d'], ]; // 内脏指数 protected $visceral = [ @@ -204,64 +162,245 @@ class Cardparts extends Base{ // 皮下脂肪 protected $sfr = [ 'man'=>[ - ['min_val'=>'0','max_val'=>'7','text'=>'标准','color'=>'#ff5656'], - ['min_val'=>'7','max_val'=>'15','text'=>'警惕','color'=>'#ffab00'], - ['min_val'=>'15','max_val'=>'50','text'=>'危险','color'=>'#5ad06d'], + ['min_val'=>'0','max_val'=>'7','text'=>'不足','color'=>'#ff5656'], + ['min_val'=>'7','max_val'=>'15','text'=>'标准','color'=>'#ffab00'], + ['min_val'=>'15','max_val'=>'50','text'=>'偏高','color'=>'#5ad06d'], ], 'woman'=>[ - ['min_val'=>'0','max_val'=>'11','text'=>'标准','color'=>'#ff5656'], - ['min_val'=>'11','max_val'=>'17','text'=>'警惕','color'=>'#ffab00'], - ['min_val'=>'17','max_val'=>'50','text'=>'危险','color'=>'#5ad06d'], + ['min_val'=>'0','max_val'=>'11','text'=>'不足','color'=>'#ff5656'], + ['min_val'=>'11','max_val'=>'17','text'=>'标准','color'=>'#ffab00'], + ['min_val'=>'17','max_val'=>'50','text'=>'偏高','color'=>'#5ad06d'], ] ]; - // 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 + + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) // 计算部分内容的横线标准以及说明文字 public function conversion_interval($data){ // dump($data); // $data['gender'] = $data['gender']==2?'woman':'man'; $gender = $data['gender']==2?'woman':'man'; $age = $data['age']['value']; + $weight = 0; $temporary_arr = [ 'top_list'=>[], 'bottom_list'=>[], ]; // dump($data); // dump($temporary_arr); - // 处理格式 + // 处理格式(顶部) foreach ($this->parameter_aggregate_top as $key => $value) { $data[$key]['key_name'] = $key; $data[$key]['desc'] = $value; + if($key == 'weight'){ + $weight = $data[$key]['value']; + } array_push($temporary_arr['top_list'],$data[$key]); } + // 处理格式(底部) foreach ($this->parameter_aggregate_bottom as $key => $value) { $data[$key]['key_name'] = $key; $data[$key]['desc'] = $value; array_push($temporary_arr['bottom_list'],$data[$key]); } + + // 处理顶部list + foreach ($temporary_arr['top_list'] as $key => $value) { + if(count($temporary_arr['top_list'][$key]['list']) > 0){ + $temporary_arr['top_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['top_list'][$key]['list'],$temporary_arr['top_list'][$key]['value'],$temporary_arr['top_list'][$key]['standard']); + } + } + + // 处理底部list foreach ($temporary_arr['bottom_list'] as $key => $value) { - // 脂肪率&脂肪量 - if($value['key_name'] == 'fat_r' || $value['key_name'] == 'fat_w'){ + // dump($value['key_name']); + // 脂肪率& + if($value['key_name'] == 'fat_r'){ if($age < 30){ $temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['29']; }else{ $temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['30']; } - $num = count($temporary_arr['bottom_list'][$key]['list'])-1; - $temporary_arr['bottom_list'][$key]['offset'] = bcdiv($temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['list'][$num]['max_val'],4)*100; + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); + } + // 脂肪量 + else if($value['key_name'] == 'fat_w'){ + if($age < 30){ + $temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['29']; + }else{ + $temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['30']; + } + $temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']); + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); + } + // 肌肉率 + else if($value['key_name'] == 'muscle'){ + // dump('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); + $temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender]; + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); + // dump($temporary_arr['bottom_list'][$key]); + } + // 肌肉量 + else if($value['key_name'] == 'muscleval'){ + // dump('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); + $temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender]; + $temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']); + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); + // dump($temporary_arr['bottom_list'][$key]); + } + // 水分 + else if($value['key_name'] == 'water'){ + $temporary_arr['bottom_list'][$key]['list'] = $this->water[$gender]; + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); + } + // 蛋白量 + else if($value['key_name'] == 'proteinval'){ + $temporary_arr['bottom_list'][$key]['list'] = $this->proteinval_protein[$gender]; + $temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']); + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); + } + // 骨重 + else if($value['key_name'] == 'bone'){ + if($gender == 'man'){ + if($weight < 60){ + $temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60']; + }else if($weight >= 60 && $weight < 75){ + $temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60_75']; + }else{ + $temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['75']; + } + }else{ + if($weight < 45){ + $temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['45']; + }else if($weight >= 45 && $weight < 60){ + $temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['45_60']; + }else{ + $temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60']; + } + } + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); + } + // 蛋白率 + else if($value['key_name'] == 'protein'){ + $temporary_arr['bottom_list'][$key]['list'] = $this->proteinval_protein[$gender]; + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); + } + // 基础代谢 + else if($value['key_name'] == 'kcal'){ + $temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($this->kcal,$weight,$value['key_name'],$age,$gender); + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); + } + // 内脏指数 + else if($value['key_name'] == 'visceral'){ + $temporary_arr['bottom_list'][$key]['list'] = $this->visceral[$gender]; + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); + } + // 皮下脂肪 + else if($value['key_name'] == 'sfr'){ + $temporary_arr['bottom_list'][$key]['list'] = $this->sfr[$gender]; + $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); } } - dump($data['gender']); - dump($data['age']['value']); - // dump($temporary_arr['top_list']); - dump($temporary_arr['bottom_list']); - die; + // dump($data['gender']); + // dump($data['age']['value']); + // // dump($temporary_arr['top_list']); + // dump($temporary_arr['bottom_list']); + // die; + return $temporary_arr; + } + + + // 计算落点百分比 + public function calculate_landing_point($data,$val,$t_val){ + $num = count($data); + $a_section = bcdiv(100,$num,2); + $temporary_data = []; + $num_0 = 0; + foreach ($data as $key => $value) { + if($t_val == $value['text']){ + $temporary_data = $value; + $num_0 = $key; + break; + } + } + $max_num = trim($temporary_data['max_val']); + $min_num = trim($temporary_data['min_val']); + if($val < $temporary_data['max_val']){ + $num_1 = bcsub($val,$min_num,2); + $num_2 = bcsub($max_num,$min_num,2); + $num_3 = bcdiv(bcdiv($num_1,$num_2,4),$num,4)*100; + $result = bcadd(bcmul($num_0,$a_section,2),$num_3,2); + }else{ + $num_3 = bcdiv(1,$num,4)*100; + $result = bcadd(bcmul($num_0,$a_section,2),$num_3,2); + } + return $result; + } + + // 计算新标准 + 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; + + // dump($data); + // dump($w); + // dump($k); } } \ No newline at end of file diff --git a/application/app/controller/Index.php b/application/app/controller/Index.php index 1de5291..56d514c 100644 --- a/application/app/controller/Index.php +++ b/application/app/controller/Index.php @@ -268,12 +268,12 @@ class Index extends Base{ // 没有数据,传递一个空的卡片 // $ return [ - [ + [[ 'id'=>'', 'acd_id'=>'2', 'record_time'=>'', 'card_name'=>'身体数据', - 'card_key'=>'', + 'card_key'=>'body', 'inside_data'=>[ [ 'key'=>'', @@ -300,7 +300,7 @@ class Index extends Base{ 'color'=>'', ], ] - ], + ]], $target_current ]; } diff --git a/application/app/controller/Pagingcontrast.php b/application/app/controller/Pagingcontrast.php index 33b58ef..f29f4bc 100644 --- a/application/app/controller/Pagingcontrast.php +++ b/application/app/controller/Pagingcontrast.php @@ -12,7 +12,12 @@ class Pagingcontrast extends Base{ protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6']; protected $db_name = ['2'=>'app_card_body_data','6'=>'app_card_skip_data','8'=>'app_card_vitalcapacity_data']; - protected $request_name = ['2'=>'get_body_record_data','6'=>'app_card_skip_data','8'=>'app_card_vitalcapacity_data']; + protected $request_result = [ + '2'=>['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI',''],'fat_w'=>['脂肪量','kg'],'fat_r'=>['脂肪率','%'],'muscleval'=>['肌肉量','kg'],'muscle'=>['肌肉率','%'],'proteinval'=>['蛋白量','kg'],'protein'=>['蛋白率','%'],'water'=>['水分',''],'bone'=>['骨重','kg'],'visceral'=>['内脏指数',''],'sfr'=>['皮下脂肪','%'],'kcal'=>['基础代谢','kcal'],'un_fat_w_weight'=>['去脂体重','kg'],'body_age'=>['体龄',''],'body_level'=>['肥胖等级',''],'body_type'=>['体型','']], + '6'=>[], + '8'=>[] + ]; + protected $pagesize = 10; ################################################请求接口################################################ @@ -30,8 +35,8 @@ class Pagingcontrast extends Base{ return $this->msg(20001); } unset($data['token']); - if(array_key_exists($data['type'],$this->request_name)){ - return $this->jump_transfer_interface($data,'group'); + if(array_key_exists($data['type'],$this->db_name)){ + return $this->jump_transfer_interface_record($data,'group'); }else{ return $this->msg(10005); } @@ -48,21 +53,49 @@ class Pagingcontrast extends Base{ return $this->msg(20001); } unset($data['token']); - if(array_key_exists($data['type'],$this->request_name)){ - return $this->jump_transfer_interface($data,'page'); + if(array_key_exists($data['type'],$this->db_name)){ + return $this->jump_transfer_interface_record($data,'page'); }else{ return $this->msg(10005); } } - - - - + // 获取详细历史数据信息(包含身体、跳绳、肺活量) + public function get_all_record_detailed_information($data = ['id'=>'30','type'=>'2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if($this->token_time_validate($data['token']) === false){ + return $this->msg(20001); + } + unset($data['token']); + + return $this->jump_transfer_interface_detailed($data); + } + // 数据对比(包含身体、跳绳、肺活量) + public function get_all_card_data_contrast($data = ['before_id'=>'33','after_id'=>'35','type'=>'2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if($this->token_time_validate($data['token']) === false){ + return $this->msg(20001); + } + unset($data['token']); + // $data = explode(',',$data['id_arr']); + // dump($data); + // die; + return $this->jump_transfer_interface_data_contrast($data); + } ################################################请求接口################################################ ################################################请求接口################################################ ################################################请求接口################################################ - public function jump_transfer_interface($data,$str){ + public function jump_transfer_interface_record($data,$str){ if($data['type'] == '2'){ return $this->get_body_record_data($data,$str); }else if($data['type'] == '6'){ @@ -71,6 +104,24 @@ class Pagingcontrast extends Base{ return $this->get_body_record_data($data,$str); } } + public function jump_transfer_interface_detailed($data){ + if($data['type'] == '2'){ + return $this->get_body_detaile_data_msg($data); + }else if($data['type'] == '6'){ + // return $this->get_body_record_data($data,$str); + }else if($data['type'] == '8'){ + // return $this->get_body_record_data($data,$str); + } + } + public function jump_transfer_interface_data_contrast($data){ + if($data['type'] == '2'){ + return $this->get_body_data_contrast($data); + }else if($data['type'] == '6'){ + // return $this->get_body_record_data($data,$str); + }else if($data['type'] == '8'){ + // return $this->get_body_record_data($data,$str); + } + } ################################################业务部分################################################ @@ -92,15 +143,21 @@ class Pagingcontrast extends Base{ and record_time between '".$data['s_time']."' and '".$data['e_time']."' and is_del = 0 order by record_time desc"); + foreach ($result as $key => $value) { - if(array_key_exists($value['r_t'], $return_result)){ - array_push($return_result[$value['r_t']], ['id'=>$value['id'],'v1'=>$value['v1'],'v2'=>$value['v2'],'v3'=>$value['v3'],'v1_name'=>'身高','v2_name'=>'体重','v3_name'=>'BMI']); - }else{ - $return_result[$value['r_t']] = [['id'=>$value['id'],'v1'=>$value['v1'],'v2'=>$value['v2'],'v3'=>$value['v3'],'v1_name'=>'身高','v2_name'=>'体重','v3_name'=>'BMI']]; - } + array_push($return_result, [ + 'id'=>$value['id'], + 'v1'=>$value['v1'], + 'v2'=>$value['v2'], + 'v3'=>$value['v3'], + 'v1_name'=>'身高', + 'v2_name'=>'体重', + 'v3_name'=>'BMI', + 'r_t'=>str_replace('-', '/', $value['r_t']) + ]); } }else{ - $result = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->field('id,record_time,height,weight,bmi')->order('record_time desc')->page($data['page'],$this->pagesize)->select(); + $result = Db::table('app_card_body_data')->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('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->count(); $return_result['rows'] = []; $return_result['pageno'] = $data['page']; @@ -115,10 +172,123 @@ class Pagingcontrast extends Base{ 'v2'=>$value['weight'], 'v3_name'=>'BMI', 'v3'=>$value['bmi'], + 'record_time'=>$value['b_time'], ]); } } return $this->msg($return_result); } + // 获取详细历史数据信息 + public function get_body_detaile_data_msg($data){ + $result = Db::table($this->db_name[$data['type']])->where(['id'=>$data['id']])->find(); + if($result){ + $result_data = []; + foreach ($this->request_result['2'] as $key => $value) { + $temporary_arr['key_name'] = $key; + $temporary_arr['name'] = $value[0]; + if($key == 'un_fat_w_weight'){ + $temporary_arr['value'] = bcsub($result['weight'],explode(',',$result['fat_r'])[0],2); + }else{ + $temporary_arr['value'] = explode(',',$result[$key])[0]; + } + $temporary_arr['unit'] = $value[1]; + array_push($result_data,$temporary_arr); + } + return $this->msg($result_data); + }else{ + return $this->msg(10004); + } + + } + // 数据对比 + public function get_body_data_contrast($data){ + // dump($data); + $data2 = [$data['before_id'],$data['after_id']]; + $data3 = implode(',',$data2); + $calculate_arr = []; + $result = Db::query(" + select + acbd.id, + acbd.height_data as height, + acbd.weight_data as weight, + acbd.bmi_data as bmi, + acbd.fat_r, + acbd.fat_w, + acbd.muscle, + acbd.muscleval, + acbd.water, + acbd.proteinval, + acbd.bone, + acbd.protein, + acbd.kcal, + acbd.visceral, + acbd.sfr, + acbd.record_time, + REPLACE(CONVERT(varchar(10), acbd.record_time, 23), '-', '/') AS b_time, + aud.nickname, + aud.gender, + aud.birthday, + aud.head_pic + from app_card_body_data as acbd + left join app_user_data as aud on acbd.aud_id=aud.id + where acbd.id in ($data3) + and acbd.is_del = 0 + "); + // dump($result); + // die; + if(!$result || count($result)<2){ + return $this->msg(10004); + } + // 调整顺序 + foreach ($result as $key => $value) { + if($value['id'] == $data2[0]){ + $calculate_arr['before'] = $value; + }else{ + $calculate_arr['after'] = $value; + } + } + // dump($calculate_arr); + // die; + + $return_data['time'] = $calculate_arr['before']['b_time'].'-'.$calculate_arr['after']['b_time']; + $return_data['headimg'] = $calculate_arr['before']['head_pic']; + $return_data['name'] = $calculate_arr['before']['nickname']; + $return_data['gender'] = $calculate_arr['before']['gender']; + $return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']); + $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time'])); + + $return_data['list'] = []; + + foreach ($calculate_arr['before'] as $key => $value) { + if(in_array($key, ['height','weight','bmi','fat_r','fat_w','muscle','muscleval','water','proteinval','bone','protein','kcal','visceral','sfr'])){ + $before_arr = explode(',', $value); + $after_arr = explode(',', $calculate_arr['after'][$key]); + // $calculate_arr['before'][$key] = explode(',', $value); + + array_push($return_data['list'], [ + 'firstresult'=>[ + 'color'=>'', + 'level'=>$before_arr[1], + 'value'=>$before_arr[0], + 'title'=>$this->request_result['2'][$key][0], + 'unit'=>$this->request_result['2'][$key][1], + 'name'=>$key, + ], + 'secondresult'=>[ + 'color'=>'', + 'level'=>$after_arr[1], + 'value'=>$after_arr[0], + 'title'=>$this->request_result['2'][$key][0], + 'unit'=>$this->request_result['2'][$key][1], + 'name'=>$key, + ], + 'diffval'=>bcsub($before_arr[0],$after_arr[0],2), + ]); + } + } + return $this->msg($return_data); + } + + } \ No newline at end of file diff --git a/application/route.php b/application/route.php index b3164cb..7a71f67 100644 --- a/application/route.php +++ b/application/route.php @@ -37,10 +37,15 @@ Route::any('/admin/index', 'admin/index/index'); // // ################################################################APP接口################################################################ // // ################################################################APP接口################################################################ // ################################公共接口################################ -// 注册接口12 +// 获取记录信息(分组)(包含身体、跳绳、肺活量) Route::any('/get_all_record_data_group', 'app/pagingcontrast/get_all_record_data_group'); -// 注册接口12 +// 获取记录信息(分页)(包含身体、跳绳、肺活量) Route::any('/get_all_record_data_page', 'app/pagingcontrast/get_all_record_data_page'); +// 获取详细历史数据信息 +Route::any('/get_all_record_detailed_information', 'app/pagingcontrast/get_all_record_detailed_information'); +// 数据对比 +Route::any('/get_all_card_data_contrast', 'app/pagingcontrast/get_all_card_data_contrast'); + // ################################登录接口################################ // 注册接口12