Authored by 李奇

修改

... ... @@ -16,11 +16,14 @@ const couponExp = {
*/
couponList(req, res, next) {
const activityId = +req.query.activity_id;
const uid = +req.query.uid || +req.session.yh_auth_uid || '';
req.ctx(expModel).couponList(activityId)
req.ctx(expModel).couponList(activityId, uid)
.then(result => {
// 初始券数据
req.session._COUPONS = result.data.activityCouponInfoBoList;
if (!req.session._EXP_COUPONS) {
// 初始券数据
req.session._EXP_COUPONS = result.data.activityCouponInfoBoList;
}
res.json(result);
}).catch(next);
},
... ... @@ -31,9 +34,16 @@ const couponExp = {
* @param res
*/
progress(req, res) {
const uid = +req.session.yh_auth_uid;
const uid = req.body.uid || +req.session.yh_auth_uid;
const shareId = aes.encryptUid(uid); // 分享标识
if (!uid) {
return res.json({
code: 401,
message: 'uid不能为空'
});
}
req.ctx(expModel).progress(uid).then(result => {
result.data.shareId = shareId;
res.json(result);
... ... @@ -60,10 +70,23 @@ const couponExp = {
receiveCoupon(req, res, next) {
let uid = +req.body.uid;
let isApp = req.body.isApp;
let users = req.session._EXP_COUPONS_GET_USERS || [];
// app登录后领券
if (isApp && uid) {
const coupons = req.session._COUPONS;
// 已领取
if (users.indexOf(uid) > -1) {
return res.json({
code: 301,
data: {
url: '//feature.yoho.cn/coupon-expansion/progress'
},
message: '用户已经领取过优惠券,重定向'
});
}
const coupons = req.session._EXP_COUPONS;
let promises = _.map(_.filter(coupons, cp => !cp.user_send), item => {
return req.ctx(expModel).getCoupon(uid, item.couponId);
... ... @@ -71,20 +94,20 @@ const couponExp = {
if (promises.length) {
Promise.all(promises).then(() => {
// const success = _.every(result, { code: 200 });
// if (!success) {
// // 领取失败、返回首页
// return res.status(301).redirect('//feature.yoho.cn/coupon-expansion');
// }
// 设置优惠券状态
_.each(coupons, item => {
item.user_send = true;
});
req.session._COUPONS = coupons;
// 进度页
res.status(301).redirect('//feature.yoho.cn/coupon-expansion/progress');
users.push(uid);
req.session._EXP_COUPONS = coupons;
req.session._EXP_COUPONS_GET_USERS = users;
return res.json({
code: 301,
data: {
url: '//feature.yoho.cn/coupon-expansion/progress'
},
message: '领取优惠券成功,重定向'
});
}).catch(next);
} else {
res.json({
... ... @@ -92,12 +115,28 @@ const couponExp = {
data: {
url: '//feature.yoho.cn/coupon-expansion/progress'
},
message: '重定向'
message: '用户已经领取过优惠券,重定向'
});
}
return;
}
// TODO H5
// 有货h5授权登录
let yhAuth = req.session.yh_auth_logged;
if (yhAuth) {
res.json({
code: 200,
message: '优惠券授权登录后即已成功领取'
});
} else {
res.json({
code: 401,
message: '请登录'
});
}
},
/**
... ... @@ -107,7 +146,7 @@ const couponExp = {
*/
yhLoginSuccess(req, res, next) {
const uid = req.query.yh_uid;
const coupons = req.session._COUPONS;
const coupons = req.session._EXP_COUPONS;
req.session.yh_auth_uid = uid;
req.session.yh_auth_logged = true;
... ... @@ -116,20 +155,12 @@ const couponExp = {
return req.ctx(expModel).getCoupon(uid, item.couponId);
});
Promise.all(promises).then(result => {
const success = _.every(result, { code: 200 });
// TODO
if (!success) {
// 领取失败、返回首页
return res.status(301).redirect('//feature.yoho.cn/coupon-expansion');
}
Promise.all(promises).then(() => {
// 设置优惠券状态
_.each(coupons, item => {
item.user_send = true;
});
req.session._COUPONS = coupons;
req.session._EXP_COUPONS = coupons;
// 进度页
res.status(301).redirect('//feature.yoho.cn/coupon-expansion/progress');
... ...
... ... @@ -8,11 +8,12 @@ class expModel extends global.yoho.BaseModel {
super(ctx);
}
couponList(id) {
couponList(activityId, uid) {
return this.get({
data: {
method: 'app.activity.getActivityUserDesc',
activity_id: id
activity_id: activityId,
uid
},
api: global.yoho.API,
param: {code: 200}
... ...
... ... @@ -9,7 +9,7 @@ const couponExp = require('./controllers/coupon-expansion');
router.get('/couponExp/couponList', couponExp.couponList);
router.post('/couponExp/receiveCoupon', couponExp.receiveCoupon);
router.get('/couponExp/progress', couponExp.progress);
router.post('/couponExp/progress', couponExp.progress);
router.get('/couponExp/yhLoginSuccess', couponExp.yhLoginSuccess);
router.post('/couponExp/friendHelp', couponExp.friendHelp);
... ...