作者 开飞机的舒克

战队排行榜修改

... ... @@ -39,14 +39,14 @@ class Bind extends Api
if (empty($unique)) {
$this->error('参数错误', ['status' => 2]);
}
// $res = \db('study')->where('unique',$unique)->value('user_id');
// if (!empty($res)){
// $this->error('当前学生已经被绑定了');
// }
$res = \db('study')->where('unique',$unique)->value('user_id');
if (!empty($res)){
$this->error('当前学生已经被绑定了');
}
$is_bind = db('user')->where('id', $user['id'])->value('bind_study');
// if ($is_bind == 1) {
// $this->error('您当前已经绑定过学生了,请勿重复操作', $is_bind);
// }
if ($is_bind == 1) {
$this->error('您当前已经绑定过学生了,请勿重复操作', $is_bind);
}
Db::startTrans();
try {
db('study')
... ... @@ -87,14 +87,14 @@ class Bind extends Api
if (empty($unique)) {
$this->error('参数错误', ['status' => 2]);
}
// $res = \db('study')->where('unique',$unique)->value('user_id');
// if (!empty($res)){
// $this->error('当前学生已经被绑定了');
// }
$res = \db('study')->where('unique',$unique)->value('user_id');
if (!empty($res)){
$this->error('当前学生已经被绑定了');
}
$is_bind = db('user')->where('id', $user['id'])->value('bind_study');
// if ($is_bind == 1) {
// $this->error('您当前已经绑定过学生了,请勿重复操作', $is_bind);
// }
if ($is_bind == 1) {
$this->error('您当前已经绑定过学生了,请勿重复操作', $is_bind);
}
Db::startTrans();
try {
db('study')
... ... @@ -229,38 +229,8 @@ class Bind extends Api
if (empty($unique) && empty($id)) {
$this->error('参数错误', ['status' => 2]);
}
$study = db('study')->where('unique', $unique)->field('id,grade,name,team,earn_score')->find();
$item = db('item')->where('id', $id)->field('score,title,campus_id')->find();
$team = \db('team')->where('title', $study['team'])->field('title,score')->find();
$sum1 = $team['score'] + $item['score']; //合计战队总分
$sum2 = $study['earn_score'] + $item['score']; //合计个人总分
Db::startTrans();
try {
db('study_score_log')->insert([
'item_id' => $id,
'campus_id' => $item['campus_id'],
'study_id' => $study['id'],
'team' => $study['team'],
'score' => $item['score'],
'memo' => $study['name'] . '参加' . $item['title'] . '加分',
'createtime' => time()
]);
db('study')
->where('id', $study['id'])
->update([
'earn_score' => $sum2,
]);
\db('team')
->where('title', $study['team'])
->update([
'score' => $sum1,
'updatetime' => time()
]);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error('连接错误', ['status' => 3]);
}
$model = new StudyScoreLog();
$model->addScore($id,$unique);
$data = db('study')->where('unique', $unique)->field('name,gender')->find();
if ($data['gender'] == 1){
$data['gender'] = '男';
... ...
... ... @@ -185,18 +185,12 @@ class Index extends Api
"msg":"提示信息"
"time": "时间戳",
"data": [
"total": 所有数据,
"per_page": 每页几行,
"current_page": 当前页,
"last_page": 最后一页,
"data": [
{
"title": "战队名称",
"score": "战队总分",
"team": 战队
},
]
},
],
"status": 1
})
*/
... ... @@ -213,12 +207,12 @@ class Index extends Api
$data = \db('study_score_log l')
->distinct('l.team')
->join('team t', 't.title = l.team')
->where('l.campus_id', $campus)
->field('t.title,t.score,l.team,l.campus_id')
->whereIn('l.campus_ids', $campus)
->field('t.title,t.score,l.team,l.campus_ids')
->order('t.score DESC')
->paginate($row, false, ['page' => $page])
->each(function ($item, $key) {
$res = db('study_score_log')->where('campus_id', $item['campus_id'])->sum('score');
$res = db('study_score_log')->where('campus_ids', $item['campus_ids'])->sum('score');
$item['score'] = floor($item['score']);
$item['percent'] = round(($item['score'] * 0.6) / $res * 100, 2);
return $item;
... ... @@ -264,7 +258,7 @@ class Index extends Api
//个人排行榜
$data = \db('study_score_log')
->field('id,SUM(score) as sum_score,study_id')
->where('campus_id', $campus)
->whereIn('campus_ids', $campus)
->group('study_id')
->order('sum_score DESC')
->paginate($row, false, ['page' => $page])
... ...
... ... @@ -2188,18 +2188,12 @@
"msg":"提示信息"
"time": "时间戳",
"data": [
"total": 所有数据,
"per_page": 每页几行,
"current_page": 当前页,
"last_page": 最后一页,
"data": [
{
"title": "战队名称",
"score": "战队总分",
"team": 战队
},
]
},
],
"status": 1
}</pre>
</div>
... ... @@ -6330,7 +6324,7 @@
</div>
<div class="col-md-6" align="right">
Generated on 2023-04-12 19:20:53 <a href="./" target="_blank">校园活动</a>
Generated on 2023-04-13 08:39:28 <a href="./" target="_blank">校园活动</a>
</div>
</div>
... ...