admin.js
2.44 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* 管理model
* @author: leo <qi.li@yoho.cn>
* @date: 28/06/2017
*/
const mysqlCli = global.yoho.utils.mysqlCli;
const TABLE_ACTIVITY = 'activity';
const TABLE_ACT_ARTICLE = 'act_article';
const TABLE_USER = 'user';
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
}
);
}
/**
* 活动文章列表
* @returns {*}
*/
actArticleList(actId) {
return mysqlCli.query(
`select taa.id, taa.content, taa.good_count goodCount, tu.user_name userName
from ${TABLE_ACT_ARTICLE} taa
inner join ${TABLE_USER} tu
on taa.user_id = tu.id
where act_id = :actId;`, {
actId
}
);
}
/**
* 删除文章
* @param id 文章ID
* @returns {*}
*/
deleteArticle(id) {
return mysqlCli.delete(
`delete from ${TABLE_ACT_ARTICLE} where id = :id;`,
{
id
}
);
}
/**
* 参与活动用户列表
* @returns {*}
*/
activityUserList(actId) {
return mysqlCli.query(
`select tu.user_phone phone
from ${TABLE_ACTIVITY} ta
inner join act_article taa
on ta.id = taa.act_id
inner join user tu
on taa.user_id = tu.id
where ta.id = :actId;`, {
actId
}
);
}
}
module.exports = AdminModel;