示例#1
0
 public function daily_recipesAction()
 {
     $tDate = date('Y-m-d');
     $tMO = new DailyrecipesModel();
     $tRow = $tMO->field('day_date')->group('day_date')->order('day_date desc')->limit('1')->fRow();
     if (!empty($tRow['day_date'])) {
         $tDate = $tRow['day_date'];
     }
     $tFUMO = new FoodunitsModel();
     $tImgUrl = Yaf_Registry::get("config")->web->url->img;
     $tDatas = $tMO->field('mt_name,mt_id,title,unit,amount,weight,fid,tag, concat(\'' . $tImgUrl . '\',thumb_img) thumb_img,protein')->where('day_date = \'' . $tDate . '\'')->order('mt_id asc')->fList();
     $tDatasnew = array();
     foreach ($tDatas as $tRow) {
         $tUnits = $tFUMO->field('amount,unit,weight')->where('fid  = ' . $tRow['fid'])->fList();
         $tDatasnew[$tRow['mt_id']][] = array_merge($tRow, array('units' => $tUnits));
     }
     Tool_Fnc::ajaxMsg('', 1, $tDatasnew);
 }
示例#2
0
 public function delAction()
 {
     $p = $_REQUEST;
     $pId = empty($p['id']) ? Tool_Fnc::ajaxMsg('ID不能为空') : intval($p['id']);
     $tDR = new FoodunitsModel();
     $tSql = 'delete from ' . $tDR->table . ' where id = ' . $pId;
     if (!$tDR->exec($tSql)) {
         Tool_Fnc::ajaxMsg('删除失败');
     }
     Tool_Fnc::ajaxMsg('删除成功', 1);
 }
示例#3
0
 public function listAction()
 {
     $p = $_REQUEST;
     $pDate = empty($p['date']) ? Tool_Fnc::ajaxMsg('日期不能为空') : trim($p['date']);
     if (!Tool_Validate::is_date($pDate)) {
         Tool_Fnc::ajaxMsg('日期不正确');
     }
     $tImgUrl = Yaf_Registry::get("config")->web->url->img;
     $tFAMO = new R_FoodaddModel();
     $tFUMO = new FoodunitsModel();
     $tFADatas = $tFAMO->field('id,fid,mt_id,mt_name,title,unit,amount,weight,protein,tag,concat(\'' . $tImgUrl . '\',thumb_img) thumb_img')->where('uid = ' . $this->tUid . ' and created >=' . strtotime($pDate) . ' and created <=' . strtotime($pDate . ' 23:59:59'))->fList();
     $tDatas = array();
     foreach ($tFADatas as $tKey => $tRow) {
         $tUnits = $tFUMO->field('amount,unit,weight')->where('fid  = ' . $tRow['fid'])->fList();
         #$tFADatas[$tKey]['units'] = $tUnits;
         $tDatas[$tRow['mt_id']][] = array_merge($tRow, array('units' => $tUnits));
     }
     Tool_Fnc::ajaxMsg('', 1, $tDatas);
 }
示例#4
0
 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);
 }
示例#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);
 }
