brand-shop.js
2.22 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
'use strict';
var api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
/**
* 查询品牌店铺优惠券结果处理
* @param {object} sizeInfo [接口原始数据]
* @return {object} [description]
*/
const processBrandCouponData = (data) => {
var dest = {},
list = data.data || {},
distCoupons = [];
list = camelCase(list);
dest.code = data.code;
_.forEach(list.coupons, function(value) {
if (!value.status) {
return;
}
let coupon = value;
coupon.money = parseInt(value.money);
if (coupon.status === 1) {
coupon.cooponStateMessage = '可以领取';
} else if (coupon.status === 2) {
coupon.cooponStateMessage = '已抢光';
} else if (coupon.status === 3) {
coupon.cooponStateMessage = '已领取';
}
distCoupons.push(coupon);
distCoupons.push(coupon);
});
if (distCoupons.length > 1) {
dest.mutilCoupon = true;
}
dest.coupons = distCoupons;
dest.message = list.message;
return dest;
};
/**
* 领取品牌店铺优惠券
* @param {object} sizeInfo [接口原始数据]
* @return {object} [description]
*/
const getBrandCouponStatus = (data) => {
var dest = {};
dest.code = data.code;
dest.message = data.message;
dest.logIn = true;
return dest;
};
/**
* 获取品牌信息及其优惠券
*/
exports.getBrandIntro = (data) => {
var defaultParam = {
method: 'app.brand.getBrandIntro'
},
infoData = Object.assign(defaultParam, data); // 处理完成后,发给后端
return api.get('', infoData).then(result => {
return processBrandCouponData(result);
}); // 所有数据返回一个 Promise,方便 Promise.all 调用
};
/**
* 用户领券
*/
exports.getCoupon = (data) => {
var defaultParam = {
method: 'app.promotion.getCoupon'
},
infoData = Object.assign(defaultParam, data); // 处理完成后,发给后端
return api.get('', infoData).then(result => {
return getBrandCouponStatus(result);
}); // 所有数据返回一个 Promise,方便 Promise.all 调用
};