BuyNowModel.js
3.9 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* @Author: Targaryen
* @Date: 2017-06-21 10:15:45
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-22 15:05:29
*/
const api = global.yoho.API;
class BuyNowModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取用户可用的优惠券张数
* @param {*} params
*/
countUsableCoupon(params) {
return api.post('', {
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
buy_number: params.buy_number
}, {cache: false});
}
/**
* 获取用户可用和不可用优惠券列表
* @param {*} params
*/
listCoupon(params) {
return api.post('', {
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
buy_number: params.buy_number
}, {cache: false});
}
/**
* 结算页面数据渲染
* @param {*} params
*/
payment(params) {
let finalParams = {
method: 'app.Buynow.payment',
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
buy_number: params.buy_number || 1,
yoho_coin_mode: params.yoho_coin_mode || 0, // 是否使用有货币
yoho_bill_term: 0, // H5 不支持分期
is_support_apple_pay: 'N', // H5 不支持 APPLE PAY
activity_id: params.activity_id || 0,
enable_red_envelopes: 0 // H5 不支持使用红包
};
return api.post('', finalParams, { cache: false });
}
/**
* 数据改变,重新计算结算数据
* @param {*} params
*/
compute(params) {
let finalParams = {
method: 'app.Buynow.compute',
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
buy_number: params.buy_number || 1,
payment_type: params.payment_type || 1,
delivery_way: params.delivery_way || 1,
use_red_envelopes: 0,
yoho_bill_term: 0,
activity_id: params.activity_id || 0
};
if (params.use_yoho_coin) {
finalParams.use_yoho_coin = params.use_yoho_coin;
}
if (params.coupon_code) {
finalParams.coupon_code = params.coupon_code;
}
if (params.promotion_code) {
finalParams.promotion_code = params.promotion_code;
}
if (params.coupon_code) {
finalParams.coupon_code = params.coupon_code;
}
return api.post('', finalParams, {cache: false});
}
/**
* 提交订单
* @param {*} params
*/
submit(params) {
let finalParams = {
method: 'app.Buynow.submit',
uid: params.uid,
cart_type: params.cart_type,
address_id: params.address_id,
delivery_time: params.delivery_time,
delivery_way: params.delivery_way,
use_yoho_coin: params.use_yoho_coin || 0,
enable_red_envelopes: 0,
payment_id: params.payment_id,
payment_type: params.payment_type || 1,
product_sku_list: JSON.stringify(params.product_sku_list),
is_print_price: params.is_print_price || 'N',
qhy_union: params.qhy_union
};
if (params.invoices_title) {
finalParams.invoices_title = params.invoices_title;
}
if (params.invoices_type_id) {
finalParams.invoices_type_id = params.invoices_type_id;
}
if (params.remark) {
finalParams.remark = params.remark;
}
if (params.activity_id) {
finalParams.activity_id = params.activity_id;
}
return api.post('', finalParams, {cache: false});
}
}
module.exports = BuyNowModel;