正在显示
3 个修改的文件
包含
23 行增加
和
65 行删除
@@ -39,14 +39,14 @@ class Bind extends Api | @@ -39,14 +39,14 @@ class Bind extends Api | ||
39 | if (empty($unique)) { | 39 | if (empty($unique)) { |
40 | $this->error('参数错误', ['status' => 2]); | 40 | $this->error('参数错误', ['status' => 2]); |
41 | } | 41 | } |
42 | -// $res = \db('study')->where('unique',$unique)->value('user_id'); | ||
43 | -// if (!empty($res)){ | ||
44 | -// $this->error('当前学生已经被绑定了'); | ||
45 | -// } | 42 | + $res = \db('study')->where('unique',$unique)->value('user_id'); |
43 | + if (!empty($res)){ | ||
44 | + $this->error('当前学生已经被绑定了'); | ||
45 | + } | ||
46 | $is_bind = db('user')->where('id', $user['id'])->value('bind_study'); | 46 | $is_bind = db('user')->where('id', $user['id'])->value('bind_study'); |
47 | -// if ($is_bind == 1) { | ||
48 | -// $this->error('您当前已经绑定过学生了,请勿重复操作', $is_bind); | ||
49 | -// } | 47 | + if ($is_bind == 1) { |
48 | + $this->error('您当前已经绑定过学生了,请勿重复操作', $is_bind); | ||
49 | + } | ||
50 | Db::startTrans(); | 50 | Db::startTrans(); |
51 | try { | 51 | try { |
52 | db('study') | 52 | db('study') |
@@ -87,14 +87,14 @@ class Bind extends Api | @@ -87,14 +87,14 @@ class Bind extends Api | ||
87 | if (empty($unique)) { | 87 | if (empty($unique)) { |
88 | $this->error('参数错误', ['status' => 2]); | 88 | $this->error('参数错误', ['status' => 2]); |
89 | } | 89 | } |
90 | -// $res = \db('study')->where('unique',$unique)->value('user_id'); | ||
91 | -// if (!empty($res)){ | ||
92 | -// $this->error('当前学生已经被绑定了'); | ||
93 | -// } | 90 | + $res = \db('study')->where('unique',$unique)->value('user_id'); |
91 | + if (!empty($res)){ | ||
92 | + $this->error('当前学生已经被绑定了'); | ||
93 | + } | ||
94 | $is_bind = db('user')->where('id', $user['id'])->value('bind_study'); | 94 | $is_bind = db('user')->where('id', $user['id'])->value('bind_study'); |
95 | -// if ($is_bind == 1) { | ||
96 | -// $this->error('您当前已经绑定过学生了,请勿重复操作', $is_bind); | ||
97 | -// } | 95 | + if ($is_bind == 1) { |
96 | + $this->error('您当前已经绑定过学生了,请勿重复操作', $is_bind); | ||
97 | + } | ||
98 | Db::startTrans(); | 98 | Db::startTrans(); |
99 | try { | 99 | try { |
100 | db('study') | 100 | db('study') |
@@ -229,38 +229,8 @@ class Bind extends Api | @@ -229,38 +229,8 @@ class Bind extends Api | ||
229 | if (empty($unique) && empty($id)) { | 229 | if (empty($unique) && empty($id)) { |
230 | $this->error('参数错误', ['status' => 2]); | 230 | $this->error('参数错误', ['status' => 2]); |
231 | } | 231 | } |
232 | - $study = db('study')->where('unique', $unique)->field('id,grade,name,team,earn_score')->find(); | ||
233 | - $item = db('item')->where('id', $id)->field('score,title,campus_id')->find(); | ||
234 | - $team = \db('team')->where('title', $study['team'])->field('title,score')->find(); | ||
235 | - $sum1 = $team['score'] + $item['score']; //合计战队总分 | ||
236 | - $sum2 = $study['earn_score'] + $item['score']; //合计个人总分 | ||
237 | - Db::startTrans(); | ||
238 | - try { | ||
239 | - db('study_score_log')->insert([ | ||
240 | - 'item_id' => $id, | ||
241 | - 'campus_id' => $item['campus_id'], | ||
242 | - 'study_id' => $study['id'], | ||
243 | - 'team' => $study['team'], | ||
244 | - 'score' => $item['score'], | ||
245 | - 'memo' => $study['name'] . '参加' . $item['title'] . '加分', | ||
246 | - 'createtime' => time() | ||
247 | - ]); | ||
248 | - db('study') | ||
249 | - ->where('id', $study['id']) | ||
250 | - ->update([ | ||
251 | - 'earn_score' => $sum2, | ||
252 | - ]); | ||
253 | - \db('team') | ||
254 | - ->where('title', $study['team']) | ||
255 | - ->update([ | ||
256 | - 'score' => $sum1, | ||
257 | - 'updatetime' => time() | ||
258 | - ]); | ||
259 | - Db::commit(); | ||
260 | - } catch (Exception $e) { | ||
261 | - Db::rollback(); | ||
262 | - $this->error('连接错误', ['status' => 3]); | ||
263 | - } | 232 | + $model = new StudyScoreLog(); |
233 | + $model->addScore($id,$unique); | ||
264 | $data = db('study')->where('unique', $unique)->field('name,gender')->find(); | 234 | $data = db('study')->where('unique', $unique)->field('name,gender')->find(); |
265 | if ($data['gender'] == 1){ | 235 | if ($data['gender'] == 1){ |
266 | $data['gender'] = '男'; | 236 | $data['gender'] = '男'; |
@@ -185,18 +185,12 @@ class Index extends Api | @@ -185,18 +185,12 @@ class Index extends Api | ||
185 | "msg":"提示信息" | 185 | "msg":"提示信息" |
186 | "time": "时间戳", | 186 | "time": "时间戳", |
187 | "data": [ | 187 | "data": [ |
188 | - "total": 所有数据, | ||
189 | - "per_page": 每页几行, | ||
190 | - "current_page": 当前页, | ||
191 | - "last_page": 最后一页, | ||
192 | - "data": [ | ||
193 | { | 188 | { |
194 | "title": "战队名称", | 189 | "title": "战队名称", |
195 | "score": "战队总分", | 190 | "score": "战队总分", |
196 | "team": 战队 | 191 | "team": 战队 |
197 | }, | 192 | }, |
198 | - ] | ||
199 | - }, | 193 | + ], |
200 | "status": 1 | 194 | "status": 1 |
201 | }) | 195 | }) |
202 | */ | 196 | */ |
@@ -213,12 +207,12 @@ class Index extends Api | @@ -213,12 +207,12 @@ class Index extends Api | ||
213 | $data = \db('study_score_log l') | 207 | $data = \db('study_score_log l') |
214 | ->distinct('l.team') | 208 | ->distinct('l.team') |
215 | ->join('team t', 't.title = l.team') | 209 | ->join('team t', 't.title = l.team') |
216 | - ->where('l.campus_id', $campus) | ||
217 | - ->field('t.title,t.score,l.team,l.campus_id') | 210 | + ->whereIn('l.campus_ids', $campus) |
211 | + ->field('t.title,t.score,l.team,l.campus_ids') | ||
218 | ->order('t.score DESC') | 212 | ->order('t.score DESC') |
219 | ->paginate($row, false, ['page' => $page]) | 213 | ->paginate($row, false, ['page' => $page]) |
220 | ->each(function ($item, $key) { | 214 | ->each(function ($item, $key) { |
221 | - $res = db('study_score_log')->where('campus_id', $item['campus_id'])->sum('score'); | 215 | + $res = db('study_score_log')->where('campus_ids', $item['campus_ids'])->sum('score'); |
222 | $item['score'] = floor($item['score']); | 216 | $item['score'] = floor($item['score']); |
223 | $item['percent'] = round(($item['score'] * 0.6) / $res * 100, 2); | 217 | $item['percent'] = round(($item['score'] * 0.6) / $res * 100, 2); |
224 | return $item; | 218 | return $item; |
@@ -264,7 +258,7 @@ class Index extends Api | @@ -264,7 +258,7 @@ class Index extends Api | ||
264 | //个人排行榜 | 258 | //个人排行榜 |
265 | $data = \db('study_score_log') | 259 | $data = \db('study_score_log') |
266 | ->field('id,SUM(score) as sum_score,study_id') | 260 | ->field('id,SUM(score) as sum_score,study_id') |
267 | - ->where('campus_id', $campus) | 261 | + ->whereIn('campus_ids', $campus) |
268 | ->group('study_id') | 262 | ->group('study_id') |
269 | ->order('sum_score DESC') | 263 | ->order('sum_score DESC') |
270 | ->paginate($row, false, ['page' => $page]) | 264 | ->paginate($row, false, ['page' => $page]) |
@@ -2188,18 +2188,12 @@ | @@ -2188,18 +2188,12 @@ | ||
2188 | "msg":"提示信息" | 2188 | "msg":"提示信息" |
2189 | "time": "时间戳", | 2189 | "time": "时间戳", |
2190 | "data": [ | 2190 | "data": [ |
2191 | - "total": 所有数据, | ||
2192 | - "per_page": 每页几行, | ||
2193 | - "current_page": 当前页, | ||
2194 | - "last_page": 最后一页, | ||
2195 | - "data": [ | ||
2196 | { | 2191 | { |
2197 | "title": "战队名称", | 2192 | "title": "战队名称", |
2198 | "score": "战队总分", | 2193 | "score": "战队总分", |
2199 | "team": 战队 | 2194 | "team": 战队 |
2200 | }, | 2195 | }, |
2201 | - ] | ||
2202 | - }, | 2196 | + ], |
2203 | "status": 1 | 2197 | "status": 1 |
2204 | }</pre> | 2198 | }</pre> |
2205 | </div> | 2199 | </div> |
@@ -6330,7 +6324,7 @@ | @@ -6330,7 +6324,7 @@ | ||
6330 | 6324 | ||
6331 | </div> | 6325 | </div> |
6332 | <div class="col-md-6" align="right"> | 6326 | <div class="col-md-6" align="right"> |
6333 | - Generated on 2023-04-12 19:20:53 <a href="./" target="_blank">校园活动</a> | 6327 | + Generated on 2023-04-13 08:39:28 <a href="./" target="_blank">校园活动</a> |
6334 | </div> | 6328 | </div> |
6335 | </div> | 6329 | </div> |
6336 | 6330 |
-
请 注册 或 登录 后发表评论