|
|
const redbagModel = require('../models/red-envelope');
|
|
|
const headerModel = require('../../../doraemon/models/header'); // 头部model
|
|
|
const valid = require('../../../utils/validator');
|
|
|
const logger = global.yoho.logger;
|
|
|
|
|
|
const redbagPage = async(req, res, next) => {
|
|
|
try {
|
|
|
let isApp = req.yoho.isApp;
|
|
|
let obj = {uid: req.user.uid || false, shareCode: req.query.shareCode || 'c80f714bf980bdc8'}; // TODO 删除测试数据
|
|
|
let obj = {uid: req.user.uid || false, shareCode: req.query.shareCode || ''};
|
|
|
|
|
|
console.log(obj);
|
|
|
let isWechat = await req.ctx(redbagModel).isWechatService(obj);
|
|
|
|
|
|
console.log(isWechat);
|
|
|
if (isWechat) {
|
|
|
let userInfo = await req.ctx(redbagModel).renderByCs(obj);
|
|
|
|
|
|
if (userInfo.data && userInfo.data.rewardType === 1) {
|
|
|
userInfo.data.rewardType = true;
|
|
|
} else if (userInfo.data && userInfo.data.rewardType === 2) {
|
|
|
userInfo.data.rewardType = false;
|
|
|
let isGetRedBag = false;
|
|
|
|
|
|
if (userInfo.code === 200) {
|
|
|
isGetRedBag = true;
|
|
|
if (userInfo.data && userInfo.data.rewardType === 1) {
|
|
|
userInfo.data.rewardType = true;
|
|
|
} else if (userInfo.data && userInfo.data.rewardType === 2) {
|
|
|
userInfo.data.rewardType = false;
|
|
|
}
|
|
|
}
|
|
|
console.log(userInfo);
|
|
|
return res.render('red-envelope/redbag-cs', {
|
|
|
pageHeader: headerModel.setNav({
|
|
|
navTitle: '红包-客服'
|
|
|
}),
|
|
|
isApp,
|
|
|
isGetRedBag,
|
|
|
width750: true,
|
|
|
localCss: true,
|
|
|
module: 'activity',
|
...
|
...
|
@@ -86,34 +87,28 @@ const receiveRedBag = async(req, res, next) => { |
|
|
return next(error);
|
|
|
}
|
|
|
};
|
|
|
const submitWxCode = async(req, res) => {
|
|
|
|
|
|
const submitWxCode = async(req, res, next) => {
|
|
|
try {
|
|
|
let obj = {uid: req.user.uid || null,
|
|
|
shareCode: req.body.shareCode || '',
|
|
|
userUid: req.body.userUid || '',
|
|
|
userCode: req.body.userCode || ''};
|
|
|
|
|
|
obj = valid(obj, {
|
|
|
uid: {type: 'uid', empty: false},
|
|
|
shareCode: {type: 'String', empty: false},
|
|
|
userUid: {type: 'number', empty: false},
|
|
|
userCode: {type: 'String', empty: false}
|
|
|
});
|
|
|
|
|
|
let userInfo = await req.ctx(redbagModel).renderByCs(obj);
|
|
|
|
|
|
obj.userInfo = userInfo.data;
|
|
|
let result = await req.ctx(redbagModel).submitWxCode(obj);
|
|
|
|
|
|
return res.json({code: 200, data: result, result: true});
|
|
|
} catch (e) {
|
|
|
logger.error(e);
|
|
|
return res.json(e);
|
|
|
return res.json(result);
|
|
|
} catch (error) {
|
|
|
return next(error);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
redbagPage,
|
|
|
receiveRedBag,
|
...
|
...
|
|