Exemple #1
0
 public function editAction()
 {
     $p = $_REQUEST;
     $pId = empty($p['id']) ? Tool_Fnc::ajaxMsg('请选择食物') : 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']);
     $tTime = time();
     $tFMO = new FoodModel();
     $tFRow = $tFMO->field('title,protein,thumb_img')->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('餐类型不存在');
     }
     $tRFDMO = new R_FoodaddModel();
     $tRFRow = $tRFDMO->field('count(*) c')->where(' id =' . $pId)->fRow();
     if (empty($tRFRow['c'])) {
         Tool_Fnc::ajaxMsg('操作异常');
     }
     $tData = array('id' => $pId, 'title' => $tFRow['title'], 'unit' => $pUnit, 'amount' => $pAmount, 'weight' => $pWeight, 'mt_id' => $pMtid, 'mt_name' => $tMTRow['name'], 'created' => $tTime, 'fid' => $pFid, 'uid' => $this->tUid, 'thumb_img' => $tFRow['thumb_img'], 'protein' => $tFRow['protein'] / 100 * $pWeight);
     if (!$tRFDMO->update($tData)) {
         Tool_Fnc::ajaxMsg('更新失败');
     }
     Tool_Fnc::ajaxMsg('更新成功', 1);
 }
Exemple #2
0
 public function searchAction()
 {
     $p = $_REQUEST;
     $pKeyword = empty($p['keyword']) ? Tool_Fnc::ajaxMsg('请填写关键词') : Tool_Fnc::safe_string($p['keyword']);
     $tMO = new FoodModel();
     $tImgUrl = Yaf_Registry::get("config")->web->url->img;
     $tDatas = $tMO->field('id fid,title,c_id cateid,c_title cate_title, concat(\'' . $tImgUrl . '\',thumb_img) thumb_img ,tag,protein')->where('title like "%' . $pKeyword . '%"')->fList();
     $tFUMO = new FoodunitsModel();
     foreach ($tDatas as $tKey => $tRow) {
         $tUnits = $tFUMO->field('amount,unit,weight')->where('fid  = ' . $tRow['fid'])->fList();
         $tDatas[$tKey]['units'] = $tUnits;
     }
     Tool_Fnc::ajaxMsg('', 1, $tDatas);
 }
Exemple #3
0
 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);
 }
Exemple #4
0
 public function foodAction()
 {
     $p = $_REQUEST;
     $pKey = empty($p['term']) ? '' : Tool_Fnc::safe_string($p['term']);
     $tMO = new FoodModel();
     if (!empty($pKey)) {
         $tWhere = 'title like "%' . $pKey . '%"';
     }
     if (!empty($pKey)) {
         $tDatas = $tMO->field('id,title,thumb_img')->where($tWhere)->limit(5)->fList();
     } else {
         $tDatas = $tMO->field('id,title,thumb_img')->limit(5)->fList();
     }
     Yaf_Dispatcher::getInstance()->autoRender(FALSE);
     die(json_encode($tDatas));
 }
Exemple #5
0
 public function addfoodAction()
 {
     $p = $_REQUEST;
     $pFid = empty($p['id']) ? Tool_Fnc::ajaxMsg('错误异常 001') : intval($p['id']);
     $tFMO = new FoodModel();
     $tRow = $tFMO->field('id,title,tag,protein,thumb_img')->where('id =' . $pFid)->fRow();
     $tRow['protein'] = floatval($tRow['protein']) / 100;
     $tFUMO = new FoodunitsModel();
     $tUnit = $tFUMO->field('id,amount,unit,weight,calory')->where(' fid = ' . $pFid)->fList();
     $tMTMO = new MealtypeModel();
     $pType = $tMTMO->field('id,name')->fList();
     $this->assign('tRow', $tRow);
     $this->assign('pUnit', $tUnit);
     $this->assign('pType', $pType);
 }
Exemple #6
0
 public function delAction()
 {
     $p = $_REQUEST;
     $pId = empty($p['id']) ? die('ID不能为空') : floatval($p['id']);
     $tMO = new FoodModel();
     $tRow = $tMO->field('large_img,thumb_img')->where('id = ' . $pId)->fRow();
     $tSql = 'delete from ' . $tMO->table . ' where id=' . $pId;
     if (!$tMO->exec($tSql)) {
         Tool_Fnc::ajaxMsg('删除失败');
     }
     if (!empty($tRow['large_img'])) {
         unlink(APPLICATION_PATH . '/public' . $tRow['large_img']);
     }
     if (!empty($tRow['thumb_img'])) {
         unlink(APPLICATION_PATH . '/public' . $tRow['thumb_img']);
     }
     $tFT = new FoodtagModel();
     $tSql = "delete from " . $tFT->table . " where fid =" . $pId;
     $tFT->exec($tSql);
     Tool_Fnc::ajaxMsg('删除成功', 1);
 }