From bc9b3c21a58bcdbf15487dae296abdecacec4bbc Mon Sep 17 00:00:00 2001 From: tiansf Date: Wed, 22 May 2024 21:37:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0card=5Fmodify=5Fweight?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/app/controller/Card.php | 109 +++++++++++++++++++++++---- application/app/controller/Index.php | 54 ++++++++----- application/app/controller/Login.php | 20 +++-- application/route.php | 3 + 4 files changed, 140 insertions(+), 46 deletions(-) diff --git a/application/app/controller/Card.php b/application/app/controller/Card.php index 7feee92..c1cb8c1 100644 --- a/application/app/controller/Card.php +++ b/application/app/controller/Card.php @@ -76,8 +76,8 @@ class Card extends Base{ // 详细卡片信息 // $data = ['id'=>'2'] public function card_data_detailed($data=['aud_id'=>'11','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ @@ -94,8 +94,8 @@ 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']){ - if(count(input()) > 0){ - $data = input(); + 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); @@ -110,10 +110,9 @@ class Card extends Base{ // 手动记录 // $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']]){ public function card_manual_recording($data = ['aud_id'=>'25','time'=>'2024-04-11 10:10:15','height'=>'165.3','weight'=>'66.1','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } 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)){ @@ -127,10 +126,26 @@ class Card extends Base{ return $this->set_user_body_data($data); } + // 修改初始体重/目标体重 + public function card_modify_weight($data = ['aud_id'=>'25','data'=>'25','type'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('data', $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->modify_weight_action($data); + } + // 获取记录信息列表 public function get_card_record_data($data = ['aud_id'=>'11','s_time'=>'2024-04-01 10:10:10','e_time'=>'2024-06-12 10:10:10','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input()) > 0){ - $data = input(); + 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)){ @@ -146,8 +161,8 @@ class Card extends Base{ } // 删除历史数据 public function card_del_record_data($data = ['id'=>'16','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); @@ -166,8 +181,8 @@ class Card extends Base{ // 数据对比 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(count(input('post.')) > 0){ + $data = input('post.'); } 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); @@ -193,7 +208,7 @@ class Card extends Base{ ->alias('acbd') ->join('app_user_data aud','acbd.aud_id = aud.id','LEFT') ->where(['acbd.aud_id'=>$data['aud_id']]) - ->order('record_time desc') + ->order('acbd.record_time desc') ->field('acbd.*,aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date') ->find(); if(!$result){ @@ -324,10 +339,26 @@ class Card extends Base{ public function set_user_body_data($data){ $data['type'] = 1; - $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('birthday,gender')->find(); + $user_data = Db::table('app_user_data')->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('app_user_data')->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']); @@ -373,7 +404,13 @@ class Card extends Base{ 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']]); + 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{ @@ -459,6 +496,46 @@ class Card extends Base{ return $data; // dump($data); } + + + ################################################card_modify_weight + public function modify_weight_action($data){ + + $result = Db::query(" + select + TOP 1 + acbd.weight, + 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']." + order by acbd.record_time desc + "); + // $result = Db::table('app_card_body_data')->where(['id'=>$data['aud_id']])->order('record_time desc')->field('weight')->find(); + if($data['type'] == 1){ + // 修改目标体重 + $bhw_date = ['target_weight'=>$data['data']]; + }else if($data['type'] == 2){ + // 修改原始体重 + $bhw_date = ['initial_weight'=>$data['data'],'initial_date' => $data['time']]; + } + $result_update = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->update($bhw_date); + if($result_update){ + $target_current = $this->base_target_initial_cumulative_weight([ + 'weight'=>$result['weight'], + 'target_weight'=>$data['type'] == 1?$data['data']:$result[0]['target_weight'], + 'initial_weight'=>$data['type'] == 2?$data['data']:$result[0]['initial_weight'], + 'initial_date'=>$data['type'] == 2?$data['time']:$result[0]['initial_date'], + ]); + return $this->msg($target_current); + }else{ + return $this->msg(10002); + } + + } + ################################################get_card_record_data // 获取历史数据记录信息列表 public function get_all_record_data($data){ diff --git a/application/app/controller/Index.php b/application/app/controller/Index.php index a443a1a..33da4a5 100644 --- a/application/app/controller/Index.php +++ b/application/app/controller/Index.php @@ -56,8 +56,8 @@ class Index extends Base{ // } // 创建用户 public function create_user_data($data = ['aan_id'=>66,'nickname'=>'王小二','birthday'=>'2019-01-01','gender'=>1,'grade'=>'二年级','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } if(!array_key_exists('token', $data)){ return $this->msg(10001); @@ -81,8 +81,8 @@ class Index extends Base{ // 获取账号下用户列表 // $type 1获取列表,2获取详细信息 public function get_user_card_list($data = ['aan_id'=>66,'type'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } if(!array_key_exists('token', $data) || !array_key_exists('aan_id', $data) || !array_key_exists('type', $data)){ return $this->msg(10001); @@ -107,19 +107,17 @@ class Index extends Base{ // 获取指定用户详细信息 public function get_user_data_information($data = ['aud_id'=>25,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){ return $this->msg(10001); } - if($this->token_time_validate($data['token']) === false){ return $this->msg(20001); } unset($data['token']); - $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,aan_id,nickname,head_pic,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,target_weight,initial_weight,initial_date')->find(); if(!$result){ return $this->msg(10003); } @@ -128,24 +126,31 @@ class Index extends Base{ if($result['card_order'] === ''){ $result['card_order'] = []; $result['card_data_list'] = []; + $result['target_current'] = $this->base_target_initial_cumulative_weight([]); }else{ $result['card_order'] = explode(',',$result['card_order']); - $result['card_data_list'] = $this->get_user_card_data_list($result['card_order'],$result['id']); + $calculation_results = $this->get_user_card_data_list($result,$result['id']); + $result['card_data_list'] = $calculation_results[0]; + $result['target_current'] = $calculation_results[1]; } // base_target_initial_cumulative_weight - // 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']); } + unset($result['target_weight']); + unset($result['initial_weight']); + unset($result['initial_date']); + // dump($result); + // die; return $this->msg($result); } // 获取所有卡片列表信息 public function get_card_all_list($data = ['aud_id'=>11,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } if(!array_key_exists('token', $data)){ return $this->msg(10001); @@ -177,8 +182,8 @@ class Index extends Base{ // 保存用户的卡片排序 public function save_user_card_order($data=['aud_id'=>11,'card_order'=>'2,8','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } if(!array_key_exists('aud_id', $data) || !array_key_exists('card_order', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); @@ -200,7 +205,7 @@ class Index extends Base{ } public function get_grade_list(){ - $data = input(); + $data = input('post.'); if(!array_key_exists('token', $data)){ return $this->msg(10001); } @@ -218,7 +223,7 @@ class Index extends Base{ $result = []; $db_arr = []; - foreach ($data as $key => $value) { + foreach ($data['card_order'] as $key => $value) { $db_arr[$value] = Db::table($this->db_name[$value])->where(['aud_id'=>$aud_id,'is_del'=>'0'])->order('id desc')->limit(1)->select(); // dump($db_arr[$value]); @@ -228,6 +233,17 @@ class Index extends Base{ unset($db_arr[$value]); } } + // 添加目标体重于当前体重差数据 + if($data['initial_date'] == null){ + $target_current = $this->base_target_initial_cumulative_weight([]); + }else{ + $target_current = $this->base_target_initial_cumulative_weight([ + 'weight'=>$db_arr['2']['weight'], + 'target_weight'=>$data['target_weight'], + 'initial_weight'=>$data['initial_weight'], + 'initial_date'=>$data['initial_date'], + ]); + } if(count($db_arr) <= 0){ // 没有数据,传递一个空的卡片 @@ -294,7 +310,7 @@ class Index extends Base{ } // dump($result); // die; - return $result; + return [$result,$target_current]; } diff --git a/application/app/controller/Login.php b/application/app/controller/Login.php index 7c8e879..5825cec 100644 --- a/application/app/controller/Login.php +++ b/application/app/controller/Login.php @@ -21,8 +21,8 @@ class Login extends Base{ // dump('123'); // phpinfo(); // die; - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } $verify_result = $this->verify_parameters($data,'register'); if(!is_array($verify_result)){ @@ -41,8 +41,8 @@ class Login extends Base{ } // 重置密码 public function reset_password($data = ['data'=>'18530934717','password'=>'ceshi1','c_password'=>'ceshi1','code'=>'491661']){ - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){ return $this->msg(10001); @@ -74,11 +74,9 @@ class Login extends Base{ // 登录 public function login_action($data = ['data'=>'18530934717','validate_data'=>'746119','type'=>'login','validate_type'=>'code']){ - - if(count(input()) > 0){ - $data = input(); + if(count(input('post.')) > 0){ + $data = input('post.'); } - if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){ return $this->msg(10001); } @@ -132,9 +130,9 @@ class Login extends Base{ * $road(是手机还是邮箱还是其他) 字符串 默认tel或email */ public function send_phone_email_code($data = ['data'=>'18530934717','type'=>'login']){ - // $data = input(); - if(count(input()) > 0){ - $data = input(); + // $data = input('post.'); + if(count(input('post.')) > 0){ + $data = input('post.'); } if(!array_key_exists('data', $data) || !array_key_exists('type', $data)){ return $this->msg(10001); diff --git a/application/route.php b/application/route.php index 756e4e9..b1f4996 100644 --- a/application/route.php +++ b/application/route.php @@ -64,6 +64,9 @@ Route::any('/get_grade_list', 'app/index/get_grade_list'); Route::any('/card_data_detailed', 'app/card/card_data_detailed'); // 手动记录接口 Route::any('/card_manual_recording', 'app/card/card_manual_recording'); +// 修改初始体重/目标体重 +Route::any('/card_modify_weight', 'app/card/card_modify_weight'); + // 获取所有记录接口 Route::any('/get_card_record_data', 'app/card/get_card_record_data'); // 删除某个历史数据