Exemple #1
0
 public function index()
 {
     $this->view->content = view('account/index.php');
     $this->view->content->user = $this->user;
     $this->view->content->address = \DB\Account\Address::row(array('user_id' => $this->user->user_id, 'is_default' => 1));
     $where = array('user_id' => $this->user->user_id, 'order_status != 4', 'order_status != 5');
     $this->view->content->order_nums = \Db\Trade\Order::count($where);
 }
Exemple #2
0
 public static function rollback_status($user_id)
 {
     \DB\Account\Address::database()->update(self::$table, array('is_default' => 0), array('user_id' => $user_id));
 }
Exemple #3
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();
 }
Exemple #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();
 }