|
|
/* eslint-disable array-callback-return */
|
|
|
const {ActWheelSurfConf, ActWheelSurfPrize, Activity, ActWheelSurfUser} = require('../../../db');
|
|
|
const mysqlCli = global.yoho.utils.mysqlCli;
|
|
|
|
|
|
class ActWheelSurfModel extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
...
|
...
|
@@ -9,9 +10,11 @@ class ActWheelSurfModel extends global.yoho.BaseModel { |
|
|
list() {
|
|
|
return Activity.findAll({where: {type: 1}});
|
|
|
}
|
|
|
|
|
|
create(data) {
|
|
|
return Activity.create(data);
|
|
|
}
|
|
|
|
|
|
async actDelete(id) {
|
|
|
await Activity.destroy({where: {id}});
|
|
|
await ActWheelSurfConf.destroy({where: {act_id: id}});
|
...
|
...
|
@@ -90,23 +93,41 @@ class ActWheelSurfModel extends global.yoho.BaseModel { |
|
|
}
|
|
|
|
|
|
userFind(obj) {
|
|
|
let page = obj.page || 1;
|
|
|
let size = obj.size || 20;
|
|
|
|
|
|
delete obj.page;
|
|
|
delete obj.size;
|
|
|
return ActWheelSurfUser.findAll({
|
|
|
include: [{
|
|
|
model: ActWheelSurfPrize,
|
|
|
as: 'ActWheelSurfPrize',
|
|
|
}, {
|
|
|
model: ActWheelSurfConf,
|
|
|
as: 'ActWheelSurfConf',
|
|
|
}],
|
|
|
where: obj,
|
|
|
offset: (page - 1) * size,
|
|
|
limit: size
|
|
|
let pageNo = obj.pageNo || 1;
|
|
|
let pageSize = obj.pageSize || 20;
|
|
|
|
|
|
obj.start = (pageNo - 1) * pageSize;
|
|
|
obj.page = pageSize;
|
|
|
|
|
|
let sql = `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 ,activity a where u.prize_id = p.id and u.act_id =:act_id and a.id=:act_id`;
|
|
|
let arr = Object.keys(obj);
|
|
|
|
|
|
arr.forEach(function(value, index) {
|
|
|
switch (obj[value]) {
|
|
|
case 'type':
|
|
|
sql += ' and p.type=:type';
|
|
|
break;
|
|
|
case 'title':
|
|
|
sql += ' and a.title=:title';
|
|
|
break;
|
|
|
case 'uid':
|
|
|
sql += ' and u.uid=:uid';
|
|
|
break;
|
|
|
case 'name':
|
|
|
sql += ' and p.name=:name';
|
|
|
break;
|
|
|
}
|
|
|
if (index === arr.length - 1) {
|
|
|
sql += 'order by u.create_time desc limit :start, :page;';
|
|
|
}
|
|
|
});
|
|
|
|
|
|
try {
|
|
|
return mysqlCli.query(sql, obj);
|
|
|
} catch (e) {
|
|
|
return Promise.reject({code: 305, result: false, msg: '服务错误,请稍等'});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|