do add shopping cart action
Showing
4 changed files
with
978 additions
and
931 deletions
@@ -17,255 +17,257 @@ use Api\Yohobuy; | @@ -17,255 +17,257 @@ use Api\Yohobuy; | ||
17 | class CartData | 17 | class CartData |
18 | { | 18 | { |
19 | 19 | ||
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 | - /** | ||
51 | - * 购物车数据 | ||
52 | - * | ||
53 | - * @param int $uid 用户ID | ||
54 | - * @param string $shoppingKey 未登录用户唯一识别码 | ||
55 | - * @return array 购物车接口返回的数据 | ||
56 | - */ | ||
57 | - public static function cartData($uid, $shoppingKey) | ||
58 | - { | ||
59 | - $param = Yohobuy::param(); | ||
60 | - $param['method'] = 'app.Shopping.cart'; | ||
61 | - | ||
62 | - if (!empty($uid)) { | ||
63 | - $param['uid'] = $uid; | ||
64 | - } | ||
65 | - if (!empty($shoppingKey)) { | ||
66 | - $param['shopping_key'] = $shoppingKey; | ||
67 | - } | ||
68 | - | ||
69 | - $param['client_secret'] = Sign::getSign($param); | ||
70 | - | ||
71 | - return Yohobuy::get(Yohobuy::API_URL, $param); | ||
72 | - } | ||
73 | - | ||
74 | - /** | ||
75 | - * 移出购物车 | ||
76 | - * | ||
77 | - * @param int $uid 用户ID | ||
78 | - * @param string $sku 商品sku列表 | ||
79 | - * @param string $shoppingKey 未登录用户唯一识别码 | ||
80 | - * @return array 接口返回的数据 | ||
81 | - */ | ||
82 | - public static function removeFromCart($uid, $sku, $shoppingKey) | ||
83 | - { | ||
84 | - $param = Yohobuy::param(); | ||
85 | - $param['method'] = 'app.Shopping.remove'; | ||
86 | - $param['product_sku_list'] = $sku; | ||
87 | - | ||
88 | - if (!empty($uid)) { | ||
89 | - $param['uid'] = $uid; | ||
90 | - } | ||
91 | - if (!empty($shoppingKey)) { | ||
92 | - $param['shopping_key'] = $shoppingKey; | ||
93 | - } | ||
94 | - | ||
95 | - $param['client_secret'] = Sign::getSign($param); | ||
96 | - | ||
97 | - return Yohobuy::get(Yohobuy::API_URL, $param); | ||
98 | - } | ||
99 | - | ||
100 | - /** | ||
101 | - * 移入收藏夹 | ||
102 | - * | ||
103 | - * @param int $uid 用户ID | ||
104 | - * @param string $sku 商品sku列表 | ||
105 | - * @return array 接口返回的数据 | ||
106 | - */ | ||
107 | - public static function addToFav($uid, $sku) | ||
108 | - { | ||
109 | - $param = Yohobuy::param(); | ||
110 | - $param['method'] = 'app.Shopping.addfavorite'; | ||
111 | - $param['product_sku_list'] = $sku; | ||
112 | - $param['uid'] = $uid; | ||
113 | - $param['client_secret'] = Sign::getSign($param); | ||
114 | - | ||
115 | - return Yohobuy::get(Yohobuy::API_URL, $param); | ||
116 | - } | ||
117 | - | ||
118 | - /** | ||
119 | - * 获取购物车商品数据 | ||
120 | - * | ||
121 | - * @param int $uid 用户ID | ||
122 | - * @param int $skn 商品skn | ||
123 | - * @return array 接口返回的数据 | ||
124 | - */ | ||
125 | - public static function cartProductData($uid, $skn) | ||
126 | - { | ||
127 | - $param = Yohobuy::param(); | ||
128 | - $param['method'] = 'app.product.data'; | ||
129 | - $param['product_skn'] = $skn; | ||
130 | - $param['showcomment'] = 'N'; | ||
131 | - $param['uid'] = $uid; | ||
132 | - $param['client_secret'] = Sign::getSign($param); | ||
133 | - | ||
134 | - return Yohobuy::get(Yohobuy::API_URL, $param); | ||
135 | - } | ||
136 | - | ||
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 | - /** | ||
156 | - * 修改购物车商品数据 | ||
157 | - * | ||
158 | - * @param int $uid 用户ID | ||
159 | - * @param string $swapData 商品数据 | ||
160 | - * @param string $shoppingKey 未登录用户唯一识别码 | ||
161 | - * @return array 接口返回的数据 | ||
162 | - */ | ||
163 | - public static function modifyCartProduct($uid, $swapData, $shoppingKey) | ||
164 | - { | ||
165 | - $param = Yohobuy::param(); | ||
166 | - $param['method'] = 'app.Shopping.swap'; | ||
167 | - $param['swap_data'] = $swapData; | ||
168 | - | ||
169 | - if (!empty($uid)) { | ||
170 | - $param['uid'] = $uid; | ||
171 | - } | ||
172 | - if ($shoppingKey !== null) { | ||
173 | - $param['shopping_key'] = $shoppingKey; | ||
174 | - } | ||
175 | - | ||
176 | - $param['client_secret'] = Sign::getSign($param); | ||
177 | - | ||
178 | - return Yohobuy::get(Yohobuy::API_URL, $param); | ||
179 | - } | ||
180 | - | ||
181 | - /** | ||
182 | - * 购物车结算 | ||
183 | - * | ||
184 | - * @param int $uid 用户ID | ||
185 | - * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
186 | - * @return array 接口返回的数据 | ||
187 | - */ | ||
188 | - public static function cartPay($uid, $cartType) | ||
189 | - { | ||
190 | - $param = Yohobuy::param(); | ||
191 | - $param['method'] = 'app.Shopping.payment'; | ||
192 | - $param['cart_type'] = $cartType; | ||
193 | - $param['uid'] = $uid; | ||
194 | - $param['client_secret'] = Sign::getSign($param); | ||
195 | - | ||
196 | - return Yohobuy::get(Yohobuy::API_URL, $param); | ||
197 | - } | ||
198 | - | ||
199 | - /** | ||
200 | - * 购物车结算--支付方式和配送方式选择 | ||
201 | - * | ||
202 | - * @param int $uid 用户ID | ||
203 | - * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
204 | - * @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 | ||
205 | - * @param string $paymentType 支付方式,1表示在线支付,2表示货到付款 | ||
206 | - * @param string $yohoCoin 使用的YOHO币数量,默认为null表示不适用 | ||
207 | - * @return array 接口返回的数据 | ||
208 | - */ | ||
209 | - public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType, $yohoCoin = null) | ||
210 | - { | ||
211 | - $param = Yohobuy::param(); | ||
212 | - $param['method'] = 'app.Shopping.compute'; | ||
213 | - $param['cart_type'] = $cartType; | ||
214 | - $param['delivery_way'] = $deliveryWay; | ||
215 | - $param['payment_type'] = $paymentType; | ||
216 | - if ($yohoCoin !== null) { | ||
217 | - $param['use_yoho_coin'] = $yohoCoin; | ||
218 | - } | ||
219 | - | ||
220 | - $param['uid'] = $uid; | ||
221 | - $param['client_secret'] = Sign::getSign($param); | ||
222 | - | ||
223 | - return Yohobuy::get(Yohobuy::API_URL, $param); | ||
224 | - } | ||
225 | - | ||
226 | - /** | ||
227 | - * 购物车结算--使用优惠券 | ||
228 | - * | ||
229 | - * @param int $uid 用户ID | ||
230 | - * @param string $couponCode 优惠券代码 | ||
231 | - * @return array 接口返回的数据 | ||
232 | - */ | ||
233 | - public static function getCoupon($uid, $couponCode) | ||
234 | - { | ||
235 | - $param = Yohobuy::param(); | ||
236 | - $param['method'] = 'app.Shopping.useCoupon'; | ||
237 | - $param['coupon_code'] = $couponCode; | ||
238 | - $param['uid'] = $uid; | ||
239 | - $param['client_secret'] = Sign::getSign($param); | ||
240 | - | ||
241 | - return Yohobuy::get(Yohobuy::API_URL, $param); | ||
242 | - } | ||
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 | - } | 20 | + /** |
21 | + * 加入购物车接口 | ||
22 | + * | ||
23 | + * @param int $productSku 商品SKU | ||
24 | + * @param int $buyNumber 购买数量 | ||
25 | + * @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品 | ||
26 | + * @param int $isEdit 是否是编辑商品SKU,0表示不是编辑 | ||
27 | + * @param null|int $promotionId 促销id,默认null(加价购有关) | ||
28 | + * @param null|int $uid 用户UID,可以不传 | ||
29 | + * @param string $shoppingKey 购物的凭证 | ||
30 | + * @return array 加入购物车接口返回的数据 | ||
31 | + */ | ||
32 | + public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit = 0, $promotionId = null, $uid = null, $shoppingKey = '') | ||
33 | + { | ||
34 | + $param = Yohobuy::param(); | ||
35 | + $param['method'] = 'app.Shopping.add'; | ||
36 | + $param['product_sku'] = $productSku; | ||
37 | + $param['buy_number'] = $buyNumber; | ||
38 | + $param['goods_type'] = $goodsType; | ||
39 | + $param['edit_product_sku'] = $isEdit; | ||
40 | + $param['selected'] = 'Y'; | ||
41 | + $param['promotion_id'] = $promotionId; | ||
42 | + $param['shopping_key'] = $shoppingKey; | ||
43 | + | ||
44 | + if (!empty($uid)) { | ||
45 | + $param['uid'] = $uid; | ||
46 | + } | ||
47 | + $param['client_secret'] = Sign::getSign($param); | ||
48 | + | ||
49 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * 购物车数据 | ||
54 | + * | ||
55 | + * @param int $uid 用户ID | ||
56 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
57 | + * @return array 购物车接口返回的数据 | ||
58 | + */ | ||
59 | + public static function cartData($uid, $shoppingKey) | ||
60 | + { | ||
61 | + $param = Yohobuy::param(); | ||
62 | + $param['method'] = 'app.Shopping.cart'; | ||
63 | + | ||
64 | + if (!empty($uid)) { | ||
65 | + $param['uid'] = $uid; | ||
66 | + } | ||
67 | + if (!empty($shoppingKey)) { | ||
68 | + $param['shopping_key'] = $shoppingKey; | ||
69 | + } | ||
70 | + | ||
71 | + $param['client_secret'] = Sign::getSign($param); | ||
72 | + | ||
73 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * 移出购物车 | ||
78 | + * | ||
79 | + * @param int $uid 用户ID | ||
80 | + * @param string $sku 商品sku列表 | ||
81 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
82 | + * @return array 接口返回的数据 | ||
83 | + */ | ||
84 | + public static function removeFromCart($uid, $sku, $shoppingKey) | ||
85 | + { | ||
86 | + $param = Yohobuy::param(); | ||
87 | + $param['method'] = 'app.Shopping.remove'; | ||
88 | + $param['product_sku_list'] = $sku; | ||
89 | + | ||
90 | + if (!empty($uid)) { | ||
91 | + $param['uid'] = $uid; | ||
92 | + } | ||
93 | + if (!empty($shoppingKey)) { | ||
94 | + $param['shopping_key'] = $shoppingKey; | ||
95 | + } | ||
96 | + | ||
97 | + $param['client_secret'] = Sign::getSign($param); | ||
98 | + | ||
99 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * 移入收藏夹 | ||
104 | + * | ||
105 | + * @param int $uid 用户ID | ||
106 | + * @param string $sku 商品sku列表 | ||
107 | + * @return array 接口返回的数据 | ||
108 | + */ | ||
109 | + public static function addToFav($uid, $sku) | ||
110 | + { | ||
111 | + $param = Yohobuy::param(); | ||
112 | + $param['method'] = 'app.Shopping.addfavorite'; | ||
113 | + $param['product_sku_list'] = $sku; | ||
114 | + $param['uid'] = $uid; | ||
115 | + $param['client_secret'] = Sign::getSign($param); | ||
116 | + | ||
117 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * 获取购物车商品数据 | ||
122 | + * | ||
123 | + * @param int $uid 用户ID | ||
124 | + * @param int $skn 商品skn | ||
125 | + * @return array 接口返回的数据 | ||
126 | + */ | ||
127 | + public static function cartProductData($uid, $skn) | ||
128 | + { | ||
129 | + $param = Yohobuy::param(); | ||
130 | + $param['method'] = 'app.product.data'; | ||
131 | + $param['product_skn'] = $skn; | ||
132 | + $param['showcomment'] = 'N'; | ||
133 | + $param['uid'] = $uid; | ||
134 | + $param['client_secret'] = Sign::getSign($param); | ||
135 | + | ||
136 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * 获取加价购商品数据 | ||
141 | + * | ||
142 | + * @param int $skn 商品skn | ||
143 | + * @param int $promotionId 加价购商品促销ID | ||
144 | + * @return array 接口返回的数据 | ||
145 | + */ | ||
146 | + public static function giftProductData($skn, $promotionId) | ||
147 | + { | ||
148 | + $param = Yohobuy::param(); | ||
149 | + $param['method'] = 'app.product.gift'; | ||
150 | + $param['product_skn'] = $skn; | ||
151 | + $param['promotion_id'] = $promotionId; | ||
152 | + $param['client_secret'] = Sign::getSign($param); | ||
153 | + | ||
154 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * 修改购物车商品数据 | ||
159 | + * | ||
160 | + * @param int $uid 用户ID | ||
161 | + * @param string $swapData 商品数据 | ||
162 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
163 | + * @return array 接口返回的数据 | ||
164 | + */ | ||
165 | + public static function modifyCartProduct($uid, $swapData, $shoppingKey) | ||
166 | + { | ||
167 | + $param = Yohobuy::param(); | ||
168 | + $param['method'] = 'app.Shopping.swap'; | ||
169 | + $param['swap_data'] = $swapData; | ||
170 | + | ||
171 | + if (!empty($uid)) { | ||
172 | + $param['uid'] = $uid; | ||
173 | + } | ||
174 | + if ($shoppingKey !== null) { | ||
175 | + $param['shopping_key'] = $shoppingKey; | ||
176 | + } | ||
177 | + | ||
178 | + $param['client_secret'] = Sign::getSign($param); | ||
179 | + | ||
180 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
181 | + } | ||
182 | + | ||
183 | + /** | ||
184 | + * 购物车结算 | ||
185 | + * | ||
186 | + * @param int $uid 用户ID | ||
187 | + * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
188 | + * @return array 接口返回的数据 | ||
189 | + */ | ||
190 | + public static function cartPay($uid, $cartType) | ||
191 | + { | ||
192 | + $param = Yohobuy::param(); | ||
193 | + $param['method'] = 'app.Shopping.payment'; | ||
194 | + $param['cart_type'] = $cartType; | ||
195 | + $param['uid'] = $uid; | ||
196 | + $param['client_secret'] = Sign::getSign($param); | ||
197 | + | ||
198 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
199 | + } | ||
200 | + | ||
201 | + /** | ||
202 | + * 购物车结算--支付方式和配送方式选择 | ||
203 | + * | ||
204 | + * @param int $uid 用户ID | ||
205 | + * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
206 | + * @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 | ||
207 | + * @param string $paymentType 支付方式,1表示在线支付,2表示货到付款 | ||
208 | + * @param string $yohoCoin 使用的YOHO币数量,默认为null表示不适用 | ||
209 | + * @return array 接口返回的数据 | ||
210 | + */ | ||
211 | + public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType, $yohoCoin = null) | ||
212 | + { | ||
213 | + $param = Yohobuy::param(); | ||
214 | + $param['method'] = 'app.Shopping.compute'; | ||
215 | + $param['cart_type'] = $cartType; | ||
216 | + $param['delivery_way'] = $deliveryWay; | ||
217 | + $param['payment_type'] = $paymentType; | ||
218 | + if ($yohoCoin !== null) { | ||
219 | + $param['use_yoho_coin'] = $yohoCoin; | ||
220 | + } | ||
221 | + | ||
222 | + $param['uid'] = $uid; | ||
223 | + $param['client_secret'] = Sign::getSign($param); | ||
224 | + | ||
225 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
226 | + } | ||
227 | + | ||
228 | + /** | ||
229 | + * 购物车结算--使用优惠券 | ||
230 | + * | ||
231 | + * @param int $uid 用户ID | ||
232 | + * @param string $couponCode 优惠券代码 | ||
233 | + * @return array 接口返回的数据 | ||
234 | + */ | ||
235 | + public static function getCoupon($uid, $couponCode) | ||
236 | + { | ||
237 | + $param = Yohobuy::param(); | ||
238 | + $param['method'] = 'app.Shopping.useCoupon'; | ||
239 | + $param['coupon_code'] = $couponCode; | ||
240 | + $param['uid'] = $uid; | ||
241 | + $param['client_secret'] = Sign::getSign($param); | ||
242 | + | ||
243 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
244 | + } | ||
245 | + | ||
246 | + /** | ||
247 | + * 购物车结算--提交结算信息 | ||
248 | + * | ||
249 | + * @param int $uid 用户ID | ||
250 | + * @param string $couponCode 优惠券代码 | ||
251 | + * @return array 接口返回的数据 | ||
252 | + */ | ||
253 | + public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin) | ||
254 | + { | ||
255 | + $param = Yohobuy::param(); | ||
256 | + $param['method'] = 'app.Shopping.submit'; | ||
257 | + $param['addressId'] = $addressId; | ||
258 | + $param['cart_type'] = $cartType; | ||
259 | + $param['delivery_time'] = $deliveryTime; | ||
260 | + $param['delivery_way'] = $deliveryWay; | ||
261 | + $param['invoices_title'] = $invoiceTitle; | ||
262 | + $param['invoices_type_id'] = $invoiceId; | ||
263 | + $param['payment_id'] = $paymentId; | ||
264 | + $param['payment_type'] = $paymentType; | ||
265 | + $param['remark'] = $remark; | ||
266 | + $param['use_yoho_coin'] = $yohoCoin; | ||
267 | + $param['uid'] = $uid; | ||
268 | + $param['client_secret'] = Sign::getSign($param); | ||
269 | + | ||
270 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
271 | + } | ||
270 | 272 | ||
271 | } | 273 | } |
@@ -123,6 +123,17 @@ class Helpers | @@ -123,6 +123,17 @@ class Helpers | ||
123 | } | 123 | } |
124 | 124 | ||
125 | /** | 125 | /** |
126 | + * 从用户加入购物车的COOKIE取出购物车凭证 | ||
127 | + * | ||
128 | + * @return string | ||
129 | + */ | ||
130 | + public static function getShoppingKeyByCookie() | ||
131 | + { | ||
132 | + $cookie = isset($_COOKIE['_spk']) ? $_COOKIE['_spk'] : ''; | ||
133 | + return $cookie; | ||
134 | + } | ||
135 | + | ||
136 | + /** | ||
126 | * 获取商品的ICON | 137 | * 获取商品的ICON |
127 | * | 138 | * |
128 | * @param int $type | 139 | * @param int $type |
@@ -171,16 +182,16 @@ class Helpers | @@ -171,16 +182,16 @@ class Helpers | ||
171 | return $result; | 182 | return $result; |
172 | } | 183 | } |
173 | 184 | ||
174 | - /** | ||
175 | - * 转换价格 | ||
176 | - * | ||
177 | - * @param float|string $price 价格 | ||
178 | - * @return float|string 转换之后的价格 | ||
179 | - */ | ||
180 | - public static function transPrice($price) | ||
181 | - { | ||
182 | - return (!empty($price) && !is_float($price)) ? $price . '.00' : $price; | ||
183 | - } | 185 | + /** |
186 | + * 转换价格 | ||
187 | + * | ||
188 | + * @param float|string $price 价格 | ||
189 | + * @return float|string 转换之后的价格 | ||
190 | + */ | ||
191 | + public static function transPrice($price) | ||
192 | + { | ||
193 | + return (!empty($price) && !is_float($price)) ? $price . '.00' : $price; | ||
194 | + } | ||
184 | 195 | ||
185 | /** | 196 | /** |
186 | * 格式化商品信息 | 197 | * 格式化商品信息 |
@@ -225,8 +236,8 @@ class Helpers | @@ -225,8 +236,8 @@ class Helpers | ||
225 | } | 236 | } |
226 | $result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y'); | 237 | $result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y'); |
227 | $result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_' | 238 | $result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_' |
228 | - . $productData['goods_list'][0]['goods_id'] | ||
229 | - . '/' . $productData['cn_alphabet'] . '.html'); | 239 | + . $productData['goods_list'][0]['goods_id'] |
240 | + . '/' . $productData['cn_alphabet'] . '.html'); | ||
230 | // APP访问需要加附加的参数 | 241 | // APP访问需要加附加的参数 |
231 | // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护 | 242 | // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护 |
232 | if ($isApp) { | 243 | if ($isApp) { |
@@ -515,7 +526,7 @@ class Helpers | @@ -515,7 +526,7 @@ class Helpers | ||
515 | public static function formatOrderGoods($orderGoods, &$count = 0, $haveLink = false) | 526 | public static function formatOrderGoods($orderGoods, &$count = 0, $haveLink = false) |
516 | { | 527 | { |
517 | $arr = array(); | 528 | $arr = array(); |
518 | - | 529 | + |
519 | foreach ($orderGoods as $key => $vo) { | 530 | foreach ($orderGoods as $key => $vo) { |
520 | $arr[$key]['thumb'] = Helpers::getImageUrl($vo['goods_image'], 90, 120); | 531 | $arr[$key]['thumb'] = Helpers::getImageUrl($vo['goods_image'], 90, 120); |
521 | $arr[$key]['name'] = $vo['product_name']; | 532 | $arr[$key]['name'] = $vo['product_name']; |
@@ -540,7 +551,7 @@ class Helpers | @@ -540,7 +551,7 @@ class Helpers | ||
540 | // 累计购买数 | 551 | // 累计购买数 |
541 | $count += intval($vo['buy_number']); | 552 | $count += intval($vo['buy_number']); |
542 | } | 553 | } |
543 | - | 554 | + |
544 | return $arr; | 555 | return $arr; |
545 | } | 556 | } |
546 | 557 |
@@ -10,217 +10,254 @@ use Plugin\Helpers; | @@ -10,217 +10,254 @@ use Plugin\Helpers; | ||
10 | */ | 10 | */ |
11 | class ShoppingCartController extends AbstractAction | 11 | class ShoppingCartController extends AbstractAction |
12 | { | 12 | { |
13 | + /* | ||
14 | + * 购物车首页 | ||
15 | + */ | ||
13 | 16 | ||
14 | - /* | ||
15 | - * 购物车首页 | ||
16 | - */ | ||
17 | public function indexAction() | 17 | public function indexAction() |
18 | { | 18 | { |
19 | $this->setTitle('购物车'); | 19 | $this->setTitle('购物车'); |
20 | $this->setNavHeader('购物车'); | 20 | $this->setNavHeader('购物车'); |
21 | 21 | ||
22 | - $shoppingKey = $this->getSession('shoppingKey'); | ||
23 | - $uid = $this->getUid(true); | 22 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); |
23 | + $uid = $this->getUid(true); | ||
24 | 24 | ||
25 | $data = array( | 25 | $data = array( |
26 | - 'shoppingCartPage' => true, | ||
27 | - 'shoppingCart' => CartModel::getCartData($uid, $shoppingKey) | 26 | + 'shoppingCartPage' => true, |
27 | + 'shoppingCart' => CartModel::getCartData($uid, $shoppingKey) | ||
28 | ); | 28 | ); |
29 | 29 | ||
30 | // 渲染模板 | 30 | // 渲染模板 |
31 | $this->_view->display('index', $data); | 31 | $this->_view->display('index', $data); |
32 | } | 32 | } |
33 | 33 | ||
34 | - /** | ||
35 | - * 移出购物车 | ||
36 | - */ | ||
37 | - public function delAction() | ||
38 | - { | ||
39 | - $result = array(); | ||
40 | - | ||
41 | - if ($this->isAjax()) { | ||
42 | - $productId = $this->post('id', 0); | ||
43 | - $uid = $this->getUid(true); | ||
44 | - $shoppingKey = $this->getSession('shoppingKey'); | ||
45 | - $result = CartModel::removeFromCart($uid, $productId, $shoppingKey); | ||
46 | - } | ||
47 | - | ||
48 | - if (empty($result)) { | ||
49 | - echo ' '; | ||
50 | - } else { | ||
51 | - $this->echoJson($result); | ||
52 | - } | ||
53 | - } | ||
54 | - | ||
55 | - /** | ||
56 | - * 移入收藏夹 | ||
57 | - */ | ||
58 | - public function colAction() | ||
59 | - { | ||
60 | - $result = array(); | ||
61 | - | ||
62 | - if ($this->isAjax()) { | ||
63 | - $productId = $this->post('id', 0); | ||
64 | - $uid = $this->getUid(true); | ||
65 | - $result = CartModel::addToFav($uid, $productId); | ||
66 | - } | ||
67 | - | ||
68 | - if (empty($result)) { | ||
69 | - echo ' '; | ||
70 | - } else { | ||
71 | - $this->echoJson($result); | ||
72 | - } | ||
73 | - } | ||
74 | - | ||
75 | - /* | ||
76 | - * 获取购物车商品数据 | ||
77 | - */ | ||
78 | - public function goodinfoAction() | ||
79 | - { | ||
80 | - $result = array(); | ||
81 | - | ||
82 | - if ($this->isAjax()) { | ||
83 | - $num = $this->get('buy_num', 1); | ||
84 | - $skn = $this->get('id', 1); | ||
85 | - $uid = $this->getUid(true); | ||
86 | - $result = CartModel::cartProductData($uid, $skn, $num); // 测试skn的ID为51172055 | ||
87 | - $result['num'] = $num; | ||
88 | - } | ||
89 | - | ||
90 | - if (empty($result)) { | ||
91 | - echo ' '; | ||
92 | - } else { | ||
93 | - $this->echoJson($result); | ||
94 | - } | ||
95 | - } | ||
96 | - | ||
97 | - /* | ||
98 | - * 获取购物车加价购商品数据 | ||
99 | - */ | ||
100 | - public function giftinfoAction() | ||
101 | - { | ||
102 | - $result = array(); | ||
103 | - | ||
104 | - if ($this->isAjax()) { | ||
105 | - $skn = $this->get('skn', null); | ||
106 | - $promotionId = $this->get('promotionId', null); | ||
107 | - $result = CartModel::giftProductData($skn, $promotionId); | ||
108 | - } | ||
109 | - | ||
110 | - if (empty($result)) { | ||
111 | - echo ' '; | ||
112 | - } else { | ||
113 | - $this->echoJson($result); | ||
114 | - } | ||
115 | - } | ||
116 | - | ||
117 | - /** | ||
118 | - * 修改购物车商品数据 | ||
119 | - */ | ||
120 | - public function modifyAction() | ||
121 | - { | ||
122 | - $result = array(); | ||
123 | - | ||
124 | - if ($this->isAjax()) { | ||
125 | - $shoppingKey = $this->getSession('shoppingKey'); | ||
126 | - $uid = $this->getUid(true); | ||
127 | - | ||
128 | - $params = array(); | ||
129 | - $params['old_product_sku']= $this->post('old_product_sku', 0); | ||
130 | - $params['new_product_sku']= $this->post('new_product_sku', 0); | ||
131 | - $params['buy_number']= $this->post('buy_number', 0); | ||
132 | - $params['selected']= $this->post('selected', null); | ||
133 | - $result = CartModel::modifyCartProduct($uid, $params, $shoppingKey); | ||
134 | - } | ||
135 | - | ||
136 | - if (empty($result)) { | ||
137 | - echo ' '; | ||
138 | - } else { | ||
139 | - $this->echoJson($result); | ||
140 | - } | ||
141 | - } | ||
142 | - | ||
143 | - /** | ||
144 | - * 购物车结算请求 | ||
145 | - */ | ||
146 | - public function payAction() | ||
147 | - { | ||
148 | - $this->setTitle('购物车'); | ||
149 | - $this->setNavHeader('购物车'); | ||
150 | - | ||
151 | - $cartType = $this->post('cartType', 'ordinary'); | ||
152 | - $uid = $this->getUid(true); | ||
153 | - $data = array( | ||
154 | - 'orderEnsurePage' => true, | ||
155 | - 'orderEnsure' => CartModel::cartPay($uid, $cartType) | ||
156 | - ); | ||
157 | - | ||
158 | - $this->_view->display('order-ensure', $data); | ||
159 | - } | ||
160 | - | ||
161 | - /** | ||
162 | - * 购物车选择支付方式和配送方式接口 | ||
163 | - */ | ||
164 | - public function payAndDeliveryAction() | ||
165 | - { | ||
166 | - $result = array(); | ||
167 | - | ||
168 | - if ($this->isAjax()) { | ||
169 | - $cartType = $this->post('cartType', 'ordinary'); | ||
170 | - $deliveryWay = $this->post('deliveryWay', 1); | ||
171 | - $paymentType = $this->post('paymentType', 1); | ||
172 | - $uid = $this->getUid(true); | ||
173 | - $result = CartModel::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType); | ||
174 | - } | ||
175 | - | ||
176 | - if (empty($result)) { | ||
177 | - echo ' '; | ||
178 | - } else { | ||
179 | - $this->echoJson($result); | ||
180 | - } | ||
181 | - } | ||
182 | - | ||
183 | - /** | ||
184 | - * 购物车输入优惠券码使用优惠券 | ||
185 | - */ | ||
186 | - public function couponAction() | ||
187 | - { | ||
188 | - $result = array(); | ||
189 | - | ||
190 | - if ($this->isAjax()) { | ||
191 | - $couponCode = $this->post('couponCode', ''); | ||
192 | - $uid = $this->getUid(true); | ||
193 | - $result = CartModel::getCoupon($uid, $couponCode); | ||
194 | - } | ||
195 | - | ||
196 | - if (empty($result)) { | ||
197 | - echo ' '; | ||
198 | - } else { | ||
199 | - $this->echoJson($result); | ||
200 | - } | ||
201 | - } | ||
202 | - | ||
203 | - /** | ||
204 | - * 购物车使用YOHO币 | ||
205 | - */ | ||
206 | - public function yohoCoinAction() | ||
207 | - { | ||
208 | - $result = array(); | ||
209 | - | ||
210 | - if ($this->isAjax()) { | ||
211 | - $cartType = $this->post('cartType', 'ordinary'); | ||
212 | - $deliveryWay = $this->post('deliveryWay', 1); | ||
213 | - $paymentType = $this->post('paymentType', 1); | ||
214 | - $yohoCoin = $this->post('yohoCoin', 1); | ||
215 | - $result = CartModel::paymentTypeAndDelivery($this->_uid, $cartType, $deliveryWay, $paymentType, $yohoCoin); | ||
216 | - } | ||
217 | - | ||
218 | - if (empty($result)) { | ||
219 | - echo ' '; | ||
220 | - } else { | ||
221 | - $this->echoJson($result); | ||
222 | - } | ||
223 | - } | 34 | + /** |
35 | + * 加入购物车 | ||
36 | + * | ||
37 | + * @param string productSku 商品的SKU | ||
38 | + * @param int buyNumber 购买数量 | ||
39 | + * @param int promotionId 促销ID, 加价购有关 | ||
40 | + * @param int goodsType 商品类型,0表示普通商品,1表示加价购商品 | ||
41 | + * @param int isEdit 是否是编辑商品SKU,0表示不是编辑 | ||
42 | + * @return json | ||
43 | + */ | ||
44 | + public function addAction() | ||
45 | + { | ||
46 | + $result = array(); | ||
47 | + | ||
48 | + if ($this->isAjax()) { | ||
49 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
50 | + $productSku = $this->post('productSku'); | ||
51 | + $buyNumber = $this->post('buyNumber', 1); | ||
52 | + $goodsType = $this->post('goodsType', 0); | ||
53 | + $promotionId = $this->post('promotionId', 0); | ||
54 | + $isEdit = $this->post('isEdit', 0); | ||
55 | + $uid = $this->getUid(true); | ||
56 | + | ||
57 | + // 执行加入购物车操作 | ||
58 | + $result = CartModel::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey); | ||
59 | + | ||
60 | + // 设置加入购物车凭证到客户端浏览器 | ||
61 | + if (isset($result['data']['shopping_key'])) { | ||
62 | + $this->setCookie('_spk', $shoppingKey); | ||
63 | + } | ||
64 | + } | ||
65 | + | ||
66 | + $this->echoJson($result); | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * 移出购物车 | ||
71 | + */ | ||
72 | + public function delAction() | ||
73 | + { | ||
74 | + $result = array(); | ||
75 | + | ||
76 | + if ($this->isAjax()) { | ||
77 | + $productId = $this->post('id', 0); | ||
78 | + $uid = $this->getUid(true); | ||
79 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
80 | + $result = CartModel::removeFromCart($uid, $productId, $shoppingKey); | ||
81 | + } | ||
82 | + | ||
83 | + if (empty($result)) { | ||
84 | + echo ' '; | ||
85 | + } else { | ||
86 | + $this->echoJson($result); | ||
87 | + } | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * 移入收藏夹 | ||
92 | + */ | ||
93 | + public function colAction() | ||
94 | + { | ||
95 | + $result = array(); | ||
96 | + | ||
97 | + if ($this->isAjax()) { | ||
98 | + $productId = $this->post('id', 0); | ||
99 | + $uid = $this->getUid(true); | ||
100 | + $result = CartModel::addToFav($uid, $productId); | ||
101 | + } | ||
102 | + | ||
103 | + if (empty($result)) { | ||
104 | + echo ' '; | ||
105 | + } else { | ||
106 | + $this->echoJson($result); | ||
107 | + } | ||
108 | + } | ||
109 | + | ||
110 | + /* | ||
111 | + * 获取购物车商品数据 | ||
112 | + */ | ||
113 | + | ||
114 | + public function goodinfoAction() | ||
115 | + { | ||
116 | + $result = array(); | ||
117 | + | ||
118 | + if ($this->isAjax()) { | ||
119 | + $num = $this->get('buy_num', 1); | ||
120 | + $skn = $this->get('id', 1); | ||
121 | + $uid = $this->getUid(true); | ||
122 | + $result = CartModel::cartProductData($uid, $skn, $num); // 测试skn的ID为51172055 | ||
123 | + $result['num'] = $num; | ||
124 | + } | ||
125 | + | ||
126 | + if (empty($result)) { | ||
127 | + echo ' '; | ||
128 | + } else { | ||
129 | + $this->echoJson($result); | ||
130 | + } | ||
131 | + } | ||
132 | + | ||
133 | + /* | ||
134 | + * 获取购物车加价购商品数据 | ||
135 | + */ | ||
136 | + | ||
137 | + public function giftinfoAction() | ||
138 | + { | ||
139 | + $result = array(); | ||
140 | + | ||
141 | + if ($this->isAjax()) { | ||
142 | + $skn = $this->get('skn', null); | ||
143 | + $promotionId = $this->get('promotionId', null); | ||
144 | + $result = CartModel::giftProductData($skn, $promotionId); | ||
145 | + } | ||
146 | + | ||
147 | + if (empty($result)) { | ||
148 | + echo ' '; | ||
149 | + } else { | ||
150 | + $this->echoJson($result); | ||
151 | + } | ||
152 | + } | ||
153 | + | ||
154 | + /** | ||
155 | + * 修改购物车商品数据 | ||
156 | + */ | ||
157 | + public function modifyAction() | ||
158 | + { | ||
159 | + $result = array(); | ||
160 | + | ||
161 | + if ($this->isAjax()) { | ||
162 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
163 | + $uid = $this->getUid(true); | ||
164 | + | ||
165 | + $params = array(); | ||
166 | + $params['old_product_sku'] = $this->post('old_product_sku', 0); | ||
167 | + $params['new_product_sku'] = $this->post('new_product_sku', 0); | ||
168 | + $params['buy_number'] = $this->post('buy_number', 0); | ||
169 | + $params['selected'] = $this->post('selected', null); | ||
170 | + $result = CartModel::modifyCartProduct($uid, $params, $shoppingKey); | ||
171 | + } | ||
172 | + | ||
173 | + if (empty($result)) { | ||
174 | + echo ' '; | ||
175 | + } else { | ||
176 | + $this->echoJson($result); | ||
177 | + } | ||
178 | + } | ||
179 | + | ||
180 | + /** | ||
181 | + * 购物车结算请求 | ||
182 | + */ | ||
183 | + public function payAction() | ||
184 | + { | ||
185 | + $this->setTitle('购物车'); | ||
186 | + $this->setNavHeader('购物车'); | ||
187 | + | ||
188 | + $cartType = $this->post('cartType', 'ordinary'); | ||
189 | + $uid = $this->getUid(true); | ||
190 | + $data = array( | ||
191 | + 'orderEnsurePage' => true, | ||
192 | + 'orderEnsure' => CartModel::cartPay($uid, $cartType) | ||
193 | + ); | ||
194 | + | ||
195 | + $this->_view->display('order-ensure', $data); | ||
196 | + } | ||
197 | + | ||
198 | + /** | ||
199 | + * 购物车选择支付方式和配送方式接口 | ||
200 | + */ | ||
201 | + public function payAndDeliveryAction() | ||
202 | + { | ||
203 | + $result = array(); | ||
204 | + | ||
205 | + if ($this->isAjax()) { | ||
206 | + $cartType = $this->post('cartType', 'ordinary'); | ||
207 | + $deliveryWay = $this->post('deliveryWay', 1); | ||
208 | + $paymentType = $this->post('paymentType', 1); | ||
209 | + $uid = $this->getUid(true); | ||
210 | + $result = CartModel::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType); | ||
211 | + } | ||
212 | + | ||
213 | + if (empty($result)) { | ||
214 | + echo ' '; | ||
215 | + } else { | ||
216 | + $this->echoJson($result); | ||
217 | + } | ||
218 | + } | ||
219 | + | ||
220 | + /** | ||
221 | + * 购物车输入优惠券码使用优惠券 | ||
222 | + */ | ||
223 | + public function couponAction() | ||
224 | + { | ||
225 | + $result = array(); | ||
226 | + | ||
227 | + if ($this->isAjax()) { | ||
228 | + $couponCode = $this->post('couponCode', ''); | ||
229 | + $uid = $this->getUid(true); | ||
230 | + $result = CartModel::getCoupon($uid, $couponCode); | ||
231 | + } | ||
232 | + | ||
233 | + if (empty($result)) { | ||
234 | + echo ' '; | ||
235 | + } else { | ||
236 | + $this->echoJson($result); | ||
237 | + } | ||
238 | + } | ||
239 | + | ||
240 | + /** | ||
241 | + * 购物车使用YOHO币 | ||
242 | + */ | ||
243 | + public function yohoCoinAction() | ||
244 | + { | ||
245 | + $result = array(); | ||
246 | + | ||
247 | + if ($this->isAjax()) { | ||
248 | + $cartType = $this->post('cartType', 'ordinary'); | ||
249 | + $deliveryWay = $this->post('deliveryWay', 1); | ||
250 | + $paymentType = $this->post('paymentType', 1); | ||
251 | + $yohoCoin = $this->post('yohoCoin', 1); | ||
252 | + $result = CartModel::paymentTypeAndDelivery($this->_uid, $cartType, $deliveryWay, $paymentType, $yohoCoin); | ||
253 | + } | ||
254 | + | ||
255 | + if (empty($result)) { | ||
256 | + echo ' '; | ||
257 | + } else { | ||
258 | + $this->echoJson($result); | ||
259 | + } | ||
260 | + } | ||
224 | 261 | ||
225 | public function giftAdvanceAction() | 262 | public function giftAdvanceAction() |
226 | { | 263 | { |
@@ -267,9 +304,10 @@ class ShoppingCartController extends AbstractAction | @@ -267,9 +304,10 @@ class ShoppingCartController extends AbstractAction | ||
267 | 'navBack' => true, 'navTitle' => '加价购'), 'shoppingCart' => $data)); | 304 | 'navBack' => true, 'navTitle' => '加价购'), 'shoppingCart' => $data)); |
268 | } | 305 | } |
269 | 306 | ||
270 | - /* | ||
271 | - * 确认订单 | ||
272 | - */ | 307 | + /* |
308 | + * 确认订单 | ||
309 | + */ | ||
310 | + | ||
273 | public function orderEnsureAction() | 311 | public function orderEnsureAction() |
274 | { | 312 | { |
275 | $data = array( | 313 | $data = array( |
@@ -342,8 +380,8 @@ class ShoppingCartController extends AbstractAction | @@ -342,8 +380,8 @@ class ShoppingCartController extends AbstractAction | ||
342 | /** | 380 | /** |
343 | * 下单流程 选择地址 | 381 | * 下单流程 选择地址 |
344 | */ | 382 | */ |
345 | - | ||
346 | - public function selectAddressAction() { | 383 | + public function selectAddressAction() |
384 | + { | ||
347 | // 设置网站标题 | 385 | // 设置网站标题 |
348 | $this->setTitle('选择地址'); | 386 | $this->setTitle('选择地址'); |
349 | $this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure')); | 387 | $this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure')); |
@@ -356,14 +394,13 @@ class ShoppingCartController extends AbstractAction | @@ -356,14 +394,13 @@ class ShoppingCartController extends AbstractAction | ||
356 | 'pageFooter' => true, | 394 | 'pageFooter' => true, |
357 | 'address' => $address | 395 | 'address' => $address |
358 | )); | 396 | )); |
359 | - | ||
360 | } | 397 | } |
361 | 398 | ||
362 | /** | 399 | /** |
363 | * 下单流程 选择优惠券 | 400 | * 下单流程 选择优惠券 |
364 | */ | 401 | */ |
365 | - | ||
366 | - public function selectCouponAction() { | 402 | + public function selectCouponAction() |
403 | + { | ||
367 | // 设置网站标题 | 404 | // 设置网站标题 |
368 | $this->setTitle('选择优惠券'); | 405 | $this->setTitle('选择优惠券'); |
369 | $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure')); | 406 | $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure')); |
@@ -376,6 +413,6 @@ class ShoppingCartController extends AbstractAction | @@ -376,6 +413,6 @@ class ShoppingCartController extends AbstractAction | ||
376 | 'pageFooter' => true, | 413 | 'pageFooter' => true, |
377 | 'address' => $address | 414 | 'address' => $address |
378 | )); | 415 | )); |
379 | - | ||
380 | } | 416 | } |
417 | + | ||
381 | } | 418 | } |
@@ -3,7 +3,6 @@ | @@ -3,7 +3,6 @@ | ||
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; | ||
7 | use Plugin\Helpers; | 6 | use Plugin\Helpers; |
8 | use Plugin\Images; | 7 | use Plugin\Images; |
9 | 8 | ||
@@ -18,465 +17,463 @@ use Plugin\Images; | @@ -18,465 +17,463 @@ use Plugin\Images; | ||
18 | class CartModel | 17 | class CartModel |
19 | { | 18 | { |
20 | 19 | ||
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 | - /** | ||
45 | - * @param integer $uid 用户ID | ||
46 | - * @param string $shoppingKey 未登录用户唯一识别码 | ||
47 | - * @return array|mixed 处理之后的购物车数据 | ||
48 | - */ | ||
49 | - public static function getCartData($uid, $shoppingKey) | ||
50 | - { | ||
51 | - $result = array('cartNav' => true); | ||
52 | - | ||
53 | - // 用户是否登录 | ||
54 | - if (empty($uid)) { | ||
55 | - $result['showLoginInfo'] = true; | ||
56 | - } | ||
57 | - | ||
58 | - // 调用接口获取购物车的数据 | ||
59 | - $cartData = CartData::cartData($uid, $shoppingKey); | ||
60 | - | ||
61 | - // 处理普通购物车和预售购物车的数据 | ||
62 | - if (isset($cartData['data']) && !empty($cartData['data'])) { | ||
63 | - $cart = $cartData['data']; | ||
64 | - | ||
65 | - /* 普通购物车 */ | ||
66 | - if(isset($cart['ordinary_cart_data'])) { | ||
67 | - $result['commonGoodsCount'] = count($cart['ordinary_cart_data']['goods_list']); | ||
68 | - $result['commonCart'] = self::procCartData($cart['ordinary_cart_data']); | ||
69 | - } | ||
70 | - | ||
71 | - /* 预售购物车 */ | ||
72 | - if(isset($cart['advance_cart_data'])) { | ||
73 | - $result['presellGoodsCount'] = count($cart['advance_cart_data']['goods_list']); | ||
74 | - $result['preSellCart'] = self::procCartData($cart['advance_cart_data']); | ||
75 | - } | ||
76 | - | ||
77 | - } | ||
78 | - | ||
79 | - return $result; | ||
80 | - } | ||
81 | - | ||
82 | - /** | ||
83 | - * 移出购物车 | ||
84 | - * | ||
85 | - * @param int $uid 用户ID | ||
86 | - * @param string $sku 商品sku列表 | ||
87 | - * @param string $shoppingKey 未登录用户唯一识别码 | ||
88 | - * @return array 接口返回的数据 | ||
89 | - */ | ||
90 | - public static function removeFromCart($uid, $sku, $shoppingKey) | ||
91 | - { | ||
92 | - $result = array('code' => 400, 'message' => '出错啦~'); | ||
93 | - | ||
94 | - // 处理sku | ||
95 | - $sku_list = json_encode(array($sku => 1)); | ||
96 | - | ||
97 | - $remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey); | ||
98 | - if ($remove && isset($remove['code'])) { | ||
99 | - $result['code'] = $remove['code']; | ||
100 | - $result['message'] = $remove['message']; | ||
101 | - } | ||
102 | - | ||
103 | - return $result; | ||
104 | - } | ||
105 | - | ||
106 | - /** | ||
107 | - * 移入收藏夹 | ||
108 | - * | ||
109 | - * @param int $uid 用户ID | ||
110 | - * @param string $sku 商品sku列表 | ||
111 | - * @return array 接口返回的数据 | ||
112 | - */ | ||
113 | - public static function addToFav($uid, $sku) | ||
114 | - { | ||
115 | - $result = array('code' => 400, 'message' => '出错啦~'); | ||
116 | - | ||
117 | - if (empty($uid)) { | ||
118 | - $result['code'] = 300; | ||
119 | - $reult['message'] = '请先登录'; | ||
120 | - $result['data'] = '/signin.html'; | ||
121 | - | ||
122 | - return $result; | ||
123 | - } | ||
124 | - | ||
125 | - // 处理sku | ||
126 | - $sku_list = json_encode(array($sku => 1)); | ||
127 | - | ||
128 | - $add = CartData::addToFav($uid, $sku_list); | ||
129 | - if ($add && isset($add['code'])) { | ||
130 | - $result['code'] = $add['code']; | ||
131 | - $result['message'] = $add['message']; | ||
132 | - } | ||
133 | - | ||
134 | - return $result; | ||
135 | - } | ||
136 | - | ||
137 | - /** | ||
138 | - * 处理购物车商品数据 | ||
139 | - * | ||
140 | - * @param int $uid 用户ID | ||
141 | - * @param int $skn 商品skn | ||
142 | - * @param int $num 购买数目 | ||
143 | - * @return array 接口返回的数据 | ||
144 | - */ | ||
145 | - public static function cartProductData($uid, $skn, $num) | ||
146 | - { | ||
147 | - $result = array('code' => 400, 'message' => '出错啦~'); | ||
148 | - | ||
149 | - $product = CartData::cartProductData($uid, $skn); | ||
150 | - if (isset($product['code']) && $product['code'] === 200) { | ||
151 | - $result['code'] = 200; | ||
152 | - $data = array(); | ||
153 | - $productData = $product['data']; | ||
154 | - | ||
155 | - // 品牌信息 | ||
156 | - if (isset($productData['brand_info']) && !empty($productData['brand_info'])) { | ||
157 | - $data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120); | ||
158 | - } | ||
159 | - | ||
160 | - $data['name'] = $productData['product_name']; | ||
161 | - $data['price'] = $productData['market_price']; | ||
162 | - $data['salePrice'] = $productData['sales_price']; | ||
163 | - $data['storage'] = $productData['storage_sum']; | ||
164 | - $data['num'] = $num; | ||
165 | - | ||
166 | - // 商品选择 | ||
167 | - if (isset($productData['goods_list'])) { | ||
168 | - $goodsList = $productData['goods_list']; | ||
169 | - | ||
170 | - $colors = array(); | ||
171 | - $oneColor = array(); | ||
172 | - $sizes = array(); | ||
173 | - $oneSize = array(); | ||
174 | - foreach ($goodsList as $val) { | ||
175 | - // 颜色 | ||
176 | - $oneColor = array(); | ||
177 | - $oneColor['id'] = $val['color_id']; | ||
178 | - $oneColor['name'] = $val['color_name']; | ||
179 | - | ||
180 | - // 尺码 | ||
181 | - foreach ($val['size_list'] as $one) { | ||
182 | - $oneSize = array(); | ||
183 | - $oneSize['id'] = $one['size_id']; | ||
184 | - $oneSize['name'] = $one['size_name']; | ||
185 | - } | ||
186 | - $sizes[] = $oneSize; | ||
187 | - | ||
188 | - $oneColor['sizes'] = $sizes; | ||
189 | - $colors[] = $oneColor; | ||
190 | - } | ||
191 | - | ||
192 | - $data['colors'] = $colors; | ||
193 | - } | ||
194 | - | ||
195 | - $result['data'] = $data; | ||
196 | - } | ||
197 | - | ||
198 | - return $result; | ||
199 | - } | ||
200 | - | ||
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 | - | ||
228 | - // 商品选择 | ||
229 | - if (isset($productData['goods_list'])) { | ||
230 | - $goodsList = $productData['goods_list']; | ||
231 | - | ||
232 | - $colors = array(); | ||
233 | - $oneColor = array(); | ||
234 | - $sizes = array(); | ||
235 | - $oneSize = array(); | ||
236 | - foreach ($goodsList as $val) { | ||
237 | - // 颜色 | ||
238 | - $oneColor = array(); | ||
239 | - $oneColor['id'] = $val['color_id']; | ||
240 | - $oneColor['name'] = $val['color_name']; | ||
241 | - | ||
242 | - // 尺码 | ||
243 | - foreach ($val['size_list'] as $one) { | ||
244 | - $oneSize = array(); | ||
245 | - $oneSize['id'] = $one['size_id']; | ||
246 | - $oneSize['name'] = $one['size_name']; | ||
247 | - } | ||
248 | - $sizes[] = $oneSize; | ||
249 | - | ||
250 | - $oneColor['sizes'] = $sizes; | ||
251 | - $colors[] = $oneColor; | ||
252 | - } | ||
253 | - | ||
254 | - $data['colors'] = $colors; | ||
255 | - } | ||
256 | - | ||
257 | - $result['data'] = $data; | ||
258 | - } | ||
259 | - | ||
260 | - return $result; | ||
261 | - } | ||
262 | - | ||
263 | - /** | ||
264 | - * 修改购物车商品数据 | ||
265 | - * | ||
266 | - * @param int $uid 用户ID | ||
267 | - * @param string $param 要更改的数据 | ||
268 | - * @param string $shoppingKey 未登录用户唯一识别码 | ||
269 | - * @return array 接口返回的数据 | ||
270 | - */ | ||
271 | - public static function modifyCartProduct($uid, $param, $shoppingKey) | ||
272 | - { | ||
273 | - $result = array('code' => 400, 'message' => '出错啦~'); | ||
274 | - | ||
275 | - // 处理要更改的数据 | ||
276 | - $swapData = json_encode(array($param)); | ||
277 | - | ||
278 | - $modify = CartData::modifyCartProduct($uid, $swapData, $shoppingKey); | ||
279 | - if ($modify && isset($modify['code'])) { | ||
280 | - $result['code'] = $modify['code']; | ||
281 | - $result['message'] = $modify['message']; | ||
282 | - } | ||
283 | - | ||
284 | - return $result; | ||
285 | - } | ||
286 | - | ||
287 | - /** | ||
288 | - * 调用购物车结算接口返回的数据处理 | ||
289 | - * | ||
290 | - * @param int $uid 用户ID | ||
291 | - * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
292 | - * @return array 接口返回的数据 | ||
293 | - */ | ||
294 | - public static function cartPay($uid, $cartType) | ||
295 | - { | ||
296 | - $result = array(); | ||
297 | - | ||
298 | - $pay = CartData::cartPay($uid, $cartType); | ||
299 | - | ||
300 | - if ($pay && isset($pay['code']) && $pay['code'] === 200) { | ||
301 | - $payReturn = $pay['data']; | ||
302 | - $result = array(); | ||
303 | - | ||
304 | - // 收货人有关信息 | ||
305 | - if (isset($payReturn['delivery_address']) && !empty($payReturn['delivery_address'])) { | ||
306 | - $result['name'] = $payReturn['delivery_address']['consignee']; | ||
307 | - $result['phoneNum'] = $payReturn['delivery_address']['mobile'] ?: $payReturn['delivery_address']['phone']; | ||
308 | - $result['address'] = $payReturn['delivery_address']['address']; | ||
309 | - } | ||
310 | - | ||
311 | - // 配送方式 | ||
312 | - if (isset($payReturn['delivery_way'])) { | ||
313 | - $oneDeliv = array(); | ||
314 | - foreach ($payReturn['delivery_way'] as $val) { | ||
315 | - $oneDeliv = array(); | ||
316 | - $oneDeliv['id'] = $val['delivery_way_id']; | ||
317 | - $oneDeliv['name'] = $val['delivery_way_name']; | ||
318 | - $oneDeliv['default'] = ($val['default'] === 'Y'); | ||
319 | - | ||
320 | - $result['dispatchMode'][] = $oneDeliv; | ||
321 | - } | ||
322 | - } | ||
323 | - | ||
324 | - // 配送时间 | ||
325 | - if (isset($payReturn['delivery_time'])) { | ||
326 | - $oneDelivTime = array(); | ||
327 | - foreach ($payReturn['delivery_time'] as $one) { | ||
328 | - $oneDelivTime = array(); | ||
329 | - $oneDelivTime['id'] = $one['delivery_time_id']; | ||
330 | - $oneDelivTime['name'] = $one['delivery_time_string']; | ||
331 | - $oneDelivTime['default'] = ($one['default'] === 'Y'); | ||
332 | - | ||
333 | - $result['dispatchTime'][] = $oneDelivTime; | ||
334 | - } | ||
335 | - } | ||
336 | - | ||
337 | - // 订单商品 | ||
338 | - if (isset($payReturn['goods_list'])) { | ||
339 | - $oneGoods = array(); | ||
340 | - foreach ($payReturn['goods_list'] as $single) { | ||
341 | - $oneGoods = array(); | ||
342 | - $oneGoods['id'] = $single['product_sku']; // TODO 未确定用哪个 | ||
343 | - $oneGoods['thumb'] = Images::getImageUrl($single['goods_images'], 120, 120); | ||
344 | - $oneGoods['name'] = $single['product_name']; | ||
345 | - $oneGoods['color'] = $single['color_name']; | ||
346 | - $oneGoods['size'] = $single['size_name']; | ||
347 | - $oneGoods['price'] = Helpers::transPrice($single['real_price']); // last_price有些带.00,有些不带,real_price都不带.00 | ||
348 | - $oneGoods['count'] = $single['buy_number']; | ||
349 | - | ||
350 | - $result['goods'][] = $oneGoods; | ||
351 | - } | ||
352 | - } | ||
353 | - | ||
354 | - // 支付方式 | ||
355 | - if (isset($payReturn['payment_way'])) { | ||
356 | - $onePay = array(); | ||
357 | - foreach ($payReturn['payment_way'] as $pay) { | ||
358 | - $onePay = array(); | ||
359 | - $onePay['id'] = $pay['payment_id']; | ||
360 | - $onePay['paymentType'] = $pay['payment_type']; | ||
361 | - $onePay['name'] = $pay['payment_type_name']; | ||
362 | - $onePay['default'] = ($pay['default'] === 'Y'); | ||
363 | - | ||
364 | - $result['paymentWay'][] = $onePay; | ||
365 | - } | ||
366 | - } | ||
367 | - | ||
368 | - // 有货币 | ||
369 | - $result['yohoCoin'] = $payReturn['yoho_coin']; | ||
370 | - | ||
371 | - // 订单数据 | ||
372 | - if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) { | ||
373 | - $result['sumPrice'] = Helpers::transPrice($payReturn['shopping_cart_data']['order_amount']); | ||
374 | - $result['salePrice'] = Helpers::transPrice($payReturn['shopping_cart_data']['discount_amount']); | ||
375 | - $result['price'] = Helpers::transPrice($payReturn['shopping_cart_data']['last_order_amount']); | ||
376 | - $result['freight'] = Helpers::transPrice($payReturn['shopping_cart_data']['shipping_cost']); | ||
377 | - } | ||
378 | - | ||
379 | - // 发票有关数据 | ||
380 | - if (isset($payReturn['invoices']) && !empty($payReturn['invoices'])) { | ||
381 | - $one = array(); | ||
382 | - foreach ($payReturn['invoices']['invoices_type_list'] as $inv) { | ||
383 | - $one = array(); | ||
384 | - $one['id'] = $inv['invoices_type_id']; | ||
385 | - $one['name'] = $inv['invoices_type_name']; | ||
386 | - | ||
387 | - $result['invoice'][] = $one; | ||
388 | - } | ||
389 | - } | ||
390 | - | ||
391 | - // 优惠券数据 | ||
392 | - $coupons = array('notUsed' => true); | ||
393 | - $coupons += UserModel::getCouponData($uid, 0, 1, true); | ||
394 | - $result['coupon'] = $coupons; | ||
395 | - } | ||
396 | - | ||
397 | - return $result; | ||
398 | - } | ||
399 | - | ||
400 | - /** | ||
401 | - * 购物车结算--支付方式和配送方式选择以及是否使用YOHO币接口返回的数据处理 | ||
402 | - * | ||
403 | - * @param int $uid 用户ID | ||
404 | - * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
405 | - * @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 | ||
406 | - * @param string $paymentType 支付方式,1表示在线支付,2表示货到付款 | ||
407 | - * @return array 接口返回的数据 | ||
408 | - */ | ||
409 | - public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType) | ||
410 | - { | ||
411 | - $result = array(); | ||
412 | - | ||
413 | - $pay = CartData::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType); | ||
414 | - if ($pay && isset($pay['code']) && $pay['code'] === 200) { | ||
415 | - $result = $pay['data']; | ||
416 | - } | ||
417 | - | ||
418 | - return $result; | ||
419 | - } | ||
420 | - | ||
421 | - /** | ||
422 | - * 购物车结算--输入优惠券代码返回的结果处理 | ||
423 | - * | ||
424 | - * @param int $uid 用户ID | ||
425 | - * @param string $couponCode 优惠券代码 | ||
426 | - * @return array 接口返回的数据 | ||
427 | - */ | ||
428 | - public static function getCoupon($uid, $couponCode) | ||
429 | - { | ||
430 | - $result = array('code' => 400, 'message' => '出错啦~'); | ||
431 | - | ||
432 | - $coupon = CartData::getCoupon($uid, $couponCode); | ||
433 | - if ($coupon && isset($coupon['code']) && $coupon['code'] === 200) { | ||
434 | - $result['code'] = $coupon['code']; | ||
435 | - $result['message'] = $coupon['message']; | ||
436 | - } | ||
437 | - | ||
438 | - return $result; | ||
439 | - } | ||
440 | - | ||
441 | - | ||
442 | - /** | ||
443 | - * 处理不同类型的购物车数据 | ||
444 | - * | ||
445 | - * @param array $data 不同类型购物车数据 | ||
446 | - * @return array $result 处理之后的不同类型购物车数据 | ||
447 | - */ | ||
448 | - private static function procCartData($data) | ||
449 | - { | ||
450 | - $result = array(); | ||
451 | - | ||
452 | - $oneGoods = array(); | ||
453 | - // 购买的商品列表 | ||
454 | - foreach ($data['goods_list'] as $value) { | ||
455 | - $oneGoods['id'] = $value['product_sku']; | ||
456 | - $oneGoods['skn'] = $value['product_skn']; | ||
457 | - $oneGoods['name'] = $value['product_name']; | ||
458 | - $oneGoods['thumb'] = Images::getImageUrl($value['goods_images'], 120, 120); | ||
459 | - $oneGoods['color'] = $value['color_name']; | ||
460 | - $oneGoods['size'] = $value['size_name']; | ||
461 | - $oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据 | ||
462 | - $oneGoods['price'] = $value['real_price']; | ||
463 | - $oneGoods['count'] = $value['buy_number']; | ||
464 | - $oneGoods['lowStocks'] = true; | ||
465 | - | ||
466 | - $result['goods'][] = $oneGoods; | ||
467 | - } | ||
468 | - // 赠品 | ||
469 | - count($data['gift_list']) && $result['freebieOrAdvanceBuy'] = true; | ||
470 | - $result['freebie'] = $data['gift_list']; | ||
471 | - // 加价购 | ||
472 | - $result['advanceBuy'] = $data['price_gift']; | ||
473 | - // 结算数据 | ||
474 | - $result['price'] = $data['shopping_cart_data']['order_amount']; | ||
475 | - $result['activityPrice'] = $data['shopping_cart_data']['discount_amount']; | ||
476 | - $result['count'] = $data['shopping_cart_data']['goods_count']; | ||
477 | - $result['sumPrice'] = $data['shopping_cart_data']['order_amount']; | ||
478 | - | ||
479 | - return $result; | ||
480 | - } | 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, $promotionId, $uid, $shoppingKey) | ||
32 | + { | ||
33 | + $result = array('code' => 400, 'message' => '出错啦~~'); | ||
34 | + | ||
35 | + $addCart = CartData::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey); | ||
36 | + if ($addCart && isset($addCart['code'])) { | ||
37 | + $result = $addCart; | ||
38 | + } | ||
39 | + | ||
40 | + return $result; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * @param integer $uid 用户ID | ||
45 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
46 | + * @return array|mixed 处理之后的购物车数据 | ||
47 | + */ | ||
48 | + public static function getCartData($uid, $shoppingKey) | ||
49 | + { | ||
50 | + $result = array('cartNav' => true); | ||
51 | + | ||
52 | + // 用户是否登录 | ||
53 | + if (empty($uid)) { | ||
54 | + $result['showLoginInfo'] = true; | ||
55 | + } | ||
56 | + | ||
57 | + // 调用接口获取购物车的数据 | ||
58 | + $cartData = CartData::cartData($uid, $shoppingKey); | ||
59 | + | ||
60 | + // 处理普通购物车和预售购物车的数据 | ||
61 | + if (isset($cartData['data']) && !empty($cartData['data'])) { | ||
62 | + $cart = $cartData['data']; | ||
63 | + | ||
64 | + /* 普通购物车 */ | ||
65 | + if (isset($cart['ordinary_cart_data'])) { | ||
66 | + $result['commonGoodsCount'] = count($cart['ordinary_cart_data']['goods_list']); | ||
67 | + $result['commonCart'] = self::procCartData($cart['ordinary_cart_data']); | ||
68 | + } | ||
69 | + | ||
70 | + /* 预售购物车 */ | ||
71 | + if (isset($cart['advance_cart_data'])) { | ||
72 | + $result['presellGoodsCount'] = count($cart['advance_cart_data']['goods_list']); | ||
73 | + $result['preSellCart'] = self::procCartData($cart['advance_cart_data']); | ||
74 | + } | ||
75 | + } | ||
76 | + | ||
77 | + return $result; | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * 移出购物车 | ||
82 | + * | ||
83 | + * @param int $uid 用户ID | ||
84 | + * @param string $sku 商品sku列表 | ||
85 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
86 | + * @return array 接口返回的数据 | ||
87 | + */ | ||
88 | + public static function removeFromCart($uid, $sku, $shoppingKey) | ||
89 | + { | ||
90 | + $result = array('code' => 400, 'message' => '出错啦~'); | ||
91 | + | ||
92 | + // 处理sku | ||
93 | + $sku_list = json_encode(array($sku => 1)); | ||
94 | + | ||
95 | + $remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey); | ||
96 | + if ($remove && isset($remove['code'])) { | ||
97 | + $result['code'] = $remove['code']; | ||
98 | + $result['message'] = $remove['message']; | ||
99 | + } | ||
100 | + | ||
101 | + return $result; | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * 移入收藏夹 | ||
106 | + * | ||
107 | + * @param int $uid 用户ID | ||
108 | + * @param string $sku 商品sku列表 | ||
109 | + * @return array 接口返回的数据 | ||
110 | + */ | ||
111 | + public static function addToFav($uid, $sku) | ||
112 | + { | ||
113 | + $result = array('code' => 400, 'message' => '出错啦~'); | ||
114 | + | ||
115 | + if (empty($uid)) { | ||
116 | + $result['code'] = 300; | ||
117 | + $reult['message'] = '请先登录'; | ||
118 | + $result['data'] = '/signin.html'; | ||
119 | + | ||
120 | + return $result; | ||
121 | + } | ||
122 | + | ||
123 | + // 处理sku | ||
124 | + $sku_list = json_encode(array($sku => 1)); | ||
125 | + | ||
126 | + $add = CartData::addToFav($uid, $sku_list); | ||
127 | + if ($add && isset($add['code'])) { | ||
128 | + $result['code'] = $add['code']; | ||
129 | + $result['message'] = $add['message']; | ||
130 | + } | ||
131 | + | ||
132 | + return $result; | ||
133 | + } | ||
134 | + | ||
135 | + /** | ||
136 | + * 处理购物车商品数据 | ||
137 | + * | ||
138 | + * @param int $uid 用户ID | ||
139 | + * @param int $skn 商品skn | ||
140 | + * @param int $num 购买数目 | ||
141 | + * @return array 接口返回的数据 | ||
142 | + */ | ||
143 | + public static function cartProductData($uid, $skn, $num) | ||
144 | + { | ||
145 | + $result = array('code' => 400, 'message' => '出错啦~'); | ||
146 | + | ||
147 | + $product = CartData::cartProductData($uid, $skn); | ||
148 | + if (isset($product['code']) && $product['code'] === 200) { | ||
149 | + $result['code'] = 200; | ||
150 | + $data = array(); | ||
151 | + $productData = $product['data']; | ||
152 | + | ||
153 | + // 品牌信息 | ||
154 | + if (isset($productData['brand_info']) && !empty($productData['brand_info'])) { | ||
155 | + $data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120); | ||
156 | + } | ||
157 | + | ||
158 | + $data['name'] = $productData['product_name']; | ||
159 | + $data['price'] = $productData['market_price']; | ||
160 | + $data['salePrice'] = $productData['sales_price']; | ||
161 | + $data['storage'] = $productData['storage_sum']; | ||
162 | + $data['num'] = $num; | ||
163 | + | ||
164 | + // 商品选择 | ||
165 | + if (isset($productData['goods_list'])) { | ||
166 | + $goodsList = $productData['goods_list']; | ||
167 | + | ||
168 | + $colors = array(); | ||
169 | + $oneColor = array(); | ||
170 | + $sizes = array(); | ||
171 | + $oneSize = array(); | ||
172 | + foreach ($goodsList as $val) { | ||
173 | + // 颜色 | ||
174 | + $oneColor = array(); | ||
175 | + $oneColor['id'] = $val['color_id']; | ||
176 | + $oneColor['name'] = $val['color_name']; | ||
177 | + | ||
178 | + // 尺码 | ||
179 | + foreach ($val['size_list'] as $one) { | ||
180 | + $oneSize = array(); | ||
181 | + $oneSize['id'] = $one['size_id']; | ||
182 | + $oneSize['name'] = $one['size_name']; | ||
183 | + } | ||
184 | + $sizes[] = $oneSize; | ||
185 | + | ||
186 | + $oneColor['sizes'] = $sizes; | ||
187 | + $colors[] = $oneColor; | ||
188 | + } | ||
189 | + | ||
190 | + $data['colors'] = $colors; | ||
191 | + } | ||
192 | + | ||
193 | + $result['data'] = $data; | ||
194 | + } | ||
195 | + | ||
196 | + return $result; | ||
197 | + } | ||
198 | + | ||
199 | + /** | ||
200 | + * 处理加价购商品数据 | ||
201 | + * | ||
202 | + * @param int $skn 商品skn | ||
203 | + * @param int $promotionId 加价购商品促销ID | ||
204 | + * @return array | ||
205 | + */ | ||
206 | + public static function giftProductData($skn, $promotionId) | ||
207 | + { | ||
208 | + $result = array(); | ||
209 | + | ||
210 | + $product = CartData::giftProductData($skn, $promotionId); | ||
211 | + if (isset($product['code']) && $product['code'] === 200) { | ||
212 | + $result['code'] = 200; | ||
213 | + $data = array(); | ||
214 | + $productData = $product['data']; | ||
215 | + | ||
216 | + // 品牌信息 | ||
217 | + if (isset($productData['brand_info']) && !empty($productData['brand_info'])) { | ||
218 | + $data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120); | ||
219 | + } | ||
220 | + | ||
221 | + $data['name'] = $productData['product_name']; | ||
222 | + $data['price'] = $productData['market_price']; | ||
223 | + $data['salePrice'] = $productData['sales_price']; | ||
224 | + $data['storage'] = $productData['storage_sum']; | ||
225 | + | ||
226 | + // 商品选择 | ||
227 | + if (isset($productData['goods_list'])) { | ||
228 | + $goodsList = $productData['goods_list']; | ||
229 | + | ||
230 | + $colors = array(); | ||
231 | + $oneColor = array(); | ||
232 | + $sizes = array(); | ||
233 | + $oneSize = array(); | ||
234 | + foreach ($goodsList as $val) { | ||
235 | + // 颜色 | ||
236 | + $oneColor = array(); | ||
237 | + $oneColor['id'] = $val['color_id']; | ||
238 | + $oneColor['name'] = $val['color_name']; | ||
239 | + | ||
240 | + // 尺码 | ||
241 | + foreach ($val['size_list'] as $one) { | ||
242 | + $oneSize = array(); | ||
243 | + $oneSize['id'] = $one['size_id']; | ||
244 | + $oneSize['name'] = $one['size_name']; | ||
245 | + } | ||
246 | + $sizes[] = $oneSize; | ||
247 | + | ||
248 | + $oneColor['sizes'] = $sizes; | ||
249 | + $colors[] = $oneColor; | ||
250 | + } | ||
251 | + | ||
252 | + $data['colors'] = $colors; | ||
253 | + } | ||
254 | + | ||
255 | + $result['data'] = $data; | ||
256 | + } | ||
257 | + | ||
258 | + return $result; | ||
259 | + } | ||
260 | + | ||
261 | + /** | ||
262 | + * 修改购物车商品数据 | ||
263 | + * | ||
264 | + * @param int $uid 用户ID | ||
265 | + * @param string $param 要更改的数据 | ||
266 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
267 | + * @return array 接口返回的数据 | ||
268 | + */ | ||
269 | + public static function modifyCartProduct($uid, $param, $shoppingKey) | ||
270 | + { | ||
271 | + $result = array('code' => 400, 'message' => '出错啦~'); | ||
272 | + | ||
273 | + // 处理要更改的数据 | ||
274 | + $swapData = json_encode(array($param)); | ||
275 | + | ||
276 | + $modify = CartData::modifyCartProduct($uid, $swapData, $shoppingKey); | ||
277 | + if ($modify && isset($modify['code'])) { | ||
278 | + $result['code'] = $modify['code']; | ||
279 | + $result['message'] = $modify['message']; | ||
280 | + } | ||
281 | + | ||
282 | + return $result; | ||
283 | + } | ||
284 | + | ||
285 | + /** | ||
286 | + * 调用购物车结算接口返回的数据处理 | ||
287 | + * | ||
288 | + * @param int $uid 用户ID | ||
289 | + * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
290 | + * @return array 接口返回的数据 | ||
291 | + */ | ||
292 | + public static function cartPay($uid, $cartType) | ||
293 | + { | ||
294 | + $result = array(); | ||
295 | + | ||
296 | + $pay = CartData::cartPay($uid, $cartType); | ||
297 | + | ||
298 | + if ($pay && isset($pay['code']) && $pay['code'] === 200) { | ||
299 | + $payReturn = $pay['data']; | ||
300 | + $result = array(); | ||
301 | + | ||
302 | + // 收货人有关信息 | ||
303 | + if (isset($payReturn['delivery_address']) && !empty($payReturn['delivery_address'])) { | ||
304 | + $result['name'] = $payReturn['delivery_address']['consignee']; | ||
305 | + $result['phoneNum'] = $payReturn['delivery_address']['mobile'] ? : $payReturn['delivery_address']['phone']; | ||
306 | + $result['address'] = $payReturn['delivery_address']['address']; | ||
307 | + } | ||
308 | + | ||
309 | + // 配送方式 | ||
310 | + if (isset($payReturn['delivery_way'])) { | ||
311 | + $oneDeliv = array(); | ||
312 | + foreach ($payReturn['delivery_way'] as $val) { | ||
313 | + $oneDeliv = array(); | ||
314 | + $oneDeliv['id'] = $val['delivery_way_id']; | ||
315 | + $oneDeliv['name'] = $val['delivery_way_name']; | ||
316 | + $oneDeliv['default'] = ($val['default'] === 'Y'); | ||
317 | + | ||
318 | + $result['dispatchMode'][] = $oneDeliv; | ||
319 | + } | ||
320 | + } | ||
321 | + | ||
322 | + // 配送时间 | ||
323 | + if (isset($payReturn['delivery_time'])) { | ||
324 | + $oneDelivTime = array(); | ||
325 | + foreach ($payReturn['delivery_time'] as $one) { | ||
326 | + $oneDelivTime = array(); | ||
327 | + $oneDelivTime['id'] = $one['delivery_time_id']; | ||
328 | + $oneDelivTime['name'] = $one['delivery_time_string']; | ||
329 | + $oneDelivTime['default'] = ($one['default'] === 'Y'); | ||
330 | + | ||
331 | + $result['dispatchTime'][] = $oneDelivTime; | ||
332 | + } | ||
333 | + } | ||
334 | + | ||
335 | + // 订单商品 | ||
336 | + if (isset($payReturn['goods_list'])) { | ||
337 | + $oneGoods = array(); | ||
338 | + foreach ($payReturn['goods_list'] as $single) { | ||
339 | + $oneGoods = array(); | ||
340 | + $oneGoods['id'] = $single['product_sku']; // TODO 未确定用哪个 | ||
341 | + $oneGoods['thumb'] = Images::getImageUrl($single['goods_images'], 120, 120); | ||
342 | + $oneGoods['name'] = $single['product_name']; | ||
343 | + $oneGoods['color'] = $single['color_name']; | ||
344 | + $oneGoods['size'] = $single['size_name']; | ||
345 | + $oneGoods['price'] = Helpers::transPrice($single['real_price']); // last_price有些带.00,有些不带,real_price都不带.00 | ||
346 | + $oneGoods['count'] = $single['buy_number']; | ||
347 | + | ||
348 | + $result['goods'][] = $oneGoods; | ||
349 | + } | ||
350 | + } | ||
351 | + | ||
352 | + // 支付方式 | ||
353 | + if (isset($payReturn['payment_way'])) { | ||
354 | + $onePay = array(); | ||
355 | + foreach ($payReturn['payment_way'] as $pay) { | ||
356 | + $onePay = array(); | ||
357 | + $onePay['id'] = $pay['payment_id']; | ||
358 | + $onePay['paymentType'] = $pay['payment_type']; | ||
359 | + $onePay['name'] = $pay['payment_type_name']; | ||
360 | + $onePay['default'] = ($pay['default'] === 'Y'); | ||
361 | + | ||
362 | + $result['paymentWay'][] = $onePay; | ||
363 | + } | ||
364 | + } | ||
365 | + | ||
366 | + // 有货币 | ||
367 | + $result['yohoCoin'] = $payReturn['yoho_coin']; | ||
368 | + | ||
369 | + // 订单数据 | ||
370 | + if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) { | ||
371 | + $result['sumPrice'] = Helpers::transPrice($payReturn['shopping_cart_data']['order_amount']); | ||
372 | + $result['salePrice'] = Helpers::transPrice($payReturn['shopping_cart_data']['discount_amount']); | ||
373 | + $result['price'] = Helpers::transPrice($payReturn['shopping_cart_data']['last_order_amount']); | ||
374 | + $result['freight'] = Helpers::transPrice($payReturn['shopping_cart_data']['shipping_cost']); | ||
375 | + } | ||
376 | + | ||
377 | + // 发票有关数据 | ||
378 | + if (isset($payReturn['invoices']) && !empty($payReturn['invoices'])) { | ||
379 | + $one = array(); | ||
380 | + foreach ($payReturn['invoices']['invoices_type_list'] as $inv) { | ||
381 | + $one = array(); | ||
382 | + $one['id'] = $inv['invoices_type_id']; | ||
383 | + $one['name'] = $inv['invoices_type_name']; | ||
384 | + | ||
385 | + $result['invoice'][] = $one; | ||
386 | + } | ||
387 | + } | ||
388 | + | ||
389 | + // 优惠券数据 | ||
390 | + $coupons = array('notUsed' => true); | ||
391 | + $coupons += UserModel::getCouponData($uid, 0, 1, true); | ||
392 | + $result['coupon'] = $coupons; | ||
393 | + } | ||
394 | + | ||
395 | + return $result; | ||
396 | + } | ||
397 | + | ||
398 | + /** | ||
399 | + * 购物车结算--支付方式和配送方式选择以及是否使用YOHO币接口返回的数据处理 | ||
400 | + * | ||
401 | + * @param int $uid 用户ID | ||
402 | + * @param string $cartType 购物车类型,ordinary表示普通购物车 | ||
403 | + * @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 | ||
404 | + * @param string $paymentType 支付方式,1表示在线支付,2表示货到付款 | ||
405 | + * @return array 接口返回的数据 | ||
406 | + */ | ||
407 | + public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType) | ||
408 | + { | ||
409 | + $result = array(); | ||
410 | + | ||
411 | + $pay = CartData::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType); | ||
412 | + if ($pay && isset($pay['code']) && $pay['code'] === 200) { | ||
413 | + $result = $pay['data']; | ||
414 | + } | ||
415 | + | ||
416 | + return $result; | ||
417 | + } | ||
418 | + | ||
419 | + /** | ||
420 | + * 购物车结算--输入优惠券代码返回的结果处理 | ||
421 | + * | ||
422 | + * @param int $uid 用户ID | ||
423 | + * @param string $couponCode 优惠券代码 | ||
424 | + * @return array 接口返回的数据 | ||
425 | + */ | ||
426 | + public static function getCoupon($uid, $couponCode) | ||
427 | + { | ||
428 | + $result = array('code' => 400, 'message' => '出错啦~'); | ||
429 | + | ||
430 | + $coupon = CartData::getCoupon($uid, $couponCode); | ||
431 | + if ($coupon && isset($coupon['code']) && $coupon['code'] === 200) { | ||
432 | + $result['code'] = $coupon['code']; | ||
433 | + $result['message'] = $coupon['message']; | ||
434 | + } | ||
435 | + | ||
436 | + return $result; | ||
437 | + } | ||
438 | + | ||
439 | + /** | ||
440 | + * 处理不同类型的购物车数据 | ||
441 | + * | ||
442 | + * @param array $data 不同类型购物车数据 | ||
443 | + * @return array $result 处理之后的不同类型购物车数据 | ||
444 | + */ | ||
445 | + private static function procCartData($data) | ||
446 | + { | ||
447 | + $result = array(); | ||
448 | + | ||
449 | + $oneGoods = array(); | ||
450 | + // 购买的商品列表 | ||
451 | + foreach ($data['goods_list'] as $value) { | ||
452 | + $oneGoods['id'] = $value['product_sku']; | ||
453 | + $oneGoods['skn'] = $value['product_skn']; | ||
454 | + $oneGoods['name'] = $value['product_name']; | ||
455 | + $oneGoods['thumb'] = Images::getImageUrl($value['goods_images'], 120, 120); | ||
456 | + $oneGoods['color'] = $value['color_name']; | ||
457 | + $oneGoods['size'] = $value['size_name']; | ||
458 | + $oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据 | ||
459 | + $oneGoods['price'] = $value['real_price']; | ||
460 | + $oneGoods['count'] = $value['buy_number']; | ||
461 | + $oneGoods['lowStocks'] = true; | ||
462 | + | ||
463 | + $result['goods'][] = $oneGoods; | ||
464 | + } | ||
465 | + // 赠品 | ||
466 | + count($data['gift_list']) && $result['freebieOrAdvanceBuy'] = true; | ||
467 | + $result['freebie'] = $data['gift_list']; | ||
468 | + // 加价购 | ||
469 | + $result['advanceBuy'] = $data['price_gift']; | ||
470 | + // 结算数据 | ||
471 | + $result['price'] = $data['shopping_cart_data']['order_amount']; | ||
472 | + $result['activityPrice'] = $data['shopping_cart_data']['discount_amount']; | ||
473 | + $result['count'] = $data['shopping_cart_data']['goods_count']; | ||
474 | + $result['sumPrice'] = $data['shopping_cart_data']['order_amount']; | ||
475 | + | ||
476 | + return $result; | ||
477 | + } | ||
481 | 478 | ||
482 | } | 479 | } |
-
Please register or login to post a comment