/** * 保存 */ public function save() { $user_name = \Core\URI::kv('user_name'); $user_mobile = \Core\URI::kv('user_mobile'); $address_province = \Core\URI::kv('address_province'); $address_city = \Core\URI::kv('address_city'); $address_area = \Core\URI::kv('address_area'); $address_street = \Core\URI::kv('address_street'); $is_default = \Core\URI::kv('is_default', 1); $v = new \Model\Validation(); $v->required($user_name)->message('用户姓名不能为空', 1000); $v->required($user_mobile)->message('用户手机号码不能为空', 1000); $v->filter_var(preg_match('/^1[34578]\\d{9}$/', $user_mobile) > 0)->message('手机号码不正确', 1000); $v->required($address_province)->message('省份不能为空', 1000); $v->required($address_city)->message('城市不能为空', 1000); $v->required($address_area)->message('区域不能为空', 1000); $v->required($address_street)->message('街道地址不能为空', 1000); if (!$v->has_error()) { if (!empty($is_default)) { \DB\Account\Address::rollback_status($this->user->user_id); } $address_id = \Core\URI::kv('id', null); $model = new \DB\Account\Address($address_id); $model->user_id = $this->user->user_id; $model->user_name = $user_name; $model->user_mobile = $user_mobile; $model->address_province = $address_province; $model->address_city = $address_city; $model->address_area = $address_area; $model->address_street = $address_street; $model->is_default = 1; $model->save(); } $v->send(); }
/** * 保存 */ public function save() { $goods_id = \Core\URI::kv('id'); $goods_nums = \Core\URI::kv('nums', 1); $cart_status = \Core\URI::kv('status', 1); $v = new \Model\Validation(); $v->required($goods_id)->message('商品编号不能为空', 1000); $goods_nums = abs(intval($goods_nums)); $v->filter_var($goods_nums > 0)->message('商品数量不能小于1', 1000); if (!$v->has_error()) { $goods = \DB\Mall\Goods::row(array('goods_id' => $goods_id, 'goods_status' => 1)); $v->required($goods)->message('商品不存在', 1000); if (!$v->has_error()) { $model = \DB\Trade\Cart::row(array('user_id' => $this->user->user_id, 'goods_id' => $goods_id)); if ($model) { $model->goods_nums = $goods_nums; $model->goods_discount_price = $goods->goods_discount_price; $model->goods_original_price = $goods->goods_original_price; $model->create_time = W_START_TIME; $model->cart_status = $cart_status; $model->update(); } else { $model = new \Db\Trade\Cart(); $model->user_id = $this->user->user_id; $model->create_time = W_START_TIME; $model->goods_id = $goods_id; $model->goods_discount_price = $goods->goods_discount_price; $model->goods_original_price = $goods->goods_original_price; $model->goods_nums = $goods_nums; $model->cart_status = $cart_status; $model->insert(); } $v->set_data(\Db\Trade\Cart::count_cart($this->user->user_id)); } } $v->send(); }
/** * 提交订单 */ 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(); }