Authored by 李奇

大转盘活动ID加解密

... ... @@ -82,7 +82,7 @@ const whSurfController = {
try {
let data = valid(req.body, {
id: {type: 'number', empty: true},
act_id: {type: 'number', empty: false},
act_id: {type: 'string', empty: false},
rule_btn_bg: {type: 'string', empty: true},
rule_url: {type: 'string', empty: true},
share_btn_bg: {type: 'string', empty: true},
... ... @@ -168,7 +168,7 @@ const whSurfController = {
if (param && param.length && param instanceof Array) {
let arr = param.map((value) => {
return valid(value, {
act_id: {type: 'number', empty: false},
act_id: {type: 'string', empty: false},
name: {type: 'string', empty: true},
type: {type: 'number', empty: true},
value: {type: 'string', empty: true},
... ... @@ -211,7 +211,7 @@ const whSurfController = {
let arr = param.map((value) => {
return valid(value, {
id: {type: 'number', empty: true},
act_id: {type: 'number', empty: false},
act_id: {type: 'string', empty: false},
name: {type: 'string', empty: true},
type: {type: 'number', empty: true},
value: {type: 'string', empty: true},
... ...
const _ = require('lodash');
const {Activity} = require('../../../db');
const mysqlCli = global.yoho.utils.mysqlCli;
const aes = require('../../../utils/aes');
class ActWheelSurfModel extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -9,29 +8,40 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
this.client = this.redis.client;
}
list() {
return Activity.findAll({where: {type: 1}});
async list() {
let len = await this.client.llenAsync('turntable:activity');
return this.client.lrangeAsync('turntable:activity', 0, len - 1).then(acts => {
return acts.filter(act => act).map(act => {
return JSON.parse(act);
});
});
}
create(data) {
return Activity.create(data);
async create(data) {
let len = await this.client.llenAsync('turntable:activity');
data.id = len + 1;
data.encryptedId = aes.encryptUid(len + 1);
return this.client.rpushAsync('turntable:activity', JSON.stringify(data));
}
async actDelete(id) {
await Activity.destroy({where: {id}});
return true;
id = parseInt(aes.decryptUid(id), 10);
return this.client.lsetAsync('turntable:activity', id - 1, '');
}
actInfo(act_id) {
return Activity.findOne({where: {id: act_id}});
let idx = parseInt(aes.decryptUid(act_id), 10) - 1;
return this.client.lrangeAsync('turntable:activity', idx, idx).then(act => {
return JSON.parse(act[0] || {});
});
}
async userFind(obj) {
let pageNo = obj.pageNo || 1;
let pageSize = obj.pageSize || 20;
let actId = obj.act_id;
let actId = parseInt(aes.decryptUid(obj.act_id), 10);
let len = await this.client.llenAsync(`turntable:${actId}:prize:users`);
return this.client.lrangeAsync(`turntable:${actId}:prize:users`, (pageNo - 1) * pageSize, pageNo * pageSize - 1).then(prizes => {
let afters = prizes.map(prize => {
prize = prize.split(':::');
... ... @@ -51,6 +61,7 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
}
async exportRecords(actId) {
actId = parseInt(aes.decryptUid(actId), 10);
let len = await this.client.llenAsync(`turntable:${actId}:prize:user`);
return this.client.lrangeAsync(`turntable:${actId}:prize:users`, 0, len - 1).then(prizes => {
return prizes.map(prize => {
... ... @@ -66,6 +77,7 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
}
getActConf(actId) {
actId = parseInt(aes.decryptUid(actId), 10);
return this.client.hgetallAsync(`turntable:${actId}`).then(conf => {
conf = conf || {};
Object.keys(conf).forEach(key => {
... ... @@ -79,10 +91,12 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
setActConf(actId, confObj) {
confObj.id = 1;
actId = parseInt(aes.decryptUid(actId), 10);
return this.client.HMSET(`turntable:${actId}`, confObj);
}
getActPrize(actId, len = 7) {
actId = parseInt(aes.decryptUid(actId), 10);
return this.client.lrangeAsync(`turntable:${actId}:prize`, 0, len)
.then(async (prizes) => {
let left = 0;
... ... @@ -97,6 +111,7 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
createActPrize(actId, prizesList) {
prizesList = prizesList || [];
actId = parseInt(aes.decryptUid(actId), 10);
let multi = this.client.multi();
prizesList.map((prize, idx) => {
... ... @@ -109,6 +124,7 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
updateActPrize(actId, prizesList) {
prizesList = prizesList || [];
actId = parseInt(aes.decryptUid(actId), 10);
let multi = this.client.multi();
prizesList.map((prize, idx) => {
... ...
... ... @@ -13,7 +13,7 @@
columns1: [
{
title: '活动ID',
key: 'id'
key: 'encryptedId'
},
{
title: '活动标题',
... ... @@ -47,7 +47,7 @@
},
on: {
click: () => {
this.conf(row.id);
this.conf(row.encryptedId);
}
}
}, '配置'),
... ... @@ -61,7 +61,7 @@
},
on: {
click: () => {
this.prizeSent(row.id);
this.prizeSent(row.encryptedId);
}
}
}, '中奖一览'),
... ... @@ -72,7 +72,7 @@
},
on: {
click: () => {
this.delete(row.id);
this.delete(row.encryptedId);
}
}
}, '删除')
... ...