|
|
/* eslint no-unused-vars: ["error", { "args": "none" }]*/
|
|
|
/* eslint-disable no-shadow, camelcase */
|
|
|
'use strict';
|
|
|
const url = require('url');
|
|
|
const moment = require('moment');
|
|
|
const _ = require('lodash');
|
|
|
const camelCase = global.yoho.camelCase;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const vipDayModel = require('../models/vipDay');
|
|
|
const auth = require('../../passport/models/auth-helper');
|
|
|
const co = require('bluebird').coroutine;
|
|
|
const util = require(global.utils + '/product-process');
|
|
|
|
|
|
|
|
|
|
|
|
exports.beforeIn = (req, res, next) => {
|
|
|
if (req.user.uid) {
|
|
|
return next();
|
|
|
// 将APP登录状态正常化
|
|
|
if (req.yoho.isApp && req.query.uid) {
|
|
|
req.user.uid = Number(req.user.uid || req.query.uid);
|
|
|
}
|
|
|
|
|
|
if (req.xhr) {
|
|
|
return res.json({
|
|
|
msg: '请先登录'
|
|
|
});
|
|
|
} else {
|
|
|
let jumpTo = new url.Url();
|
|
|
|
|
|
jumpTo.pathname = '/signin.html';
|
|
|
req.yoho.isApp && (jumpTo.search = 'yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http://m.yohobuy.com/activity/vip-day"}}}');
|
|
|
// 未登录
|
|
|
if (!req.user.uid) {
|
|
|
if (req.xhr) {
|
|
|
return res.json({
|
|
|
code: 401,
|
|
|
message: '抱歉,您还未登录',
|
|
|
redirect: '/signin.html'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
jumpTo = url.format(jumpTo);
|
|
|
return res.redirect(jumpTo);
|
|
|
return res.redirect(helpers.urlFormat('/signin.html', {
|
|
|
refer: req.originalUrl
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
next();
|
|
|
};
|
|
|
|
|
|
exports.index = (req, res, next) => {
|
...
|
...
|
@@ -33,14 +40,28 @@ exports.index = (req, res, next) => { |
|
|
res.locals.page = 'vipday_entry';
|
|
|
res.locals.width750 = true;
|
|
|
|
|
|
res.render('vip_day/index', {
|
|
|
pageStyle: 'vip-day entry',
|
|
|
vipgoods: [
|
|
|
[1, 2, 3],
|
|
|
[1, 2, 3],
|
|
|
[1, 2, 3]
|
|
|
]
|
|
|
});
|
|
|
let cate = {
|
|
|
goods1: [51203592, 51228151, 51315660],
|
|
|
goods2: [51338322, 51299644, 51344316],
|
|
|
goods3: [51374524, 51333192, 51311138]
|
|
|
};
|
|
|
|
|
|
vipDayModel.getGoods(cate)
|
|
|
.then(result => {
|
|
|
// console.log(result.data)
|
|
|
if (result.code !== 200) {
|
|
|
return Promise.reject('error');
|
|
|
}
|
|
|
|
|
|
res.render('vip_day/index', {
|
|
|
title: '会员日活动',
|
|
|
pageStyle: 'vip-day entry',
|
|
|
goods1: result.data.goods1,
|
|
|
goods2: result.data.goods2,
|
|
|
goods3: result.data.goods3
|
|
|
});
|
|
|
return;
|
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
exports.crazyWheel = (req, res, next) => {
|
...
|
...
|
@@ -48,12 +69,13 @@ exports.crazyWheel = (req, res, next) => { |
|
|
res.locals.page = 'vipday_wheel';
|
|
|
res.locals.width750 = true;
|
|
|
|
|
|
if (!res.session.playwheel) {
|
|
|
if (!req.session.playwheel) {
|
|
|
return res.redirect('/activity/vip-day');
|
|
|
}
|
|
|
|
|
|
vipDayModel.getJoinNum(1).then(result => {
|
|
|
res.render('vip_day/crazy_wheel', {
|
|
|
title: '会员日-疯狂大转盘',
|
|
|
pageStyle: 'vip-day game',
|
|
|
isWheel: true,
|
|
|
joinNum: result && result.data || 0,
|
...
|
...
|
@@ -68,10 +90,12 @@ exports.crazyLuck = (req, res, next) => { |
|
|
res.locals.page = 'vipday_luck';
|
|
|
res.locals.width750 = true;
|
|
|
|
|
|
co(function* (){
|
|
|
co(function* () {
|
|
|
let coins = yield vipDayModel.getCoins(uid);
|
|
|
let joinNum = yield vipDayModel.getJoinNum(2);
|
|
|
|
|
|
res.render('vip_day/crazy_luck', {
|
|
|
title: '拼手气',
|
|
|
pageStyle: 'vip-day game',
|
|
|
isLuck: true,
|
|
|
coin: coins && coins.data && (coins.data.total > 9999 ? (coins.data.total / 10000).toFixed(2) + '万' : coins.data.total),
|
...
|
...
|
@@ -95,7 +119,6 @@ exports.signin = (req, res, next) => { |
|
|
exports.saveMsg = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
let content = req.body.content;
|
|
|
|
|
|
auth.profile(uid)
|
|
|
.then(profile => {
|
|
|
// 1. get nick_name
|
...
|
...
|
@@ -107,7 +130,7 @@ exports.saveMsg = (req, res, next) => { |
|
|
})
|
|
|
.then(result => {
|
|
|
if (result.code === 200 && result.data === 1) {
|
|
|
res.session.playwheel = true;
|
|
|
req.session.playwheel = true;
|
|
|
}
|
|
|
|
|
|
res.json(result);
|
...
|
...
|
@@ -117,7 +140,15 @@ exports.saveMsg = (req, res, next) => { |
|
|
|
|
|
// 获取 会员日的 用户留言
|
|
|
exports.fetchMsg = (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
|
|
let uid;
|
|
|
|
|
|
if (global.yoho.isApp) {
|
|
|
uid = req.query.uid;
|
|
|
} else {
|
|
|
uid = req.user.uid;
|
|
|
}
|
|
|
|
|
|
uid = uid || 0;
|
|
|
|
|
|
vipDayModel.queryLeaveWordsList(uid).then(result => {
|
|
|
return res.json(result);
|
...
|
...
|
@@ -154,7 +185,7 @@ exports.luckResult = (req, res, next) => { |
|
|
|
|
|
let coin = r1.data.total;
|
|
|
|
|
|
console.log(coin);
|
|
|
// console.log(coin);
|
|
|
if (coin < 20) {
|
|
|
return { code: 400, message: '有货币不够...' };
|
|
|
}
|
...
|
...
|
|