public static function map(FoodOrder $foodOrder, array $properties)
 {
     //        var_dump($properties);
     //        die();
     if (array_key_exists('order_id', $properties)) {
         $foodOrder->setOrderId($properties['order_id']);
     }
     if (array_key_exists('user_id', $properties)) {
         $foodOrder->setUserId($properties['user_id']);
     }
     if (array_key_exists('full_name', $properties)) {
         $foodOrder->setFullName($properties['full_name']);
     }
     if (array_key_exists('email', $properties)) {
         $foodOrder->setEmail($properties['email']);
     }
     if (array_key_exists('product_id', $properties)) {
         $foodOrder->setProductId($properties['product_id']);
     }
     if (array_key_exists('phone_number', $properties)) {
         $foodOrder->setPhoneNumber($properties['phone_number']);
     }
     if (array_key_exists('product_name', $properties)) {
         $foodOrder->setProductName($properties['product_name']);
     }
     if (array_key_exists('date', $properties)) {
         $formattedDate = $properties['date'];
         $date = self::createDateTime($formattedDate);
         if ($date) {
             $foodOrder->setDate($date);
         }
     }
 }
<?php

//script of editing the order
$errors = array();
$foodOrder = null;
$edit = array_key_exists('id', $_GET);
if ($edit) {
    $foodOrder = Utils::getFoodOrderByGetId();
} else {
    // set defaults
    $foodOrder = new FoodOrder();
    // $foodOrder ->  setPickupTime( new PickupTime());
    $foodOrder->setDate(new DateTime());
    // get product id from GET
    $product_id = $_GET['product_id'];
    $foodOrder->setProductId($product_id);
    //$flightBooking->setPriority(Todo::PRIORITY_MEDIUM);
    //$dueOn = new DateTime("+1 day");
    //$dueOn->setTime(0, 0, 0);
    //$flightBooking->setDueOn($dueOn);
}
if (array_key_exists('cancel', $_POST)) {
    // redirect
    Utils::redirect('home');
} elseif (array_key_exists('save', $_POST)) {
    // for security reasons, do not map the whole $_POST['todo']
    //pretending to have values in $_POST
    //$data = array('first_name' => 'Bob', 'no_of_passengers' => 2);
    //populate with user data
    $user_id = 1;
    //get from session
Beispiel #3
0
 public function actionOrderView()
 {
     //创建查询条件
     $criteria = new CDbCriteria();
     $criteria->order = 't.create_time DESC';
     //按时间倒序排
     //如果没有指定日期,默认查询当天的订单统计
     $date = Yii::app()->request->getParam('date');
     if ($date) {
         $today = strtotime(date($date));
         if (!$today) {
             throw new CHttpException(404, '日期格式设置有误');
         } else {
             if ($today > time()) {
                 throw new CHttpException(404, '设置的日期不能超过今天');
             }
         }
         $tomorrow = $today + 24 * 3600;
     } else {
         $today = strtotime(date('Y-m-d'));
         $tomorrow = strtotime(date('Y-m-d', time() + 24 * 3600));
     }
     $criteria->condition = '(t.status = :status1 OR t.status = :status2) AND t.create_time > :today AND t.create_time < :tomorrow';
     $criteria->params = array(':status1' => 1, ':status2' => 2, ':today' => $today, ':tomorrow' => $tomorrow);
     $model = FoodOrder::model()->with('shops', 'members')->findAll($criteria);
     $data = array();
     $_total_price = 0;
     $tongji = array();
     //存储所有订餐的人员名单
     $orderList = array();
     //处理查询得到的每一条订单
     //k表示键值,v表示每一条订单
     foreach ($model as $k => $v) {
         $_total_price += $v->total_price;
         $data[$k] = $v->attributes;
         $data[$k]['product_info'] = unserialize($v->product_info);
         $data[$k]['shop_name'] = $v->shops->name;
         $data[$k]['user_name'] = $v->members->name;
         $data[$k]['create_time'] = date('Y-m-d H:i:s', $v->create_time);
         $data[$k]['status_text'] = Yii::app()->params['order_status'][$v->status];
         $data[$k]['status_color'] = Yii::app()->params['status_color'][$v->status];
         //统计
         $tongji[$v->shop_id]['name'] = $v->shops->name;
         $tongji[$v->shop_id]['product'][] = unserialize($v->product_info);
         //将所有订单按shopName,username,orderinfo存储起来
         $orderList[$v->shop_id]['food_class'] = $v->shops->name;
         $orderList[$v->shop_id]['order'][$v->food_user_id]['user_name'] = $v->members->name;
         $orderList[$v->shop_id]['order'][$v->food_user_id]['order_info'][] = unserialize($v->product_info);
     }
     //按餐类和地点重新组织为orderviewlist
     $orderViewList = array();
     //统计结果
     $result = array();
     $foodTotalCount = 0;
     foreach ($orderList as $k => $v) {
         $result[$k]['name'] = $v['food_class'];
         $orderViewList[$k]['foodClass'] = $v['food_class'];
         $shop_total_price = 0;
         $foodsShopTotalCount = 0;
         foreach ($v['order'] as $lk => $lv) {
             //$orderViewList[$k]['order'][$lk]['userName']=$lv['user_name'];
             foreach ($lv['order_info'] as $_k => $_v) {
                 foreach ($_v as $kk => $vv) {
                     $shop_total_price += $vv['smallTotal'];
                     $foodsShopTotalCount += $vv['Count'];
                     $result[$k]['product'][$vv['Id']]['name'] = $vv['Name'];
                     if ($result[$k]['product'][$vv['Id']]['count']) {
                         $result[$k]['product'][$vv['Id']]['count'] += $vv['Count'];
                     } else {
                         $result[$k]['product'][$vv['Id']]['count'] = $vv['Count'];
                     }
                     if ($result[$k]['product'][$vv['Id']]['smallTotal']) {
                         $result[$k]['product'][$vv['Id']]['smallTotal'] += $vv['smallTotal'];
                     } else {
                         $result[$k]['product'][$vv['Id']]['smallTotal'] = $vv['smallTotal'];
                     }
                     //LCF:统计orderViewList列表
                     //orderview
                     if ($orderViewList[$k]['locations'][$vv['Id']]['count']) {
                         $orderViewList[$k]['locations'][$vv['Id']]['count'] += $vv['Count'];
                     } else {
                         $orderViewList[$k]['locations'][$vv['Id']]['count'] = $vv['Count'];
                     }
                     $orderViewList[$k]['locations'][$vv['Id']]['locationName'] = $vv['Name'];
                     $orderViewList[$k]['locations'][$vv['Id']]['orderItems'][$lk]['userName'] = $lv['user_name'];
                     $orderViewList[$k]['locations'][$vv['Id']]['orderItems'][$lk]['count'] += $vv['Count'];
                 }
             }
         }
         $result[$k]['shop_total_price'] = $shop_total_price;
         $orderViewList[$k]['totalCount'] = $foodsShopTotalCount;
         $foodTotalCount += $foodsShopTotalCount;
     }
     //输出到前端
     $this->render('orderView', array('foodTotalCount' => $foodTotalCount, 'orderViewList' => $orderViewList, 'data' => $data, 'statistics' => $result, 'total_price' => $_total_price, 'date' => $date));
 }
 public function loadModel($id)
 {
     $model = FoodOrder::model()->with('shops', 'members')->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 private function getParams(FoodOrder $foodOrder)
 {
     // var_dump($foodOrder);
     // die();
     $params = array(':order_id' => $foodOrder->getOrderId(), ':user_id' => $foodOrder->getUserId(), ':full_name' => $foodOrder->getFullName(), ':email' => $foodOrder->getEmail(), ':phone_number' => $foodOrder->getPhoneNumber(), ':product_id' => $foodOrder->getProductId(), ':status' => $foodOrder->getStatus());
     //        if ($flightBooking->getId()) {
     //            // unset created date, this one is never updated
     //            unset($params[':created_on']);
     //        }
     return $params;
 }
Beispiel #6
0
 public function actionCancelOrder()
 {
     if (Yii::app()->request->isAjaxRequest) {
         $food_order_id = Yii::app()->request->getParam('id');
         if (!$food_order_id) {
             $this->errorOutput(array('errorCode' => 1, 'errorText' => '没有id'));
         }
         //判断当前时间有没有已经过了订餐的时间,如果过了订餐的时间,就不能取消订单了,只能让妹子操作后台取消
         if (!Yii::app()->check_time->isOnTime()) {
             $this->errorOutput(array('errorCode' => 1, 'errorText' => '已经过了订餐时间,您暂时不能取消订单,如果确实需要取消,请联系前台妹子'));
         }
         $orderInfo = FoodOrder::model()->find('id=:id AND food_user_id=:food_user_id', array(':id' => $food_order_id, ':food_user_id' => Yii::app()->user->member_userinfo['id']));
         if (!$orderInfo) {
             $this->errorOutput(array('errorCode' => 1, 'errorText' => '该订单不存在'));
         } else {
             if ($orderInfo->status != 1) {
                 $this->errorOutput(array('errorCode' => 1, 'errorText' => '该订单不能被取消'));
             }
         }
         $orderInfo->status = 3;
         if ($orderInfo->save()) {
             //创建一条订单日志
             $foodOrderLog = new FoodOrderLog();
             $foodOrderLog->food_order_id = $food_order_id;
             $foodOrderLog->status = $orderInfo->status;
             $foodOrderLog->create_time = time();
             if ($foodOrderLog->save()) {
                 $this->output(array('success' => 1, 'successText' => '取消订单成功'));
             } else {
                 $this->errorOutput(array('errorCode' => 1, 'errorText' => '更新订单状态失败'));
             }
         } else {
             $this->errorOutput(array('errorCode' => 1, 'errorText' => '取消订单失败'));
         }
     } else {
         throw new CHttpException(404, Yii::t('yii', '非法操作'));
     }
 }
Beispiel #7
0
 public function actionConfirmOrder()
 {
     //检查在不在订餐时间内
     if (!Yii::app()->check_time->isOnTime()) {
         Error::output(Error::ERR_NOT_IN_TIME);
     }
     //接收传递过来的订单
     $menuInfo = Yii::app()->request->getParam('menu_info');
     $menuInfo = json_decode($menuInfo, 1);
     if ($menuInfo) {
         $shop_id = 0;
         $totalPrice = 0;
         //记录总价
         $orderData = array();
         //根据传递过来的订单构造数据
         foreach ($menuInfo as $k => $v) {
             $menu = Menus::model()->find('id = :id AND status = :status', array(':id' => $v['id'], ':status' => 2));
             if (!$menu) {
                 Error::output(Error::ERR_ORDER_DATA_WRONG);
             }
             if (!$shop_id) {
                 $shop_id = $menu->shop_id;
             } elseif ($menu->shop_id != $shop_id) {
                 Error::output(Error::ERR_MENU_NOT_SAME_SHOP);
             }
             $orderData[] = array('Id' => $menu->id, 'Name' => $menu->name, 'Count' => intval($v['nums']), 'Price' => $menu->price, 'smallTotal' => $menu->price * $v['nums']);
             $totalPrice += $menu->price * $v['nums'];
         }
         if (!$shop_id || empty($orderData)) {
             Error::output(Error::ERR_ORDER_DATA_WRONG);
         }
         //获取当前用户信息,查看用户账户余额够不够付款
         if ($this->module->user['balance'] < $totalPrice && !in_array($this->module->user['id'], Yii::app()->params['allow_user_id'])) {
             Error::output(Error::ERR_BALANCE_NOT_ENOUGH);
         }
         //构建数据
         $foodOrder = new FoodOrder();
         $foodOrder->shop_id = $shop_id;
         $foodOrder->order_number = date('YmdHis', time()) . Common::getRandNums(6);
         $foodOrder->food_user_id = $this->module->user['id'];
         $foodOrder->total_price = $totalPrice;
         $foodOrder->create_time = time();
         $foodOrder->product_info = serialize($orderData);
         if ($foodOrder->save()) {
             //记录订单动态
             $foodOrderLog = new FoodOrderLog();
             $foodOrderLog->food_order_id = $foodOrder->id;
             $foodOrderLog->create_time = time();
             $foodOrderLog->save();
             Out::jsonOutput(array('return' => 1));
             //下单成功
         } else {
             Error::output(Error::ERR_SAVE_FAIL);
         }
     }
 }