...
|
...
|
@@ -7,6 +7,7 @@ use app\api\model\Study; |
|
|
use app\api\model\StudyScore;
|
|
|
use app\common\controller\Api;
|
|
|
use app\common\library\Auth;
|
|
|
use app\common\model\ScoreLog;
|
|
|
use think\Db;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -22,57 +23,45 @@ class Index extends Api |
|
|
* @ApiTitle (首页)
|
|
|
* @ApiMethod (POST)
|
|
|
* @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": "当前登录用户绑定的学生"
|
|
|
},
|
|
|
]
|
|
|
"id": '学生id',
|
|
|
"name": "学生姓名",
|
|
|
"score_num": "学生分数",
|
|
|
"rank": "排名"
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
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);
|
|
|
$sid = \db('study')->where('user_id', $userinfo['id'])->find();
|
|
|
$count = \db('study_score_log')->where(
|
|
|
[
|
|
|
'study_id' => $sid['id'],
|
|
|
'campus_id' => $campus,
|
|
|
]
|
|
|
)->sum('score');
|
|
|
$data = \db('study_score_log')->field('study_id, SUM(score) as sum_score')->group('study_id')->order('sum_score', 'desc')->select();
|
|
|
$list = [];
|
|
|
foreach ($data as $k => $v) {
|
|
|
if ($v['study_id'] == $sid['id']) {
|
|
|
$list['id'] = $sid['id'];
|
|
|
$list['name'] = $sid['name'];
|
|
|
$list['score_num'] = $v['sum_score'];
|
|
|
$list['rank'] = $k + 1;
|
|
|
}
|
|
|
}
|
|
|
$this->success('获取成功', $list);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (获取轮播图)
|
|
|
* @ApiMethod (POST)
|
...
|
...
|
@@ -91,7 +80,8 @@ class Index extends Api |
|
|
"createtime_text": "2023-03-07"
|
|
|
})
|
|
|
*/
|
|
|
public function getBanner(){
|
|
|
public function getBanner()
|
|
|
{
|
|
|
$data = \db('banner')
|
|
|
->order('createtime DESC')
|
|
|
->select();
|
...
|
...
|
@@ -99,8 +89,8 @@ class Index extends Api |
|
|
$data[$k]['images'] = cdnurl($v['images'], true);
|
|
|
$data[$k]['url'] = cdnurl($v['url'], true);
|
|
|
}
|
|
|
if (!$data){
|
|
|
$this->error('当前还没有轮播图',['status'=>2]);
|
|
|
if (!$data) {
|
|
|
$this->error('当前还没有轮播图', ['status' => 2]);
|
|
|
}
|
|
|
$this->success('获取轮播图成功', $data);
|
|
|
}
|
...
|
...
|
@@ -122,7 +112,7 @@ class Index extends Api |
|
|
"updatetime": "更新时间",
|
|
|
"is_url_text": "否",
|
|
|
"createtime_text": "2023-03-07"
|
|
|
})
|
|
|
})
|
|
|
*/
|
|
|
public function banner()
|
|
|
{
|
...
|
...
|
@@ -232,7 +222,7 @@ class Index extends Api |
|
|
->order('sum_score DESC')
|
|
|
->paginate($row, false, ['page' => $page])
|
|
|
->each(function ($item, $key) {
|
|
|
$item['study'] = db('study')->where('id', $item['study_id'])->value('name');
|
|
|
$item['study_name'] = db('study')->where('id', $item['study_id'])->value('name');
|
|
|
return $item;
|
|
|
});
|
|
|
//最终显示
|
...
|
...
|
|