wheel-surf.js
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* eslint-disable array-callback-return */
const {ActWheelSurfConf, ActWheelSurfPrize, Activity} = require('../../../db');
class ActWheelSurfModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
list() {
return Activity.findAll({where: {type: 1}})
}
create(data) {
return Activity.create(data);
}
actDelete(id) {
return Activity.findOne({where: {id}}).then(activity => {
return activity.destroy();
});
}
configModify(obj) {
if (obj.id) {
let where = {id: obj.id};
delete obj.id;
return ActWheelSurfConf.update(obj, {where: where});
} else {
return ActWheelSurfConf.create(obj);
}
}
configList() {
return ActWheelSurfConf.findAll();
}
configFindOne(act_id) {
return ActWheelSurfConf.findOne({where: {act_id}});
}
prizeCreate(arr) {
return ActWheelSurfPrize.bulkCreate(arr);
}
prizeUpdate(arr) {
try {
arr.map((value) => {
let where = {id: value.id};
delete value.id;
ActWheelSurfPrize.update(value, {where: where});
});
return Promise.resolve({code: 200, result: true});
} catch (e) {
return Promise.resolve({code: 201, result: false, msg: e});
}
}
prizeFindByActId(act_id) {
return ActWheelSurfPrize.findAll({where: {act_id}});
}
}
module.exports = ActWheelSurfModel;