function CreateFoodTables($types)
 {
     $foodModel = new FoodModel();
     $foodArray = $foodModel->GetFoodByType($types);
     $result = "";
     foreach ($foodArray as $key => $food) {
         $result = $result . "<table class = 'foodTable'>\n                        <tr>\n                            <th rowspan='6' width = '150px' ><img runat = 'server' src = '{$food->FoodImg}' /></th>\n                            \n                            \n                            <th width = '75px' >FoodId : </th>\n                            <td>{$food->FoodId}</td>\n                        </tr>\n                          \n                        <tr>\n                            <th width = '75px' >Name : </th>\n                            <td>{$food->FoodName}</td>\n                        </tr>\n                        \n                        <tr>\n                            <th>Type : </th>\n                            <td>{$food->FoodType}</td>\n                        </tr>\n                        \n                        <tr>\n                            <th>Price : </th>\n                            <td>{$food->Price}</td>\n                        </tr>\n                        \n                    \n                        \n                                         \n                     </table>";
     }
     return $result;
 }
Exemple #2
0
 public function orderAction()
 {
     $orderId = $this->getRequest()->getRequest('order_id');
     $FoodOrderModel = FoodOrderModel::getInstance();
     if ($orderId) {
         $foodList = FoodModel::getInstance()->fetchToDataFlow(array());
         $foodOrderList = $FoodOrderModel->fetchToDataFlow(array('_id' => $orderId));
         // 关联的餐厅
         $relatedRestaurantList = [];
         // 最终订单的数据结构
         $orderList = [];
         /**
         * {
                     {restaurantId}: {
         *          {foodId}: {count}
         *      }
         * }
         *
         */
         foreach ($foodOrderList[$orderId]['foods'] as $food) {
             $tmpFoodId = $food['food_id'];
             $tmpCount = $food['count'];
             $tmpRestaurant = $foodList[$food['food_id']]['restaurant'];
             $relatedRestaurantList[] = $tmpRestaurant;
             if (isset($orderList[$tmpRestaurant])) {
                 if (isset($orderList[$tmpRestaurant][$tmpFoodId])) {
                     $orderList[$tmpRestaurant][$tmpFoodId] = $tmpCount;
                 }
             } else {
                 $orderList[$tmpRestaurant] = array($tmpFoodId => $tmpCount);
             }
         }
         RestaurantModel::getInstance()->fetchToDataFlow(array('_id' => array('$in' => $relatedRestaurantList)));
         $this->dataFlow->toFlow(array('FOID' => $orderId, 'orderId' => $orderId, 'orderList' => $orderList, 'prevOrderId' => $FoodOrderModel->getPrevOrderId($orderId), 'nextOrderId' => $FoodOrderModel->getNextOrderId($orderId), 'orderTime' => round(intval($foodOrderList[$orderId]['create_time']->__toString()) / 1000)));
         $this->response();
     } else {
         throw new Exception('缺少订单id');
     }
 }
Exemple #3
0
 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;
 }
Exemple #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);
 }
Exemple #5
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 #6
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 #7
0
 /**
  * 订单
  */
 public function orderAction()
 {
     $foodList = FoodModel::getInstance()->fetchToDataFlow(array());
     $groupOrderNo = $this->getRequest()->getRequest('group_order_no');
     $GroupOrderModel = GroupOrderModel::getInstance();
     if ($groupOrderNo) {
         $groupOrderNo = intval($groupOrderNo);
         $GroupOrderModel->fetchToDataFlow(array('order_no' => $groupOrderNo));
         $foodOrderList = FoodOrderModel::getInstance()->fetchToDataFlow(array('group_order' => $groupOrderNo));
         $this->dataFlow->toFlow(array('isPaid' => true, 'groupOrderNo' => $groupOrderNo, 'prevGroupOrderNo' => $GroupOrderModel->getPrevGroupOrderNo($groupOrderNo), 'nextGroupOrderNo' => $GroupOrderModel->getNextGroupOrderNo($groupOrderNo)));
     } else {
         $foodOrderList = FoodOrderModel::getInstance()->fetchAllNotPayOrdersToFlow();
         $this->dataFlow->toFlow(array('isPaid' => false, 'prevGroupOrderNo' => $GroupOrderModel->getPrevGroupOrderNo()));
     }
     // 关联的用户
     $relatedUserList = [];
     // 关联的餐厅
     $relatedRestaurantList = [];
     // 最终订单的数据结构
     $orderList = [];
     /**
     * {
            {restaurantId}: {
     *          {foodId}: {
                    'count': 12,
     *              'user': [{userId}]
     *          }
     *      }
     * }
     *
     */
     foreach ($foodOrderList as $foodOrderId => $foodOrder) {
         $relatedUserList[] = $foodOrder['user'];
         foreach ($foodOrder['foods'] as $food) {
             $tmpFoodId = $food['food_id'];
             $tmpCount = $food['count'];
             $tmpRestaurant = $foodList[$food['food_id']]['restaurant'];
             $relatedRestaurantList[] = $tmpRestaurant;
             if (isset($orderList[$tmpRestaurant])) {
                 if (isset($orderList[$tmpRestaurant][$tmpFoodId])) {
                     $orderList[$tmpRestaurant][$tmpFoodId]['count'] += $tmpCount;
                     $orderList[$tmpRestaurant][$tmpFoodId]['user'][] = $food['user'];
                 } else {
                     $orderList[$tmpRestaurant][$tmpFoodId] = array('count' => $tmpCount, 'user' => [$foodOrder['user']]);
                 }
             } else {
                 $orderList[$tmpRestaurant] = array($tmpFoodId => array('count' => $tmpCount, 'user' => [$foodOrder['user']]));
             }
         }
     }
     UserModel::getInstance()->fetchToDataFlow(array('_id' => array('$in' => $relatedUserList)));
     RestaurantModel::getInstance()->fetchToDataFlow(array('_id' => array('$in' => $relatedRestaurantList)));
     $this->dataFlow->toFlow(array('orderList' => $orderList));
     $this->response();
 }
Exemple #8
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);
 }
Exemple #9
0
 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;
 }
Exemple #10
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;
 }