coupon.js
3.31 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
var API = require('../../../library/api').API;
var api = new API();
const library = '../../../library';
const sign = require(`${library}/sign`);
/**
* 分享页面基础参数
* @param {object} sizeInfo [接口原始数据]
* @return {object} [description]
*/
const getPageInfo = (pageInfo) => {
var dest = {};
dest.shareTitle = pageInfo.data.shareTitle;
dest.shareDesc = pageInfo.data.shareContent;
dest.shareImg = pageInfo.data.shareImgUrl;
dest.shareLink = pageInfo.data.shareUrl;
dest.code = pageInfo.code;
dest.activityID = pageInfo.id;
dest.title = pageInfo.data.h5Title;
dest.activityDesc = pageInfo.data.activityDesc;
dest.couponPic = pageInfo.data.couponPic;
dest.oldUserCouponPic = pageInfo.data.oldUserCouponPic;
dest.mobile = pageInfo.data.mobile;
//强制活动开始,活动上线产品要求这样设置
pageInfo.data.flag = 1;
if (pageInfo.data.flag === 1) {
dest.bgImg = pageInfo.data.activityNormalPic;
} else {
dest.bgImg = pageInfo.data.activityEndPic;
dest.ended = true;
}
dest.message = pageInfo.data.returnMsg;
// 清空变量,释放内存
pageInfo = {};
return dest;
};
const getUserStatus = (param) => {
var dest = {};
dest.code = param.code;
dest.title = param.data.h5Title;
dest.returnCode = param.data.returnCode;
dest.mobile = param.data.mobile;
if (param.data.returnCode === 0) {
dest.geted = true;
} else if (param.data.returnCode === 1) {
dest.wrongNumb = true;
} else if (param.data.returnCode === 2) {
dest.newUser = true;
} else if (param.data.returnCode === 8) {
dest.oldUserAskCouponOnceMore = true;
} else if (param.data.returnCode === 5) {
dest.vertifyWrong = true;
} else {
dest.ended = true;
}
if (param.data.newUser === 1) {
dest.newUser = true;
}
dest.message = param.data.returnMsg;
// 清空变量,释放内存
param = {};
return dest;
};
/**
* 获取分享页面数据
*/
exports.getPageInfo = (data) => {
var defaultParam = {
method: 'app.activity.getInfoOfOrderShare'
},
// 处理完成后,发给后端
infoData = Object.assign(defaultParam, data);
return api.get('', sign.apiSign(infoData)).then(result => {
return getPageInfo(result);
}); // 所有数据返回一个 Promise,方便 Promise.all 调用
};
/**
* 输入手机号领券,新用户返回验证码
*/
exports.getCoupon = (data) => {
var defaultParam = {
method: 'wap.order.drawOrderShareCoupon'
},
// 处理完成后,发给后端
phoneData = Object.assign(defaultParam, data);
return api.get('', sign.apiSign(phoneData)).then(result => {
return getUserStatus(result);
}); // 所有数据返回一个 Promise,方便 Promise.all 调用
};
/**
* 验证注册码进行注册并发券
*/
exports.registerAndSendCoupon = (data) => {
var defaultParam = {
method: 'wap.order.registerAndSendCoupon'
},
// 处理完成后,发给后端
verifyData = Object.assign(defaultParam, data);
return api.get('', sign.apiSign(verifyData)).then(result => {
return getUserStatus(result);
}); // 所有数据返回一个 Promise,方便 Promise.all 调用
};