作者 潘浩文

个人中心接口

@@ -243,23 +243,25 @@ class SignController extends RestBaseController @@ -243,23 +243,25 @@ class SignController extends RestBaseController
243 //用户信息 243 //用户信息
244 $user=Db::name('user')->where('id',$this->getUserId())->find(); 244 $user=Db::name('user')->where('id',$this->getUserId())->find();
245 //判断是否是第一次周打卡 245 //判断是否是第一次周打卡
246 - $re=Db::name('user_week_sign')->where('user_id',$user['id'])->find(); 246 + $re=Db::name('user_week_sign')->where('user_id',$user['id'])->order('create_time','desc')->find();
247 if (!$re){ 247 if (!$re){
248 - $param['pregnant_week']=$user['pregnant_week'];  
249 - $param['day']=ceil((time()-$user['register_time'])/(60*60*21));  
250 $param['weight']=$user['before_weight']; 248 $param['weight']=$user['before_weight'];
251 $paramService=new ParamService(); 249 $paramService=new ParamService();
252 - 250 + $param['status']=$paramService->status($user['before_weight'],$user['height']);
  251 + $param['increase']=0;
  252 + $param['overplus']=$paramService->overplus($user['before_weight'],$user['height']);
  253 + }else{
  254 + $param['weight']=$re['weight'];
  255 + $param['increase']=$re['weight']-$user['before_weight'];
  256 + $paramService=new ParamService();
  257 + $param['overplus']=$paramService->overplus($user['before_weight'],$user['height'])-($re['weight']-$user['before_weight']);
  258 + $record=Db::name('user_week_sign')->where('user_id',$user['id'])->select();
253 } 259 }
  260 + $param['day']=ceil((time()-$user['register_time'])/(60*60*21));
  261 + $param['pregnant_week']=$user['pregnant_week'];
254 //返回 262 //返回
255 $this->success('日打卡信息',array( 263 $this->success('日打卡信息',array(
256 - 'all'=>$user['all_sign_day'],  
257 - 'last'=>$user['stay_sign_day'],  
258 - 'longest'=>$user['longest_sign_day'],  
259 - 'morning'=>$daySign['morning'],  
260 - 'noon'=>$daySign['noon'],  
261 - 'night'=>$daySign['night'],  
262 - 'sleep'=>$daySign['sleep'], 264 + $param,$record
263 )); 265 ));
264 } 266 }
265 } 267 }
@@ -27,4 +27,30 @@ class ParamService @@ -27,4 +27,30 @@ class ParamService
27 } 27 }
28 return $status; 28 return $status;
29 } 29 }
  30 +
  31 + public function overplus($weight=0,$height=0){
  32 + $bmi=$weight/pow(($height/100),2);
  33 + if($bmi<18.5){
  34 + $overplus=18;
  35 + }elseif (18.5<=$bmi&&$bmi<=24.9){
  36 + $overplus=16;
  37 + }elseif (25<$bmi){
  38 + $overplus=11.5;
  39 + }
  40 + return $overplus;
  41 + }
  42 +
  43 + public function allIncrease($weight=0,$height=0){
  44 + $bmi=$weight/pow(($height/100),2);
  45 + if($bmi<=18.5){
  46 + $status='消瘦';
  47 + }elseif (18.5<$bmi&&$bmi<=23.9){
  48 + $status='正常';
  49 + }elseif (24<$bmi&&$bmi<=27.9){
  50 + $status='超重';
  51 + }elseif ($bmi>=28){
  52 + $status='肥胖';
  53 + }
  54 + return $status;
  55 + }
30 } 56 }