Exemple #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');
     }
 }
Exemple #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();
 }