Bind.php
9.6 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\model\Item;
use app\common\model\RadarScore;
use app\common\model\Study;
use app\common\model\StudyScoreLog;
use app\common\model\Team;
use think\Db;
use think\Exception;
use think\exception\PDOException;
/**
* 绑定资质
* @ApiWeigh (96)
*/
class Bind extends Api
{
protected $noNeedLogin = [''];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (输入手环ID绑定信息)
* @ApiMethod (POST)
* @ApiParams (name="unique", type="string", required=true, description="手环id")
* @ApiReturn ({
"code":"状态码",
"msg": "提示消息",
"data": {}
})
*/
public function inUnique()
{
$unique = $this->request->param('unique');
$user = $this->auth->getUserinfo();
if (empty($unique)) {
$this->error('参数错误', ['status' => 2]);
}
$res = \db('study')->where(['unique'=>$unique])->find();
if (!empty($res['user_id'])){
$this->error('当前学生已经被绑定了');
}
$users = db('user')->where('id', $user['id'])->find();
//halt($users);
// if ($users['bind_study'] == 1) {
// $this->error('您当前已经绑定过学生了,请勿重复操作');
// }
Db::startTrans();
try {
db('study')
->where('unique', $unique)
->update([
'user_id' => $user['id'],
'updatetime' => time()
]);
$update = [
'bind_study' => 1,
'updatetime' => time()
];
if ($users['is_teach'] == 0){
$update['nickname'] = $res['name']."家长";
}
\db('user')
->where('id', $user['id'])
->update($update);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error('参数错误', $e->getMessage());
}
$data = db('study')->where('unique', $unique)->field('id,grade,name')->find();
$this->success('绑定成功',$data);
}
/**
* @ApiTitle (扫码绑定信息)
* @ApiMethod (POST)
* @ApiParams (name="unique", type="string", required=true, description="手环id[条形码编号]")
* @ApiReturn ({
"code":"状态码",
"msg": "提示消息",
"data": {}
})
*/
public function scanCode()
{
$unique = $this->request->param('unique');
$user = $this->auth->getUserinfo();
if (empty($unique)) {
$this->error('参数错误', ['status' => 2]);
}
$res = \db('study')->where(['unique'=>$unique])->find();
if (!empty($res['user_id'])){
$this->error('当前学生已经被绑定了');
}
$users = db('user')->where('id', $user['id'])->find();
// if ($users['bind_study'] == 1) {
// $this->error('您当前已经绑定过学生了,请勿重复操作');
// }
Db::startTrans();
try {
db('study')
->where('unique', $unique)
->update([
'user_id' => $user['id'],
'updatetime' => time()
]);
$update = [
'bind_study' => 1,
'updatetime' => time()
];
if ($users['is_teach'] == 0){
$update['nickname'] = $res['name']."家长";
}
\db('user')
->where('id', $user['id'])
->update($update);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error('参数错误', $e->getMessage());
}
$data = db('study')->where('unique', $unique)->field('id,grade,name')->find();
$this->success('绑定成功', $data);
}
/**
* @ApiTitle (项目管理[老师])
* @ApiMethod (POST)
* @ApiReturn ({
"code":"状态码",
"msg": "提示消息",
"data": {
"id": 项目id,
"title": "项目名称",
}
})
*/
public function teachItem()
{
$user = $this->auth->getUserinfo();
$data = db('item')
->where('user_id', $user['id'])
->field('id,title')
->select();
if (empty($data)) {
$this->error('当前还未关联项目', ['status' => 2]);
}
$this->success('获取项目成功', $data);
}
/**
* @ApiTitle (学生校区)
* @ApiMethod (POST)
* @ApiReturn ({
"code": "状态码",
"msg": "获取校区成功",
"time": "时间",
"data": [
{
"campus_id": "校区id",
"campus_title": "校区名称"
}
]
})
*/
public function studyCampus(){
$user = $this->auth->getUserinfo();
$sid = db('study')
->where('user_id', $user['id'])
->value('id');
$data = \db('study_score_log l')
->distinct('campus_id')
->join('campus c','c.id = l.campus_id')
->where('study_id',$sid)
->field('campus_id,c.title as campus_title')
->select();
if (empty($data)){
$this->error('当前学生还未有项目关联校区',['status'=>2]);
}
$this->success('获取校区成功', $data);
}
/**
* @ApiTitle (活动现场[扫码])
* @ApiMethod (POST)
* @ApiParams (name="id", type="string", required=true, description="项目id")
* @ApiParams (name="unique", type="string", required=true, description="条形码唯一标识")
* @ApiReturn ({
"code":"状态码",
"msg": "提示消息",
"data": {
"name": "姓名",
"gender": "性别",
}
})
*/
public function scanBarCode()
{
$id = $this->request->param('id');
$unique = $this->request->param('unique');
if (empty($unique) && empty($id)) {
$this->error('参数错误', ['status' => 2]);
}
$model = new StudyScoreLog();
$model->addScore($id,$unique);
//halt($res);
$data = db('study')->where('unique', $unique)->field('name,gender')->find();
if ($data['gender'] == 1){
$data['gender'] = '男';
}else{
$data['gender'] = '女';
}
$this->success('扫码成功', $data);
}
/**
* @ApiTitle (活动现场[手动输入])
* @ApiMethod (POST)
* @ApiParams (name="id", type="string", required=true, description="项目id")
* @ApiParams (name="unique", type="string", required=true, description="条形码唯一标识")
* @ApiReturn ({
"code":"状态码",
"msg": "提示消息",
"data": {
"name": "姓名",
"gender": "性别",
}
})
*/
public function inputBar()
{
$id = $this->request->param('id');
$unique = $this->request->param('unique');
if (empty($unique) && empty($id)) {
$this->error('参数错误', ['status' => 2]);
}
$model = new StudyScoreLog();
$find = $model->addScore($id,$unique);
if (empty($find)){
$this->error('扫码无效');
}else{
$data = db('study')->where('unique', $unique)->field('name,gender')->find();
if ($data['gender'] == 1){
$data['gender'] = '男';
}else{
$data['gender'] = '女';
}
$this->success('扫码成功', $data);
}
}
/**
* @ApiTitle (绑定后获取头像昵称)
*/
public function study(){
$user = $this->auth->getUserinfo();
$sid = \db('study')->where('user_id', $user['id'])->value('id');
//获取学生的信息
$data = \db('study')->where('id', $sid)->field('avatar,name,earn_score')->find();
$data['avatar'] = cdnurl( $data['avatar'], true);
$this->success('',$data);
}
/**
* @ApiTitle (获取学生信息)
* @ApiMethod (POST)
* @ApiParams (name="cid", type="string", required=true, description="校区id")
* @ApiReturn ({
"code":"状态码",
"msg": "提示消息",
"data": {
"avatar": "学生头像",
"name": "学生名称",
"earn_score": "学生获得分数"
"item": 雷达图项目{
"total": 1,
"per_page": 3,
"current_page": 1,
"last_page": 1,
"data": [
{
"item_id": 项目id,
"sum_score": "项目分数",
"title": "维度名称"
},
]
},}
})
*/
public function getScore()
{
$user = $this->auth->getUserinfo();
$cid = $this->request->param('cid');
$sid = \db('study')->where('user_id', $user['id'])->value('id');
//获取学生的信息
$data = \db('study')->where('id', $sid)->field('avatar,name,earn_score')->find();
$data['avatar'] = cdnurl($data['avatar'], true);
//获取雷达维度
//halt($sid);
$model = new RadarScore();
$data['item'] = $model->where('campus_id',$cid)->where('study_id',$sid)->field('radar_id,score')
->paginate(9,false)
->each(function ($item,$key){
$item['title'] = \db('radar')->where('id',$item['radar_id'])->value('title');
$item['sum_score'] = $item['score'];
return $item;
});
$this->success('获取成功', $data);
}
}