|
|
/* 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 auth = require('../../passport/models/auth-helper');
|
|
|
const co = require('bluebird').coroutine;
|
|
|
|
|
|
|
|
|
function humanNum_wan(num) {
|
|
|
return num;
|
|
|
|
|
|
// if (num > 9999) {
|
|
|
// num = (num / 10000).toFixed(2) + '万'
|
|
|
// }
|
|
|
|
|
|
// return num;
|
|
|
}
|
|
|
|
|
|
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';
|
|
|
res.locals.width750 = true;
|
|
|
|
|
|
let cate = {
|
|
|
goods1: [51281456, 51228151, 51315660],
|
|
|
goods2: [51362376, 51339512, 51316684],
|
|
|
goods3: [51374524, 51338322, 51344316]
|
|
|
};
|
|
|
|
|
|
if (req.app.get('env') !== 'production') {
|
|
|
cate = {
|
|
|
goods1: [512581904, 512581902, 512581900],
|
|
|
goods2: [512581822, 512581816, 512581812],
|
|
|
goods3: [512581806, 512581796, 512581792]
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
vipDayModel.getGoods(cate)
|
|
|
.then(result => {
|
|
|
// console.log(result.data)
|
|
|
if (result.code !== 200) {
|
|
|
return Promise.reject('error');
|
|
|
}
|
|
|
|
|
|
res.render('vip-day/vip-day1028/index', {
|
|
|
title: '会员日活动',
|
|
|
pageStyle: 'vip-day10 entry',
|
|
|
goods1: result.data.goods1,
|
|
|
goods2: result.data.goods2,
|
|
|
goods3: result.data.goods3
|
|
|
});
|
|
|
return;
|
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
exports.crazyWheel = (req, res, next) => {
|
|
|
res.locals.module = 'activity';
|
|
|
res.locals.page = 'vipday-wheel10';
|
|
|
res.locals.width750 = true;
|
|
|
|
|
|
if (!req.session.playwheel) {
|
|
|
return res.redirect('/activity/vip-day10');
|
|
|
}
|
|
|
|
|
|
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_day10/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;
|
|
|
let prize_type = 3;
|
|
|
|
|
|
return vipDayModel.addPrizeLog(uid, prize_type).then(result => {
|
|
|
return res.json(result);
|
|
|
}).catch(next);
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
exports.checkIsStudent = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
|
|
|
vipDayModel.checkIsStudent(uid).then(result => {
|
|
|
console.log(result);
|
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
exports.luckResult = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
let prize_type = 1;
|
|
|
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 = 1;
|
|
|
|
|
|
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);
|
|
|
});
|
|
|
}; |
...
|
...
|
|