public function normalAction() { $p = $_REQUEST; $tFMO = new FoodModel(); $tImgUrl = Yaf_Registry::get("config")->web->url->img; $tSql = 'select id fid,title,c_id cateid,c_title cate_title, concat(\'' . $tImgUrl . '\',thumb_img) thumb_img ,tag,protein from ' . $tFMO->table . ' where suggest = 1 order by count desc,protein desc'; $tDRDatas = $tFMO->query($tSql); $tFUMO = new FoodunitsModel(); foreach ($tDRDatas as &$v) { $v['units'] = $tFUMO->field('unit,amount,weight')->where(' fid = ' . $v['fid'])->fList(); } Tool_Fnc::ajaxMsg('', 1, $tDRDatas); }
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 diethomeAction() { $p = $_REQUEST; $pDate = empty($p['date']) ? Tool_Fnc::ajaxMsg('日期不能为空') : trim($p['date']); $pDid = empty($p['did']) ? Tool_Fnc::ajaxMsg('DID不能为空') : trim($p['did']); if (!Tool_Validate::az09($pDid)) { Tool_Fnc::ajaxMsg('did格式不正确'); } if (!Tool_Validate::is_date($pDate)) { Tool_Fnc::ajaxMsg('日期不正确'); } $tFAMO = new I_FoodaddModel(); $tFMO = new FoodModel(); $tDatas = array(); $tSql = 'select * from (select fid,unit,amount,weight from ' . $tFAMO->table . ' where did = \'' . $pDid . '\' 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'] = array('total' => 90, 'surplus' => 0, 'number' => 0); if (!count($tList)) { Tool_Fnc::ajaxMsg('', 1, $tDatas); } #已经摄取 foreach ($tList as $tRow) { $tDatas['protein']['number'] += $tRow['protein'] / 100 * $tRow['weight']; #蛋白质 } unset($tList); $tDatas['protein']['total'] = 90; $tDatas['protein']['surplus'] = 90 - $tDatas['protein']['number']; Tool_Fnc::ajaxMsg('', 1, $tDatas); exit; }