Exemplo n.º 1
0
 /**
  * 删除商品
  */
 public function delete()
 {
     $ids = \Core\URI::kv('ids');
     $v = new \Model\Validation();
     $v->required($ids)->message('参数错误', 1000);
     if (!$v->has_error()) {
         $id_arr = explode('-', $ids);
         foreach ($id_arr as $id) {
             $model = \DB\Trade\Cart::row(array('user_id' => $this->user->user_id, 'goods_id' => $id));
             if ($model) {
                 $model->delete();
             }
         }
         $v->set_data(\Db\Trade\Cart::count_cart($this->user->user_id));
     }
     $v->send();
 }
Exemplo n.º 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();
 }
Exemplo n.º 3
0
 /**
  * 催单
  */
 public function order_hurry()
 {
     $v = new \Model\Validation();
     $order_id = \Core\URI::kv('id');
     $order = \Db\Trade\Order::row(array('order_id' => $order_id, 'user_id' => $this->user->user_id));
     $time_start = \Core\Cookie::get('time_start');
     $v->required($order)->message('订单不存在', 1000);
     if (!$v->has_error()) {
         if (empty($time_start)) {
             \Core\Cookie::set('time_start', W_START_TIME);
             //@todo 更新催单时间
             $order->hurry_status = 1;
             $order->hurry_time = W_START_TIME;
             $order->update();
             $v->set_data(\Core\URI::a2p(array('trade' => 'order', 'id' => $order->id)));
         } else {
             if (W_START_TIME - $time_start > 600) {
                 //@todo 更新催单时间
                 $order->hurry_status = 1;
                 $order->hurry_time = W_START_TIME;
                 $order->update();
                 $v->set_data(\Core\URI::a2p(array('trade' => 'order', 'id' => $order->id)));
             }
             $v->required(false)->message('已经收到,正在加急处理', 1000);
         }
     }
     $v->send();
 }
Exemplo n.º 4
0
 /**
  * 删除地址
  */
 public function delete()
 {
     $ids = \Core\URI::kv('ids');
     $v = new \Model\Validation();
     $v->required($ids)->message('参数错误', 1000);
     if (!$v->has_error()) {
         $id_arr = explode('-', $ids);
         foreach ($id_arr as $id) {
             $model = new \DB\Account\Address($id);
             $model->delete();
         }
         // 查看是否还有默认地址
         $row = \DB\Account\Address::row(array('user_id' => $this->user->user_id, 'is_default' => 1));
         if (empty($row)) {
             // 如果没有默认地址,重新设置最后一个地址为默认地址
             $row = \DB\Account\Address::row(array('user_id' => $this->user->user_id), array('create_time' => 'desc'));
             if ($row) {
                 $row->is_default = 1;
                 $row->save();
             }
         }
     }
     $v->send();
 }
Exemplo n.º 5
0
 public function tab3_part()
 {
     $limit = 5;
     $page = \Core\URI::kv('page', 1);
     $start = ($page - 1) * $limit;
     $rows = \DB\Mall\Goods::fetch(array('goods_status' => 1, 'category_id' => 3), $limit, $start, array('goods_order' => 'desc'));
     $v = new \Model\Validation();
     if (!empty($rows)) {
         $view = view('main/tab3_part.php');
         $view->rows = $rows;
         $view->user = $this->user;
         $rs = $view->__toString();
         $v->set_data($rs);
     } else {
         $v->required(false)->message('没有更多了...');
     }
     $v->send();
 }
Exemplo n.º 6
0
 public function get()
 {
     $v = new \Model\Validation();
     $order_id = \Core\URI::kv('id');
     $order = \Db\Trade\Order::row(array('order_id' => $order_id));
     $v->required($order)->message('订单不存在', 1000);
     if (!$v->has_error()) {
         $view = view('order/get.php');
         $view->rows = unserialize($order->cart_text);
         //var_dump($view->rows);exit();
         $v->set_data($view->__toString());
     }
     $v->send();
 }