Authored by 李奇

用户端修改

... ... @@ -10,7 +10,7 @@ const whSurfController = {
getNowConf: async function(req, res) {
try {
let data = valid(req.body, {
act_id: {type: 'number', empty: false},
act_id: {type: 'string', empty: false},
uid: {type: 'number', empty: true},
});
let result = await req.ctx(wheelSurfModel).getNowConf(data);
... ... @@ -25,7 +25,7 @@ const whSurfController = {
// 校验用户登录
try {
let data = valid(req.body, {
act_id: {type: 'number', empty: false},
act_id: {type: 'string', empty: false},
uid: {type: 'number', empty: false},
sessionKey: {type: 'string', empty: false},
appVersion: {type: 'string', empty: false},
... ... @@ -42,7 +42,7 @@ const whSurfController = {
getUserPrize: async function(req, res) {
try {
let data = valid(req.body, {
act_id: {type: 'number', empty: false},
act_id: {type: 'string', empty: false},
uid: {type: 'number', empty: false},
});
let result = await req.ctx(wheelSurfModel).getUserPrize(data);
... ...
const {Activity} = require('../../../db');
const _ = require('lodash');
const aes = require('../../../utils/aes');
const logger = global.yoho.logger;
const _sender = global.yoho.sender;
const mysqlCli = global.yoho.utils.mysqlCli;
/**
* 上报
... ... @@ -58,6 +60,19 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel {
try {
let data = {};
// 兼容线上活动
if (+obj.act_id !== 44) {
try {
obj.act_id = parseInt(aes.decryptUid(obj.act_id), 10);
} catch (err) {
obj.act_id = 0;
}
}
if (!obj.act_id) {
return {};
}
data.conf = await this.client.hgetallAsync(`turntable:${obj.act_id}`)
.then(conf => {
conf = conf || {};
... ... @@ -87,7 +102,10 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel {
}
}
let act = await Activity.findOne({where: {id: obj.act_id}});
let idx = obj.act_id - 1;
let act = await this.client.lrangeAsync('turntable:activity', idx, idx).then(act => {
return JSON.parse(act[0] || {});
});
let nowDate = new Date();
nowDate = parseInt(nowDate.getTime() / 1000);
... ... @@ -130,6 +148,20 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel {
async goPrize(obj) {
try {
// 校验有效活动时间
// 兼容线上活动
if (+obj.act_id !== 44) {
try {
obj.act_id = parseInt(aes.decryptUid(obj.act_id), 10);
} catch (err) {
obj.act_id = 0;
}
}
if (!obj.act_id) {
return {};
}
let act = await Activity.findOne({where: {id: obj.act_id}});
let nowDate = new Date();
... ... @@ -331,15 +363,56 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel {
}
async getUserPrize(obj) {
// 兼容线上活动
if (+obj.act_id !== 44) {
try {
obj.act_id = parseInt(aes.decryptUid(obj.act_id), 10);
} catch (err) {
obj.act_id = 0;
}
}
if (!obj.act_id) {
return {};
}
try {
return await this.client.zrevrangeAsync(`turntable:${obj.act_id}:user:${obj.uid}:prize`, 0, 300)
.then(prizes => {
return prizes.map(prize => {
return JSON.parse(prize.split(':::')[0]);
}).filter(prize => {
return prize.type !== 1;
// 兼容线上活动奖品
if (+obj.act_id === 44) {
let oddPrizes = [];
try {
oddPrizes = await mysqlCli.query(
`select u.id, u.act_id act_id, u.prize_id prize_id, u.create_time createTime, p.name name,p.type type ,p.value value,p.img img
from act_wheel_surf_user u , act_wheel_surf_prize p where u.prize_id = p.id and u.act_id =:act_id and u.uid = :uid and type != :type
order by u.create_time desc`, {act_id: obj.act_id, uid: obj.uid, type: 1});
oddPrizes = oddPrizes.map(prize => {
});
});
} catch(e) {
logger.error(e);
}
return this.client.zrevrangeAsync(`turntable:${obj.act_id}:user:${obj.uid}:prize`, 0, 300)
.then(prizes => {
prizes = prizes.concat(oddPrizes);
return prizes.map(prize => {
return JSON.parse(prize.split(':::')[0]);
}).filter(prize => {
return prize.type !== 1;
});
});
} else {
return await this.client.zrevrangeAsync(`turntable:${obj.act_id}:user:${obj.uid}:prize`, 0, 300)
.then(prizes => {
return prizes.map(prize => {
return JSON.parse(prize.split(':::')[0]);
}).filter(prize => {
return prize.type !== 1;
});
});
}
} catch (e) {
logger.error(e);
return Promise.reject({code: 305, result: false, msg: '服务错误,请稍等'});
... ...