|
|
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) => {
|
...
|
...
|
|