Authored by 李奇

获取奖品兼容线上活动44

@@ -10,7 +10,7 @@ const whSurfController = { @@ -10,7 +10,7 @@ const whSurfController = {
10 getNowConf: async function(req, res) { 10 getNowConf: async function(req, res) {
11 try { 11 try {
12 let data = valid(req.body, { 12 let data = valid(req.body, {
13 - act_id: {type: 'number', empty: false}, 13 + act_id: {type: 'string', empty: false},
14 uid: {type: 'number', empty: true}, 14 uid: {type: 'number', empty: true},
15 }); 15 });
16 let result = await req.ctx(wheelSurfModel).getNowConf(data); 16 let result = await req.ctx(wheelSurfModel).getNowConf(data);
@@ -25,7 +25,7 @@ const whSurfController = { @@ -25,7 +25,7 @@ const whSurfController = {
25 // 校验用户登录 25 // 校验用户登录
26 try { 26 try {
27 let data = valid(req.body, { 27 let data = valid(req.body, {
28 - act_id: {type: 'number', empty: false}, 28 + act_id: {type: 'string', empty: false},
29 uid: {type: 'number', empty: false}, 29 uid: {type: 'number', empty: false},
30 sessionKey: {type: 'string', empty: false}, 30 sessionKey: {type: 'string', empty: false},
31 appVersion: {type: 'string', empty: false}, 31 appVersion: {type: 'string', empty: false},
@@ -42,7 +42,7 @@ const whSurfController = { @@ -42,7 +42,7 @@ const whSurfController = {
42 getUserPrize: async function(req, res) { 42 getUserPrize: async function(req, res) {
43 try { 43 try {
44 let data = valid(req.body, { 44 let data = valid(req.body, {
45 - act_id: {type: 'number', empty: false}, 45 + act_id: {type: 'string', empty: false},
46 uid: {type: 'number', empty: false}, 46 uid: {type: 'number', empty: false},
47 }); 47 });
48 let result = await req.ctx(wheelSurfModel).getUserPrize(data); 48 let result = await req.ctx(wheelSurfModel).getUserPrize(data);
1 const {Activity} = require('../../../db'); 1 const {Activity} = require('../../../db');
2 const _ = require('lodash'); 2 const _ = require('lodash');
  3 +const aes = require('../../../utils/aes');
3 const logger = global.yoho.logger; 4 const logger = global.yoho.logger;
4 const _sender = global.yoho.sender; 5 const _sender = global.yoho.sender;
  6 +const mysqlCli = global.yoho.utils.mysqlCli;
5 7
6 /** 8 /**
7 * 上报 9 * 上报
@@ -58,6 +60,19 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel { @@ -58,6 +60,19 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel {
58 try { 60 try {
59 let data = {}; 61 let data = {};
60 62
  63 + // 兼容线上活动
  64 + if (+obj.act_id !== 44) {
  65 + try {
  66 + obj.act_id = parseInt(aes.decryptUid(obj.act_id), 10);
  67 + } catch (err) {
  68 + obj.act_id = 0;
  69 + }
  70 + }
  71 +
  72 + if (!obj.act_id) {
  73 + return {};
  74 + }
  75 +
61 data.conf = await this.client.hgetallAsync(`turntable:${obj.act_id}`) 76 data.conf = await this.client.hgetallAsync(`turntable:${obj.act_id}`)
62 .then(conf => { 77 .then(conf => {
63 conf = conf || {}; 78 conf = conf || {};
@@ -87,7 +102,10 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel { @@ -87,7 +102,10 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel {
87 } 102 }
88 } 103 }
89 104
90 - let act = await Activity.findOne({where: {id: obj.act_id}}); 105 + let idx = obj.act_id - 1;
  106 + let act = await this.client.lrangeAsync('turntable:activity', idx, idx).then(act => {
  107 + return JSON.parse(act[0] || {});
  108 + });
91 let nowDate = new Date(); 109 let nowDate = new Date();
92 110
93 nowDate = parseInt(nowDate.getTime() / 1000); 111 nowDate = parseInt(nowDate.getTime() / 1000);
@@ -130,6 +148,20 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel { @@ -130,6 +148,20 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel {
130 async goPrize(obj) { 148 async goPrize(obj) {
131 try { 149 try {
132 // 校验有效活动时间 150 // 校验有效活动时间
  151 +
  152 + // 兼容线上活动
  153 + if (+obj.act_id !== 44) {
  154 + try {
  155 + obj.act_id = parseInt(aes.decryptUid(obj.act_id), 10);
  156 + } catch (err) {
  157 + obj.act_id = 0;
  158 + }
  159 + }
  160 +
  161 + if (!obj.act_id) {
  162 + return {};
  163 + }
  164 +
133 let act = await Activity.findOne({where: {id: obj.act_id}}); 165 let act = await Activity.findOne({where: {id: obj.act_id}});
134 let nowDate = new Date(); 166 let nowDate = new Date();
135 167
@@ -331,15 +363,51 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel { @@ -331,15 +363,51 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel {
331 } 363 }
332 364
333 async getUserPrize(obj) { 365 async getUserPrize(obj) {
  366 + // 兼容线上活动
  367 + if (+obj.act_id !== 44) {
  368 + try {
  369 + obj.act_id = parseInt(aes.decryptUid(obj.act_id), 10);
  370 + } catch (err) {
  371 + obj.act_id = 0;
  372 + }
  373 + }
  374 +
  375 + if (!obj.act_id) {
  376 + return [];
  377 + }
  378 +
334 try { 379 try {
335 - return await this.client.zrevrangeAsync(`turntable:${obj.act_id}:user:${obj.uid}:prize`, 0, 300)  
336 - .then(prizes => {  
337 - return prizes.map(prize => {  
338 - return JSON.parse(prize.split(':::')[0]);  
339 - }).filter(prize => {  
340 - return prize.type !== 1; 380 + // 兼容线上活动奖品
  381 + if (+obj.act_id === 44) {
  382 + let oddPrizes = [];
  383 +
  384 + try {
  385 + oddPrizes = await mysqlCli.query(
  386 + `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
  387 + 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
  388 + order by u.create_time desc`, {act_id: obj.act_id, uid: obj.uid, type: 1});
  389 + } catch(e) {
  390 + logger.error(e);
  391 + }
  392 +
  393 + return this.client.zrevrangeAsync(`turntable:${obj.act_id}:user:${obj.uid}:prize`, 0, 300)
  394 + .then(prizes => {
  395 + return prizes.map(prize => {
  396 + return JSON.parse(prize.split(':::')[0]);
  397 + }).filter(prize => {
  398 + return prize.type !== 1;
  399 + }).concat(oddPrizes);
341 }); 400 });
342 - }); 401 + } else {
  402 + return await this.client.zrevrangeAsync(`turntable:${obj.act_id}:user:${obj.uid}:prize`, 0, 300)
  403 + .then(prizes => {
  404 + return prizes.map(prize => {
  405 + return JSON.parse(prize.split(':::')[0]);
  406 + }).filter(prize => {
  407 + return prize.type !== 1;
  408 + });
  409 + });
  410 + }
343 } catch (e) { 411 } catch (e) {
344 logger.error(e); 412 logger.error(e);
345 return Promise.reject({code: 305, result: false, msg: '服务错误,请稍等'}); 413 return Promise.reject({code: 305, result: false, msg: '服务错误,请稍等'});