Ejemplo n.º 1
0
 public function editAction()
 {
     $p = $_REQUEST;
     $pId = empty($p['id']) ? die('id不能为空') : intval($p['id']);
     $tTP = new MealtypeModel();
     $pType = $tTP->field('id,name')->fList();
     $this->assign('pType', $pType);
     $tDR = new DailyrecipesModel();
     $tRow = $tDR->where(' id = ' . $pId)->fRow();
     $this->assign('tRow', $tRow);
     $tFU = new FoodunitsModel();
     $pUnit = $tFU->field('id,amount,unit,weight,calory')->where(' fid = ' . $tRow['fid'])->fList();
     $this->assign('pUnit', $pUnit);
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $pMid = empty($p['mt_id']) ? Tool_Fnc::ajaxMsg('请选择餐类型') : intval($p['mt_id']);
         $tTRow = $tTP->field('id,name')->where(" id = " . $pMid)->fRow();
         $pFid = empty($p['fid']) ? Tool_Fnc::ajaxMsg('食物id不能为空') : intval($p['fid']);
         $pTitle = empty($p['title']) ? Tool_Fnc::ajaxMsg('食物名称不能为空') : Tool_Fnc::safe_string($p['title']);
         $pDaydate = empty($p['day_date']) ? Tool_Fnc::ajaxMsg('日期不能为空') : Tool_Fnc::safe_string($p['day_date']);
         $pDaydate = date('Y-m-d', strtotime($pDaydate));
         $pAmount = empty($p['amount']) ? Tool_Fnc::ajaxMsg('数量不能为空') : floatval($p['amount']);
         $pProtein = empty($p['protein']) ? Tool_Fnc::ajaxMsg('蛋白质不能为空') : floatval($p['protein']);
         $pWeight = empty($p['weight']) ? Tool_Fnc::ajaxMsg('重量不能为空') : intval($p['weight']);
         $pUid = empty($p['unit']) ? Tool_Fnc::ajaxMsg('单位不能为空') : intval($p['unit']);
         $pUnit = $pUid === 999999 ? '两' : '克';
         $tFU = new FoodunitsModel();
         $pUnits = $tFU->field('amount,unit,weight,calory')->where(' id = ' . $pUid)->fRow();
         if (!empty($pUnits['unit'])) {
             $pUnit = $pUnits['unit'];
             $pWeight = $pAmount * floatVal($pUnits['weight']);
         }
         $pTag = empty($p['tag']) ? '' : Tool_Fnc::safe_string($p['tag']);
         $tTime = time();
         $tData = array('id' => $pId, 'fid' => $pFid, 'title' => $pTitle, 'day_date' => $pDaydate, 'protein' => $pProtein, 'amount' => $pAmount, 'unit' => $pUnit, 'weight' => $pWeight, 'tag' => $pTag, 'thumb_img' => $p['thumb_img'], 'updated' => $tTime, 'mt_id' => $tTRow['id'], 'mt_name' => $tTRow['name']);
         $tDRM = new DailyrecipesModel();
         if (!$tDRM->update($tData)) {
             Tool_Fnc::ajaxMsg('修改失败');
         }
         Tool_Fnc::ajaxMsg('修改成功', 1);
     }
 }