|
|
/* eslint no-unused-vars: ["error", { "args": "none" }]*/
|
|
|
/* eslint-disable no-shadow, camelcase */
|
|
|
'use strict';
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const vipDayModel = require('../models/vipDay10');
|
|
|
const co = require('bluebird').coroutine;
|
|
|
|
|
|
|
|
|
function humanNum_wan(num) {
|
|
|
return num;
|
|
|
|
|
|
// if (num > 9999) {
|
|
|
// num = (num / 10000).toFixed(2) + '万'
|
|
|
// }
|
|
|
|
|
|
// return num;
|
|
|
}
|
|
|
|
|
|
exports.checkIsStudent = (req, res, next) => {
|
|
|
let uid = req.user.uid || req.query.uid;
|
|
|
|
|
|
vipDayModel.checkIsStudent(uid).then(result => {
|
|
|
res.json(result);
|
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
exports.beforeIn = (req, res, next) => {
|
|
|
// 将APP登录状态正常化
|
|
|
if (req.yoho.isApp) {
|
|
|
req.user.uid = Number(req.user.uid || req.query.uid);
|
|
|
}
|
|
|
|
|
|
// 未登录
|
|
|
if (!req.user.uid) {
|
|
|
if (req.xhr) {
|
|
|
return res.json({
|
|
|
code: 401,
|
|
|
message: '抱歉,您还未登录',
|
|
|
redirect: '/signin.html'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return res.redirect(helpers.urlFormat('/signin.html', {
|
|
|
refer: req.originalUrl
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
next();
|
|
|
};
|
|
|
|
|
|
exports.index = (req, res, next) => {
|
|
|
res.locals.module = 'activity';
|
|
|
res.locals.page = 'vipday-entry10';
|
|
|
|
|
|
let cate = {
|
|
|
goods1: [51140408, 51334392, 51300342, 51188891, 51243402, 51389870],
|
|
|
goods2: [51315800, 51388146, 51344242, 51294920, 51414498, 51337292],
|
|
|
goods3: [51397576, 51410158, 51289104]
|
|
|
};
|
|
|
|
|
|
if (req.app.get('env') !== 'production') {
|
|
|
cate = {
|
|
|
goods1: [51140408, 51334392, 51300342, 51188891, 51243402, 51389870],
|
|
|
goods2: [51315800, 51388146, 51344242, 51294920, 51414498, 51337292],
|
|
|
goods3: [51397576, 51410158, 51289104]
|
|
|
};
|
|
|
}
|
|
|
|
|
|
co(function*() {
|
|
|
let isStudent = false;
|
|
|
|
|
|
// 获取学生信息
|
|
|
if (req.user.uid || req.query.uid) {
|
|
|
let result = yield vipDayModel.checkIsStudent(req.user.uid || req.query.uid);
|
|
|
|
|
|
result.data && Number(result.data.isStudent) === 1 && (isStudent = true);
|
|
|
}
|
|
|
|
|
|
// 获取商品信息
|
|
|
let goodList = yield vipDayModel.getGoods(cate);
|
|
|
|
|
|
res.render('vip-day/vip-day1028/index', {
|
|
|
title: '会员日活动',
|
|
|
pageStyle: 'vip-day10 entry',
|
|
|
isStudent: isStudent,
|
|
|
goods1: goodList.data && goodList.data.goods1 || [],
|
|
|
goods2: goodList.data && goodList.data.goods2 || [],
|
|
|
goods3: goodList.data && goodList.data.goods3 || [],
|
|
|
});
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
exports.crazyWheel = (req, res, next) => {
|
|
|
res.locals.module = 'activity';
|
|
|
res.locals.page = 'vipday-wheel10';
|
|
|
res.locals.width750 = true;
|
|
|
|
|
|
vipDayModel.getJoinNum(1).then(result => {
|
|
|
let joins = result && result.data || 0;
|
|
|
|
|
|
res.render('vip-day/vip-day1028/crazy-wheel', {
|
|
|
title: '疯狂大转盘',
|
|
|
pageStyle: 'vip-day10 game',
|
|
|
isWheel: true,
|
|
|
joins: humanNum_wan(joins),
|
|
|
joinNum: joins
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
|
|
|
exports.crazyLuck = (req, res, next) => {
|
|
|
const uid = req.user.uid;
|
|
|
|
|
|
res.locals.module = 'activity';
|
|
|
res.locals.page = 'vipday-luck10';
|
|
|
res.locals.width750 = true;
|
|
|
|
|
|
co(function*() {
|
|
|
let coins = yield vipDayModel.getCoins(uid);
|
|
|
let joinNum = yield vipDayModel.getJoinNum(2);
|
|
|
|
|
|
coins = (coins && coins.data && coins.data.total) || 0;
|
|
|
joinNum = (joinNum && joinNum.data) || 0;
|
|
|
|
|
|
res.render('vip-day/vip-day1028/crazy-luck', {
|
|
|
title: '拼手气',
|
|
|
pageStyle: 'vip-day10 game',
|
|
|
isLuck: true,
|
|
|
coins: humanNum_wan(coins),
|
|
|
coinNum: coins,
|
|
|
joins: humanNum_wan(joinNum),
|
|
|
joinNum: joinNum,
|
|
|
});
|
|
|
})().catch(next);
|
|
|
};
|
|
|
|
|
|
|
|
|
/* 会员日签到 */
|
|
|
exports.signin = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
|
|
|
return vipDayModel.signin(uid)
|
|
|
.then(function(result) {
|
|
|
res.json(result);
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
exports.wheelResult = (req, res, next) => {
|
|
|
let uid = req.user.uid || req.query.uid;
|
|
|
let prize_type = 3;
|
|
|
|
|
|
return vipDayModel.addPrizeLog(uid, prize_type).then(result => {
|
|
|
return res.json(result);
|
|
|
}).catch(next);
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
exports.luckResult = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
let prize_type = 3;
|
|
|
let cost = 20;
|
|
|
|
|
|
let handle = co(function*(uid) {
|
|
|
// 查询用户 有货币
|
|
|
let r1 = yield vipDayModel.getCoins(uid);
|
|
|
|
|
|
if (r1.code !== 200) {
|
|
|
return {
|
|
|
code: r1.code,
|
|
|
message: '请求不合法'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
let coin = r1.data.total;
|
|
|
|
|
|
// console.log(coin);
|
|
|
if (coin < 20) {
|
|
|
return { code: 400, message: '有货币不够...' };
|
|
|
}
|
|
|
|
|
|
// 得出 中奖结果
|
|
|
let result = yield vipDayModel.addPrizeLog(uid, prize_type);
|
|
|
|
|
|
if (result.code !== 200) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
Object.assign(result, { coin: coin - cost + result.data });
|
|
|
return result;
|
|
|
});
|
|
|
|
|
|
handle(uid).then(function(result) {
|
|
|
return res.json(result);
|
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
exports.luckResultCollect = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
let prize_type = 3;
|
|
|
|
|
|
return vipDayModel.queryPrizeLog(uid, prize_type).then(result => {
|
|
|
if (result.code === 200 && result.data) {
|
|
|
result.data = result.data.filter(award => award.prizeValue);
|
|
|
}
|
|
|
|
|
|
res.json(result);
|
|
|
});
|
|
|
}; |
|
|
\ No newline at end of file |
...
|
...
|
|