...
|
...
|
@@ -6,6 +6,57 @@ const paymentProcess = require(global.utils + '/payment-process'); |
|
|
const shoppingAPI = require('../../serverAPI/order/shopping');
|
|
|
|
|
|
/**
|
|
|
* 转换价格
|
|
|
*
|
|
|
* @param float|string $price 价格
|
|
|
* @param boolean $isSepcialZero 是否需要特殊的0,默认否
|
|
|
* @return float|string 转换之后的价格
|
|
|
*/
|
|
|
const transPrice = (price, isSepcialZero) => {
|
|
|
if (!isSepcialZero) {
|
|
|
isSepcialZero = false;
|
|
|
}
|
|
|
|
|
|
return price;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
*有货币使用前端方案显示及是否可单击判断
|
|
|
*/
|
|
|
const _yohoCoinCompute = (orderCompute) => {
|
|
|
let yohoCoinData = {
|
|
|
totalYohoCoinNum: 0,
|
|
|
yohoCoin: 0,
|
|
|
useYohoCoin: 0,
|
|
|
yohoCoinClick: 0,
|
|
|
yohoCoinMsg: '',
|
|
|
yoho_coin_pay_rule: []
|
|
|
};
|
|
|
|
|
|
if (!orderCompute || !orderCompute.yoho_coin_pay_rule) {
|
|
|
return yohoCoinData;
|
|
|
}
|
|
|
|
|
|
_.assign(yohoCoinData, {
|
|
|
totalYohoCoinNum: orderCompute.total_yoho_coin_num ? parseInt(orderCompute.total_yoho_coin_num, 10) : 0,
|
|
|
yohoCoin: orderCompute.yoho_coin ? transPrice(orderCompute.yoho_coin) : 0,
|
|
|
useYohoCoin: orderCompute.use_yoho_coin ? transPrice(orderCompute.use_yoho_coin) : 0,
|
|
|
yoho_coin_pay_rule: orderCompute.yoho_coin_pay_rule
|
|
|
});
|
|
|
|
|
|
if (yohoCoinData.totalYohoCoinNum < 100) {
|
|
|
yohoCoinData.yohoCoinMsg = `共${yohoCoinData.totalYohoCoinNum}有货币,满${orderCompute.yoho_coin_pay_rule.num_limit}可用`;
|
|
|
} else if (yohoCoinData.useYohoCoin > 0 || yohoCoinData.yohoCoin > 0) {
|
|
|
yohoCoinData.yohoCoinMsg = '可抵¥' + (yohoCoinData.useYohoCoin > 0 ? yohoCoinData.useYohoCoin : yohoCoinData.yohoCoin);
|
|
|
yohoCoinData.yohoCoinClick = 1;
|
|
|
} else {
|
|
|
yohoCoinData.yohoCoinMsg = '不满足有货币使用条件';
|
|
|
}
|
|
|
|
|
|
return yohoCoinData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 调用购物车结算接口返回的数据处理
|
|
|
*
|
|
|
*
|
...
|
...
|
@@ -20,9 +71,7 @@ const shoppingAPI = require('../../serverAPI/order/shopping'); |
|
|
* @param bool $isAjax 是否是异步请求
|
|
|
* @return array 接口返回的数据
|
|
|
*/
|
|
|
exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumber, isAjax) => {
|
|
|
isAjax = isAjax || false;
|
|
|
|
|
|
exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumber, activityInfo) => {
|
|
|
let result = {};
|
|
|
let skuList = [];
|
|
|
let isLimitGoods = skn && sku && buyNumber; // 存在sku, skn 和buyNumber时为限购商品
|
...
|
...
|
@@ -53,8 +102,15 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb |
|
|
);
|
|
|
}
|
|
|
|
|
|
// 区分套餐量贩和普通商品
|
|
|
let cartPayAPI = shoppingAPI.cartPayAPI(uid, cartType, 0, skuList);
|
|
|
|
|
|
if (activityInfo) {
|
|
|
cartPayAPI = shoppingAPI.cartPayAPI(uid, cartType, 0, skuList, activityInfo);
|
|
|
}
|
|
|
|
|
|
return Promise.all([
|
|
|
shoppingAPI.cartPayAPI(uid, cartType, 0, skuList), // 0. 订单数据
|
|
|
cartPayAPI, // 0. 订单数据
|
|
|
orderComputeAPI,
|
|
|
shoppingAPI.getValidCouponCount(uid) // 2. 有效优惠券
|
|
|
]).then(res => {
|
...
|
...
|
@@ -89,6 +145,143 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
|
|
|
*
|
|
|
* @param int $uid 用户ID
|
|
|
* @param string $cartType 购物车类型,ordinary表示普通购物车
|
|
|
* @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
|
|
|
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
|
|
|
* @param string $couponCode 优惠券码
|
|
|
* @param mixed $yohoCoin 使用的有货币数量
|
|
|
* @param string $skuList 购买限购商品时需要传递的参数
|
|
|
* @return array 接口返回的数据
|
|
|
*/
|
|
|
exports.orderCompute = (uid, cartType, deliveryWay, paymentType, couponCode, yohoCoin, skuList) => {
|
|
|
return shoppingAPI.orderComputeAPI(uid, cartType, deliveryWay, paymentType, couponCode, yohoCoin, skuList).then(result => {
|
|
|
if (result && result.data) {
|
|
|
result.data.use_yoho_coin = transPrice(result.data.use_yoho_coin);
|
|
|
result.data.yohoCoinCompute = _yohoCoinCompute(result.data);
|
|
|
return result.data;
|
|
|
} else {
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
|
|
|
exports.ticketsOrderCompute = (uid, productSku, buyNumber, yohoCoin) => {
|
|
|
return shoppingAPI.checkTickets(uid, productSku, buyNumber, yohoCoin).then(result => {
|
|
|
if (result && result.data) {
|
|
|
result.data.shopping_cart_data.use_yoho_coin = transPrice(result.data.shopping_cart_data.use_yoho_coin);
|
|
|
result.data.yohoCoinCompute = _.yohoCoinCompute(result.data.shopping_cart_data);
|
|
|
|
|
|
return result.data;
|
|
|
} else {
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 购物车结算--提交结算信息
|
|
|
*
|
|
|
* @param int $uid 用户ID
|
|
|
* @param int $addressId 地址ID
|
|
|
* @param int $cartType 购物车类型ID
|
|
|
* @param int $deliveryTime 寄送时间ID
|
|
|
* @param int $deliveryWay 寄送方式ID
|
|
|
* @param array $invoices 发票参数数组
|
|
|
* @param int $paymentId 支付方式ID
|
|
|
* @param int $paymentType 支付类型ID
|
|
|
* @param string $remark 留言
|
|
|
* @param string $couponCode 优惠券码
|
|
|
* @param mixed $yohoCoin 使用的有货币数量或为空
|
|
|
* @param string $skuList 购买限购商品时需要传递的参数
|
|
|
* @param string $qhyUnio 友盟有关信息
|
|
|
* @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息
|
|
|
* @param int $times
|
|
|
* @param null $activityInfo 套餐数据
|
|
|
* @return array 接口返回的数据
|
|
|
*/
|
|
|
exports.orderSub = (uid, addressId, cartType, deliveryTime,
|
|
|
deliveryWay, invoices, paymentId, paymentType, remark,
|
|
|
couponCode, yohoCoin, skuList, qhyUnio = '',
|
|
|
userAgent, times, activityInfo = null) => {
|
|
|
|
|
|
if (!userAgent) {
|
|
|
userAgent = null;
|
|
|
}
|
|
|
|
|
|
if (!times) {
|
|
|
times = 1;
|
|
|
}
|
|
|
|
|
|
if (!activityInfo) {
|
|
|
activityInfo = null;
|
|
|
}
|
|
|
|
|
|
if (!addressId) {
|
|
|
return Promise.resolve({code: 401, message: '配送地址不能为空'});
|
|
|
}
|
|
|
|
|
|
if (!deliveryTime) {
|
|
|
return Promise.resolve({code: 402, message: '请选择配送时间'});
|
|
|
}
|
|
|
|
|
|
if (!deliveryWay) {
|
|
|
return Promise.resolve({code: 403, message: '请选择配送方式'});
|
|
|
}
|
|
|
|
|
|
return shoppingAPI.orderSub(uid, addressId, cartType, deliveryTime,
|
|
|
deliveryWay, invoices, paymentId, paymentType,
|
|
|
remark, couponCode, yohoCoin, skuList, qhyUnio,
|
|
|
userAgent, times, activityInfo).then(orderSubRes => {
|
|
|
let finalResult = {};
|
|
|
|
|
|
if (orderSubRes && orderSubRes.data && orderSubRes.data.is_hint === 'Y') {
|
|
|
finalResult.code = 409;
|
|
|
|
|
|
if (orderSubRes.data.hintInfo) {
|
|
|
let productName = _.get('orderSubRes', 'data.hintInfo.productName', '');
|
|
|
|
|
|
if (productName.length > 50) { // TODO 需要检查长度是否正确
|
|
|
orderSubRes.data.hintInfo.productName =
|
|
|
productName.substring(0, 47) + '...';
|
|
|
}
|
|
|
|
|
|
finalResult.message = [
|
|
|
encodeURI(productName + _.get(orderSubRes, 'data.hintInfo.suffix', '')),
|
|
|
encodeURI(_.get(orderSubRes, 'data.hintInfo.lastLine', ''))
|
|
|
];
|
|
|
}
|
|
|
|
|
|
finalResult.buttons = [
|
|
|
{
|
|
|
href: helpers.urlFormat('/cart/index/index'),
|
|
|
text: '重新选择商品',
|
|
|
class: ''
|
|
|
},
|
|
|
{
|
|
|
href: '',
|
|
|
text: '继续结算',
|
|
|
class: 'order-tip-btnred'
|
|
|
}
|
|
|
];
|
|
|
} else if (orderSubRes && orderSubRes.code) {
|
|
|
finalResult = orderSubRes;
|
|
|
} else {
|
|
|
finalResult = {
|
|
|
code: 400,
|
|
|
message: '出错啦'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
return finalResult;
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 处理优惠券列表数据
|
|
|
*
|
|
|
* @param int $uid 用户ID
|
...
|
...
|
|