|
@@ -16,11 +16,14 @@ const couponExp = { |
|
@@ -16,11 +16,14 @@ const couponExp = { |
16
|
*/
|
16
|
*/
|
17
|
couponList(req, res, next) {
|
17
|
couponList(req, res, next) {
|
18
|
const activityId = +req.query.activity_id;
|
18
|
const activityId = +req.query.activity_id;
|
|
|
19
|
+ const uid = +req.query.uid || +req.session.yh_auth_uid || '';
|
19
|
|
20
|
|
20
|
- req.ctx(expModel).couponList(activityId)
|
21
|
+ req.ctx(expModel).couponList(activityId, uid)
|
21
|
.then(result => {
|
22
|
.then(result => {
|
22
|
- // 初始券数据
|
|
|
23
|
- req.session._COUPONS = result.data.activityCouponInfoBoList;
|
23
|
+ if (!req.session._EXP_COUPONS) {
|
|
|
24
|
+ // 初始券数据
|
|
|
25
|
+ req.session._EXP_COUPONS = result.data.activityCouponInfoBoList;
|
|
|
26
|
+ }
|
24
|
res.json(result);
|
27
|
res.json(result);
|
25
|
}).catch(next);
|
28
|
}).catch(next);
|
26
|
},
|
29
|
},
|
|
@@ -31,9 +34,16 @@ const couponExp = { |
|
@@ -31,9 +34,16 @@ const couponExp = { |
31
|
* @param res
|
34
|
* @param res
|
32
|
*/
|
35
|
*/
|
33
|
progress(req, res) {
|
36
|
progress(req, res) {
|
34
|
- const uid = +req.session.yh_auth_uid;
|
37
|
+ const uid = req.body.uid || +req.session.yh_auth_uid;
|
35
|
const shareId = aes.encryptUid(uid); // 分享标识
|
38
|
const shareId = aes.encryptUid(uid); // 分享标识
|
36
|
|
39
|
|
|
|
40
|
+ if (!uid) {
|
|
|
41
|
+ return res.json({
|
|
|
42
|
+ code: 401,
|
|
|
43
|
+ message: 'uid不能为空'
|
|
|
44
|
+ });
|
|
|
45
|
+ }
|
|
|
46
|
+
|
37
|
req.ctx(expModel).progress(uid).then(result => {
|
47
|
req.ctx(expModel).progress(uid).then(result => {
|
38
|
result.data.shareId = shareId;
|
48
|
result.data.shareId = shareId;
|
39
|
res.json(result);
|
49
|
res.json(result);
|
|
@@ -60,10 +70,23 @@ const couponExp = { |
|
@@ -60,10 +70,23 @@ const couponExp = { |
60
|
receiveCoupon(req, res, next) {
|
70
|
receiveCoupon(req, res, next) {
|
61
|
let uid = +req.body.uid;
|
71
|
let uid = +req.body.uid;
|
62
|
let isApp = req.body.isApp;
|
72
|
let isApp = req.body.isApp;
|
|
|
73
|
+ let users = req.session._EXP_COUPONS_GET_USERS || [];
|
63
|
|
74
|
|
64
|
// app登录后领券
|
75
|
// app登录后领券
|
65
|
if (isApp && uid) {
|
76
|
if (isApp && uid) {
|
66
|
- const coupons = req.session._COUPONS;
|
77
|
+
|
|
|
78
|
+ // 已领取
|
|
|
79
|
+ if (users.indexOf(uid) > -1) {
|
|
|
80
|
+ return res.json({
|
|
|
81
|
+ code: 301,
|
|
|
82
|
+ data: {
|
|
|
83
|
+ url: '//feature.yoho.cn/coupon-expansion/progress'
|
|
|
84
|
+ },
|
|
|
85
|
+ message: '用户已经领取过优惠券,重定向'
|
|
|
86
|
+ });
|
|
|
87
|
+ }
|
|
|
88
|
+
|
|
|
89
|
+ const coupons = req.session._EXP_COUPONS;
|
67
|
|
90
|
|
68
|
let promises = _.map(_.filter(coupons, cp => !cp.user_send), item => {
|
91
|
let promises = _.map(_.filter(coupons, cp => !cp.user_send), item => {
|
69
|
return req.ctx(expModel).getCoupon(uid, item.couponId);
|
92
|
return req.ctx(expModel).getCoupon(uid, item.couponId);
|
|
@@ -71,20 +94,20 @@ const couponExp = { |
|
@@ -71,20 +94,20 @@ const couponExp = { |
71
|
|
94
|
|
72
|
if (promises.length) {
|
95
|
if (promises.length) {
|
73
|
Promise.all(promises).then(() => {
|
96
|
Promise.all(promises).then(() => {
|
74
|
- // const success = _.every(result, { code: 200 });
|
|
|
75
|
- // if (!success) {
|
|
|
76
|
- // // 领取失败、返回首页
|
|
|
77
|
- // return res.status(301).redirect('//feature.yoho.cn/coupon-expansion');
|
|
|
78
|
- // }
|
|
|
79
|
-
|
|
|
80
|
- // 设置优惠券状态
|
|
|
81
|
_.each(coupons, item => {
|
97
|
_.each(coupons, item => {
|
82
|
item.user_send = true;
|
98
|
item.user_send = true;
|
83
|
});
|
99
|
});
|
84
|
- req.session._COUPONS = coupons;
|
|
|
85
|
-
|
|
|
86
|
- // 进度页
|
|
|
87
|
- res.status(301).redirect('//feature.yoho.cn/coupon-expansion/progress');
|
100
|
+ users.push(uid);
|
|
|
101
|
+ req.session._EXP_COUPONS = coupons;
|
|
|
102
|
+ req.session._EXP_COUPONS_GET_USERS = users;
|
|
|
103
|
+
|
|
|
104
|
+ return res.json({
|
|
|
105
|
+ code: 301,
|
|
|
106
|
+ data: {
|
|
|
107
|
+ url: '//feature.yoho.cn/coupon-expansion/progress'
|
|
|
108
|
+ },
|
|
|
109
|
+ message: '领取优惠券成功,重定向'
|
|
|
110
|
+ });
|
88
|
}).catch(next);
|
111
|
}).catch(next);
|
89
|
} else {
|
112
|
} else {
|
90
|
res.json({
|
113
|
res.json({
|
|
@@ -92,12 +115,28 @@ const couponExp = { |
|
@@ -92,12 +115,28 @@ const couponExp = { |
92
|
data: {
|
115
|
data: {
|
93
|
url: '//feature.yoho.cn/coupon-expansion/progress'
|
116
|
url: '//feature.yoho.cn/coupon-expansion/progress'
|
94
|
},
|
117
|
},
|
95
|
- message: '重定向'
|
118
|
+ message: '用户已经领取过优惠券,重定向'
|
96
|
});
|
119
|
});
|
97
|
}
|
120
|
}
|
|
|
121
|
+
|
|
|
122
|
+ return;
|
98
|
}
|
123
|
}
|
99
|
|
124
|
|
100
|
- // TODO H5
|
125
|
+ // 有货h5授权登录
|
|
|
126
|
+ let yhAuth = req.session.yh_auth_logged;
|
|
|
127
|
+
|
|
|
128
|
+ if (yhAuth) {
|
|
|
129
|
+ res.json({
|
|
|
130
|
+ code: 200,
|
|
|
131
|
+ message: '优惠券授权登录后即已成功领取'
|
|
|
132
|
+ });
|
|
|
133
|
+
|
|
|
134
|
+ } else {
|
|
|
135
|
+ res.json({
|
|
|
136
|
+ code: 401,
|
|
|
137
|
+ message: '请登录'
|
|
|
138
|
+ });
|
|
|
139
|
+ }
|
101
|
},
|
140
|
},
|
102
|
|
141
|
|
103
|
/**
|
142
|
/**
|
|
@@ -107,7 +146,7 @@ const couponExp = { |
|
@@ -107,7 +146,7 @@ const couponExp = { |
107
|
*/
|
146
|
*/
|
108
|
yhLoginSuccess(req, res, next) {
|
147
|
yhLoginSuccess(req, res, next) {
|
109
|
const uid = req.query.yh_uid;
|
148
|
const uid = req.query.yh_uid;
|
110
|
- const coupons = req.session._COUPONS;
|
149
|
+ const coupons = req.session._EXP_COUPONS;
|
111
|
|
150
|
|
112
|
req.session.yh_auth_uid = uid;
|
151
|
req.session.yh_auth_uid = uid;
|
113
|
req.session.yh_auth_logged = true;
|
152
|
req.session.yh_auth_logged = true;
|
|
@@ -116,20 +155,12 @@ const couponExp = { |
|
@@ -116,20 +155,12 @@ const couponExp = { |
116
|
return req.ctx(expModel).getCoupon(uid, item.couponId);
|
155
|
return req.ctx(expModel).getCoupon(uid, item.couponId);
|
117
|
});
|
156
|
});
|
118
|
|
157
|
|
119
|
- Promise.all(promises).then(result => {
|
|
|
120
|
- const success = _.every(result, { code: 200 });
|
|
|
121
|
-
|
|
|
122
|
- // TODO
|
|
|
123
|
- if (!success) {
|
|
|
124
|
- // 领取失败、返回首页
|
|
|
125
|
- return res.status(301).redirect('//feature.yoho.cn/coupon-expansion');
|
|
|
126
|
- }
|
|
|
127
|
-
|
158
|
+ Promise.all(promises).then(() => {
|
128
|
// 设置优惠券状态
|
159
|
// 设置优惠券状态
|
129
|
_.each(coupons, item => {
|
160
|
_.each(coupons, item => {
|
130
|
item.user_send = true;
|
161
|
item.user_send = true;
|
131
|
});
|
162
|
});
|
132
|
- req.session._COUPONS = coupons;
|
163
|
+ req.session._EXP_COUPONS = coupons;
|
133
|
|
164
|
|
134
|
// 进度页
|
165
|
// 进度页
|
135
|
res.status(301).redirect('//feature.yoho.cn/coupon-expansion/progress');
|
166
|
res.status(301).redirect('//feature.yoho.cn/coupon-expansion/progress');
|