...
|
...
|
@@ -2,282 +2,253 @@ |
|
|
const _ = require('lodash');
|
|
|
const api = global.yoho.API;
|
|
|
|
|
|
/**
|
|
|
* 购物车结算
|
|
|
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
|
|
|
* @param int $uid 用户ID
|
|
|
* @param string $cartType 购物车类型,ordinary表示普通购物车
|
|
|
* @param int $isUseYohoCoin 是否使用有货币,0不使用, 1使用
|
|
|
* @param string $skuList 购买限购商品时需要传递的参数
|
|
|
* @return see doc
|
|
|
*/
|
|
|
exports.cartPayAPI = (params) => {
|
|
|
if (!params.activityInfo) {
|
|
|
params.activityInfo = null;
|
|
|
}
|
|
|
class shoppingModel extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 购物车结算
|
|
|
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
|
|
|
*/
|
|
|
cartPayAPI(params) {
|
|
|
if (!params.activityInfo) {
|
|
|
params.activityInfo = null;
|
|
|
}
|
|
|
|
|
|
let param = {
|
|
|
method: params.activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment',
|
|
|
enable_red_envelopes: 0, // h5不返回红包
|
|
|
cart_type: params.cart_type,
|
|
|
yoho_coin_mode: params.yoho_coin_mode,
|
|
|
uid: params.uid
|
|
|
};
|
|
|
|
|
|
// 购买限购商品时需要传递product_sku_list参数
|
|
|
if (!_.isEmpty(params.product_sku_list)) {
|
|
|
param.product_sku_list = JSON.stringify(params.product_sku_list);
|
|
|
}
|
|
|
let param = {
|
|
|
method: params.activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment',
|
|
|
enable_red_envelopes: 0, // h5不返回红包
|
|
|
cart_type: params.cart_type,
|
|
|
yoho_coin_mode: params.yoho_coin_mode,
|
|
|
uid: params.uid
|
|
|
};
|
|
|
|
|
|
// 购买限购商品时需要传递product_sku_list参数
|
|
|
if (!_.isEmpty(params.product_sku_list)) {
|
|
|
param.product_sku_list = JSON.stringify(params.product_sku_list);
|
|
|
}
|
|
|
|
|
|
// 购买套装和量贩商品时数据处理
|
|
|
if (params.activityInfo) {
|
|
|
param.activity_id = params.activityInfo.activity_id;
|
|
|
param.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list);
|
|
|
}
|
|
|
// 购买套装和量贩商品时数据处理
|
|
|
if (params.activityInfo) {
|
|
|
param.activity_id = params.activityInfo.activity_id;
|
|
|
param.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list);
|
|
|
}
|
|
|
|
|
|
return api.get('', param, {cache: false});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
|
|
|
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
|
|
|
* @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 see doc
|
|
|
*
|
|
|
*
|
|
|
* Note:
|
|
|
* 1. 大多数情况下,调用完此接口,请显示的调用 utils/payment-process.js@yohoCoinCompute;
|
|
|
* 2. 除非同时调用app.Shopping.payment 与该接口,用改接口的data值替换app.Shopping.payment相关值,
|
|
|
* 显示调用utils/payment-process.js@tranformPayment(他会帮你调yohoCoinCompute)处理payment的data;
|
|
|
*/
|
|
|
exports.orderComputeAPI = (params) => {
|
|
|
let finalParams = {
|
|
|
method: params.activityInfo ? 'app.Shopping.easyCompute' : 'app.Shopping.compute',
|
|
|
cart_type: params.cart_type,
|
|
|
delivery_way: params.delivery_way,
|
|
|
payment_type: params.payment_type,
|
|
|
uid: params.uid
|
|
|
};
|
|
|
|
|
|
if (params.coupon_code) {
|
|
|
finalParams.coupon_code = params.coupon_code;
|
|
|
return api.get('', param, {cache: false});
|
|
|
}
|
|
|
|
|
|
if (params.use_yoho_coin) {
|
|
|
finalParams.use_yoho_coin = params.use_yoho_coin;
|
|
|
}
|
|
|
/**
|
|
|
* 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
|
|
|
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
|
|
|
*/
|
|
|
orderComputeAPI(params) {
|
|
|
let finalParams = {
|
|
|
method: params.activityInfo ? 'app.Shopping.easyCompute' : 'app.Shopping.compute',
|
|
|
cart_type: params.cart_type,
|
|
|
delivery_way: params.delivery_way,
|
|
|
payment_type: params.payment_type,
|
|
|
uid: params.uid
|
|
|
};
|
|
|
|
|
|
if (!_.isEmpty(params.product_sku_list) && !params.activityInfo) {
|
|
|
finalParams.product_sku_list = JSON.stringify(params.product_sku_list);
|
|
|
}
|
|
|
if (params.coupon_code) {
|
|
|
finalParams.coupon_code = params.coupon_code;
|
|
|
}
|
|
|
|
|
|
// 购买套餐商品需要的数据
|
|
|
if (params.activityInfo) {
|
|
|
finalParams.activity_id = params.activityInfo.activity_id;
|
|
|
finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list);
|
|
|
}
|
|
|
if (params.use_yoho_coin) {
|
|
|
finalParams.use_yoho_coin = params.use_yoho_coin;
|
|
|
}
|
|
|
|
|
|
return api.get('', finalParams, {code: 200});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 校验电子票
|
|
|
* @param int $uid
|
|
|
* @param int $productSku
|
|
|
* @param int $buyNumber
|
|
|
* @param int $useYohoCoin
|
|
|
* @param bool|int $yohoCoinMode 1:使用有货币;0:不使用有货币
|
|
|
* @return array
|
|
|
* @author sefon 2016-7-2 18:12:30
|
|
|
*/
|
|
|
exports.checkTickets = (uid, productSku, buyNumber, useYohoCoin, yohoCoinMode) => {
|
|
|
if (!useYohoCoin) {
|
|
|
useYohoCoin = 0;
|
|
|
}
|
|
|
if (!_.isEmpty(params.product_sku_list) && !params.activityInfo) {
|
|
|
finalParams.product_sku_list = JSON.stringify(params.product_sku_list);
|
|
|
}
|
|
|
|
|
|
if (!yohoCoinMode) {
|
|
|
yohoCoinMode = true;
|
|
|
}
|
|
|
// 购买套餐商品需要的数据
|
|
|
if (params.activityInfo) {
|
|
|
finalParams.activity_id = params.activityInfo.activity_id;
|
|
|
finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list);
|
|
|
}
|
|
|
|
|
|
let params = {
|
|
|
method: 'app.shopping.ticket',
|
|
|
uid: uid,
|
|
|
product_sku: productSku,
|
|
|
buy_number: buyNumber,
|
|
|
use_yoho_coin: useYohoCoin
|
|
|
};
|
|
|
|
|
|
if (!yohoCoinMode) {
|
|
|
_.assign(params, {
|
|
|
yoho_coin_mode: 0
|
|
|
});
|
|
|
}
|
|
|
return api.get('', finalParams, {code: 200});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 校验电子票
|
|
|
* @param int $uid
|
|
|
* @param int $productSku
|
|
|
* @param int $buyNumber
|
|
|
* @param int $useYohoCoin
|
|
|
* @param bool|int $yohoCoinMode 1:使用有货币;0:不使用有货币
|
|
|
* @return array
|
|
|
* @author sefon 2016-7-2 18:12:30
|
|
|
*/
|
|
|
checkTickets(uid, productSku, buyNumber, useYohoCoin, yohoCoinMode) {
|
|
|
if (!useYohoCoin) {
|
|
|
useYohoCoin = 0;
|
|
|
}
|
|
|
|
|
|
return api.get('', params, {code: 200});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 购物车结算--提交结算信息
|
|
|
*
|
|
|
* @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|null $userAgent 联盟过来用户下单时需要的User-Agent信息
|
|
|
* @param $times
|
|
|
* @param null $activityInfo 套餐信息
|
|
|
* @param @param otherParams 其他参数
|
|
|
* @return array 接口返回的数据
|
|
|
*/
|
|
|
exports.orderSub = (params) => {
|
|
|
let finalParams = {
|
|
|
method: params.activityInfo ? 'app.Shopping.easySubmit' : 'app.Shopping.submit',
|
|
|
address_id: params.address_id,
|
|
|
cart_type: params.cart_type,
|
|
|
delivery_time: params.delivery_time,
|
|
|
delivery_way: params.delivery_way,
|
|
|
payment_id: params.payment_id,
|
|
|
payment_type: params.payment_type,
|
|
|
remark: params.remark,
|
|
|
uid: params.uid,
|
|
|
udid: params.udid,
|
|
|
is_print_price: params.is_print_price
|
|
|
};
|
|
|
|
|
|
/* tar add 161130 结算优化 */
|
|
|
if (params.times === 2 || params.times === '2') {
|
|
|
finalParams.is_continue_buy = 'Y';
|
|
|
} else {
|
|
|
finalParams.is_continue_buy = 'N';
|
|
|
}
|
|
|
if (!yohoCoinMode) {
|
|
|
yohoCoinMode = true;
|
|
|
}
|
|
|
|
|
|
// 发票内容写死明细
|
|
|
if (params.invoices.invoices_type_id) {
|
|
|
finalParams.invoice_content = 12;
|
|
|
}
|
|
|
let params = {
|
|
|
method: 'app.shopping.ticket',
|
|
|
uid: uid,
|
|
|
product_sku: productSku,
|
|
|
buy_number: buyNumber,
|
|
|
use_yoho_coin: useYohoCoin
|
|
|
};
|
|
|
|
|
|
if (!yohoCoinMode) {
|
|
|
_.assign(params, {
|
|
|
yoho_coin_mode: 0
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 发票类型 纸质 1 ,电子 2
|
|
|
if (params.invoices.invoices_type) {
|
|
|
finalParams.invoices_type = params.invoices.invoices_type;
|
|
|
}
|
|
|
return api.get('', params, {code: 200});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 购物车结算--提交结算信息
|
|
|
*/
|
|
|
orderSub(params) {
|
|
|
let finalParams = {
|
|
|
method: params.activityInfo ? 'app.Shopping.easySubmit' : 'app.Shopping.submit',
|
|
|
address_id: params.address_id,
|
|
|
cart_type: params.cart_type,
|
|
|
delivery_time: params.delivery_time,
|
|
|
delivery_way: params.delivery_way,
|
|
|
payment_id: params.payment_id,
|
|
|
payment_type: params.payment_type,
|
|
|
remark: params.remark,
|
|
|
uid: params.uid,
|
|
|
udid: params.udid,
|
|
|
is_print_price: params.is_print_price
|
|
|
};
|
|
|
|
|
|
/* tar add 161130 结算优化 */
|
|
|
if (params.times === 2 || params.times === '2') {
|
|
|
finalParams.is_continue_buy = 'Y';
|
|
|
} else {
|
|
|
finalParams.is_continue_buy = 'N';
|
|
|
}
|
|
|
|
|
|
// 发票类型:个人 1, 企业 2
|
|
|
if (params.invoices.invoice_payable_type) {
|
|
|
finalParams.invoice_payable_type = params.invoices.invoice_payable_type;
|
|
|
}
|
|
|
// 发票内容写死明细
|
|
|
if (params.invoices.invoices_type_id) {
|
|
|
finalParams.invoice_content = 12;
|
|
|
}
|
|
|
|
|
|
// 收票人手机号码
|
|
|
if (params.invoices.receiverMobile) {
|
|
|
finalParams.receiverMobile = params.invoices.receiverMobile;
|
|
|
}
|
|
|
// 发票类型 纸质 1 ,电子 2
|
|
|
if (params.invoices.invoices_type) {
|
|
|
finalParams.invoices_type = params.invoices.invoices_type;
|
|
|
}
|
|
|
|
|
|
// 发票抬头
|
|
|
if (params.invoices.invoices_title) {
|
|
|
finalParams.invoices_title = params.invoices.invoices_title;
|
|
|
}
|
|
|
// 发票类型:个人 1, 企业 2
|
|
|
if (params.invoices.invoice_payable_type) {
|
|
|
finalParams.invoice_payable_type = params.invoices.invoice_payable_type;
|
|
|
}
|
|
|
|
|
|
// 购买方纳税人识别号,需要开具电子发票且发票抬头为单位信息时为必填项
|
|
|
if (params.invoices.buyerTaxNumber) {
|
|
|
finalParams.buyerTaxNumber = params.invoices.buyerTaxNumber;
|
|
|
}
|
|
|
// 收票人手机号码
|
|
|
if (params.invoices.receiverMobile) {
|
|
|
finalParams.receiverMobile = params.invoices.receiverMobile;
|
|
|
}
|
|
|
|
|
|
if (params.coupon_code) {
|
|
|
finalParams.coupon_code = params.coupon_code;
|
|
|
}
|
|
|
// 发票抬头
|
|
|
if (params.invoices.invoices_title) {
|
|
|
finalParams.invoices_title = params.invoices.invoices_title;
|
|
|
}
|
|
|
|
|
|
if (params.use_yoho_coin) {
|
|
|
finalParams.use_yoho_coin = params.use_yoho_coin;
|
|
|
}
|
|
|
// 购买方纳税人识别号,需要开具电子发票且发票抬头为单位信息时为必填项
|
|
|
if (params.invoices.buyerTaxNumber) {
|
|
|
finalParams.buyerTaxNumber = params.invoices.buyerTaxNumber;
|
|
|
}
|
|
|
|
|
|
if (params.coupon_code) {
|
|
|
finalParams.coupon_code = params.coupon_code;
|
|
|
}
|
|
|
|
|
|
if (params.use_yoho_coin) {
|
|
|
finalParams.use_yoho_coin = params.use_yoho_coin;
|
|
|
}
|
|
|
|
|
|
// 购买限购商品时需要传递product_sku_list参数
|
|
|
if (params.product_sku_list && !params.activityInfo) {
|
|
|
finalParams.product_sku_list = JSON.stringify(params.product_sku_list);
|
|
|
}
|
|
|
|
|
|
// 购买限购商品时需要传递product_sku_list参数
|
|
|
if (params.product_sku_list && !params.activityInfo) {
|
|
|
finalParams.product_sku_list = JSON.stringify(params.product_sku_list);
|
|
|
// 购买套餐商品需要的数据
|
|
|
if (params.activityInfo) {
|
|
|
finalParams.activity_id = params.activityInfo.activity_id;
|
|
|
finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list); // TODO 检查 JSON 是否正常
|
|
|
}
|
|
|
|
|
|
// 友盟有关信息的传递
|
|
|
if (params.qhy_union) {
|
|
|
finalParams.qhy_union = params.qhy_union;
|
|
|
}
|
|
|
|
|
|
// 是否是微信商城
|
|
|
if (params.isWechat) {
|
|
|
finalParams.client_type = 'wechat';
|
|
|
}
|
|
|
|
|
|
return api.post('', finalParams, {
|
|
|
headers: {
|
|
|
'X-Forwarded-For': params.ip || '',
|
|
|
'User-Agent': params.userAgent
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 购买套餐商品需要的数据
|
|
|
if (params.activityInfo) {
|
|
|
finalParams.activity_id = params.activityInfo.activity_id;
|
|
|
finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list); // TODO 检查 JSON 是否正常
|
|
|
|
|
|
/**
|
|
|
* 获取用户可用的优惠券张数
|
|
|
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
|
|
|
* @param uid int 用户uid
|
|
|
* @return see doc
|
|
|
*/
|
|
|
getValidCouponCount(uid) {
|
|
|
let param = {
|
|
|
method: 'app.Shopping.countUsableCoupon',
|
|
|
uid
|
|
|
};
|
|
|
|
|
|
return api.get('', param);
|
|
|
}
|
|
|
|
|
|
// 友盟有关信息的传递
|
|
|
if (params.qhy_union) {
|
|
|
finalParams.qhy_union = params.qhy_union;
|
|
|
|
|
|
/**
|
|
|
* 获取用户优惠券列表,可用和不可用
|
|
|
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
|
|
|
* @param uid int 用户uid
|
|
|
* @return see doc
|
|
|
*/
|
|
|
listCoupon(params) {
|
|
|
let param = {
|
|
|
method: 'app.Shopping.listCoupon',
|
|
|
uid: params.uid,
|
|
|
delivery_way: params.delivery_way,
|
|
|
is_group_frees: params.is_group_frees
|
|
|
};
|
|
|
|
|
|
return api.get('', param);
|
|
|
}
|
|
|
|
|
|
// 是否是微信商城
|
|
|
if (params.isWechat) {
|
|
|
finalParams.client_type = 'wechat';
|
|
|
/**
|
|
|
* 购物车结算--使用优惠券
|
|
|
* @param uid int 用户uid
|
|
|
* @param couponCode string 优惠券代码
|
|
|
* @return
|
|
|
*/
|
|
|
useCoupon(uid, couponCode) {
|
|
|
let param = {
|
|
|
method: 'app.Shopping.useCoupon',
|
|
|
coupon_code: couponCode,
|
|
|
uid
|
|
|
};
|
|
|
|
|
|
return api.get('', param);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return api.post('', finalParams, {
|
|
|
headers: {
|
|
|
'X-Forwarded-For': params.ip || '',
|
|
|
'User-Agent': params.userAgent
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取用户可用的优惠券张数
|
|
|
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
|
|
|
* @param uid int 用户uid
|
|
|
* @return see doc
|
|
|
*/
|
|
|
exports.getValidCouponCount = uid => {
|
|
|
let param = {
|
|
|
method: 'app.Shopping.countUsableCoupon',
|
|
|
uid
|
|
|
};
|
|
|
|
|
|
return api.get('', param);
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取用户优惠券列表,可用和不可用
|
|
|
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
|
|
|
* @param uid int 用户uid
|
|
|
* @return see doc
|
|
|
*/
|
|
|
exports.listCoupon = params => {
|
|
|
let param = {
|
|
|
method: 'app.Shopping.listCoupon',
|
|
|
uid: params.uid,
|
|
|
delivery_way: params.delivery_way,
|
|
|
is_group_frees: params.is_group_frees
|
|
|
};
|
|
|
|
|
|
return api.get('', param);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 购物车结算--使用优惠券
|
|
|
* @param uid int 用户uid
|
|
|
* @param couponCode string 优惠券代码
|
|
|
* @return
|
|
|
*/
|
|
|
exports.useCoupon = (uid, couponCode) => {
|
|
|
let param = {
|
|
|
method: 'app.Shopping.useCoupon',
|
|
|
coupon_code: couponCode,
|
|
|
uid
|
|
|
};
|
|
|
|
|
|
return api.get('', param);
|
|
|
}; |
|
|
module.exports = shoppingModel; |
...
|
...
|
|