添加限购商品支付的接口(新增app.Shopping.payment,app.Shopping.compute,app.Shopping.submit增加
product_skn_list参数) Code Review By Rock Zhang
Showing
3 changed files
with
63 additions
and
15 deletions
@@ -248,16 +248,23 @@ class CartData | @@ -248,16 +248,23 @@ class CartData | ||
248 | * | 248 | * |
249 | * @param int $uid 用户ID | 249 | * @param int $uid 用户ID |
250 | * @param string $cartType 购物车类型,ordinary表示普通购物车 | 250 | * @param string $cartType 购物车类型,ordinary表示普通购物车 |
251 | - * @param int $isUseYohoCoin 是否使用有货币,默认0不使用, 1使用 | 251 | + * @param int $isUseYohoCoin 是否使用有货币,0不使用, 1使用 |
252 | + * @param string $skuList 购买限购商品时需要传递的参数 | ||
252 | * @return array 接口返回的数据 | 253 | * @return array 接口返回的数据 |
253 | */ | 254 | */ |
254 | - public static function cartPay($uid, $cartType, $isUseYohoCoin = 0) | 255 | + public static function cartPay($uid, $cartType, $isUseYohoCoin, $skuList) |
255 | { | 256 | { |
256 | $param = Yohobuy::param(); | 257 | $param = Yohobuy::param(); |
257 | $param['method'] = 'app.Shopping.payment'; | 258 | $param['method'] = 'app.Shopping.payment'; |
258 | $param['cart_type'] = $cartType; | 259 | $param['cart_type'] = $cartType; |
259 | $param['yoho_coin_mode'] = $isUseYohoCoin; | 260 | $param['yoho_coin_mode'] = $isUseYohoCoin; |
260 | $param['uid'] = $uid; | 261 | $param['uid'] = $uid; |
262 | + | ||
263 | + // 购买限购商品时需要传递product_sku_list参数 | ||
264 | + if (!empty($skuList)) { | ||
265 | + $param['product_sku_list'] = $skuList; | ||
266 | + } | ||
267 | + | ||
261 | $param['client_secret'] = Sign::getSign($param); | 268 | $param['client_secret'] = Sign::getSign($param); |
262 | 269 | ||
263 | return Yohobuy::get(Yohobuy::API_URL, $param); | 270 | return Yohobuy::get(Yohobuy::API_URL, $param); |
@@ -272,9 +279,10 @@ class CartData | @@ -272,9 +279,10 @@ class CartData | ||
272 | * @param int $paymentType 支付方式,1表示在线支付,2表示货到付款 | 279 | * @param int $paymentType 支付方式,1表示在线支付,2表示货到付款 |
273 | * @param string $couponCode 优惠券码 | 280 | * @param string $couponCode 优惠券码 |
274 | * @param mixed $yohoCoin 使用的YOHO币数量 | 281 | * @param mixed $yohoCoin 使用的YOHO币数量 |
282 | + * @param string $skuList 购买限购商品时需要传递的参数 | ||
275 | * @return array 接口返回的数据 | 283 | * @return array 接口返回的数据 |
276 | */ | 284 | */ |
277 | - public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin) | 285 | + public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList) |
278 | { | 286 | { |
279 | $param = Yohobuy::param(); | 287 | $param = Yohobuy::param(); |
280 | $param['method'] = 'app.Shopping.compute'; | 288 | $param['method'] = 'app.Shopping.compute'; |
@@ -288,6 +296,11 @@ class CartData | @@ -288,6 +296,11 @@ class CartData | ||
288 | $param['use_yoho_coin'] = $yohoCoin; | 296 | $param['use_yoho_coin'] = $yohoCoin; |
289 | } | 297 | } |
290 | 298 | ||
299 | + // 购买限购商品时需要传递product_sku_list参数 | ||
300 | + if (!empty($skuList)) { | ||
301 | + $param['product_sku_list'] = $skuList; | ||
302 | + } | ||
303 | + | ||
291 | $param['uid'] = $uid; | 304 | $param['uid'] = $uid; |
292 | $param['client_secret'] = Sign::getSign($param); | 305 | $param['client_secret'] = Sign::getSign($param); |
293 | 306 | ||
@@ -346,9 +359,10 @@ class CartData | @@ -346,9 +359,10 @@ class CartData | ||
346 | * @param string $remark 留言 | 359 | * @param string $remark 留言 |
347 | * @param string $couponCode 优惠券码 | 360 | * @param string $couponCode 优惠券码 |
348 | * @param mixed $yohoCoin 使用的YOHO币数量或为空 | 361 | * @param mixed $yohoCoin 使用的YOHO币数量或为空 |
362 | + * @param string $skuList 购买限购商品时需要传递的参数 | ||
349 | * @return array 接口返回的数据 | 363 | * @return array 接口返回的数据 |
350 | */ | 364 | */ |
351 | - public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin) | 365 | + public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList) |
352 | { | 366 | { |
353 | $param = Yohobuy::param(); | 367 | $param = Yohobuy::param(); |
354 | $param['debug'] = 'Y'; | 368 | $param['debug'] = 'Y'; |
@@ -375,6 +389,12 @@ class CartData | @@ -375,6 +389,12 @@ class CartData | ||
375 | if (!empty($yohoCoin)) { | 389 | if (!empty($yohoCoin)) { |
376 | $param['use_yoho_coin'] = $yohoCoin; | 390 | $param['use_yoho_coin'] = $yohoCoin; |
377 | } | 391 | } |
392 | + | ||
393 | + // 购买限购商品时需要传递product_sku_list参数 | ||
394 | + if (!empty($skuList)) { | ||
395 | + $param['product_sku_list'] = $skuList; | ||
396 | + } | ||
397 | + | ||
378 | $param['uid'] = $uid; | 398 | $param['uid'] = $uid; |
379 | $param['client_secret'] = Sign::getSign($param); | 399 | $param['client_secret'] = Sign::getSign($param); |
380 | 400 |
@@ -314,13 +314,30 @@ class CartModel | @@ -314,13 +314,30 @@ class CartModel | ||
314 | * @param int $uid 用户ID | 314 | * @param int $uid 用户ID |
315 | * @param string $cartType 购物车类型,ordinary表示普通购物车 | 315 | * @param string $cartType 购物车类型,ordinary表示普通购物车 |
316 | * @param array $orderInfo cookie中记录的一些订单有关数据 | 316 | * @param array $orderInfo cookie中记录的一些订单有关数据 |
317 | + * @param string $limitCode 限购商品的限购码,用户限购商品购买 | ||
318 | + * @param string $sku 商品sku,用于限购商品购买 | ||
319 | + * @param stirng $skn 商品skn,用于限购商品购买 | ||
320 | + * @param int $buyNumber 购买商品数目,用户限购商品支付 | ||
317 | * @return array 接口返回的数据 | 321 | * @return array 接口返回的数据 |
318 | */ | 322 | */ |
319 | - public static function cartPay($uid, $cartType, $orderInfo) | 323 | + public static function cartPay($uid, $cartType, $orderInfo, $limitCode, $sku, $skn, $buyNumber) |
320 | { | 324 | { |
321 | $result = array(); | 325 | $result = array(); |
322 | 326 | ||
323 | - $pay = CartData::cartPay($uid, $cartType); | 327 | + $skuList = ''; |
328 | + if (!empty($sku) && !empty($skn) && !empty($buyNumber)) { // 存在sku,skn和buyNumber时 | ||
329 | + $skuList = json_encode(array( | ||
330 | + array( | ||
331 | + 'type' => 'limitcode', | ||
332 | + 'limitproductcode' => $limitCode, | ||
333 | + 'skn' => $skn, | ||
334 | + 'sku' => $sku, | ||
335 | + 'buy_number' => $buyNumber | ||
336 | + ) | ||
337 | + )); | ||
338 | + } | ||
339 | + | ||
340 | + $pay = CartData::cartPay($uid, $cartType, 0, $skuList); | ||
324 | 341 | ||
325 | // 商品为空返回 | 342 | // 商品为空返回 |
326 | if (!$pay || empty($pay['data']['goods_list'])) { | 343 | if (!$pay || empty($pay['data']['goods_list'])) { |
@@ -335,7 +352,7 @@ class CartModel | @@ -335,7 +352,7 @@ class CartModel | ||
335 | 352 | ||
336 | // cookie保存的数据 | 353 | // cookie保存的数据 |
337 | if (!empty($orderInfo)) { | 354 | if (!empty($orderInfo)) { |
338 | - $orderCompute = self::orderCompute($uid, $cartType, $orderInfo['deliveryId'], $orderInfo['paymentTypeId'], $orderInfo['couponCode'], $orderInfo['yohoCoin']); | 355 | + $orderCompute = self::orderCompute($uid, $cartType, $orderInfo['deliveryId'], $orderInfo['paymentTypeId'], $orderInfo['couponCode'], $orderInfo['yohoCoin'], $skuList); |
339 | } | 356 | } |
340 | 357 | ||
341 | // 根据地址id查询地址信息 | 358 | // 根据地址id查询地址信息 |
@@ -503,13 +520,14 @@ class CartModel | @@ -503,13 +520,14 @@ class CartModel | ||
503 | * @param int $paymentType 支付方式,1表示在线支付,2表示货到付款 | 520 | * @param int $paymentType 支付方式,1表示在线支付,2表示货到付款 |
504 | * @param string $couponCode 优惠券码 | 521 | * @param string $couponCode 优惠券码 |
505 | * @param mixed $yohoCoin 使用的YOHO币数量 | 522 | * @param mixed $yohoCoin 使用的YOHO币数量 |
523 | + * @param string $skuList 购买限购商品时需要传递的参数 | ||
506 | * @return array 接口返回的数据 | 524 | * @return array 接口返回的数据 |
507 | */ | 525 | */ |
508 | - public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin) | 526 | + public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList) |
509 | { | 527 | { |
510 | $result = array(); | 528 | $result = array(); |
511 | 529 | ||
512 | - $compute = CartData::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin); | 530 | + $compute = CartData::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList); |
513 | if ($compute && isset($compute['code']) && $compute['code'] === 200) { | 531 | if ($compute && isset($compute['code']) && $compute['code'] === 200) { |
514 | // 有货币添加.00后缀 | 532 | // 有货币添加.00后缀 |
515 | $compute['data']['use_yoho_coin'] = Helpers::transPrice($compute['data']['use_yoho_coin']); | 533 | $compute['data']['use_yoho_coin'] = Helpers::transPrice($compute['data']['use_yoho_coin']); |
@@ -596,9 +614,10 @@ class CartModel | @@ -596,9 +614,10 @@ class CartModel | ||
596 | * @param string $remark 留言 | 614 | * @param string $remark 留言 |
597 | * @param string $couponCode 优惠券码 | 615 | * @param string $couponCode 优惠券码 |
598 | * @param mixed $yohoCoin 使用的YOHO币数量或为空 | 616 | * @param mixed $yohoCoin 使用的YOHO币数量或为空 |
617 | + * @param string $skuList 购买限购商品时需要传递的参数 | ||
599 | * @return array 接口返回的数据 | 618 | * @return array 接口返回的数据 |
600 | */ | 619 | */ |
601 | - public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin) | 620 | + public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList) |
602 | { | 621 | { |
603 | $result = array('code' => 400, 'message' => '出错啦'); | 622 | $result = array('code' => 400, 'message' => '出错啦'); |
604 | 623 | ||
@@ -612,7 +631,7 @@ class CartModel | @@ -612,7 +631,7 @@ class CartModel | ||
612 | $result['code'] = 403; | 631 | $result['code'] = 403; |
613 | $result['message'] = '请选择配送方式'; | 632 | $result['message'] = '请选择配送方式'; |
614 | } else { | 633 | } else { |
615 | - $orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin); | 634 | + $orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList); |
616 | if ($orderSubRes && isset($orderSubRes['code'])) { | 635 | if ($orderSubRes && isset($orderSubRes['code'])) { |
617 | $result = $orderSubRes; | 636 | $result = $orderSubRes; |
618 | } | 637 | } |
@@ -285,7 +285,7 @@ class IndexController extends AbstractAction | @@ -285,7 +285,7 @@ class IndexController extends AbstractAction | ||
285 | 285 | ||
286 | $this->setTitle('确认订单'); | 286 | $this->setTitle('确认订单'); |
287 | $this->setNavHeader('确认订单', Helpers::url('/cart/index/index'), false); // 不显示右上角home按钮 | 287 | $this->setNavHeader('确认订单', Helpers::url('/cart/index/index'), false); // 不显示右上角home按钮 |
288 | - // 购物车商品为空跳转到购物车页面 | 288 | + |
289 | $cartType = $this->get('cartType', ''); | 289 | $cartType = $this->get('cartType', ''); |
290 | $cookieData = $this->getCookie('order-info', null); | 290 | $cookieData = $this->getCookie('order-info', null); |
291 | $orderInfo = array(); | 291 | $orderInfo = array(); |
@@ -294,8 +294,15 @@ class IndexController extends AbstractAction | @@ -294,8 +294,15 @@ class IndexController extends AbstractAction | ||
294 | $cartType = $orderInfo['cartType']; | 294 | $cartType = $orderInfo['cartType']; |
295 | } | 295 | } |
296 | 296 | ||
297 | + // 如果传递了code, sku,skn,buy_number就代表是限购商品 | ||
298 | + $limitCode = $this->get('code', ''); | ||
299 | + $sku = $this->get('sku', ''); | ||
300 | + $skn = $this->get('skn', ''); | ||
301 | + $buyNumber = $this->get('buy_number', ''); | ||
302 | + | ||
303 | + // 购物车商品为空跳转到购物车页面 | ||
297 | $uid = $this->getUid(true); | 304 | $uid = $this->getUid(true); |
298 | - $order = CartModel::cartPay($uid, $cartType, $orderInfo); | 305 | + $order = CartModel::cartPay($uid, $cartType, $orderInfo, $limitCode, $sku, $skn, $buyNumber); |
299 | if (isset($order['cartUrl'])) { | 306 | if (isset($order['cartUrl'])) { |
300 | $this->go($order['cartUrl']); | 307 | $this->go($order['cartUrl']); |
301 | } | 308 | } |
@@ -323,7 +330,8 @@ class IndexController extends AbstractAction | @@ -323,7 +330,8 @@ class IndexController extends AbstractAction | ||
323 | $couponCode = $this->post('couponCode', null); | 330 | $couponCode = $this->post('couponCode', null); |
324 | $yohoCoin = $this->post('yohoCoin', null); | 331 | $yohoCoin = $this->post('yohoCoin', null); |
325 | $uid = $this->getUid(true); | 332 | $uid = $this->getUid(true); |
326 | - $result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin); | 333 | + $skuList = $this->post('skuList', ''); |
334 | + $result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin, $skuList); | ||
327 | } | 335 | } |
328 | 336 | ||
329 | $this->echoJson($result); | 337 | $this->echoJson($result); |
@@ -423,7 +431,8 @@ class IndexController extends AbstractAction | @@ -423,7 +431,8 @@ class IndexController extends AbstractAction | ||
423 | $remark = $this->post('msg', null); | 431 | $remark = $this->post('msg', null); |
424 | $couponCode = $this->post('couponCode', null); | 432 | $couponCode = $this->post('couponCode', null); |
425 | $yohoCoin = $this->post('yohoCoin', 1); | 433 | $yohoCoin = $this->post('yohoCoin', 1); |
426 | - $result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin); | 434 | + $skuList = $this->post('skuList', ''); |
435 | + $result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin, $skuList); | ||
427 | 436 | ||
428 | // 记录下单异常的数据 | 437 | // 记录下单异常的数据 |
429 | if (empty($result)) { | 438 | if (empty($result)) { |
-
Please register or login to post a comment