Esempio n. 1
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');
     }
 }
Esempio n. 2
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();
 }
Esempio n. 3
0
 public function index()
 {
     if (in_array(Auth::getCapability(), array(CAPABILITY_ADMINISTRATOR))) {
         Model::autoloadModel('restaurant');
         $model = new RestaurantModel($this->db);
         $this->para = new stdClass();
         if (isset($_POST['type'])) {
             $this->para->type = $_POST['type'];
         }
         if (isset($_POST['orderby'])) {
             $this->para->orderby = $_POST['orderby'];
         }
         if (isset($_POST['order'])) {
             $this->para->order = $_POST['order'];
         }
         if (isset($_POST['page'])) {
             $this->para->page = $_POST['page'];
         }
         if (isset($_POST['s'])) {
             $this->para->s = $_POST['s'];
         }
         if (isset($_POST['paged'])) {
             $this->para->paged = $_POST['paged'];
         }
         if (isset($_POST['restaurants'])) {
             $this->para->restaurants = $_POST['restaurants'];
         }
         if (isset($_POST['action'])) {
             $this->para->action = $_POST['action'];
         }
         if (isset($_POST['action2'])) {
             $this->para->action2 = $_POST['action2'];
         }
         if (isset($_POST['city_show'])) {
             $this->para->city_show = $_POST['city_show'];
         }
         if (isset($_POST['current_rating'])) {
             $this->para->current_rating = $_POST['current_rating'];
         }
         if (isset($_POST['vote_times'])) {
             $this->para->vote_times = $_POST['vote_times'];
         }
         if (isset($_POST['restaurants_per_page'])) {
             $this->para->restaurants_per_page = $_POST['restaurants_per_page'];
         }
         if (isset($_POST['adv_setting'])) {
             $this->para->adv_setting = $_POST['adv_setting'];
         }
         if (isset($this->para->adv_setting) && $this->para->adv_setting == "adv_setting") {
             $model->changeAdvSetting($this->para);
         }
         if (isset($this->para->type) && in_array($this->para->type, array("action", "action2")) && isset($this->para->restaurants)) {
             $model->executeAction($this->para);
         }
         $model->search($this->view, $this->para);
         if (count((array) $this->para) > 0) {
             $this->view->ajax = TRUE;
             $this->view->renderAdmin(RENDER_VIEW_RESTAURANT_INDEX, TRUE);
         } else {
             $this->view->renderAdmin(RENDER_VIEW_RESTAURANT_INDEX);
         }
     } else {
         $this->login();
     }
 }