coupon.js
2.08 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
'use strict';
const _ = require('lodash');
const crypto = global.yoho.crypto;
const api = global.yoho.API;
const couponStatus = {
1: '立即领取',
2: '已抢光',
3: '已领取'
};
/**
* [查询商品详情页优惠券]
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/促销/product_detail_page_coupon.md
*/
exports.queryProdPageCoupons = (uid, skn, brandId) => {
const param = {
method: 'app.coupons.queryProdPageCoupons',
uid,
skn,
brandId
};
return api.get('', param);
};
/**
* [用户领券]
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/促销/promotion.md
*/
exports.getCoupon = (uid, couponId) => {
const param = {
method: 'app.promotion.getCoupon',
uid,
couponId
};
return api.post('', param);
};
/**
* [获取店铺优惠券列表]
* @param {[type]} params [参数]
* @return {[type]} []
*/
exports.shopCouponsList = (params) => {
return api.get('', Object.assign({
method: 'shop.coupons.list'
}, params), {
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>}
*/
exports.receiveCoupon = (uid, couponId) => {
return api.get('', {
method: 'app.promotion.getCoupon',
couponId: couponId,
uid: uid
}).then(result => {
return result;
});
};