|
|
'use strict';
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
const api = global.yoho.api;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const paymentProcess = require(global.utils + '/payment-process');
|
|
|
|
|
|
/**
|
|
|
* 购物车结算
|
|
|
*
|
|
|
* @param int uid 用户ID
|
|
|
* @param string cartType 购物车类型,ordinary表示普通购物车
|
|
|
* @param int isUseYohoCoin 是否使用有货币,0不使用, 1使用
|
|
|
* @param string skuList 购买限购商品时需要传递的参数
|
|
|
* @param int $uid 用户ID
|
|
|
* @param string $cartType 购物车类型,ordinary表示普通购物车
|
|
|
* @param int $isUseYohoCoin 是否使用有货币,0不使用, 1使用
|
|
|
* @param string $skuList 购买限购商品时需要传递的参数
|
|
|
* @return array 接口返回的数据
|
|
|
*/
|
|
|
exports.cartPay = (uid, cartType, isUseYohoCoin, skuList) => {
|
|
|
function cartPayAPI(uid, cartType, isUseYohoCoin, skuList) {
|
|
|
let param = {
|
|
|
method: 'app.Shopping.payment',
|
|
|
enable_red_envelopes: 0, // h5不返回红包
|
...
|
...
|
@@ -20,9 +23,62 @@ exports.cartPay = (uid, cartType, isUseYohoCoin, skuList) => { |
|
|
uid: uid
|
|
|
};
|
|
|
|
|
|
if (skuList) {
|
|
|
// 购买限购商品时需要传递product_sku_list参数
|
|
|
if (!_.isEmpty(skuList)) {
|
|
|
param.product_sku_list = skuList;
|
|
|
}
|
|
|
|
|
|
return api.get('', param);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 调用购物车结算接口返回的数据处理
|
|
|
*
|
|
|
* @param int $uid 用户ID
|
|
|
* @param string $cartType 购物车类型,ordinary表示普通购物车
|
|
|
* @param array $orderInfo cookie中记录的一些订单有关数据
|
|
|
* @param string $limitProductCode 限购商品码,用户限购商品购买
|
|
|
* @param string $sku 商品sku,用于限购商品购买
|
|
|
* @param stirng $skn 商品skn,用于限购商品购买
|
|
|
* @param int $buyNumber 购买商品数目,用户限购商品支付
|
|
|
* @param bool $isAjax 是否是异步请求
|
|
|
* @return array 接口返回的数据
|
|
|
*/
|
|
|
exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumber, isAjax) => {
|
|
|
isAjax = isAjax || false;
|
|
|
|
|
|
let result = {};
|
|
|
let skuList = null;
|
|
|
let isLimitGoods = skn && sku && buyNumber; // 存在sku, skn 和buyNumber时为限购商品
|
|
|
|
|
|
if (isLimitGoods) {
|
|
|
skuList = {
|
|
|
type: 'limitcode',
|
|
|
limitproductcode: limitProductCode,
|
|
|
buy_number: buyNumber,
|
|
|
skn,
|
|
|
sku
|
|
|
};
|
|
|
|
|
|
result.isLimit = true;
|
|
|
}
|
|
|
|
|
|
return cartPayAPI(uid, cartType, 0, skuList)
|
|
|
.then(pay => {
|
|
|
let goodsList = _.get(pay, 'data.goods_list', []);
|
|
|
|
|
|
if (_.isEmpty(goodsList)) {
|
|
|
if (isLimitGoods) {
|
|
|
result.error = true;
|
|
|
result.message = pay.message;
|
|
|
} else {
|
|
|
result.cartUrl = helpers.urlFormat('/cart/index/new');
|
|
|
}
|
|
|
|
|
|
return pay;
|
|
|
}
|
|
|
|
|
|
return paymentProcess.tranformPayment(pay.data, orderInfo);
|
|
|
});
|
|
|
}; |
...
|
...
|
|