diff --git a/application/app/controller/Base.php b/application/app/controller/Base.php index e2197cf..c39969c 100644 --- a/application/app/controller/Base.php +++ b/application/app/controller/Base.php @@ -11,6 +11,20 @@ class Base extends Controller{ protected $base_call_method = ['内部']; protected $token_time = 86400*1; + protected $return_data_all = [ + // '0' => ['success',[]], + '10001'=>'关键参数缺失', + '10002'=>'操作失败', + '10003'=>'信息核实错误', + '10004'=>'未核实到数据', + '10005'=>'未核实到数据', + '10006'=>'未核实到数据', + '10007'=>'未核实到数据', + '10008'=>'未核实到数据', + '10009'=>'未核实到数据', + '10010'=>'未核实到数据', + '20001'=>'登录失效', + ]; ################################################################接口################################################################ ################################################################接口################################################################ @@ -145,35 +159,17 @@ class Base extends Controller{ return $ageInMonthsPrecise; } - // 查找设备 - // $data = ['device_code'=>'asdkljiouoi'] - public function base_device_check($data = ['device_code'=>'asdkljiouoi']){ - // $data = input(); - $result = Db::query(" - select - adcd.id, - adcd.bind_account_id as activation_state, - adds.is_del as device_state - from app_device_code_data as adcd - left join app_device_data as adds on adds.id = adcd.add_id - where - adcd.machine_code = '".$data['device_code']."' - "); - - if(count($result) == 1){ - return $this->msg(0,'success',['device_state'=>$result[0]['device_state'],'activation_state'=>$result[0]['activation_state']]); - }else if(count($result) < 1){ - return $this->msg(10001,'未找到设备'); - }else{ - $this->abnormal_data_log_action(0,'device_check-设备查询出错,结果为'.count($result).',合理值应为1或0','app_device_code_data,app_device_data'); - return $this->msg(10002,'未找到设备'); - } - } - - public function msg($code,$msg='',$data=[]){ - return json(['code'=>$code,'msg'=>$msg,'data'=>$data]); + public function msg($data,$str=''){ + if(is_array($data)){ + return json(['code'=>0,'msg'=>'success','data'=>$data]); + }else{ + if($str != ''){ + return json(['code'=>$data,'msg'=>$str]); + } + return json(['code'=>$data,'msg'=>$this->return_data_all[$data]]); + } } diff --git a/application/app/controller/Card.php b/application/app/controller/Card.php index a1107c0..3e29454 100644 --- a/application/app/controller/Card.php +++ b/application/app/controller/Card.php @@ -69,40 +69,6 @@ class Card extends Base{ ################################################################接口################################################################ ################################################################接口################################################################ - - - // // 获取卡片列表 - // // $data = ['id'=>'2','time'=>'1991-04-20',content=>'15个'] - // public function get_card_list($data = ['aud_id'=>'2','time'=>'1991-04-20','content'=>'15个']){ - // $data = input(); - // if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('content', $data)){ - // return $this->msg(10001,'数据格式错误'); - // } - - // $result = Db::table('app_card_data_log')->insert(['aud_id'=>$data['id'],'log_time'=>$data['time'],'content'=>$data['content'],'create_time'=>date('Y-m-d H:i:s')]); - // if($result){ - // return $this->msg(0,'success'); - // }else{ - // return $this->msg(10003,'添加失败'); - // } - // } - - // 获取基础卡片信息 - // $data = ['id'=>'2'] - // public function card_data_base($data = ['aud_id'=>'11']){ - // if(count(input()) > 0){ - // $data = input(); - // } - // if(!array_key_exists('aud_id', $data)){ - // return $this->msg(10001,'数据格式错误'); - // } - // $result = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('record_time,height,weight,bmi')->find(); - // if(!$result){ - // return $this->msg(10002,'未找到数据'); - // }else{ - // return $this->msg(0,'success',$result); - // } - // } // 详细卡片信息 // $data = ['id'=>'2'] @@ -110,23 +76,38 @@ class Card extends Base{ if(count(input()) > 0){ $data = input(); } + + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001,'登录失效'); + return $this->msg(20001); } unset($data['token']); - if(!array_key_exists('aud_id', $data)){ - return $this->msg(10001,'关键参数缺失'); - } return $this->get_user_body_data($data); - // if($data['acd_id'] == '2'){ - // // 基础身体信息卡片 - - - // } } + // 曲线页面-曲线接口 + public function card_curve_chart($data = ['aud_id'=>'11','type'=>'weight','s_time'=>'2024-04-01 10:10:10','e_time'=>'2024-04-11 10:10:10','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + if(count(input()) > 0){ + $data = input(); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('type', $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']); + + return $this->curve_chart_action($data); + } + // 曲线页面-底部统计 + public function card_curve_target(){ + + } // 手动记录 // $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1'] // public function card_manual_recording($data = ['acd_id'=>'2','aud_id'=>'11','time'=>'2024-04-11 10:10:10','data'=>['height'=>'175.1','weight'=>'77.1']]){ @@ -134,32 +115,68 @@ class Card extends Base{ if(count(input()) > 0){ $data = input(); } + + 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); + } if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001,'登录失效'); + return $this->msg(20001); } unset($data['token']); - if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data)){ - return $this->msg(10001,'关键参数缺失'); - } $data['acd_id'] = '2'; return $this->set_user_body_data($data); } // 获取记录信息列表 - function get_card_record_data($data = ['aud_id'=>'11','s_time'=>'2024-04-01 10:10:10','e_time'=>'2024-04-12 10:10:10']){ - if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){ - return $this->msg(10001,'关键参数缺失'); + public function get_card_record_data($data = ['aud_id'=>'11','s_time'=>'2024-04-01 10:10:10','e_time'=>'2024-04-12 10:10:10','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + if(count(input()) > 0){ + $data = input(); } + + 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); } + // 删除历史数据 + public function card_del_record_data($data = ['id'=>'16','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + if(count(input()) > 0){ + $data = input(); + } + if(!array_key_exists('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']); + $user_data = Db::table('app_card_body_data')->where(['id'=>$data['id']])->update(['is_del'=>1]); + if($user_data){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } // 数据对比 - function card_data_contrast($data = ['acd_id'=>'2','aud_id'=>'11','s_time'=>'2024-04-01 10:10:10','e_time'=>'2024-04-12 10:10:10']){ - if(!array_key_exists('acd_id', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){ - return $this->msg(10001,'关键参数缺失'); + public function card_data_contrast($data = ['acd_id'=>'2','aud_id'=>'11','s_time'=>'2024-04-01 10:10:10','e_time'=>'2024-04-12 10:10:10']){ + if(count(input()) > 0){ + $data = input(); } + if(!array_key_exists('acd_id', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){ + return $this->msg(10001); + } + if($this->token_time_validate($data['token']) === false){ + return $this->msg(20001); + } + unset($data['token']); + if($data['acd_id'] == '2'){ return $this->body_data_contrast($data); }else if($data['acd_id'] == '6'){ @@ -169,13 +186,33 @@ class Card extends Base{ ################################################################身体数据卡片接口################################################################ ################################################################身体数据卡片接口################################################################ + public function curve_chart_action($data){ + $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('target_weight,initial_weight,initial_date')->find(); + // dump($user_data); + if($user_data){ + if($user_data['initial_date']){ + $result_data['target_weight'] = $user_data['target_weight'].'kg'; + $result_data['initial_weight'] = $user_data['initial_weight'].'kg'; + $result_data['initial_date'] = $this->daysSince($user_data['initial_date']).'天'; + }else{ + $result_data['target_weight'] = ''; + $result_data['initial_weight'] = ''; + $result_data['initial_date'] = ''; + } + }else{ + return $this->msg(10003); + } + dump($result_data); + $user_data_list = Db::query("select record_time,weight,bmi,muscleval,fat_w from app_card_body_data where aud_id='".$data['aud_id']."'and record_time between '".$data['s_time']."' and '".$data['e_time']."' order by record_time desc"); + dump($user_data_list); + } // weight height muscle fat // 查询曲线数据 public function body_curve_data($data=['aud_id'=>'11','acd_id'=>'2','type'=>'weight','s_time'=>'2024-04-01 10:10:10','e_time'=>'2024-04-11 10:10:10']){ if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('type', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){ - return $this->msg(10001,'关键参数缺失'); + return $this->msg(10001); } $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('target_weight,initial_weight,initial_date')->find(); // dump($user_data); @@ -190,7 +227,7 @@ class Card extends Base{ $result_data['initial_date'] = ''; } }else{ - return $this->msg(10002,'未找到用户数据'); + return $this->msg(10003); } $user_data_list = Db::query("select record_time,weight,bmi,muscleval,fat_w from app_card_body_data where aud_id='".$data['aud_id']."'and record_time between '".$data['s_time']."' and '".$data['e_time']."' order by record_time desc"); @@ -214,11 +251,11 @@ class Card extends Base{ // } $result_data['list'] = $data_arr; - return $this->msg(0,'success',$result_data); + return $this->msg([]); } // 获取各类历史数据记录信息列表 - function get_all_record_data($data){ + public function get_all_record_data($data){ $result = Db::query(" select @@ -229,22 +266,32 @@ class Card extends Base{ from ".$this->db_name[$data['acd_id']]." 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"); + // dump($result); + // die; $return_result = []; foreach ($result as $key => $value) { + $result[$key]['v1_name'] = '身高'; + $result[$key]['v2_name'] = '体重'; + $result[$key]['v3_name'] = 'BMI'; 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']]); + 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']]]; + $return_result[$value['r_t']] = [['id'=>$value['id'],'v1'=>$value['v1'],'v2'=>$value['v2'],'v3'=>$value['v3'],'v1_name'=>'身高','v2_name'=>'体重','v3_name'=>'BMI']]; } } - return $this->msg(0,'success',['original'=>$result,'optimization'=>$return_result]); + + // dump($result); + // dump($return_result); + // die; + return $this->msg(['original'=>$result,'optimization'=>$return_result]); // return ; } // 身体数据对比 - function body_data_contrast($data = ['acd_id'=>'2','data'=>[1,10]]){ + public function body_data_contrast($data = ['acd_id'=>'2','data'=>[1,10]]){ $between_num = implode(',',$data['data']); $calculate_arr = []; $result = Db::query(" @@ -264,7 +311,7 @@ class Card extends Base{ where acbd.id in (".$between_num.") "); if(!$result || count($result)<2){ - return $this->msg(10001,'数据查询错误'); + return $this->msg(10003); } foreach ($data['data'] as $key => $value) { foreach ($result as $k => $v) { @@ -293,18 +340,21 @@ class Card extends Base{ $return_data['execl_data']['bmi'] = ['BMI',bcsub($calculate_arr[1]['bmi'],$calculate_arr[0]['bmi'],1),$calculate_arr[0]['bmi'],$calculate_arr[1]['bmi']]; // dump($return_data); // die; - return $this->msg(0,'success',$return_data); + return $this->msg($return_data); } ################################################################身体数据卡片业务 // 用户身体数据卡片记录 - function set_user_body_data($data){ + public function set_user_body_data($data){ // if(!array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data)){ // return $this->msg(10001,'数据格式错误'); // } $data['type'] = 1; $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('birthday,gender')->find(); + if(!$user_data){ + return $this->msg(10003); + } $result_data['height'] = $data['height']; $result_data['weight'] = $data['weight']; $result_data['age'] = $this->calculate_age($user_data['birthday']); @@ -312,6 +362,13 @@ class Card extends Base{ $result_data['adc'] = array_key_exists('impedance', $data)?$data['impedance']:550; $calculate_body_formula = new Calculatebody(); $get_body_value = $calculate_body_formula->calculate_body_data_result($result_data); + $get_body_value['gender'] = $user_data['gender']; + $get_body_value['birthday'] = $user_data['birthday']; + $get_body_value = $this->hwb_standard($get_body_value); + // dump($get_body_value); + // // dump($get_body_value['脂肪率']); + // // dump(implode(',',$get_body_value['脂肪率'])); + // die; $set_user_data = Db::table('app_card_body_data')->insert([ 'acd_id'=>$data['acd_id'], 'aud_id'=>$data['aud_id'], @@ -320,8 +377,11 @@ class Card extends Base{ 'last_update_time'=>date('Y-m-d H:i:s'), 'age'=>$get_body_value['age'], 'height'=>$get_body_value['身高'], + 'height_data'=>$get_body_value['身高2'], 'weight'=>$get_body_value['体重'], + 'weight_data'=>$get_body_value['体重2'], 'bmi'=>$get_body_value['BMI'], + 'bmi_data'=>$get_body_value['BMI2'], 'score'=>$get_body_value['身体得分'], 'fat_r'=> implode(',',$get_body_value['脂肪率']), 'fat_w'=>implode(',',$get_body_value['脂肪量']), @@ -340,17 +400,17 @@ class Card extends Base{ if($set_user_data){ // 返回简要数据 if($data['type'] == 1){ - return $this->msg(0,'success',['acd_id'=>2,'height'=>$get_body_value['身高'].'CM','weight'=>$get_body_value['体重'].'公斤','bmi'=>$get_body_value['BMI']]); + return $this->msg(['acd_id'=>2,'height'=>$get_body_value['身高'].',CM','weight'=>$get_body_value['体重'].',公斤','bmi'=>$get_body_value['BMI']]); } }else{ - return $this->msg(10002,'数据存储失败'); + return $this->msg(10002); } } // 用户身体数据卡片获取 - function get_user_body_data($data){ + public function get_user_body_data($data){ $result = Db::table('app_card_body_data') ->alias('acbd') ->join('app_user_data aud','acbd.aud_id = aud.id','LEFT') @@ -364,17 +424,18 @@ class Card extends Base{ // $result['age'] = 14; // die; if(!$result){ - return $this->msg(10002,'未找到数据'); + return $this->msg(10003); }else{ $result_end = $this->processing_return_data_new($result); // dump($result_end); // die; - return $this->msg(0,'success',$result_end); + return $this->msg($result_end); } } // 返回数据处理 - function processing_return_data_new($data){ + public function processing_return_data_new($data){ + // dump($data); $result_end_data = []; $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday'])*100; $gender_val = $data['gender']; @@ -398,7 +459,7 @@ class Card extends Base{ } - // 如果大于16岁(成人) + // 如果小于16岁(儿童) if($data['age'] < $this->age_limit){ if(array_key_exists($key, $this->bhw_list)){ $result_end_data[$key]['list'] = $this->bhw_list[$key]; @@ -415,7 +476,7 @@ class Card extends Base{ $result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z2sd']; } }else if($key == 'height'){ - $bhw_date = Db::table('pc_heightstand2')->where("month >= $month_num")->order('month')->limit(1)->select(); + $bhw_date = Db::table('pc_heightstand2')->where("month >= $month_num and sex = '$gender_val'")->order('month')->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']; @@ -428,7 +489,7 @@ class Card extends Base{ $result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd']; } }else if($key == 'weight'){ - $bhw_date = Db::table('pc_weightstand2')->where("month >= $month_num")->order('month')->limit(1)->select(); + $bhw_date = Db::table('pc_weightstand2')->where("month >= $month_num and sex = '$gender_val'")->order('month')->limit(1)->select(); // dump($value); // dump($bhw_date);/ if($bhw_date){ @@ -447,94 +508,83 @@ class Card extends Base{ } } } + // dump($data['age']); + // dump($result_end_data); + // die; return $result_end_data; } - // // 返回数据处理 - // function processing_return_data($data){ - // $result_end_data = []; - // $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday'])*100; - // $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'){ - // // 如果大于16岁(成人) - // if($data['age'] >= $this->age_limit){ - // $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)){ - // $result_end_data[$key]['color'] = $this->standard_color[$key][$result_end_data[$key]['standard']]; - // } - // }else{ - // if(array_key_exists($key, $this->bhw_list)){ - // $result_end_data[$key] = $this->result_end_data_mould; - // $result_end_data[$key]['list'] = $this->bhw_list[$key]; - // 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)){ - // $result_end_data[$key]['color'] = $this->standard_color[$key][$result_end_data[$key]['standard']]; - // } - // if($key == 'bmi'){ - // // dump($month_num); - // $bhw_date = Db::table('pc_bmistand2')->where("month >= $month_num and sex = '$gender_val'")->order('month')->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('pc_heightstand2')->where("month >= $month_num")->order('month')->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('pc_weightstand2')->where("month >= $month_num")->order('month')->limit(1)->select(); - // // dump($value); - // // dump($bhw_date);/ - // 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; - // } + + + // 添加身高体重bmi的标准 + public function hwb_standard($data){ + + $linshi_data = []; + $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday'])*100; + $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('pc_heightstand2')->where("month >= $month_num and sex = '$gender_val'")->order('month')->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('pc_weightstand2')->where("month >= $month_num and sex = '$gender_val'")->order('month')->limit(1)->select(); + if($bhw_date){ + $linshi_data['体重'][0]['max_val'] = $bhw_date[0]['f2sd']; + $linshi_data['体重'][1]['min_val'] = $bhw_date[0]['f2sd']; + $linshi_data['体重'][1]['max_val'] = $bhw_date[0]['f1sd']; + $linshi_data['体重'][2]['min_val'] = $bhw_date[0]['f1sd']; + $linshi_data['体重'][2]['max_val'] = $bhw_date[0]['z1sd']; + $linshi_data['体重'][3]['min_val'] = $bhw_date[0]['z1sd']; + $linshi_data['体重'][3]['max_val'] = $bhw_date[0]['z2sd']; + $linshi_data['体重'][4]['min_val'] = $bhw_date[0]['z2sd']; + $linshi_data['体重'][4]['max_val'] = $bhw_date[0]['z3sd']; + } + }else if($key =='BMI'){ + $linshi_data['BMI'] = $this->bhw_list['bmi']; + $bhw_date = Db::table('pc_bmistand2')->where("month >= $month_num and sex = '$gender_val'")->order('month')->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']; + } + } + } + + foreach ($linshi_data as $key => $value) { + foreach ($value as $k => $v) { + if($data[$key] > $v['min_val'] && $data[$key] < $v['max_val']){ + $data[$key.'2'] = $data[$key].','.$v['text'].','.$v['color']; + } + + } + } + + }else{ + $data['身高2'] = $data['身高'].',无,无'; + $data['体重2'] = $data['身高'].',无,无'; + $data['BMI2'] = $data['身高'].',无,无'; + } + // dump($data); + return $data; + // dump($data); + } + ################################################################跳绳数据卡片接口################################################################ ################################################################跳绳数据卡片接口################################################################ diff --git a/application/app/controller/Index.php b/application/app/controller/Index.php index 6fe6bab..2c75e79 100644 --- a/application/app/controller/Index.php +++ b/application/app/controller/Index.php @@ -13,10 +13,36 @@ class Index extends Base{ protected $db_name = ['2'=>'app_card_body_data','6'=>'app_card_skip_data','8'=>'app_card_vitalcapacity_data']; // protected $card_key = ['2'=>'body','6'=>'skip','8'=>'vitalcapacity']; protected $card_data = [ - '2'=>['身体数据',['height','weight','bmi','record_time']], + '2'=>['身体数据','body_data',['height'=>['身高','cm'],'weight'=>['体重','公斤'],'bmi'=>['BMI','无']]], // 'skip'=>['跳绳数据',['height,weight,bmi,record_time']], - '8'=>['肺活量',['average','record_time']], + '8'=>['肺活量','vitalcapacity_data',['average'=>['本次数据','ml']]], ]; + + protected $data_name_unit = [ + 'height'=>['身高','cm','pc_heightstand2'], + 'weight'=>['体重','公斤','pc_weightstand2'], + 'bmi'=>['BMI','','pc_bmistand2'], + 'average'=>['肺活量','ml','pc_vitalcapacity_standard'] + ]; + + protected $grade_list = [ + ['id'=>'nothing','name'=>'无'], + ['id'=>'grade_s_1','name'=>'小学一年级'], + ['id'=>'grade_s_2','name'=>'小学二年级'], + ['id'=>'grade_s_3','name'=>'小学三年级'], + ['id'=>'grade_s_4','name'=>'小学四年级'], + ['id'=>'grade_s_5','name'=>'小学五年级'], + ['id'=>'grade_s_6','name'=>'小学六年级'], + ['id'=>'grade_m_1','name'=>'初中一年级'], + ['id'=>'grade_m_2','name'=>'初中二年级'], + ['id'=>'grade_m_3','name'=>'初中三年级'], + ['id'=>'grade_h_1','name'=>'高中一年级'], + ['id'=>'grade_h_2','name'=>'高中二年级'], + ['id'=>'grade_h_3','name'=>'高中三年级'], + ['id'=>'grade_u_12','name'=>'大学一、二年级'], + ['id'=>'grade_u_34','name'=>'大学三、四年级'] + ]; + ################################################################个人资料卡################################################################ ################################################################个人资料卡################################################################ ################################################################个人资料卡################################################################ @@ -33,19 +59,22 @@ class Index extends Base{ if(count(input()) > 0){ $data = input(); } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001,'登录失效'); + return $this->msg(20001); } unset($data['token']); $verify_result = $this->verify_parameters($data,'register'); if(!is_array($verify_result)){ - return $this->msg(10002,$verify_result); + return $this->msg(10001,$verify_result); } $result = Db::table('app_user_data')->insert($verify_result); if($result){ - return $this->msg(0,'success'); + return $this->msg([]); }else{ - return $this->msg(10001,'创建失败'); + return $this->msg(10002); } } @@ -55,8 +84,12 @@ class Index extends Base{ if(count(input()) > 0){ $data = input(); } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001,'登录失效'); + return $this->msg(20001); } unset($data['token']); $result = Db::table('app_user_data')->where(['aan_id'=>$data['aan_id']])->select(); @@ -69,34 +102,42 @@ class Index extends Base{ }else{ $temporary_data = $result; } - return $this->msg(0,'success',$temporary_data); + return $this->msg($temporary_data); } // 获取指定用户详细信息 - public function get_user_data_information($data = ['aud_id'=>11,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function get_user_data_information($data = ['aud_id'=>20,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ if(count(input()) > 0){ $data = input(); } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001,'登录失效'); + return $this->msg(20001); } unset($data['token']); - $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,aan_id,nickname,birthday,gender,card_order')->find(); + $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,aan_id,nickname,head_pic,birthday,gender,card_order')->find(); + if(!$result){ + return $this->msg(10003); + } unset($result['ROW_NUMBER']); + $result['age'] = $this->calculate_age($result['birthday']); if($result['card_order'] === ''){ - $result['age'] = $this->calculate_age($result['birthday']); $result['card_order'] = []; $result['card_data_list'] = []; }else{ $result['card_order'] = explode(',',$result['card_order']); $result['card_data_list'] = $this->get_user_card_data_list($result['card_order'],$result['id']); } - + // dump($result); + // die; $result['birthday'] = str_replace('-', '/', $result['birthday']); foreach ($result['card_data_list'] as $key => $value) { $result['card_data_list'][$key]['record_time'] = str_replace('-', '/', $result['card_data_list'][$key]['record_time']); } - return $this->msg(0,'success',$result); + return $this->msg($result); } // 获取所有卡片列表信息 @@ -104,11 +145,17 @@ class Index extends Base{ if(count(input()) > 0){ $data = input(); } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001,'登录失效'); + return $this->msg(20001); } unset($data['token']); $user_card_list = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,card_order')->find(); + if(!$user_card_list){ + return $this->msg(10003); + } unset($user_card_list['ROW_NUMBER']); $user_card_list['card_order'] = explode(',',$user_card_list['card_order']); $all_card_list = Db::table('app_card_data')->field('id,name')->select(); @@ -123,7 +170,7 @@ class Index extends Base{ } } ksort($result['user']); - return $this->msg(0,'success',$result); + return $this->msg($result); } // 保存用户的卡片排序 @@ -131,49 +178,78 @@ class Index extends Base{ if(count(input()) > 0){ $data = input(); } + if(!array_key_exists('aud_id', $data) || !array_key_exists('card_order', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001,'登录失效'); + return $this->msg(20001); } unset($data['token']); - if(!array_key_exists('aud_id', $data) || !array_key_exists('card_order', $data)){ - return $this->msg(10001,'数据参数错误'); - } if(!$this->is_num_array(explode(',',$data['card_order']))){ - return $this->msg(10002,'数据内参数格式或值错误'); + return $this->msg(10001,'数据内参数格式或值错误'); } $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->update(['card_order'=>$data['card_order']]); if($result){ - return $this->msg(0,'success'); + return $this->msg([]); }else{ - return $this->msg(10003,'保存失败或未发生改变'); + return $this->msg(10002); } } + + public function get_grade_list(){ + $data = input(); + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if($this->token_time_validate($data['token']) === false){ + return $this->msg(20001); + } + return $this->msg($this->grade_list); + } ################################获取账号下信息操作################################ + // 获取账号下首页卡片的基础数据 public function get_user_card_data_list($data,$aud_id){ + $result = []; - $temporary_arr = []; + $db_arr = []; foreach ($data as $key => $value) { - $temporary_arr[$value] = Db::table($this->db_name[$value])->where(['aud_id'=>$aud_id])->order('id desc')->limit(1)->select(); + $db_arr[$value] = Db::table($this->db_name[$value])->where(['aud_id'=>$aud_id,'is_del'=>'0'])->order('id desc')->limit(1)->select(); + $db_arr[$value] = $db_arr[$value][0]; } - foreach ($temporary_arr as $key => $value) { - if(!array_key_exists($key, $this->card_data)){ - // dump($key.'====in'); - continue; - } - foreach ($value[0] as $k => $v) { - // dump($k); - if(in_array($k, $this->card_data[$key][1])){ - $result[$key][$k] = $v; + + foreach ($db_arr as $key => $value) { + $temporary_arr = []; + $temporary_arr['id'] = $value['id']; + $temporary_arr['acd_id'] = $value['acd_id']; + $temporary_arr['record_time'] = $value['record_time']; + // $temporary_arr['value'] = $value['record_time']; + $temporary_arr['card_name'] = $this->card_data[$value['acd_id']][0]; + $temporary_arr['inside_data'] = []; + if(array_key_exists($value['acd_id'],$this->card_data)){ + + foreach ($this->card_data[$value['acd_id']][2] as $k => $v) { + $tem_arr_2 = explode(',', $db_arr[$key][$k."_data"]); + array_push($temporary_arr['inside_data'],[ + 'key'=>$k, + 'name'=>$v[0], + 'value'=>$tem_arr_2[0], + 'unit'=>$v[1]!='无'?$v[1]:'', + 'standard'=>$tem_arr_2[1]!='无'?$tem_arr_2[1]:'', + 'color'=>$tem_arr_2[2]!='无'?$tem_arr_2[2]:'' + ]); } } - $result[$key]['name'] = $this->card_data[$key][0]; + array_push($result,$temporary_arr); } + return $result; - } + } + + ################################################################other################################################################ ################################################################other################################################################ @@ -213,9 +289,13 @@ class Index extends Base{ $parameter['birthday'] = $data['birthday']; $parameter['gender'] = $data['gender']; $parameter['grade'] = $data['grade']; + $parameter['card_order'] = '2,8'; $parameter['create_time'] = date('Y-m-d H:i:s'); $parameter['last_update_time'] = date('Y-m-d H:i:s'); - + $parameter_pd = Db::table('app_account_number')->where(['id'=>$parameter['aan_id']])->count(); + if($parameter_pd <= 0){ + return '该账户不存在'; + } $result = Db::table('app_user_data')->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id']])->count(); if($result>0){ return '该成员已存在'; diff --git a/application/app/controller/Vitalcapacity.php b/application/app/controller/Vitalcapacity.php index 8cdb13b..4435e19 100644 --- a/application/app/controller/Vitalcapacity.php +++ b/application/app/controller/Vitalcapacity.php @@ -147,25 +147,38 @@ class Vitalcapacity extends Base{ // return $result; } - - - - - - - ################################################################肺活量数据卡片接口################################################################ - ################################################################肺活量数据卡片接口################################################################ - // 记录肺活量数据 - public function vitalcapacity_data_set($data = ['aud_id'=>'11','acd_id'=>8,'times'=>[1991,2001,2024],'average'=>2005]){ + public function vitalcapacity_data_set($data = ['aud_id'=>'20','times'=>[1991,2001,2024],'token'=>'0dafb98a10995c98b5a33b7d59d986ca','record_time'=>"2024-05-08 11:49:21"]){ + if(count(input()) > 0){ + $data = input(); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('times', $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']); + $average_num = intval(array_sum($data['times'])/count($data['times'])); + + $user_msg = Db::name('app_user_data')->where(['id'=>$data['aud_id']])->field('grade,gender')->find(); + $str = "sex = ".$user_msg['gender']." and ".$user_msg['grade']." <= ".$average_num; + + $user_achievement = Db::name('pc_vitalcapacity_standard')->where("sex = ".$user_msg['gender']." and ".$user_msg['grade']." <= ".$average_num)->order($user_msg['grade'] .' desc')->limit(1)->select(); + $result = Db::name('app_card_vitalcapacity_data')->insert([ 'one'=>$data['times'][0], 'two'=>$data['times'][1], 'three'=>$data['times'][2], - 'average'=>$data['average'], + 'average'=>$average_num, + 'score'=>$user_achievement[0]['score'], + 'average_data'=>$average_num.','.$user_achievement[0]['level'].',无', 'aud_id'=>$data['aud_id'], - 'acd_id'=>$data['acd_id'], - 'create_time'=>date('Y-m-d H:i:s')]); + 'acd_id'=>8, + 'create_time'=>date('Y-m-d H:i:s'), + 'record_time'=>array_key_exists('record_time', $data)?$data['record_time']:date('Y-m-d H:i:s') + ]); + if($result){ return $this->msg(0,'success'); @@ -176,6 +189,15 @@ class Vitalcapacity extends Base{ } + + + + ################################################################肺活量数据卡片接口################################################################ + ################################################################肺活量数据卡片接口################################################################ + + + + ################################################################other################################################################ ################################################################other################################################################ ################################################################other################################################################ diff --git a/application/route.php b/application/route.php index 26034d4..0b2cdc8 100644 --- a/application/route.php +++ b/application/route.php @@ -56,6 +56,9 @@ Route::any('/get_user_data_information', 'app/index/get_user_data_information'); Route::any('/get_card_all_list', 'app/index/get_card_all_list'); // 保存用户的卡片排序 Route::any('/save_user_card_order', 'app/index/save_user_card_order'); +// 获取年级列表 +Route::any('/get_grade_list', 'app/index/get_grade_list'); + // ################################身体数据卡片接口################################ // 报告页详情 Route::any('/card_data_detailed', 'app/card/card_data_detailed'); @@ -63,6 +66,13 @@ Route::any('/card_data_detailed', 'app/card/card_data_detailed'); Route::any('/card_manual_recording', 'app/card/card_manual_recording'); // 获取所有记录接口 Route::any('/get_card_record_data', 'app/card/get_card_record_data'); +// 删除某个历史数据 +Route::any('/card_del_record_data', 'app/card/card_del_record_data'); + +// 曲线页面图表 +Route::any('/card_curve_chart', 'app/card/card_curve_chart'); +// 曲线页面底部目标 +Route::any('/card_curve_target', 'app/card/card_curve_target'); // ################################跳绳接口################################ // 查找设备 Route::any('/skip_device_check', 'app/skip/skip_device_check');