admin.js
1.27 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
/**
* 管理model
* @author: leo <qi.li@yoho.cn>
* @date: 28/06/2017
*/
const mysqlCli = global.yoho.utils.mysqlCli;
const TABLE_ACTIVITY = 'activity';
class AdminModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 创建活动
* @param title 活动标题
* @param startTime 活动开始时间
* @param endTime 活动结束时间
* @returns {*}
*/
createActivity({title, startTime, endTime}) {
return mysqlCli.insert(
`insert into ${TABLE_ACTIVITY} (title, start_time, end_time) values (:title, :startTime, :endTime);`,
{
title,
startTime,
endTime
}
);
}
/**
* 活动列表
* @returns {*}
*/
activityList() {
return mysqlCli.query(
`select id, title, start_time startTime, end_time endTime, create_time createTime from ${TABLE_ACTIVITY};`
);
}
/**
* 删除活动
* @param actId 活动ID
* @returns {*}
*/
deleteActivity(actId) {
return mysqlCli.delete(
`delete from ${TABLE_ACTIVITY} where id = :actId;`,
{
actId
}
);
}
}
module.exports = AdminModel;