Beispiel #1
0
 public function initialize()
 {
     parent::initialize();
     $this->view = view('layout/index.php');
     $this->user = \Model\Authorize\Oauth::login_user();
     \Core\View::$title = '文和友老长沙外卖';
 }
Beispiel #2
0
 /**
  * 提交订单
  */
 public function confirm()
 {
     //\Core\View::$title = '确认订单';
     $this->user = \Model\Authorize\Oauth::login_user();
     $v = new \Model\Validation();
     $v->required($this->user)->message('用户未登录', 1000);
     if (!$v->has_error()) {
         $address_id = \Core\URI::kv('address_id');
         $pay_type = \Core\URI::kv('pay_type', 0);
         $pick_time = \Core\URI::kv('pick_time');
         $order_remark = \Core\URI::kv('order_remark');
         if (empty($pick_time)) {
             $pick_time = W_START_TIME;
         } else {
             $pick_time = strtotime($pick_time);
         }
         $goods_id = \Core\URI::kv('id');
         $nums = \Core\URI::kv('nums');
         $nums = abs(intval($nums));
         if (!empty($goods_id)) {
             $cart = array();
             $goods = \DB\Mall\Goods::row(array('goods_id' => $goods_id));
             $v->required($goods)->message('商品不存在', 1000);
             $v->min_val($nums, 1)->message('数量不能小于1', 1000);
             if (!$v->has_error()) {
                 $row = new \Db\Trade\Cart();
                 $row->user_id = $this->user->user_id;
                 $row->goods_id = $goods->goods_id;
                 $row->goods_nums = $nums;
                 $row->goods_discount_price = $goods->goods_discount_price;
                 $row->goods_original_price = $goods->goods_original_price;
                 $row->cart_status = 1;
                 $row->create_time = W_START_TIME;
                 $row->goods = $goods;
                 $cart[] = $row;
                 //dump($cart);exit();
             }
         } else {
             $cart = \Db\Trade\Cart::fetch(array('user_id' => $this->user->user_id, 'cart_status' => 1));
             foreach ($cart as $c) {
                 $c->goods->load();
             }
             $v->filter_var(!empty($cart))->message('购物车为空', 1000);
         }
         $address = \DB\Account\Address::row(array('user_id' => $this->user->user_id, 'address_id' => $address_id));
         $v->filter_var(!empty($address))->message('配送地址不存在', 1000);
         if (!$v->has_error()) {
             $order = new \Db\Trade\Order();
             $order_id = $order->create_from_cart($cart, $pay_type, $pick_time, $address->user_name, $address->user_mobile, $address->address_province, $address->address_city, $address->address_area, $address->address_street, $order_remark);
             $v->set_data($order_id);
         }
     }
     $v->send();
 }
Beispiel #3
0
 public function initialize()
 {
     parent::initialize();
     $this->view = view('layout/index.php');
     $this->user = \Model\Authorize\Oauth::login_user();
 }