|
@@ -7,6 +7,7 @@ use app\api\model\Study; |
|
@@ -7,6 +7,7 @@ use app\api\model\Study; |
7
|
use app\api\model\StudyScore;
|
7
|
use app\api\model\StudyScore;
|
8
|
use app\common\controller\Api;
|
8
|
use app\common\controller\Api;
|
9
|
use app\common\library\Auth;
|
9
|
use app\common\library\Auth;
|
|
|
10
|
+use app\common\model\ScoreLog;
|
10
|
use think\Db;
|
11
|
use think\Db;
|
11
|
|
12
|
|
12
|
/**
|
13
|
/**
|
|
@@ -22,57 +23,45 @@ class Index extends Api |
|
@@ -22,57 +23,45 @@ class Index extends Api |
22
|
* @ApiTitle (首页)
|
23
|
* @ApiTitle (首页)
|
23
|
* @ApiMethod (POST)
|
24
|
* @ApiMethod (POST)
|
24
|
* @ApiParams (name="campus", type="string", required=true, description="校区id[必填]")
|
25
|
* @ApiParams (name="campus", type="string", required=true, description="校区id[必填]")
|
25
|
- * @ApiParams (name="row", type="string", required=false, description="每页显示行数[非必填]")
|
|
|
26
|
- * @ApiParams (name="page", type="string", required=false, description="当前页[非必填]")
|
|
|
27
|
* @ApiReturn ({"code":状态码,
|
26
|
* @ApiReturn ({"code":状态码,
|
28
|
"msg":"提示信息"
|
27
|
"msg":"提示信息"
|
29
|
"time": "时间戳",
|
28
|
"time": "时间戳",
|
30
|
- "data": [
|
|
|
31
|
- "total": 所有数据,
|
|
|
32
|
- "per_page": 每页几行,
|
|
|
33
|
- "current_page": 当前页,
|
|
|
34
|
- "last_page": 最后一页,
|
|
|
35
|
"data": {
|
29
|
"data": {
|
36
|
- "id": 分数id,
|
|
|
37
|
- "sum_score": "总分",
|
|
|
38
|
- "study_id": '学生id',
|
|
|
39
|
- "study": "学生姓名",
|
|
|
40
|
- "active_study_score": 当前登录用户绑定的学生总分,
|
|
|
41
|
- "active_study_info": "当前登录用户绑定的学生"
|
|
|
42
|
- },
|
|
|
43
|
- ]
|
30
|
+ "id": '学生id',
|
|
|
31
|
+ "name": "学生姓名",
|
|
|
32
|
+ "score_num": "学生分数",
|
|
|
33
|
+ "rank": "排名"
|
|
|
34
|
+ }
|
44
|
})
|
35
|
})
|
45
|
*/
|
36
|
*/
|
46
|
public function index()
|
37
|
public function index()
|
47
|
{
|
38
|
{
|
48
|
$campus = $this->request->param('campus');
|
39
|
$campus = $this->request->param('campus');
|
49
|
- $row = $this->request->param('row');
|
|
|
50
|
- $page = $this->request->param('page');
|
|
|
51
|
- $row = $row ? $row : 10;
|
|
|
52
|
- $page = $page ? $page : 1;
|
|
|
53
|
if (empty($campus)) {
|
40
|
if (empty($campus)) {
|
54
|
$this->error('参数错误', ['status' => 2]);
|
41
|
$this->error('参数错误', ['status' => 2]);
|
55
|
}
|
42
|
}
|
56
|
$userinfo = $this->auth->getUserinfo();
|
43
|
$userinfo = $this->auth->getUserinfo();
|
57
|
- $sid = \db('study')->where('user_id', $userinfo['id'])->value('id');
|
|
|
58
|
- //个人排行榜
|
|
|
59
|
- $data = \db('study_score_log')
|
|
|
60
|
- ->field('id,SUM(score) as sum_score,study_id')
|
|
|
61
|
- ->where('campus_id', $campus)
|
|
|
62
|
- ->group('study_id')
|
|
|
63
|
- ->order('sum_score DESC')
|
|
|
64
|
- ->paginate($row, false, ['page' => $page])
|
|
|
65
|
- ->each(function ($item, $key) {
|
|
|
66
|
- $item['study'] = db('study')->where('id', $item['study_id'])->value('name');
|
|
|
67
|
- return $item;
|
|
|
68
|
- });
|
|
|
69
|
- $data['active_study_score'] = \db('study_score_log')
|
|
|
70
|
- ->where(['study_id' => $sid, 'campus_id' => $campus])
|
|
|
71
|
- ->sum('score');
|
|
|
72
|
- $data['active_study_info'] = \db('study')->where('id', $sid)->value('name');
|
|
|
73
|
- $this->success('获取成功', $data);
|
44
|
+ $sid = \db('study')->where('user_id', $userinfo['id'])->find();
|
|
|
45
|
+ $count = \db('study_score_log')->where(
|
|
|
46
|
+ [
|
|
|
47
|
+ 'study_id' => $sid['id'],
|
|
|
48
|
+ 'campus_id' => $campus,
|
|
|
49
|
+ ]
|
|
|
50
|
+ )->sum('score');
|
|
|
51
|
+ $data = \db('study_score_log')->field('study_id, SUM(score) as sum_score')->group('study_id')->order('sum_score', 'desc')->select();
|
|
|
52
|
+ $list = [];
|
|
|
53
|
+ foreach ($data as $k => $v) {
|
|
|
54
|
+ if ($v['study_id'] == $sid['id']) {
|
|
|
55
|
+ $list['id'] = $sid['id'];
|
|
|
56
|
+ $list['name'] = $sid['name'];
|
|
|
57
|
+ $list['score_num'] = $v['sum_score'];
|
|
|
58
|
+ $list['rank'] = $k + 1;
|
|
|
59
|
+ }
|
|
|
60
|
+ }
|
|
|
61
|
+ $this->success('获取成功', $list);
|
74
|
}
|
62
|
}
|
75
|
|
63
|
|
|
|
64
|
+
|
76
|
/**
|
65
|
/**
|
77
|
* @ApiTitle (获取轮播图)
|
66
|
* @ApiTitle (获取轮播图)
|
78
|
* @ApiMethod (POST)
|
67
|
* @ApiMethod (POST)
|
|
@@ -91,7 +80,8 @@ class Index extends Api |
|
@@ -91,7 +80,8 @@ class Index extends Api |
91
|
"createtime_text": "2023-03-07"
|
80
|
"createtime_text": "2023-03-07"
|
92
|
})
|
81
|
})
|
93
|
*/
|
82
|
*/
|
94
|
- public function getBanner(){
|
83
|
+ public function getBanner()
|
|
|
84
|
+ {
|
95
|
$data = \db('banner')
|
85
|
$data = \db('banner')
|
96
|
->order('createtime DESC')
|
86
|
->order('createtime DESC')
|
97
|
->select();
|
87
|
->select();
|
|
@@ -99,8 +89,8 @@ class Index extends Api |
|
@@ -99,8 +89,8 @@ class Index extends Api |
99
|
$data[$k]['images'] = cdnurl($v['images'], true);
|
89
|
$data[$k]['images'] = cdnurl($v['images'], true);
|
100
|
$data[$k]['url'] = cdnurl($v['url'], true);
|
90
|
$data[$k]['url'] = cdnurl($v['url'], true);
|
101
|
}
|
91
|
}
|
102
|
- if (!$data){
|
|
|
103
|
- $this->error('当前还没有轮播图',['status'=>2]);
|
92
|
+ if (!$data) {
|
|
|
93
|
+ $this->error('当前还没有轮播图', ['status' => 2]);
|
104
|
}
|
94
|
}
|
105
|
$this->success('获取轮播图成功', $data);
|
95
|
$this->success('获取轮播图成功', $data);
|
106
|
}
|
96
|
}
|
|
@@ -232,7 +222,7 @@ class Index extends Api |
|
@@ -232,7 +222,7 @@ class Index extends Api |
232
|
->order('sum_score DESC')
|
222
|
->order('sum_score DESC')
|
233
|
->paginate($row, false, ['page' => $page])
|
223
|
->paginate($row, false, ['page' => $page])
|
234
|
->each(function ($item, $key) {
|
224
|
->each(function ($item, $key) {
|
235
|
- $item['study'] = db('study')->where('id', $item['study_id'])->value('name');
|
225
|
+ $item['study_name'] = db('study')->where('id', $item['study_id'])->value('name');
|
236
|
return $item;
|
226
|
return $item;
|
237
|
});
|
227
|
});
|
238
|
//最终显示
|
228
|
//最终显示
|