shopping.js
3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict';
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 = (uid, cartType, isUseYohoCoin, skuList) => {
let param = {
method: 'app.Shopping.payment',
enable_red_envelopes: 0, // h5不返回红包
cart_type: cartType,
yoho_coin_mode: isUseYohoCoin,
uid: uid
};
// 购买限购商品时需要传递product_sku_list参数
if (!_.isEmpty(skuList)) {
param.product_sku_list = skuList;
}
return api.get('', param);
};
/**
* 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
* 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 = (uid, cartType, deliveWay, paymentType, couponCode, yohoCoin, skuList) => {
let param = {
method: 'app.Shopping.compute',
cart_type: cartType,
delive_way: deliveWay,
payment_type: paymentType
};
if (couponCode) {
param.coupon_code = couponCode;
}
if (yohoCoin) {
param.use_yoho_coin = yohoCoin;
}
if (!_.isEmpty(skuList)) {
param.product_sku_list = skuList;
}
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.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 = uid => {
let param = {
method: 'app.Shopping.listCoupon',
uid
};
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);
};