coupon.js
3.92 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
/**
* 分享页面基础参数
* @param {object} sizeInfo [接口原始数据]
* @return {object} [description]
*/
const getPageInfo = (pageInfo) => {
var dest = {};
if (pageInfo && pageInfo.data) {
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.data.id;
dest.title = pageInfo.data.h5Title;
dest.activityDesc = pageInfo.data.activityDesc;
dest.formatActivityDesc = pageInfo.data.formatActivityDesc;
dest.couponPic = pageInfo.data.couponPic;
dest.oldUserCouponPic = pageInfo.data.oldUserCouponPic;
dest.mobile = pageInfo.data.mobile;
dest.wechatShare = true;
dest.secondScreenPic = pageInfo.data.secondScreenPic;
dest.activityEndPic = pageInfo.data.activityEndPic;
dest.buttonLink = pageInfo.data.buttonLink;
if (pageInfo.data.flag === 3 || pageInfo.data.flag === 4 || pageInfo.data.flag === 5) {
// flag为3 表示活动结束 , 4 表示未开始
dest.bgImg = pageInfo.data.activityEndPic;
dest.ended = true;
} else {
dest.bgImg = pageInfo.data.activityNormalPic;
}
dest.message = pageInfo.data.returnMsg;
}
return dest;
};
const getUserStatus = (param) => {
var dest = {};
dest.code = param.code;
dest.coupon = param && param.data && param.data.coupon;
dest.returnCode = param && param.data && param.data.returnCode;
dest.mobile = param && param.data && param.data.mobile;
if (param && param.data) {
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;
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取分享页面数据
*/
getPageInfo(data) {
let defaultParam = {
method: 'app.activity.getInfoOfOrderShare'
};
let infoData = Object.assign(defaultParam, data); // 处理完成后,发给后端
return this.get({
data: infoData
}).then(result => {
return getPageInfo(result);
}); // 所有数据返回一个 Promise,方便 Promise.all 调用
}
/**
* 输入手机号领券,新用户返回验证码
*/
getCoupon(data) {
let defaultParam = {
method: 'wap.order.drawOrderShareCoupon'
};
// 处理完成后,发给后端
let phoneData = Object.assign(defaultParam, data);
return this.get({
data: phoneData
}).then(result => {
return getUserStatus(result);
}); // 所有数据返回一个 Promise,方便 Promise.all 调用
}
/**
* 验证注册码进行注册并发券
*/
registerAndSendCoupon(data) {
let defaultParam = {
method: 'wap.order.registerAndSendCoupon'
};
// 处理完成后,发给后端
let verifyData = Object.assign(defaultParam, data);
return this.get({
data: verifyData
}).then(result => {
return getUserStatus(result);
}); // 所有数据返回一个 Promise,方便 Promise.all 调用
}
};