y100.js
3.65 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const Y100Model = require('../models/y100');
const GET_SUCCESS = '获取成功';
const INVALID_PARAMS = '参数错误';
const y100 = {
/**
* Y100文章列表
* @param req
* @param res
* @param next
*/
async y100List(req, res, next) {
const {actId, pageNo = 1, pageSize = 20, tag = '', top = 1} = req.query;
let top_int = parseInt(top, 10);
if (!actId) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
try {
const result = await req.ctx(Y100Model).articleY100List({
actId,
pageNo,
pageSize,
tag,
top: top_int
});
return res.json({
code: 200,
data: result,
pageNo: +pageNo,
pageSize: +pageSize,
message: GET_SUCCESS
});
} catch (err) {
return next(err);
}
},
/**
* Y100文章列表-随机
* @param req
* @param res
* @param next
*/
async y100RandomList(req, res, next) {
const {actId, num} = req.query;
if (!actId || num > 100) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
try {
const result = await req.ctx(Y100Model).articleY100RandomList({
actId,
num
});
return res.json({
code: 200,
data: result,
message: GET_SUCCESS
});
} catch (err) {
return next(err);
}
},
/**
* Y100详情
* @param req
* @param res
* @param next
*/
async y100Detail(req, res, next) {
const {id} = req.query;
if (!id) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
try {
const result = await req.ctx(Y100Model).articleY100Detail(id);
return res.json({
code: 200,
data: result,
});
} catch (err) {
return next(err);
}
},
async y100DeviceScan(req, res, next) {
const {openId, avatar, deviceNo, actId, userName} = req.body;
console.log(req.body);
if (!deviceNo || !openId) {
return res.json({
code: 400
});
}
try {
const result = await req.ctx(Y100Model).deviceUse({openId, avatar, deviceNo, actId, userName});
return res.json(result);
} catch (err) {
return next(err);
}
},
async y100DevicePost(req, res, next) {
const {openId, deviceNo, actId, userImage, userLabel} = req.body;
if (!deviceNo || !openId) {
return res.json({
code: 400
});
}
try {
const result = await req.ctx(Y100Model).devicePost({openId, deviceNo, actId, userImage, userLabel});
return res.json(result);
} catch (err) {
return next(err);
}
},
async checkDeviceStatus(req, res, next) {
const {deviceNo, actId} = req.query;
if (!deviceNo || !actId) {
return res.json({
code: 400
});
}
try {
const result = await req.ctx(Y100Model).checkDeviceStatus({deviceNo, actId});
return res.json(result);
} catch (err) {
return next(err);
}
}
};
module.exports = y100;