修改购物车结算页面的一些接口
Code Review By Rock Zhang
Showing
4 changed files
with
207 additions
and
196 deletions
@@ -201,19 +201,23 @@ class CartData | @@ -201,19 +201,23 @@ class CartData | ||
201 | * | 201 | * |
202 | * @param int $uid 用户ID | 202 | * @param int $uid 用户ID |
203 | * @param string $cartType 购物车类型,ordinary表示普通购物车 | 203 | * @param string $cartType 购物车类型,ordinary表示普通购物车 |
204 | - * @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 | ||
205 | - * @param string $paymentType 支付方式,1表示在线支付,2表示货到付款 | ||
206 | - * @param string $yohoCoin 使用的YOHO币数量,默认为null表示不适用 | 204 | + * @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 |
205 | + * @param int $paymentType 支付方式,1表示在线支付,2表示货到付款 | ||
206 | + * @param string $couponCode 优惠券码 | ||
207 | + * @param mixed $yohoCoin 使用的YOHO币数量 | ||
207 | * @return array 接口返回的数据 | 208 | * @return array 接口返回的数据 |
208 | */ | 209 | */ |
209 | - public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType, $yohoCoin = null) | 210 | + public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin) |
210 | { | 211 | { |
211 | $param = Yohobuy::param(); | 212 | $param = Yohobuy::param(); |
212 | $param['method'] = 'app.Shopping.compute'; | 213 | $param['method'] = 'app.Shopping.compute'; |
213 | $param['cart_type'] = $cartType; | 214 | $param['cart_type'] = $cartType; |
214 | $param['delivery_way'] = $deliveryWay; | 215 | $param['delivery_way'] = $deliveryWay; |
215 | $param['payment_type'] = $paymentType; | 216 | $param['payment_type'] = $paymentType; |
216 | - if ($yohoCoin !== null) { | 217 | + if (!empty($couponCode)) { |
218 | + $param['coupon_code'] = $couponCode; | ||
219 | + } | ||
220 | + if (!empty($yohoCoin)) { | ||
217 | $param['use_yoho_coin'] = $yohoCoin; | 221 | $param['use_yoho_coin'] = $yohoCoin; |
218 | } | 222 | } |
219 | 223 | ||
@@ -230,7 +234,7 @@ class CartData | @@ -230,7 +234,7 @@ class CartData | ||
230 | * @param string $couponCode 优惠券代码 | 234 | * @param string $couponCode 优惠券代码 |
231 | * @return array 接口返回的数据 | 235 | * @return array 接口返回的数据 |
232 | */ | 236 | */ |
233 | - public static function getCoupon($uid, $couponCode) | 237 | + public static function searchCoupon($uid, $couponCode) |
234 | { | 238 | { |
235 | $param = Yohobuy::param(); | 239 | $param = Yohobuy::param(); |
236 | $param['method'] = 'app.Shopping.useCoupon'; | 240 | $param['method'] = 'app.Shopping.useCoupon'; |
@@ -242,10 +246,38 @@ class CartData | @@ -242,10 +246,38 @@ class CartData | ||
242 | } | 246 | } |
243 | 247 | ||
244 | /** | 248 | /** |
249 | + * 购物车结算--获取优惠券列表 | ||
250 | + * | ||
251 | + * @param int $uid 用户ID | ||
252 | + * @return array 接口返回的数据 | ||
253 | + */ | ||
254 | + public static function getCouponList($uid) | ||
255 | + { | ||
256 | + $param = Yohobuy::param(); | ||
257 | + $param['method'] = 'app.coupons.lists'; | ||
258 | + $param['type'] = 'notuse'; | ||
259 | + $param['page'] = 1; | ||
260 | + $param['limit'] = 1000; | ||
261 | + $param['uid'] = $uid; | ||
262 | + $param['client_secret'] = Sign::getSign($param); | ||
263 | + | ||
264 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
265 | + } | ||
266 | + | ||
267 | + /** | ||
245 | * 购物车结算--提交结算信息 | 268 | * 购物车结算--提交结算信息 |
246 | * | 269 | * |
247 | * @param int $uid 用户ID | 270 | * @param int $uid 用户ID |
248 | - * @param string $couponCode 优惠券代码 | 271 | + * @param int $addressId 地址ID |
272 | + * @param int $cartType 购物车类型ID | ||
273 | + * @param int $deliveryTime 寄送时间ID | ||
274 | + * @param int $deliveryWay 寄送方式ID | ||
275 | + * @param string $invoiceTitle 发票说明 | ||
276 | + * @param int $invoiceId 发票类型ID | ||
277 | + * @param int $paymentId 支付方式ID | ||
278 | + * @param int $paymentType 支付类型ID | ||
279 | + * @param string $remark 留言 | ||
280 | + * @param mixed $yohoCoin 使用的YOHO币数量或为空 | ||
249 | * @return array 接口返回的数据 | 281 | * @return array 接口返回的数据 |
250 | */ | 282 | */ |
251 | public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin) | 283 | public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin) |
@@ -256,12 +288,19 @@ class CartData | @@ -256,12 +288,19 @@ class CartData | ||
256 | $param['cart_type'] = $cartType; | 288 | $param['cart_type'] = $cartType; |
257 | $param['delivery_time'] = $deliveryTime; | 289 | $param['delivery_time'] = $deliveryTime; |
258 | $param['delivery_way'] = $deliveryWay; | 290 | $param['delivery_way'] = $deliveryWay; |
291 | + if (!empty($invoiceTitle)) { | ||
259 | $param['invoices_title'] = $invoiceTitle; | 292 | $param['invoices_title'] = $invoiceTitle; |
293 | + } | ||
294 | + if (!empty($invoiceId)) { | ||
260 | $param['invoices_type_id'] = $invoiceId; | 295 | $param['invoices_type_id'] = $invoiceId; |
296 | + } | ||
297 | + | ||
261 | $param['payment_id'] = $paymentId; | 298 | $param['payment_id'] = $paymentId; |
262 | $param['payment_type'] = $paymentType; | 299 | $param['payment_type'] = $paymentType; |
263 | $param['remark'] = $remark; | 300 | $param['remark'] = $remark; |
301 | + if (!empty($yohoCoin)) { | ||
264 | $param['use_yoho_coin'] = $yohoCoin; | 302 | $param['use_yoho_coin'] = $yohoCoin; |
303 | + } | ||
265 | $param['uid'] = $uid; | 304 | $param['uid'] = $uid; |
266 | $param['client_secret'] = Sign::getSign($param); | 305 | $param['client_secret'] = Sign::getSign($param); |
267 | 306 |
@@ -143,16 +143,17 @@ class ShoppingCartController extends AbstractAction | @@ -143,16 +143,17 @@ class ShoppingCartController extends AbstractAction | ||
143 | /** | 143 | /** |
144 | * 购物车结算请求 | 144 | * 购物车结算请求 |
145 | */ | 145 | */ |
146 | - public function payAction() | 146 | + public function orderEnsureAction() |
147 | { | 147 | { |
148 | $this->setTitle('购物车'); | 148 | $this->setTitle('购物车'); |
149 | $this->setNavHeader('购物车'); | 149 | $this->setNavHeader('购物车'); |
150 | 150 | ||
151 | $cartType = $this->post('cartType', 'ordinary'); | 151 | $cartType = $this->post('cartType', 'ordinary'); |
152 | + $cookieData = $this->getCookie('orderInfo', null); | ||
152 | $uid = $this->getUid(true); | 153 | $uid = $this->getUid(true); |
153 | $data = array( | 154 | $data = array( |
154 | 'orderEnsurePage' => true, | 155 | 'orderEnsurePage' => true, |
155 | - 'orderEnsure' => CartModel::cartPay($uid, $cartType) | 156 | + 'orderEnsure' => CartModel::cartPay($uid, $cartType, $cookieData) |
156 | ); | 157 | ); |
157 | 158 | ||
158 | 159 | ||
@@ -160,38 +161,16 @@ class ShoppingCartController extends AbstractAction | @@ -160,38 +161,16 @@ class ShoppingCartController extends AbstractAction | ||
160 | } | 161 | } |
161 | 162 | ||
162 | /** | 163 | /** |
163 | - * 购物车选择支付方式和配送方式接口 | ||
164 | - */ | ||
165 | - public function payAndDeliveryAction() | ||
166 | - { | ||
167 | - $result = array(); | ||
168 | - | ||
169 | - if ($this->isAjax()) { | ||
170 | - $cartType = $this->post('cartType', 'ordinary'); | ||
171 | - $deliveryWay = $this->post('deliveryWay', 1); | ||
172 | - $paymentType = $this->post('paymentType', 1); | ||
173 | - $uid = $this->getUid(true); | ||
174 | - $result = CartModel::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType); | ||
175 | - } | ||
176 | - | ||
177 | - if (empty($result)) { | ||
178 | - echo ' '; | ||
179 | - } else { | ||
180 | - $this->echoJson($result); | ||
181 | - } | ||
182 | - } | ||
183 | - | ||
184 | - /** | ||
185 | * 购物车输入优惠券码使用优惠券 | 164 | * 购物车输入优惠券码使用优惠券 |
186 | */ | 165 | */ |
187 | - public function couponAction() | 166 | + public function couponSearchAction() |
188 | { | 167 | { |
189 | $result = array(); | 168 | $result = array(); |
190 | 169 | ||
191 | if ($this->isAjax()) { | 170 | if ($this->isAjax()) { |
192 | - $couponCode = $this->post('couponCode', ''); | 171 | + $couponCode = $this->get('couponCode', ''); |
193 | $uid = $this->getUid(true); | 172 | $uid = $this->getUid(true); |
194 | - $result = CartModel::getCoupon($uid, $couponCode); | 173 | + $result = CartModel::searchCoupon($uid, $couponCode); |
195 | } | 174 | } |
196 | 175 | ||
197 | if (empty($result)) { | 176 | if (empty($result)) { |
@@ -202,18 +181,16 @@ class ShoppingCartController extends AbstractAction | @@ -202,18 +181,16 @@ class ShoppingCartController extends AbstractAction | ||
202 | } | 181 | } |
203 | 182 | ||
204 | /** | 183 | /** |
205 | - * 购物车使用YOHO币 | 184 | + * 购物车结算--获取优惠券列表 |
206 | */ | 185 | */ |
207 | - public function yohoCoinAction() | 186 | + public function couponListAction() |
208 | { | 187 | { |
209 | $result = array(); | 188 | $result = array(); |
210 | 189 | ||
211 | if ($this->isAjax()) { | 190 | if ($this->isAjax()) { |
212 | - $cartType = $this->post('cartType', 'ordinary'); | ||
213 | - $deliveryWay = $this->post('deliveryWay', 1); | ||
214 | - $paymentType = $this->post('paymentType', 1); | ||
215 | - $yohoCoin = $this->post('yohoCoin', 1); | ||
216 | - $result = CartModel::paymentTypeAndDelivery($this->_uid, $cartType, $deliveryWay, $paymentType, $yohoCoin); | 191 | + $uid = $this->getUid(true); |
192 | + $page = $this->get('page', 1); | ||
193 | + $result = CartModel::getCouponList($uid); | ||
217 | } | 194 | } |
218 | 195 | ||
219 | if (empty($result)) { | 196 | if (empty($result)) { |
@@ -223,133 +200,17 @@ class ShoppingCartController extends AbstractAction | @@ -223,133 +200,17 @@ class ShoppingCartController extends AbstractAction | ||
223 | } | 200 | } |
224 | } | 201 | } |
225 | 202 | ||
226 | - public function giftAdvanceAction() | ||
227 | - { | ||
228 | - $data = array( | ||
229 | - 'advance' => array( | ||
230 | - array( | ||
231 | - 'title' => '【izzue】加¥19购袜子', | ||
232 | - 'goods' => array( | ||
233 | - 'id' => 1, | ||
234 | - 'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/09/17/03/014cacfa5c458b9732c68adf1af15d7a45.jpg?imageMogr2/thumbnail/120x120/extent/120x120/background/d2hpdGU=/position/center/quality/90', | ||
235 | - 'name' => 'Life.After.Life纯棉短袜', | ||
236 | - 'salePrice' => 19, | ||
237 | - 'price' => 99, | ||
238 | - 'count' => 1 | ||
239 | - ) | ||
240 | - ), | ||
241 | - array( | ||
242 | - 'title' => '【银鳞堂】加¥9购手绳', | ||
243 | - 'goods' => array( | ||
244 | - 'id' => 1, | ||
245 | - 'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/10/03/10/01bc1878f9154e77ac4f7a6003c954f1b8.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90', | ||
246 | - 'name' => '银鳞堂民族风牛皮手绳', | ||
247 | - 'salePrice' => 9, | ||
248 | - 'price' => 19, | ||
249 | - 'count' => 1 | ||
250 | - ) | ||
251 | - ) | ||
252 | - ) | ||
253 | - ); | ||
254 | - | ||
255 | - $data = array( | ||
256 | - 'gift' => array( | ||
257 | - 'id' => 1, | ||
258 | - 'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/09/17/03/014cacfa5c458b9732c68adf1af15d7a45.jpg?imageMogr2/thumbnail/120x120/extent/120x120/background/d2hpdGU=/position/center/quality/90', | ||
259 | - 'name' => 'Life.After.Life纯棉短袜', | ||
260 | - 'color' => '黄色', | ||
261 | - 'size' => 'L', | ||
262 | - 'price' => 0, | ||
263 | - 'count' => 1 | ||
264 | - ) | ||
265 | - ); | ||
266 | - | ||
267 | - $this->_view->display('gift-advance', array('giftAdvancePage' => true, 'pageHeader' => array( | ||
268 | - 'navBack' => true, 'navTitle' => '加价购'), 'shoppingCart' => $data)); | ||
269 | - } | ||
270 | - | ||
271 | - /* | ||
272 | - * 确认订单 | ||
273 | - */ | ||
274 | - public function orderEnsureAction() | ||
275 | - { | ||
276 | - $data = array( | ||
277 | - 'orderEnsurePage' => true, | ||
278 | - 'orderEnsure' => array( | ||
279 | - 'name' => '申建军', | ||
280 | - 'phoneNum' => '12345678', | ||
281 | - 'address' => '江苏省南京市建邺区', | ||
282 | - 'dispatchMode' => array( | ||
283 | - array( | ||
284 | - 'id' => 1, | ||
285 | - 'name' => '普通快递¥10' | ||
286 | - ), | ||
287 | - array( | ||
288 | - 'id' => 2, | ||
289 | - 'name' => '顺丰速运¥15(仅支持顺丰克配送的地区)' | ||
290 | - ) | ||
291 | - ), | ||
292 | - 'dispatchTime' => array( | ||
293 | - array( | ||
294 | - 'id' => 1, | ||
295 | - 'name' => '工作日、双休日、节假日均可送货' | ||
296 | - ), | ||
297 | - array( | ||
298 | - 'id' => 2, | ||
299 | - 'name' => '只工作日送货' | ||
300 | - ), | ||
301 | - array( | ||
302 | - 'id' => 3, | ||
303 | - 'name' => '只双休日、节假日送货' | ||
304 | - ) | ||
305 | - ), | ||
306 | - 'goods' => array( | ||
307 | - array( | ||
308 | - 'id' => 1, | ||
309 | - 'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90', | ||
310 | - 'name' => 'Adidas Originals ZX FLUXM22508', | ||
311 | - 'color' => '黄', | ||
312 | - 'size' => '43', | ||
313 | - 'price' => '699.00', | ||
314 | - 'count' => '2' | ||
315 | - ), | ||
316 | - array( | ||
317 | - 'id' => 1, | ||
318 | - 'thumb' => 'http://img10.static.yhbimg.com/goodsimg/2015/11/04/05/0188f1aca49ac478a565ec029b5d2d4a6c.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90', | ||
319 | - 'name' => 'B.Duck浴室玩伴mini浮水鸭', | ||
320 | - 'gift' => true, | ||
321 | - 'color' => '黄', | ||
322 | - 'size' => '43', | ||
323 | - 'price' => '0.00', | ||
324 | - 'count' => '1' | ||
325 | - ) | ||
326 | - ), | ||
327 | - 'coupon' => array( | ||
328 | - 'count' => 1, | ||
329 | - 'notUsed' => true | ||
330 | - ), | ||
331 | - 'yohoCoin' => '0', | ||
332 | - 'invoice' => true, | ||
333 | - 'sumPrice' => 900, | ||
334 | - 'salePrice' => 90, | ||
335 | - 'freight' => 0, | ||
336 | - 'price' => 810 | ||
337 | - ) | ||
338 | - ); | ||
339 | - | ||
340 | - $this->_view->display('order-ensure', $data); | ||
341 | - } | ||
342 | - | ||
343 | /** | 203 | /** |
344 | * 下单流程 选择地址 | 204 | * 下单流程 选择地址 |
345 | */ | 205 | */ |
346 | 206 | ||
347 | - public function selectAddressAction() { | 207 | + public function selectAddressAction() |
208 | + { | ||
348 | // 设置网站标题 | 209 | // 设置网站标题 |
349 | $this->setTitle('选择地址'); | 210 | $this->setTitle('选择地址'); |
350 | $this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure')); | 211 | $this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure')); |
351 | 212 | ||
352 | - $uid = $this->_uid; | 213 | + $uid = $this->getUid(true); |
353 | $address = UserModel::getAddressData($uid); | 214 | $address = UserModel::getAddressData($uid); |
354 | 215 | ||
355 | $this->_view->display('select-address', array( | 216 | $this->_view->display('select-address', array( |
@@ -364,19 +225,50 @@ class ShoppingCartController extends AbstractAction | @@ -364,19 +225,50 @@ class ShoppingCartController extends AbstractAction | ||
364 | * 下单流程 选择优惠券 | 225 | * 下单流程 选择优惠券 |
365 | */ | 226 | */ |
366 | 227 | ||
367 | - public function selectCouponAction() { | 228 | + public function selectCouponAction() |
229 | + { | ||
368 | // 设置网站标题 | 230 | // 设置网站标题 |
369 | $this->setTitle('选择优惠券'); | 231 | $this->setTitle('选择优惠券'); |
370 | $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure')); | 232 | $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure')); |
371 | 233 | ||
372 | $uid = $this->_uid; | 234 | $uid = $this->_uid; |
373 | - $address = UserModel::getAddressData($uid); | ||
374 | 235 | ||
375 | $this->_view->display('select-coupon', array( | 236 | $this->_view->display('select-coupon', array( |
376 | 'selectCouponPage' => true, | 237 | 'selectCouponPage' => true, |
377 | - 'pageFooter' => true, | ||
378 | - 'address' => $address | 238 | + 'pageFooter' => true |
379 | )); | 239 | )); |
380 | 240 | ||
381 | } | 241 | } |
242 | + | ||
243 | + /** | ||
244 | + * 确认结算订单 | ||
245 | + */ | ||
246 | + public function orderSubAction() | ||
247 | + { | ||
248 | + $result = array(); | ||
249 | + | ||
250 | + if ($this->isAjax()) { | ||
251 | + $uid = $this->getUid(true); | ||
252 | + $addressId = $this->post('addressId', null); | ||
253 | + $cartType = $this->post('cartType', 'ordinary'); // 默认普通购物车 | ||
254 | + $deliveryTime = $this->post('deliveryTime', 1); // 默认只工作日配送 | ||
255 | + $deliveryWay = $this->post('deliveryWay', 1); // 默认普通快递 | ||
256 | + $invoiceTitle = $this->post('invoiceTitle', null); | ||
257 | + $invoiceId = $this->post('invoiceId', null); | ||
258 | + $paymentId = $this->post('paymentId', 15); | ||
259 | + $paymentType = $this->post('paymentType', 1); // 默认在线支付 | ||
260 | + $remark = $this->post('remark', null); // 默认在线支付 | ||
261 | + $yohoCoin = $this->post('yohoCoin', 1); | ||
262 | + $result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin); | ||
263 | + } | ||
264 | + | ||
265 | + if (empty($result)) { | ||
266 | + echo ' '; | ||
267 | + } else { | ||
268 | + // 提交成功清除Cookie | ||
269 | + $this->setCookie('orderInfo', null); | ||
270 | + | ||
271 | + $this->echoJson($result); | ||
272 | + } | ||
273 | + } | ||
382 | } | 274 | } |
@@ -289,9 +289,10 @@ class CartModel | @@ -289,9 +289,10 @@ class CartModel | ||
289 | * | 289 | * |
290 | * @param int $uid 用户ID | 290 | * @param int $uid 用户ID |
291 | * @param string $cartType 购物车类型,ordinary表示普通购物车 | 291 | * @param string $cartType 购物车类型,ordinary表示普通购物车 |
292 | + * @param null|string $cookieData cookie中记录的一些订单有关数据 | ||
292 | * @return array 接口返回的数据 | 293 | * @return array 接口返回的数据 |
293 | */ | 294 | */ |
294 | - public static function cartPay($uid, $cartType) | 295 | + public static function cartPay($uid, $cartType, $cookieData) |
295 | { | 296 | { |
296 | $result = array(); | 297 | $result = array(); |
297 | 298 | ||
@@ -299,13 +300,28 @@ class CartModel | @@ -299,13 +300,28 @@ class CartModel | ||
299 | 300 | ||
300 | if ($pay && isset($pay['code']) && $pay['code'] === 200) { | 301 | if ($pay && isset($pay['code']) && $pay['code'] === 200) { |
301 | $payReturn = $pay['data']; | 302 | $payReturn = $pay['data']; |
302 | - $result = array(); | 303 | + $orderInfo = array(); |
304 | + $address = array(); | ||
305 | + $orderCompute = array(); | ||
306 | + | ||
307 | + // cookie保存的数据 | ||
308 | + if (!empty($cookieData)) { | ||
309 | + $orderInfo = json_decode($cookieData, true); | ||
310 | + $orderCompute = self::orderCompute($uid, $cartType, $orderInfo['deliveryId'], $orderInfo['paymentTypeId'], $orderInfo['couponCode'], $orderInfo['yohoCoin']); | ||
311 | + } | ||
312 | + | ||
313 | + // 根据地址id查询地址信息 | ||
314 | + if (isset($orderInfo['addressId'])) { | ||
315 | + $address = UserModel::getAddressDataById($uid, $orderInfo['addressId']); | ||
316 | + } | ||
303 | 317 | ||
304 | // 收货人有关信息 | 318 | // 收货人有关信息 |
305 | if (isset($payReturn['delivery_address']) && !empty($payReturn['delivery_address'])) { | 319 | 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']; | 320 | + $result['addressId'] = isset($address['address_id']) ? $address['address_id'] : $payReturn['delivery_address']['address_id']; |
321 | + $result['name'] = isset($address['consignee']) ? $address['consignee'] : $payReturn['delivery_address']['consignee']; | ||
322 | + $result['phoneNum'] = isset($address['mobile']) ? $address['mobile'] : $payReturn['delivery_address']['mobile']; | ||
323 | + $result['address'] = isset($address['address']) ? $address['address'] : $payReturn['delivery_address']['address']; | ||
324 | + $result['isSupport'] = ($payReturn['delivery_address']['is_support'] === 'Y'); | ||
309 | } | 325 | } |
310 | 326 | ||
311 | // 配送方式 | 327 | // 配送方式 |
@@ -316,6 +332,7 @@ class CartModel | @@ -316,6 +332,7 @@ class CartModel | ||
316 | $oneDeliv['id'] = $val['delivery_way_id']; | 332 | $oneDeliv['id'] = $val['delivery_way_id']; |
317 | $oneDeliv['name'] = $val['delivery_way_name']; | 333 | $oneDeliv['name'] = $val['delivery_way_name']; |
318 | $oneDeliv['default'] = ($val['default'] === 'Y'); | 334 | $oneDeliv['default'] = ($val['default'] === 'Y'); |
335 | + isset($orderInfo['deliveryId']) && $orderInfo['deliveryId'] === $oneDeliv['id'] && $oneDeliv['isSelected'] = true; | ||
319 | 336 | ||
320 | $result['dispatchMode'][] = $oneDeliv; | 337 | $result['dispatchMode'][] = $oneDeliv; |
321 | } | 338 | } |
@@ -329,6 +346,7 @@ class CartModel | @@ -329,6 +346,7 @@ class CartModel | ||
329 | $oneDelivTime['id'] = $one['delivery_time_id']; | 346 | $oneDelivTime['id'] = $one['delivery_time_id']; |
330 | $oneDelivTime['name'] = $one['delivery_time_string']; | 347 | $oneDelivTime['name'] = $one['delivery_time_string']; |
331 | $oneDelivTime['default'] = ($one['default'] === 'Y'); | 348 | $oneDelivTime['default'] = ($one['default'] === 'Y'); |
349 | + isset($orderInfo['deliveryTimeId']) && $orderInfo['deliveryTimeId'] === $oneDelivTime['id'] && $oneDeliv['isSelected'] = true; | ||
332 | 350 | ||
333 | $result['dispatchTime'][] = $oneDelivTime; | 351 | $result['dispatchTime'][] = $oneDelivTime; |
334 | } | 352 | } |
@@ -366,14 +384,18 @@ class CartModel | @@ -366,14 +384,18 @@ class CartModel | ||
366 | } | 384 | } |
367 | 385 | ||
368 | // 有货币 | 386 | // 有货币 |
369 | - $result['yohoCoin'] = $payReturn['yoho_coin']; | 387 | + $result['yohoCoin'] = isset($orderCompute['use_yoho_coin']) ? isset($orderCompute['use_yoho_coin']) : $payReturn['yoho_coin']; |
370 | 388 | ||
371 | // 订单数据 | 389 | // 订单数据 |
372 | if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) { | 390 | 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']); | 391 | + $sumPrice = isset($orderCompute['order_amount']) ? $orderCompute['order_amount'] : $payReturn['shopping_cart_data']['order_amount']; |
392 | + $salePrice = isset($orderCompute['discount_amount']) ? $orderCompute['discount_amount'] : $payReturn['shopping_cart_data']['discount_amount']; | ||
393 | + $price = isset($orderCompute['last_order_amount']) ? $orderCompute['last_order_amount'] : $payReturn['shopping_cart_data']['last_order_amount']; | ||
394 | + $freight = isset($orderCompute['promotion_formula_list']['promotion_amount']) ? $orderCompute['promotion_formula_list']['promotion_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list']['promotion_amount']; | ||
395 | + $result['sumPrice'] = Helpers::transPrice($sumPrice); | ||
396 | + $result['salePrice'] = Helpers::transPrice($salePrice); | ||
397 | + $result['price'] = Helpers::transPrice($price); | ||
398 | + $result['freight'] = strtr($freight, '¥', '') . '.00'; | ||
377 | } | 399 | } |
378 | 400 | ||
379 | // 发票有关数据 | 401 | // 发票有关数据 |
@@ -390,7 +412,8 @@ class CartModel | @@ -390,7 +412,8 @@ class CartModel | ||
390 | 412 | ||
391 | // 优惠券数据 | 413 | // 优惠券数据 |
392 | $coupons = array('notUsed' => true); | 414 | $coupons = array('notUsed' => true); |
393 | - $coupons += UserModel::getCouponData($uid, 0, 1, true); | 415 | + !empty($orderCompute['coupon_amount']) && $coupons['notUsed'] = $orderInfo['couponName']; |
416 | + $coupons += self::getCouponList($uid, 0, 1, true); | ||
394 | $result['coupon'] = $coupons; | 417 | $result['coupon'] = $coupons; |
395 | } | 418 | } |
396 | 419 | ||
@@ -402,17 +425,19 @@ class CartModel | @@ -402,17 +425,19 @@ class CartModel | ||
402 | * | 425 | * |
403 | * @param int $uid 用户ID | 426 | * @param int $uid 用户ID |
404 | * @param string $cartType 购物车类型,ordinary表示普通购物车 | 427 | * @param string $cartType 购物车类型,ordinary表示普通购物车 |
405 | - * @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 | ||
406 | - * @param string $paymentType 支付方式,1表示在线支付,2表示货到付款 | 428 | + * @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运 |
429 | + * @param int $paymentType 支付方式,1表示在线支付,2表示货到付款 | ||
430 | + * @param string $couponCode 优惠券码 | ||
431 | + * @param mixed $yohoCoin 使用的YOHO币数量 | ||
407 | * @return array 接口返回的数据 | 432 | * @return array 接口返回的数据 |
408 | */ | 433 | */ |
409 | - public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType) | 434 | + public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin) |
410 | { | 435 | { |
411 | $result = array(); | 436 | $result = array(); |
412 | 437 | ||
413 | - $pay = CartData::paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType); | ||
414 | - if ($pay && isset($pay['code']) && $pay['code'] === 200) { | ||
415 | - $result = $pay['data']; | 438 | + $compute = CartData::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin); |
439 | + if ($compute && isset($compute['code']) && $compute['code'] === 200) { | ||
440 | + $result = $compute['data']; | ||
416 | } | 441 | } |
417 | 442 | ||
418 | return $result; | 443 | return $result; |
@@ -425,14 +450,78 @@ class CartModel | @@ -425,14 +450,78 @@ class CartModel | ||
425 | * @param string $couponCode 优惠券代码 | 450 | * @param string $couponCode 优惠券代码 |
426 | * @return array 接口返回的数据 | 451 | * @return array 接口返回的数据 |
427 | */ | 452 | */ |
428 | - public static function getCoupon($uid, $couponCode) | 453 | + public static function searchCoupon($uid, $couponCode) |
429 | { | 454 | { |
430 | $result = array('code' => 400, 'message' => '出错啦~'); | 455 | $result = array('code' => 400, 'message' => '出错啦~'); |
431 | 456 | ||
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']; | 457 | + $coupon = CartData::searchCoupon($uid, $couponCode); |
458 | + if ($coupon && isset($coupon['code'])) { | ||
459 | + $result = $coupon; | ||
460 | + } | ||
461 | + | ||
462 | + return $result; | ||
463 | + } | ||
464 | + | ||
465 | + /** | ||
466 | + * 处理优惠券列表数据 | ||
467 | + * | ||
468 | + * @param int $uid 用户ID | ||
469 | + * @param boolean $onlyTotal 只返回总数 | ||
470 | + * @return array|mixed 处理之后的优惠券数据 | ||
471 | + */ | ||
472 | + public static function getCouponList($uid, $onlyTotal = false) | ||
473 | + { | ||
474 | + $result = array(); | ||
475 | + | ||
476 | + // 调用接口获取优惠券数据 | ||
477 | + $coupons = CartData::getCouponList($uid); | ||
478 | + | ||
479 | + // 处理优惠券数据 | ||
480 | + if (isset($coupons['data'])) { | ||
481 | + | ||
482 | + if ($onlyTotal) { | ||
483 | + $result['count'] = $coupons['data']['total']; | ||
484 | + } else { | ||
485 | + $couponArr = array(); | ||
486 | + isset($coupons['data']['couponList']) && $couponArr = $coupons['data']['couponList']; | ||
487 | + | ||
488 | + foreach ($couponArr as &$val) { | ||
489 | + $notAvailableRes = self::searchCoupon($uid, $val['couponCode']); | ||
490 | + // 处理可用的优惠券 | ||
491 | + if (isset($notAvailableRes['code']) && $notAvailableRes['code'] !== 200) { | ||
492 | + $val['notAvailable'] = true; | ||
493 | + } | ||
494 | + } | ||
495 | + !empty($couponArr) && $result['coupons'] = $couponArr; | ||
496 | + } | ||
497 | + } | ||
498 | + | ||
499 | + return $result; | ||
500 | + } | ||
501 | + | ||
502 | + /** | ||
503 | + * 购物车结算--提交结算信息 | ||
504 | + * | ||
505 | + * @param int $uid 用户ID | ||
506 | + * @param int $addressId 地址ID | ||
507 | + * @param int $cartType 购物车类型ID | ||
508 | + * @param int $deliveryTime 寄送时间ID | ||
509 | + * @param int $deliveryWay 寄送方式ID | ||
510 | + * @param string $invoiceTitle 发票说明 | ||
511 | + * @param int $invoiceId 发票类型ID | ||
512 | + * @param int $paymentId 支付方式ID | ||
513 | + * @param int $paymentType 支付类型ID | ||
514 | + * @param string $remark 留言 | ||
515 | + * @param mixed $yohoCoin 使用的YOHO币数量或为空 | ||
516 | + * @return array 接口返回的数据 | ||
517 | + */ | ||
518 | + public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin) | ||
519 | + { | ||
520 | + $result = array(); | ||
521 | + | ||
522 | + $orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin); | ||
523 | + if ($orderSubRes && isset($orderSubRes['code']) && $orderSubRes['code'] === 200) { | ||
524 | + $result = $orderSubRes; | ||
436 | } | 525 | } |
437 | 526 | ||
438 | return $result; | 527 | return $result; |
@@ -374,10 +374,9 @@ class UserModel | @@ -374,10 +374,9 @@ class UserModel | ||
374 | * @param int $uid 用户ID | 374 | * @param int $uid 用户ID |
375 | * @param int $status 优惠券状态,0表示未使用,1表示已使用 | 375 | * @param int $status 优惠券状态,0表示未使用,1表示已使用 |
376 | * @param int $page 第几页 | 376 | * @param int $page 第几页 |
377 | - * @param boolean $onlyTotal 只返回总数 | ||
378 | * @return array|mixed 处理之后的优惠券数据 | 377 | * @return array|mixed 处理之后的优惠券数据 |
379 | */ | 378 | */ |
380 | - public static function getCouponData($uid, $status, $page, $onlyTotal = false) | 379 | + public static function getCouponData($uid, $status, $page) |
381 | { | 380 | { |
382 | $result = array(); | 381 | $result = array(); |
383 | 382 | ||
@@ -386,7 +385,6 @@ class UserModel | @@ -386,7 +385,6 @@ class UserModel | ||
386 | 385 | ||
387 | // 没有获取到优惠券时 | 386 | // 没有获取到优惠券时 |
388 | if (!$coupons) { | 387 | if (!$coupons) { |
389 | - $result['topURL'] = '/product/new'; | ||
390 | $result['noRecord'] = true; | 388 | $result['noRecord'] = true; |
391 | 389 | ||
392 | return $result; | 390 | return $result; |
@@ -395,15 +393,8 @@ class UserModel | @@ -395,15 +393,8 @@ class UserModel | ||
395 | // 处理优惠券数据 | 393 | // 处理优惠券数据 |
396 | if (isset($coupons['data'])) { | 394 | if (isset($coupons['data'])) { |
397 | 395 | ||
398 | - if ($onlyTotal) { | ||
399 | - $result['count'] = $coupons['data']['total']; | ||
400 | - | ||
401 | - return $result; | ||
402 | - } | ||
403 | - | ||
404 | // 不能再查到结果了 | 396 | // 不能再查到结果了 |
405 | if ($page == 1 && $coupons['data']['total'] === 0) { | 397 | if ($page == 1 && $coupons['data']['total'] === 0) { |
406 | - $result['walkwayUrl'] = '/product/new'; | ||
407 | $result['noRecord'] = true; | 398 | $result['noRecord'] = true; |
408 | } else { | 399 | } else { |
409 | $couponArr = array(); | 400 | $couponArr = array(); |
-
Please register or login to post a comment