コード例 #1
0
ファイル: Food.php プロジェクト: tanqinwang/test_own
 public function editAction()
 {
     $p = $_REQUEST;
     $pId = empty($p['id']) ? Tool_Fnc::ajaxMsg('操作错误 001') : intval($p['id']);
     $pFid = empty($p['fid']) ? Tool_Fnc::ajaxMsg('食物ID不能为空') : intval($p['fid']);
     $pUnit = empty($p['unit']) ? Tool_Fnc::ajaxMsg('单位不能为空') : Tool_Fnc::safe_string($p['unit']);
     $pAmount = empty($p['amount']) ? Tool_Fnc::ajaxMsg('数量不能为空') : floatval($p['amount']);
     $pWeight = empty($p['weight']) ? Tool_Fnc::ajaxMsg('重量不能为空') : floatval($p['weight']);
     $pMtid = empty($p['mt_id']) ? Tool_Fnc::ajaxMsg('餐类型不能为空') : intval($p['mt_id']);
     $pDid = empty($p['did']) ? Tool_Fnc::ajaxMsg('DID不能为空') : trim($p['did']);
     $tTime = time();
     if (!Tool_Validate::az09($pDid)) {
         Tool_Fnc::ajaxMsg('did格式不正确');
     }
     $tFMO = new FoodModel();
     $tFRow = $tFMO->field('title,tag,thumb_img,protein')->where('id = ' . $pFid)->fRow();
     if (!count($tFRow)) {
         Tool_Fnc::ajaxMsg('食物不存在');
     }
     $tMTMO = new MealtypeModel();
     $tMTRow = $tMTMO->field('name')->where('id = ' . $pMtid)->fRow();
     if (!count($tMTRow)) {
         Tool_Fnc::ajaxMsg('餐类型不存在');
     }
     $tIFDMO = new I_FoodaddModel();
     $tData = array('title' => $tFRow['title'], 'tag' => $tFRow['tag'], 'thumb_img' => $tFRow['thumb_img'], 'unit' => $pUnit, 'amount' => $pAmount, 'weight' => $pWeight, 'mt_id' => $pMtid, 'mt_name' => $tMTRow['name'], 'fid' => $pFid, 'did' => $pDid, 'protein' => $tFRow['protein'] / 100 * $pWeight);
     $tIFDRow = $tIFDMO->field('id')->where(' id = ' . $pId . ' and did = \'' . $pDid . '\' and mt_id = ' . $pMtid)->fRow();
     if (!empty($tIFDRow['id'])) {
         $tData = array_merge($tData, array('updated' => $tTime, 'id' => $tIFDRow['id']));
         if (!$tIFDMO->update($tData)) {
             Tool_Fnc::ajaxMsg('操作失败 002');
         }
     } else {
         $tData = array_merge($tData, array('created' => $tTime));
         if (!$tIFDMO->insert($tData)) {
             Tool_Fnc::ajaxMsg('操作失败 003');
         }
     }
     Tool_Fnc::ajaxMsg('操作成功', 1);
 }