示例#6
0
 public function indexAction()
 {
     exit;
     #$db = new SQLite3('/home/zhangyueru/data/www/dakang_www/shell/foods.db');
     #$res = $db->query('select * from foods');
     #$data = $db->fetchArray($res);
     #print_r($data);
     #
     header('Content-type:text/html;charset=utf-8');
     $tFMO = new FoodModel();
     $tFUMO = new FoodunitsModel();
     $tFTMO = new FoodtagModel();
     $tSqlite = new Orm_Sqlite('/home/zhangyueru/data/www/dakang_www/shell/food.db');
     $res = $tSqlite->query('select a.*,s.name ctitle  from (select fd.thumb_image_url,fd.large_image_url,fd.ingredient,lights,cate_id,fd.name,fd.units from foods f, food_detail fd where f.id = fd.parent_id) a,categories s where a.cate_id = s.id');
     $ii = 0;
     while ($tRow = $res->fetchArray()) {
         $tTime = time();
         $ii++;
         $large_image_url = '';
         $thumb_image_url = '';
         if (!empty($tRow['thumb_image_url']) && $tRow['thumb_image_url'] != 'null') {
             $thumb_image_url = '/foodimg/small/' . $tTime . '_' . rand(1000, 99999) . '.jpg';
             $this->saveimg($tRow['thumb_image_url'], $thumb_image_url);
             echo 'thumb';
         }
         if (!empty($tRow['large_image_url']) && $tRow['large_image_url'] != 'null') {
             $large_image_url = '/foodimg/' . $tTime . '_' . rand(1000, 99999) . '.jpg';
             $this->saveimg($tRow['large_image_url'], $large_image_url);
             echo 'large';
         }
         $i = json_decode($tRow['ingredient'], true);
         $l = json_decode($tRow['lights'], true);
         $tTag = array();
         foreach ($l as $tKey => $tVal) {
             if (empty($tVal)) {
                 continue;
             }
             $tTag[$tKey] = $tVal;
         }
         $tTag = implode('|', $tTag);
         $i['calcium'] = empty($i['calcium']) ? 0 : $i['calcium'];
         $i['vitamin_a'] = empty($i['vitamin_a']) ? 0 : $i['vitamin_a'];
         $i['zinc'] = empty($i['zinc']) ? 0 : $i['zinc'];
         $i['magnesium'] = empty($i['magnesium']) ? 0 : $i['magnesium'];
         $i['vitamin_c'] = empty($i['vitamin_c']) ? 0 : $i['vitamin_c'];
         $i['fiber_dietary'] = empty($i['fiber_dietary']) ? 0 : $i['fiber_dietary'];
         $i['selenium'] = empty($i['selenium']) ? 0 : $i['selenium'];
         $i['copper'] = empty($i['copper']) ? 0 : $i['copper'];
         $i['carbohydrate'] = empty($i['carbohydrate']) ? 0 : $i['carbohydrate'];
         $i['phosphor'] = empty($i['phosphor']) ? 0 : $i['phosphor'];
         $i['fat'] = empty($i['fat']) ? 0 : $i['fat'];
         $i['niacin'] = empty($i['niacin']) ? 0 : $i['niacin'];
         $i['vitamin_e'] = empty($i['vitamin_e']) ? 0 : $i['vitamin_e'];
         $i['manganese'] = empty($i['manganese']) ? 0 : $i['manganese'];
         $i['cholesterol'] = empty($i['cholesterol']) ? 0 : $i['cholesterol'];
         $i['iron'] = empty($i['iron']) ? 0 : $i['iron'];
         $i['kalium'] = empty($i['kalium']) ? 0 : $i['kalium'];
         $i['natrium'] = empty($i['natrium']) ? 0 : $i['natrium'];
         $i['thiamine'] = empty($i['thiamine']) ? 0 : $i['thiamine'];
         $i['protein'] = empty($i['protein']) ? 0 : $i['protein'];
         $i['lactoflavin'] = empty($i['lactoflavin']) ? 0 : $i['lactoflavin'];
         $i['calory'] = empty($i['calory']) ? 0 : $i['calory'];
         $i['carotene'] = empty($i['carotene']) ? 0 : $i['carotene'];
         $tSql = 'insert into food values("%s","%s",%d,%d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,"%s","%s",%s,"%s","%s")';
         $tSql = sprintf($tSql, '', $tRow['name'], $tTime, 0, $i['calcium'], $i['vitamin_a'], $i['zinc'], $i['magnesium'], $i['vitamin_c'], $i['fiber_dietary'], $i['selenium'], $i['copper'], $i['carbohydrate'], $i['phosphor'], $i['fat'], $i['niacin'], $i['vitamin_e'], $i['manganese'], $i['cholesterol'], $i['iron'], $i['kalium'], $i['natrium'], $i['thiamine'], $i['protein'], $i['lactoflavin'], $i['calory'], $i['carotene'], $tTag, $thumb_image_url, $tRow['cate_id'], $tRow['ctitle'], $large_image_url);
         $tFid = $tFMO->exec($tSql);
         foreach ($l as $tKey => $tVal) {
             if (empty($tVal)) {
                 continue;
             }
             $tData = array('title' => $tKey, 'fid' => $tFid, 'flag' => $tVal);
             $tFTMO->insert($tData);
         }
         $tUnitsArr = json_decode($tRow['units'], true);
         foreach ($tUnitsArr as $tURow) {
             $tData = array('amount' => $tURow['amount'], 'unit' => $tURow['unit'], 'fid' => $tFid, 'calory' => $tURow['calory'], 'weight' => $tURow['weight']);
             $tFUMO->insert($tData);
         }
         echo $ii . "\r\n";
     }
     die;
 }