Showing
3 changed files
with
383 additions
and
66 deletions
@@ -18,15 +18,54 @@ class CartData | @@ -18,15 +18,54 @@ class CartData | ||
18 | { | 18 | { |
19 | 19 | ||
20 | /** | 20 | /** |
21 | + * 加入购物车接口 | ||
22 | + * | ||
23 | + * @param int $productSku 商品SKU | ||
24 | + * @param int $buyNumber 购买数量 | ||
25 | + * @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品 | ||
26 | + * @param int int $isEdit 是否是编辑商品SKU,0表示不是编辑 | ||
27 | + * @param null|int $promotionId 促销id,默认null(加价购有关) | ||
28 | + * @param null|int $uid 用户UID,可以不传 | ||
29 | + * @return array 加入购物车接口返回的数据 | ||
30 | + */ | ||
31 | + public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit = 0, $promotionId = null, $uid = null) | ||
32 | + { | ||
33 | + $param = Yohobuy::param(); | ||
34 | + $param['method'] = 'app.Shopping.add'; | ||
35 | + $param['product_sku'] = $productSku; | ||
36 | + $param['buy_number'] = $buyNumber; | ||
37 | + $param['goods_type'] = $goodsType; | ||
38 | + $param['edit_product_sku'] = $isEdit; | ||
39 | + $param['selected'] = 'Y'; | ||
40 | + $param['promotion_id'] = $promotionId; | ||
41 | + | ||
42 | + if ($uid !== null) { | ||
43 | + $param['uid'] = $uid; | ||
44 | + } | ||
45 | + $param['client_secret'] = Sign::getSign($param); | ||
46 | + | ||
47 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
21 | * 购物车数据 | 51 | * 购物车数据 |
22 | * | 52 | * |
53 | + * @param int $uid 用户ID | ||
54 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
23 | * @return array 购物车接口返回的数据 | 55 | * @return array 购物车接口返回的数据 |
24 | */ | 56 | */ |
25 | - public static function cartData($uid) | 57 | + public static function cartData($uid, $shoppingKey) |
26 | { | 58 | { |
27 | $param = Yohobuy::param(); | 59 | $param = Yohobuy::param(); |
28 | $param['method'] = 'app.Shopping.cart'; | 60 | $param['method'] = 'app.Shopping.cart'; |
29 | - $param['uid'] = $uid; | 61 | + |
62 | + if (!empty($uid)) { | ||
63 | + $param['uid'] = $uid; | ||
64 | + } | ||
65 | + if (!empty($shoppingKey)) { | ||
66 | + $param['shopping_key'] = $shoppingKey; | ||
67 | + } | ||
68 | + | ||
30 | $param['client_secret'] = Sign::getSign($param); | 69 | $param['client_secret'] = Sign::getSign($param); |
31 | 70 | ||
32 | return Yohobuy::get(Yohobuy::API_URL, $param); | 71 | return Yohobuy::get(Yohobuy::API_URL, $param); |
@@ -37,14 +76,22 @@ class CartData | @@ -37,14 +76,22 @@ class CartData | ||
37 | * | 76 | * |
38 | * @param int $uid 用户ID | 77 | * @param int $uid 用户ID |
39 | * @param string $sku 商品sku列表 | 78 | * @param string $sku 商品sku列表 |
79 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
40 | * @return array 接口返回的数据 | 80 | * @return array 接口返回的数据 |
41 | */ | 81 | */ |
42 | - public static function removeFromCart($uid, $sku) | 82 | + public static function removeFromCart($uid, $sku, $shoppingKey) |
43 | { | 83 | { |
44 | $param = Yohobuy::param(); | 84 | $param = Yohobuy::param(); |
45 | $param['method'] = 'app.Shopping.remove'; | 85 | $param['method'] = 'app.Shopping.remove'; |
46 | $param['product_sku_list'] = $sku; | 86 | $param['product_sku_list'] = $sku; |
47 | - $param['uid'] = $uid; | 87 | + |
88 | + if (!empty($uid)) { | ||
89 | + $param['uid'] = $uid; | ||
90 | + } | ||
91 | + if (!empty($shoppingKey)) { | ||
92 | + $param['shopping_key'] = $shoppingKey; | ||
93 | + } | ||
94 | + | ||
48 | $param['client_secret'] = Sign::getSign($param); | 95 | $param['client_secret'] = Sign::getSign($param); |
49 | 96 | ||
50 | return Yohobuy::get(Yohobuy::API_URL, $param); | 97 | return Yohobuy::get(Yohobuy::API_URL, $param); |
@@ -88,18 +135,44 @@ class CartData | @@ -88,18 +135,44 @@ class CartData | ||
88 | } | 135 | } |
89 | 136 | ||
90 | /** | 137 | /** |
138 | + * 获取加价购商品数据 | ||
139 | + * | ||
140 | + * @param int $skn 商品skn | ||
141 | + * @param int $promotionId 加价购商品促销ID | ||
142 | + * @return array 接口返回的数据 | ||
143 | + */ | ||
144 | + public static function giftProductData($skn, $promotionId) | ||
145 | + { | ||
146 | + $param = Yohobuy::param(); | ||
147 | + $param['method'] = 'app.product.gift'; | ||
148 | + $param['product_skn'] = $skn; | ||
149 | + $param['promotion_id'] = $promotionId; | ||
150 | + $param['client_secret'] = Sign::getSign($param); | ||
151 | + | ||
152 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
153 | + } | ||
154 | + | ||
155 | + /** | ||
91 | * 修改购物车商品数据 | 156 | * 修改购物车商品数据 |
92 | * | 157 | * |
93 | * @param int $uid 用户ID | 158 | * @param int $uid 用户ID |
94 | * @param string $swapData 商品数据 | 159 | * @param string $swapData 商品数据 |
160 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
95 | * @return array 接口返回的数据 | 161 | * @return array 接口返回的数据 |
96 | */ | 162 | */ |
97 | - public static function modifyCartProduct($uid, $swapData) | 163 | + public static function modifyCartProduct($uid, $swapData, $shoppingKey) |
98 | { | 164 | { |
99 | $param = Yohobuy::param(); | 165 | $param = Yohobuy::param(); |
100 | $param['method'] = 'app.Shopping.swap'; | 166 | $param['method'] = 'app.Shopping.swap'; |
101 | $param['swap_data'] = $swapData; | 167 | $param['swap_data'] = $swapData; |
102 | - $param['uid'] = $uid; | 168 | + |
169 | + if (!empty($uid)) { | ||
170 | + $param['uid'] = $uid; | ||
171 | + } | ||
172 | + if ($shoppingKey !== null) { | ||
173 | + $param['shopping_key'] = $shoppingKey; | ||
174 | + } | ||
175 | + | ||
103 | $param['client_secret'] = Sign::getSign($param); | 176 | $param['client_secret'] = Sign::getSign($param); |
104 | 177 | ||
105 | return Yohobuy::get(Yohobuy::API_URL, $param); | 178 | return Yohobuy::get(Yohobuy::API_URL, $param); |
@@ -168,4 +241,31 @@ class CartData | @@ -168,4 +241,31 @@ class CartData | ||
168 | return Yohobuy::get(Yohobuy::API_URL, $param); | 241 | return Yohobuy::get(Yohobuy::API_URL, $param); |
169 | } | 242 | } |
170 | 243 | ||
244 | + /** | ||
245 | + * 购物车结算--提交结算信息 | ||
246 | + * | ||
247 | + * @param int $uid 用户ID | ||
248 | + * @param string $couponCode 优惠券代码 | ||
249 | + * @return array 接口返回的数据 | ||
250 | + */ | ||
251 | + public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin) | ||
252 | + { | ||
253 | + $param = Yohobuy::param(); | ||
254 | + $param['method'] = 'app.Shopping.submit'; | ||
255 | + $param['addressId'] = $addressId; | ||
256 | + $param['cart_type'] = $cartType; | ||
257 | + $param['delivery_time'] = $deliveryTime; | ||
258 | + $param['delivery_way'] = $deliveryWay; | ||
259 | + $param['invoices_title'] = $invoiceTitle; | ||
260 | + $param['invoices_type_id'] = $invoiceId; | ||
261 | + $param['payment_id'] = $paymentId; | ||
262 | + $param['payment_type'] = $paymentType; | ||
263 | + $param['remark'] = $remark; | ||
264 | + $param['use_yoho_coin'] = $yohoCoin; | ||
265 | + $param['uid'] = $uid; | ||
266 | + $param['client_secret'] = Sign::getSign($param); | ||
267 | + | ||
268 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
269 | + } | ||
270 | + | ||
171 | } | 271 | } |
@@ -9,33 +9,21 @@ use Plugin\Helpers; | @@ -9,33 +9,21 @@ use Plugin\Helpers; | ||
9 | */ | 9 | */ |
10 | class ShoppingCartController extends AbstractAction | 10 | class ShoppingCartController extends AbstractAction |
11 | { | 11 | { |
12 | - protected $_uid; | ||
13 | - | ||
14 | - /** | ||
15 | - * 初始化 | ||
16 | - */ | ||
17 | - public function init() | ||
18 | - { | ||
19 | - // 检查用户是否登录, 未登录则跳转到登录页 | ||
20 | - $this->_uid = $this->getUid(); | ||
21 | - if (!$this->_uid) { | ||
22 | - $this->go(Helpers::url('/signin.html')); | ||
23 | - } | ||
24 | - | ||
25 | - parent::init(); | ||
26 | - } | ||
27 | 12 | ||
28 | /* | 13 | /* |
29 | - * 首页 | 14 | + * 购物车首页 |
30 | */ | 15 | */ |
31 | public function indexAction() | 16 | public function indexAction() |
32 | { | 17 | { |
33 | $this->setTitle('购物车'); | 18 | $this->setTitle('购物车'); |
34 | $this->setNavHeader('购物车'); | 19 | $this->setNavHeader('购物车'); |
35 | 20 | ||
21 | + $shoppingKey = $this->getSession('shoppingKey'); | ||
22 | + $uid = $this->getUid(true); | ||
23 | + | ||
36 | $data = array( | 24 | $data = array( |
37 | 'shoppingCartPage' => true, | 25 | 'shoppingCartPage' => true, |
38 | - 'shoppingCart' => CartModel::getCartData($this->_uid) | 26 | + 'shoppingCart' => CartModel::getCartData($uid, $shoppingKey) |
39 | ); | 27 | ); |
40 | 28 | ||
41 | // 渲染模板 | 29 | // 渲染模板 |
@@ -51,7 +39,9 @@ class ShoppingCartController extends AbstractAction | @@ -51,7 +39,9 @@ class ShoppingCartController extends AbstractAction | ||
51 | 39 | ||
52 | if ($this->isAjax()) { | 40 | if ($this->isAjax()) { |
53 | $productId = $this->post('id', 0); | 41 | $productId = $this->post('id', 0); |
54 | - $result = CartModel::removeFromCart($this->_uid, $productId); | 42 | + $uid = $this->getUid(true); |
43 | + $shoppingKey = $this->getSession('shoppingKey'); | ||
44 | + $result = CartModel::removeFromCart($uid, $productId, $shoppingKey); | ||
55 | } | 45 | } |
56 | 46 | ||
57 | if (empty($result)) { | 47 | if (empty($result)) { |
@@ -70,7 +60,50 @@ class ShoppingCartController extends AbstractAction | @@ -70,7 +60,50 @@ class ShoppingCartController extends AbstractAction | ||
70 | 60 | ||
71 | if ($this->isAjax()) { | 61 | if ($this->isAjax()) { |
72 | $productId = $this->post('id', 0); | 62 | $productId = $this->post('id', 0); |
73 | - $result = CartModel::addToFav($this->_uid, $productId); | 63 | + $uid = $this->getUid(true); |
64 | + $result = CartModel::addToFav($uid, $productId); | ||
65 | + } | ||
66 | + | ||
67 | + if (empty($result)) { | ||
68 | + echo ' '; | ||
69 | + } else { | ||
70 | + $this->echoJson($result); | ||
71 | + } | ||
72 | + } | ||
73 | + | ||
74 | + /* | ||
75 | + * 获取购物车商品数据 | ||
76 | + */ | ||
77 | + public function goodinfoAction() | ||
78 | + { | ||
79 | + $result = array(); | ||
80 | + | ||
81 | + if ($this->isAjax()) { | ||
82 | + $num = $this->get('buy_num', 1); | ||
83 | + $skn = $this->get('id', 1); | ||
84 | + $uid = $this->getUid(true); | ||
85 | + $result = CartModel::cartProductData($uid, $skn, $num); // 测试skn的ID为51172055 | ||
86 | + $result['num'] = $num; | ||
87 | + } | ||
88 | + | ||
89 | + if (empty($result)) { | ||
90 | + echo ' '; | ||
91 | + } else { | ||
92 | + $this->echoJson($result); | ||
93 | + } | ||
94 | + } | ||
95 | + | ||
96 | + /* | ||
97 | + * 获取购物车加价购商品数据 | ||
98 | + */ | ||
99 | + public function giftinfoAction() | ||
100 | + { | ||
101 | + $result = array(); | ||
102 | + | ||
103 | + if ($this->isAjax()) { | ||
104 | + $skn = $this->get('skn', null); | ||
105 | + $promotionId = $this->get('promotionId', null); | ||
106 | + $result = CartModel::giftProductData($skn, $promotionId); | ||
74 | } | 107 | } |
75 | 108 | ||
76 | if (empty($result)) { | 109 | if (empty($result)) { |
@@ -88,13 +121,15 @@ class ShoppingCartController extends AbstractAction | @@ -88,13 +121,15 @@ class ShoppingCartController extends AbstractAction | ||
88 | $result = array(); | 121 | $result = array(); |
89 | 122 | ||
90 | if ($this->isAjax()) { | 123 | if ($this->isAjax()) { |
124 | + $shoppingKey = $this->getSession('shoppingKey'); | ||
125 | + $uid = $this->getUid(true); | ||
91 | 126 | ||
92 | $params = array(); | 127 | $params = array(); |
93 | $params['old_product_sku']= $this->post('old_product_sku', 0); | 128 | $params['old_product_sku']= $this->post('old_product_sku', 0); |
94 | $params['new_product_sku']= $this->post('new_product_sku', 0); | 129 | $params['new_product_sku']= $this->post('new_product_sku', 0); |
95 | $params['buy_number']= $this->post('buy_number', 0); | 130 | $params['buy_number']= $this->post('buy_number', 0); |
96 | $params['selected']= $this->post('selected', null); | 131 | $params['selected']= $this->post('selected', null); |
97 | - $result = CartModel::modifyCartProduct($this->_uid, $params); | 132 | + $result = CartModel::modifyCartProduct($uid, $params, $shoppingKey); |
98 | } | 133 | } |
99 | 134 | ||
100 | if (empty($result)) { | 135 | if (empty($result)) { |
@@ -109,18 +144,18 @@ class ShoppingCartController extends AbstractAction | @@ -109,18 +144,18 @@ class ShoppingCartController extends AbstractAction | ||
109 | */ | 144 | */ |
110 | public function payAction() | 145 | public function payAction() |
111 | { | 146 | { |
112 | - $result = array(); | 147 | + $this->setTitle('购物车'); |
148 | + $this->setNavHeader('购物车'); | ||
113 | 149 | ||
114 | - if ($this->isAjax()) { | ||
115 | - $cartType = $this->post('cartType', 'ordinary'); | ||
116 | - $result = CartModel::cartPay($this->_uid, $cartType); | ||
117 | - } | 150 | + $cartType = $this->post('cartType', 'ordinary'); |
151 | + $uid = $this->getUid(true); | ||
152 | + $data = array( | ||
153 | + 'orderEnsurePage' => true, | ||
154 | + 'orderEnsure' => CartModel::cartPay($uid, $cartType) | ||
155 | + ); | ||
118 | 156 | ||
119 | - if (empty($result)) { | ||
120 | - echo ' '; | ||
121 | - } else { | ||
122 | - $this->echoJson($result); | ||
123 | - } | 157 | + |
158 | + $this->_view->display('order-ensure', $data); | ||
124 | } | 159 | } |
125 | 160 | ||
126 | /** | 161 | /** |
@@ -134,7 +169,8 @@ class ShoppingCartController extends AbstractAction | @@ -134,7 +169,8 @@ class ShoppingCartController extends AbstractAction | ||
134 | $cartType = $this->post('cartType', 'ordinary'); | 169 | $cartType = $this->post('cartType', 'ordinary'); |
135 | $deliveryWay = $this->post('deliveryWay', 1); | 170 | $deliveryWay = $this->post('deliveryWay', 1); |
136 | $paymentType = $this->post('paymentType', 1); | 171 | $paymentType = $this->post('paymentType', 1); |
137 | - $result = CartModel::paymentTypeAndDelivery($this->_uid, $cartType, $deliveryWay, $paymentType); | 172 | + $uid = $this->getUid(true); |
173 | + $result = CartModel::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType); | ||
138 | } | 174 | } |
139 | 175 | ||
140 | if (empty($result)) { | 176 | if (empty($result)) { |
@@ -153,7 +189,8 @@ class ShoppingCartController extends AbstractAction | @@ -153,7 +189,8 @@ class ShoppingCartController extends AbstractAction | ||
153 | 189 | ||
154 | if ($this->isAjax()) { | 190 | if ($this->isAjax()) { |
155 | $couponCode = $this->post('couponCode', ''); | 191 | $couponCode = $this->post('couponCode', ''); |
156 | - $result = CartModel::getCoupon($this->_uid, $couponCode); | 192 | + $uid = $this->getUid(true); |
193 | + $result = CartModel::getCoupon($uid, $couponCode); | ||
157 | } | 194 | } |
158 | 195 | ||
159 | if (empty($result)) { | 196 | if (empty($result)) { |
@@ -230,6 +267,9 @@ class ShoppingCartController extends AbstractAction | @@ -230,6 +267,9 @@ class ShoppingCartController extends AbstractAction | ||
230 | 'navBack' => true, 'navTitle' => '加价购'), 'shoppingCart' => $data)); | 267 | 'navBack' => true, 'navTitle' => '加价购'), 'shoppingCart' => $data)); |
231 | } | 268 | } |
232 | 269 | ||
270 | + /* | ||
271 | + * 确认订单 | ||
272 | + */ | ||
233 | public function orderEnsureAction() { | 273 | public function orderEnsureAction() { |
234 | $data = array( | 274 | $data = array( |
235 | 'orderEnsurePage' => true, | 275 | 'orderEnsurePage' => true, |
@@ -310,21 +350,4 @@ class ShoppingCartController extends AbstractAction | @@ -310,21 +350,4 @@ class ShoppingCartController extends AbstractAction | ||
310 | } | 350 | } |
311 | } | 351 | } |
312 | 352 | ||
313 | - public function goodinfoAction() | ||
314 | - { | ||
315 | - $result = array(); | ||
316 | - | ||
317 | - if ($this->isAjax()) { | ||
318 | - $num = $this->get('buy_num', 1); | ||
319 | - $skn = $this->get('id', 1); | ||
320 | - $result = CartModel::cartProductData($this->_uid, $skn, $num); // 测试skn的ID为51172055 | ||
321 | - $result['num'] = $num; | ||
322 | - } | ||
323 | - | ||
324 | - if (empty($result)) { | ||
325 | - echo ' '; | ||
326 | - } else { | ||
327 | - $this->echoJson($result); | ||
328 | - } | ||
329 | - } | ||
330 | } | 353 | } |
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | namespace Index; | 3 | namespace Index; |
4 | 4 | ||
5 | use LibModels\Wap\Home\CartData; | 5 | use LibModels\Wap\Home\CartData; |
6 | +use LibModels\Wap\Home\UserData; | ||
6 | use Plugin\Helpers; | 7 | use Plugin\Helpers; |
7 | use Plugin\Images; | 8 | use Plugin\Images; |
8 | 9 | ||
@@ -18,18 +19,44 @@ class CartModel | @@ -18,18 +19,44 @@ class CartModel | ||
18 | { | 19 | { |
19 | 20 | ||
20 | /** | 21 | /** |
22 | + * 加入购物车 | ||
23 | + * | ||
24 | + * @param int $productSku 商品SKU | ||
25 | + * @param int $buyNumber 购买数量 | ||
26 | + * @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品 | ||
27 | + * @param int int $isEdit 是否是编辑商品SKU,0表示不是编辑 | ||
28 | + * @param null|int $promotionId 促销id,默认null(加价购有关) | ||
29 | + * @param null|int $uid 用户UID,可以不传 | ||
30 | + * @return array 加入购物车接口返回的数据 | ||
31 | + */ | ||
32 | + public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid) | ||
33 | + { | ||
34 | + $result = array('code' => 400, 'message' => '出错啦~~'); | ||
35 | + | ||
36 | + $addCart = CartData::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid); | ||
37 | + if ($addCart && isset($addCart['code'])) { | ||
38 | + $result = $addCart; | ||
39 | + } | ||
40 | + | ||
41 | + return $result; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
21 | * @param integer $uid 用户ID | 45 | * @param integer $uid 用户ID |
46 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
22 | * @return array|mixed 处理之后的购物车数据 | 47 | * @return array|mixed 处理之后的购物车数据 |
23 | */ | 48 | */ |
24 | - public static function getCartData($uid) | 49 | + public static function getCartData($uid, $shoppingKey) |
25 | { | 50 | { |
26 | - $result = array( | ||
27 | - 'cartNav' => true, | ||
28 | - 'showLoginInfo' => true | ||
29 | - ); | 51 | + $result = array('cartNav' => true); |
52 | + | ||
53 | + // 用户是否登录 | ||
54 | + if (empty($uid)) { | ||
55 | + $result['showLoginInfo'] = true; | ||
56 | + } | ||
30 | 57 | ||
31 | // 调用接口获取购物车的数据 | 58 | // 调用接口获取购物车的数据 |
32 | - $cartData = CartData::cartData($uid); | 59 | + $cartData = CartData::cartData($uid, $shoppingKey); |
33 | 60 | ||
34 | // 处理普通购物车和预售购物车的数据 | 61 | // 处理普通购物车和预售购物车的数据 |
35 | if (isset($cartData['data']) && !empty($cartData['data'])) { | 62 | if (isset($cartData['data']) && !empty($cartData['data'])) { |
@@ -57,16 +84,17 @@ class CartModel | @@ -57,16 +84,17 @@ class CartModel | ||
57 | * | 84 | * |
58 | * @param int $uid 用户ID | 85 | * @param int $uid 用户ID |
59 | * @param string $sku 商品sku列表 | 86 | * @param string $sku 商品sku列表 |
87 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
60 | * @return array 接口返回的数据 | 88 | * @return array 接口返回的数据 |
61 | */ | 89 | */ |
62 | - public static function removeFromCart($uid, $sku) | 90 | + public static function removeFromCart($uid, $sku, $shoppingKey) |
63 | { | 91 | { |
64 | $result = array('code' => 400, 'message' => '出错啦~'); | 92 | $result = array('code' => 400, 'message' => '出错啦~'); |
65 | 93 | ||
66 | // 处理sku | 94 | // 处理sku |
67 | $sku_list = json_encode(array($sku => 1)); | 95 | $sku_list = json_encode(array($sku => 1)); |
68 | 96 | ||
69 | - $remove = CartData::removeFromCart($uid, $sku_list); | 97 | + $remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey); |
70 | if ($remove && isset($remove['code'])) { | 98 | if ($remove && isset($remove['code'])) { |
71 | $result['code'] = $remove['code']; | 99 | $result['code'] = $remove['code']; |
72 | $result['message'] = $remove['message']; | 100 | $result['message'] = $remove['message']; |
@@ -86,6 +114,14 @@ class CartModel | @@ -86,6 +114,14 @@ class CartModel | ||
86 | { | 114 | { |
87 | $result = array('code' => 400, 'message' => '出错啦~'); | 115 | $result = array('code' => 400, 'message' => '出错啦~'); |
88 | 116 | ||
117 | + if (empty($uid)) { | ||
118 | + $result['code'] = 300; | ||
119 | + $reult['message'] = '请先登录'; | ||
120 | + $result['data'] = '/signin.html'; | ||
121 | + | ||
122 | + return $result; | ||
123 | + } | ||
124 | + | ||
89 | // 处理sku | 125 | // 处理sku |
90 | $sku_list = json_encode(array($sku => 1)); | 126 | $sku_list = json_encode(array($sku => 1)); |
91 | 127 | ||
@@ -163,20 +199,84 @@ class CartModel | @@ -163,20 +199,84 @@ class CartModel | ||
163 | } | 199 | } |
164 | 200 | ||
165 | /** | 201 | /** |
202 | + * 处理加价购商品数据 | ||
203 | + * | ||
204 | + * @param int $skn 商品skn | ||
205 | + * @param int $promotionId 加价购商品促销ID | ||
206 | + * @return array | ||
207 | + */ | ||
208 | + public static function giftProductData($skn, $promotionId) | ||
209 | + { | ||
210 | + $result = array(); | ||
211 | + | ||
212 | + $product = CartData::giftProductData($skn, $promotionId); | ||
213 | + if (isset($product['code']) && $product['code'] === 200) { | ||
214 | + $result['code'] = 200; | ||
215 | + $data = array(); | ||
216 | + $productData = $product['data']; | ||
217 | + | ||
218 | + // 品牌信息 | ||
219 | + if (isset($productData['brand_info']) && !empty($productData['brand_info'])) { | ||
220 | + $data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120); | ||
221 | + } | ||
222 | + | ||
223 | + $data['name'] = $productData['product_name']; | ||
224 | + $data['price'] = $productData['market_price']; | ||
225 | + $data['salePrice'] = $productData['sales_price']; | ||
226 | + $data['storage'] = $productData['storage_sum']; | ||
227 | + $data['num'] = $num; | ||
228 | + | ||
229 | + // 商品选择 | ||
230 | + if (isset($productData['goods_list'])) { | ||
231 | + $goodsList = $productData['goods_list']; | ||
232 | + | ||
233 | + $colors = array(); | ||
234 | + $oneColor = array(); | ||
235 | + $sizes = array(); | ||
236 | + $oneSize = array(); | ||
237 | + foreach ($goodsList as $val) { | ||
238 | + // 颜色 | ||
239 | + $oneColor = array(); | ||
240 | + $oneColor['id'] = $val['color_id']; | ||
241 | + $oneColor['name'] = $val['color_name']; | ||
242 | + | ||
243 | + // 尺码 | ||
244 | + foreach ($val['size_list'] as $one) { | ||
245 | + $oneSize = array(); | ||
246 | + $oneSize['id'] = $one['size_id']; | ||
247 | + $oneSize['name'] = $one['size_name']; | ||
248 | + } | ||
249 | + $sizes[] = $oneSize; | ||
250 | + | ||
251 | + $oneColor['sizes'] = $sizes; | ||
252 | + $colors[] = $oneColor; | ||
253 | + } | ||
254 | + | ||
255 | + $data['colors'] = $colors; | ||
256 | + } | ||
257 | + | ||
258 | + $result['data'] = $data; | ||
259 | + } | ||
260 | + | ||
261 | + return $result; | ||
262 | + } | ||
263 | + | ||
264 | + /** | ||
166 | * 修改购物车商品数据 | 265 | * 修改购物车商品数据 |
167 | * | 266 | * |
168 | * @param int $uid 用户ID | 267 | * @param int $uid 用户ID |
169 | * @param string $param 要更改的数据 | 268 | * @param string $param 要更改的数据 |
269 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
170 | * @return array 接口返回的数据 | 270 | * @return array 接口返回的数据 |
171 | */ | 271 | */ |
172 | - public static function modifyCartProduct($uid, $param) | 272 | + public static function modifyCartProduct($uid, $param, $shoppingKey) |
173 | { | 273 | { |
174 | $result = array('code' => 400, 'message' => '出错啦~'); | 274 | $result = array('code' => 400, 'message' => '出错啦~'); |
175 | 275 | ||
176 | // 处理要更改的数据 | 276 | // 处理要更改的数据 |
177 | $swapData = json_encode(array($param)); | 277 | $swapData = json_encode(array($param)); |
178 | 278 | ||
179 | - $modify = CartData::modifyCartProduct($uid, $swapData); | 279 | + $modify = CartData::modifyCartProduct($uid, $swapData, $shoppingKey); |
180 | if ($modify && isset($modify['code'])) { | 280 | if ($modify && isset($modify['code'])) { |
181 | $result['code'] = $modify['code']; | 281 | $result['code'] = $modify['code']; |
182 | $result['message'] = $modify['message']; | 282 | $result['message'] = $modify['message']; |
@@ -197,8 +297,102 @@ class CartModel | @@ -197,8 +297,102 @@ class CartModel | ||
197 | $result = array(); | 297 | $result = array(); |
198 | 298 | ||
199 | $pay = CartData::cartPay($uid, $cartType); | 299 | $pay = CartData::cartPay($uid, $cartType); |
300 | + | ||
200 | if ($pay && isset($pay['code']) && $pay['code'] === 200) { | 301 | if ($pay && isset($pay['code']) && $pay['code'] === 200) { |
201 | - $result = $pay['data']; | 302 | + $payReturn = $pay['data']; |
303 | + $result = array(); | ||
304 | + | ||
305 | + // 收货人有关信息 | ||
306 | + if (isset($payReturn['delivery_address']) && !empty($payReturn['delivery_address'])) { | ||
307 | + $result['name'] = $payReturn['delivery_address']['consignee']; | ||
308 | + $result['phoneNum'] = $payReturn['delivery_address']['mobile'] ?: $payReturn['delivery_address']['phone']; | ||
309 | + $result['address'] = $payReturn['delivery_address']['address']; | ||
310 | + } | ||
311 | + | ||
312 | + // 配送方式 | ||
313 | + if (isset($payReturn['delivery_way'])) { | ||
314 | + $oneDeliv = array(); | ||
315 | + foreach ($payReturn['delivery_way'] as $val) { | ||
316 | + $oneDeliv = array(); | ||
317 | + $oneDeliv['id'] = $val['delivery_way_id']; | ||
318 | + $oneDeliv['name'] = $val['delivery_way_name']; | ||
319 | + $oneDeliv['default'] = ($val['default'] === 'Y'); | ||
320 | + | ||
321 | + $result['dispatchMode'][] = $oneDeliv; | ||
322 | + } | ||
323 | + } | ||
324 | + | ||
325 | + // 配送时间 | ||
326 | + if (isset($payReturn['delivery_time'])) { | ||
327 | + $oneDelivTime = array(); | ||
328 | + foreach ($payReturn['delivery_time'] as $one) { | ||
329 | + $oneDelivTime = array(); | ||
330 | + $oneDelivTime['id'] = $one['delivery_time_id']; | ||
331 | + $oneDelivTime['name'] = $one['delivery_time_string']; | ||
332 | + $oneDelivTime['default'] = ($one['default'] === 'Y'); | ||
333 | + | ||
334 | + $result['dispatchTime'][] = $oneDelivTime; | ||
335 | + } | ||
336 | + } | ||
337 | + | ||
338 | + // 订单商品 | ||
339 | + if (isset($payReturn['goods_list'])) { | ||
340 | + $oneGoods = array(); | ||
341 | + foreach ($payReturn['goods_list'] as $single) { | ||
342 | + $oneGoods = array(); | ||
343 | + $oneGoods['id'] = $single['product_sku']; // TODO 未确定用哪个 | ||
344 | + $oneGoods['thumb'] = Images::getImageUrl($single['goods_images'], 120, 120); | ||
345 | + $oneGoods['name'] = $single['product_name']; | ||
346 | + $oneGoods['color'] = $single['color_name']; | ||
347 | + $oneGoods['size'] = $single['size_name']; | ||
348 | + $oneGoods['price'] = Helpers::transPrice($single['real_price']); // last_price有些带.00,有些不带,real_price都不带.00 | ||
349 | + $oneGoods['count'] = $single['buy_number']; | ||
350 | + | ||
351 | + $result['goods'][] = $oneGoods; | ||
352 | + } | ||
353 | + } | ||
354 | + | ||
355 | + // 支付方式 | ||
356 | + if (isset($payReturn['payment_way'])) { | ||
357 | + $onePay = array(); | ||
358 | + foreach ($payReturn['payment_way'] as $pay) { | ||
359 | + $onePay = array(); | ||
360 | + $onePay['id'] = $pay['payment_id']; | ||
361 | + $onePay['paymentType'] = $pay['payment_type']; | ||
362 | + $onePay['name'] = $pay['payment_type_name']; | ||
363 | + $onePay['default'] = ($pay['default'] === 'Y'); | ||
364 | + | ||
365 | + $result['paymentWay'][] = $onePay; | ||
366 | + } | ||
367 | + } | ||
368 | + | ||
369 | + // 有货币 | ||
370 | + $result['yohoCoin'] = $payReturn['yoho_coin']; | ||
371 | + | ||
372 | + // 订单数据 | ||
373 | + if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) { | ||
374 | + $result['sumPrice'] = Helpers::transPrice($payReturn['shopping_cart_data']['order_amount']); | ||
375 | + $result['salePrice'] = Helpers::transPrice($payReturn['shopping_cart_data']['discount_amount']); | ||
376 | + $result['price'] = Helpers::transPrice($payReturn['shopping_cart_data']['last_order_amount']); | ||
377 | + $result['freight'] = Helpers::transPrice($payReturn['shopping_cart_data']['shipping_cost']); | ||
378 | + } | ||
379 | + | ||
380 | + // 发票有关数据 | ||
381 | + if (isset($payReturn['invoices']) && !empty($payReturn['invoices'])) { | ||
382 | + $one = array(); | ||
383 | + foreach ($payReturn['invoices']['invoices_type_list'] as $inv) { | ||
384 | + $one = array(); | ||
385 | + $one['id'] = $inv['invoices_type_id']; | ||
386 | + $one['name'] = $inv['invoices_type_name']; | ||
387 | + | ||
388 | + $result['invoice'][] = $one; | ||
389 | + } | ||
390 | + } | ||
391 | + | ||
392 | + // 优惠券数据 | ||
393 | + $coupons = array('notUsed' => true); | ||
394 | + $coupons += UserModel::getCouponData($uid, 0, 1, true); | ||
395 | + $result['coupon'] = $coupons; | ||
202 | } | 396 | } |
203 | 397 | ||
204 | return $result; | 398 | return $result; |
-
Please register or login to post a comment