coupon.js
2.52 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
'use strict';
const _ = require('lodash');
const crypto = global.yoho.crypto;
const couponStatus = {
1: '立即领取',
2: '已抢光',
3: '已领取'
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* [查询商品详情页优惠券]
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/促销/product_detail_page_coupon.md
*/
queryProdPageCoupons(uid, skn, brandId) {
const param = {
method: 'app.coupons.queryProdPageCoupons',
uid,
skn,
brandId
};
return this.get({
data: param
});
}
/**
* [用户领券]
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/促销/promotion.md
*/
getCoupon(uid, couponId) {
const param = {
method: 'app.promotion.getCoupon',
uid,
couponId
};
return this.post({
data: param
});
}
/**
* [获取店铺优惠券列表]
* @param {[type]} params [参数]
* @return {[type]} []
*/
shopCouponsList(params) {
return this.get({
data: Object.assign({
method: 'shop.coupons.list'
}, params),
param: {
cache: params.uid ? false : 180
}
}).then(result => {
let shopCoupons = [];
if (result && result.data) {
_.forEach(result.data, value => {
shopCoupons.push({
validity: value.couponValidity,
id: crypto.encryption('', value.coupon_id + ''),
name: value.coupon_name,
pic: value.coupon_pic,
money: parseInt(value.money, 10),
status: couponStatus[value.status] || '立即领取'
});
});
}
return {
couponsOne: shopCoupons.length <= 1,
coupons: shopCoupons
};
});
}
/**
* 用戶領券
* @param uid
* @param couponId
* @returns {*|Promise.<TResult>}
*/
receiveCoupon(uid, couponId) {
return this.get({
data: {
method: 'app.promotion.getCoupon',
couponId: couponId,
uid: uid
}
}).then(result => {
return result;
});
}
};