public function diethomeAction() { $p = $_REQUEST; $pDate = empty($p['date']) ? Tool_Fnc::ajaxMsg('日期不能为空') : trim($p['date']); if (!Tool_Validate::is_date($pDate)) { Tool_Fnc::ajaxMsg('日期不正确'); } $tFAMO = new R_FoodaddModel(); $tFMO = new FoodModel(); $tDWLMO = new DryweightlogModel(); $tDatas = array(); $tDWLRow['weight'] = $tDWLMO->is_dryweight($this->tUid, $pDate); $tArr = $tFMO->diet('protein', $tDWLRow['weight']); $tDatas['protein']['total'] = $tArr['start']; $tSql = 'select * from (select fid,unit,amount,weight from ' . $tFAMO->table . ' where uid = ' . $this->tUid . ' and created >=' . strtotime($pDate) . ' and created <=' . strtotime($pDate . ' 23:59:59') . ') fa, ' . $tFMO->table . ' f where fa.fid = f.id'; $tList = $tFMO->query($tSql); $tDatas['protein']['surplus'] = 0; $tDatas['protein']['number'] = 0; if (!count($tList)) { Tool_Fnc::ajaxMsg('', 1, $tDatas); } #已经摄取 foreach ($tList as $tRow) { $tDatas['protein']['number'] += $tRow['protein'] / 100 * $tRow['weight']; #蛋白质 } unset($tList); #应摄取 #蛋白质 $tSurplus = $tArr['end'] - $tDatas['protein']['number']; $tDatas['protein']['surplus'] = $tSurplus <= 0 ? 0 : $tSurplus; Tool_Fnc::ajaxMsg('', 1, $tDatas); exit; }
public function infoAction() { $p = $_REQUEST; $pDate = empty($p['date']) ? Tool_Fnc::ajaxMsg('日期不能为空') : trim($p['date']); if (!Tool_Validate::is_date($pDate)) { Tool_Fnc::ajaxMsg('日期不正确'); } $tTime = time(); $tDWLMO = new DryweightlogModel(); $tDWLRow['weight'] = $tDWLMO->is_dryweight($this->tUid, $pDate); #$tDWLRow = $tDWLMO->field('weight')->where('uid = ' . $this->tUid . ' and date = \''.$pDate.'\'')->fRow(); #if(!count($tDWLRow)){Tool_Fnc::ajaxMsg('干体重log不存在');} $tRWMO = new R_WeightModel(); $tDatas = $tRWMO->field('number,type')->where('uid = ' . $this->tUid . ' and date = \'' . $pDate . '\'')->fList(); foreach ($tDatas as $tKey => $tRow) { $tIncrease = number_format(($tRow['number'] - $tDWLRow['weight']) / $tDWLRow['weight'] * 100, 1); $tStatus = 0; #if($tIncrease >= 0 && $tIncrease < 3){$tStatus = 1;} if ($tIncrease < 3) { $tStatus = 1; } elseif ($tIncrease >= 3 && $tIncrease < 5) { $tStatus = 2; } elseif ($tIncrease >= 5 && $tIncrease < 8) { $tStatus = 3; } else { $tStatus = 4; } $tDatas[$tKey]['increase'] = $tIncrease; $tDatas[$tKey]['status'] = $tStatus; } Tool_Fnc::ajaxMsg('', 1, array('list' => $tDatas, 'dry_weight' => $tDWLRow['weight'])); exit; }