Index.php
7.1 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
<?php
namespace app\api\controller;
use app\api\model\Banner;
use app\api\model\Study;
use app\api\model\StudyScore;
use app\common\controller\Api;
use app\common\library\Auth;
use think\Db;
/**
* 首页接口
* @ApiWeigh (98)
*/
class Index extends Api
{
protected $noNeedLogin = ['teamRank', 'personRank'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (首页)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="campus", type="string", required=true, description="校区id[必填]")
* @ApiParams (name="row", type="string", required=false, description="每页显示行数[非必填]")
* @ApiParams (name="page", type="string", required=false, description="当前页[非必填]")
* @ApiReturn ({"code":状态码,
"msg":"提示信息"
"time": "时间戳",
"data": [
"total": 所有数据,
"per_page": 每页几行,
"current_page": 当前页,
"last_page": 最后一页,
"data": {
"id": 分数id,
"sum_score": "总分",
"study_id": '学生id',
"study": "学生姓名",
"active_study_score": 当前登录用户绑定的学生总分,
"active_study_info": "当前登录用户绑定的学生"
},
]
})
*/
public function index()
{
$campus = $this->request->param('campus');
$row = $this->request->param('row');
$page = $this->request->param('page');
$row = $row ? $row : 10;
$page = $page ? $page : 1;
if (empty($campus)) {
$this->error('参数错误', ['status' => 2]);
}
$userinfo = $this->auth->getUserinfo();
$sid = \db('study')->where('user_id', $userinfo['id'])->value('id');
//个人排行榜
$data = \db('study_score_log')
->field('id,SUM(score) as sum_score,study_id')
->where('campus_id', $campus)
->group('study_id')
->order('sum_score DESC')
->paginate($row, false, ['page' => $page])
->each(function ($item, $key) {
$item['study'] = db('study')->where('id', $item['study_id'])->value('name');
return $item;
});
$data['active_study_score'] = \db('study_score_log')
->where(['study_id' => $sid, 'campus_id' => $campus])
->sum('score');
$data['active_study_info'] = \db('study')->where('id', $sid)->value('name');
$this->success('获取成功', [$data, 'status' => 1]);
}
/**
* @ApiTitle (轮播跳转)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="string", required=true, description="轮播图id")
* @ApiReturn ({"code":状态码,
"msg":"提示信息"
"time": "时间戳",
"data": [
"id": 轮播图id,
"title": "轮播图标题",
"images": "轮播图地址",
"is_url": "是否为外链",
"url": "链接地址",
"createtime": “创建时间”,
"updatetime": "更新时间",
"is_url_text": "否",
"createtime_text": "2023-03-07"
})
*/
public function banner()
{
$id = $this->request->param('id');
if (empty($id)) {
$this->error('参数错误', ['status' => 2]);
}
$data = Banner::where('id', $id)
->order('createtime DESC')
->select();
foreach ($data as $k => $v) {
$data[$k]['images'] = cdnurl($v['images'], true);
if ($data[$k]['is_url'] == 1) {
$data[$k]['url'] = cdnurl($v['url'], true);
} elseif ($data[$k]['is_url'] == 0) {
$v['url'] = null;
}
}
$this->success('获取轮播图成功', [$data, 'status' => 1]);
}
/**
* @ApiTitle (战队排行榜)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="campus", type="string", required=true, description="校区id[必填]")
* @ApiParams (name="row", type="string", required=false, description="每页显示行数[非必填]")
* @ApiParams (name="page", type="string", required=false, description="当前页[非必填]")
* @ApiReturn ({"code":状态码,
"msg":"提示信息"
"time": "时间戳",
"data": [
"total": 所有数据,
"per_page": 每页几行,
"current_page": 当前页,
"last_page": 最后一页,
"data": [
{
"title": "战队名称",
"score": "战队总分",
"team_id": 战队id
},
]
},
"status": 1
})
*/
public function teamRank()
{
$row = $this->request->param('row');
$page = $this->request->param('page');
$row = $row ? $row : 10;
$page = $page ? $page : 1;
$campus = $this->request->param('campus');
if (empty($campus)) {
$this->error('参数错误', ['status' => 2]);
}
$data = \db('study_score_log l')
->distinct('l.team_id')
->join('team t', 't.id = l.team_id')
->where('l.campus_id', $campus)
->field('t.title,t.score,l.team_id')
->order('t.score DESC')
->paginate($row, false, ['page' => $page]);
//最终显示
$this->success('战队排行榜', [$data, 'status' => 1]);
}
/**
* @ApiTitle (个人排行榜)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="campus", type="string", required=true, description="校区id[必填]")
* @ApiParams (name="row", type="string", required=false, description="每页显示行数[非必填]")
* @ApiParams (name="page", type="string", required=false, description="当前页[非必填]")
* @ApiReturn ({"code":状态码,
"msg":"提示信息"
"time": "时间戳",
"data": [
"total": 所有数据,
"per_page": 每页几行,
"current_page": 当前页,
"last_page": 最后一页,
"data": {
"id": 分数id,
"sum_score": "总分",
"study_id": '学生id',
"study": "学生姓名",
},
]
})
*/
public function personRank()
{
$campus = $this->request->param('campus');
$row = $this->request->param('row');
$page = $this->request->param('page');
$user = $this->auth->getUserinfo();
$row = $row ? $row : 10;
$page = $page ? $page : 1;
if (empty($campus)) {
$this->error('参数错误', ['status' => 2]);
}
//个人排行榜
$data = \db('study_score_log')
->field('id,SUM(score) as sum_score,study_id')
->where('campus_id', $campus)
->group('study_id')
->order('sum_score DESC')
->paginate($row, false, ['page' => $page])
->each(function ($item, $key) {
$item['study'] = db('study')->where('id', $item['study_id'])->value('name');
return $item;
});
//最终显示
$this->success('个人排行榜', [$data, 'status' => 1]);
}
}