正在显示
3 个修改的文件
包含
80 行增加
和
32 行删除
@@ -198,38 +198,6 @@ class Bind extends Api | @@ -198,38 +198,6 @@ class Bind extends Api | ||
198 | } | 198 | } |
199 | $model = new StudyScoreLog(); | 199 | $model = new StudyScoreLog(); |
200 | $model->addScore($id,$unique); | 200 | $model->addScore($id,$unique); |
201 | - $study = db('study')->where('unique', $unique)->field('id,grade,name,team,earn_score')->find(); | ||
202 | - $item = db('item')->where('id', $id)->field('score,title,campus_id')->find(); | ||
203 | - $team = \db('team')->where('title', $study['team'])->field('title,score')->find(); | ||
204 | - $sum1 = $team['score'] + $item['score']; //合计战队总分 | ||
205 | - $sum2 = $study['earn_score'] + $item['score']; //合计个人总分 | ||
206 | - Db::startTrans(); | ||
207 | - try { | ||
208 | - db('study_score_log')->insert([ | ||
209 | - 'item_id' => $id, | ||
210 | - 'campus_id' => $item['campus_id'], | ||
211 | - 'study_id' => $study['id'], | ||
212 | - 'team' => $study['team'], | ||
213 | - 'score' => $item['score'], | ||
214 | - 'memo' => $study['name'] . '参加' . $item['title'] . '加分', | ||
215 | - 'createtime' => time() | ||
216 | - ]); | ||
217 | - db('study') | ||
218 | - ->where('id', $study['id']) | ||
219 | - ->update([ | ||
220 | - 'earn_score' => $sum2, | ||
221 | - ]); | ||
222 | - \db('team') | ||
223 | - ->where('title', $study['team']) | ||
224 | - ->update([ | ||
225 | - 'score' => $sum1, | ||
226 | - 'updatetime' => time() | ||
227 | - ]); | ||
228 | - Db::commit(); | ||
229 | - } catch (Exception $e) { | ||
230 | - Db::rollback(); | ||
231 | - $this->error('连接错误', ['status' => 3]); | ||
232 | - } | ||
233 | $data = db('study')->where('unique', $unique)->field('name,gender')->find(); | 201 | $data = db('study')->where('unique', $unique)->field('name,gender')->find(); |
234 | if ($data['gender'] == 1){ | 202 | if ($data['gender'] == 1){ |
235 | $data['gender'] = '男'; | 203 | $data['gender'] = '男'; |
application/common/model/RadarScore.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace app\common\model; | ||
4 | + | ||
5 | +use think\Model; | ||
6 | + | ||
7 | +class RadarScore extends Model | ||
8 | +{ | ||
9 | + | ||
10 | + // 表名 | ||
11 | + protected $name = 'radar_score'; | ||
12 | + // 自动写入时间戳字段 | ||
13 | + protected $autoWriteTimestamp = 'int'; | ||
14 | + // 定义时间戳字段名 | ||
15 | + protected $createTime = 'createtime'; | ||
16 | + protected $updateTime = 'updatetime'; | ||
17 | + // 追加属性 | ||
18 | + protected $append = [ | ||
19 | + | ||
20 | + ]; | ||
21 | + | ||
22 | +} |
@@ -2,6 +2,8 @@ | @@ -2,6 +2,8 @@ | ||
2 | 2 | ||
3 | namespace app\common\model; | 3 | namespace app\common\model; |
4 | 4 | ||
5 | +use think\Db; | ||
6 | +use think\Exception; | ||
5 | use think\Model; | 7 | use think\Model; |
6 | 8 | ||
7 | class StudyScoreLog extends Model | 9 | class StudyScoreLog extends Model |
@@ -26,7 +28,63 @@ class StudyScoreLog extends Model | @@ -26,7 +28,63 @@ class StudyScoreLog extends Model | ||
26 | $item = new Item(); | 28 | $item = new Item(); |
27 | $stu = $study->where('unique',$unique)->find()->toArray(); | 29 | $stu = $study->where('unique',$unique)->find()->toArray(); |
28 | $xm = $item->where('id',$id)->find()->toArray(); | 30 | $xm = $item->where('id',$id)->find()->toArray(); |
31 | + $team = $team->where('title', $stu['team'])->field('title,score')->find(); | ||
32 | + $radar = explode(',',$xm['radar_ids']); | ||
33 | + $score = explode(',',$xm['score']); | ||
34 | + $sum_score = 0; | ||
35 | + $list = []; | ||
36 | + foreach ($score as $k) { | ||
37 | + $sum_score += $k; | ||
38 | + } | ||
39 | + //halt($sum_score); | ||
40 | + foreach ($radar as $k1 => $v1){ | ||
41 | + foreach ($score as $k2 => $v2){ | ||
42 | + if ($k1 == $k2){ | ||
43 | + $list[$k1]['radar'] = $v1; | ||
44 | + $list[$k1]['score'] = $v2; | ||
45 | + } | ||
46 | + } | ||
47 | + } | ||
48 | + //halt($list); | ||
49 | + $sum1 = $team['score'] + $sum_score; //合计战队总分 | ||
50 | + $sum2 = $stu['earn_score'] + $sum_score; //合计个人总分 | ||
51 | + $data = [ | ||
52 | + 'item_id' => $id, | ||
53 | + 'campus_ids' => $xm['campus_ids'], | ||
54 | + 'study_id' => $stu['id'], | ||
55 | + 'team' => $stu['team'], | ||
56 | + 'score' => $sum_score, | ||
57 | + 'memo' => $stu['name'] . '参加' . $xm['title'] . '加分', | ||
58 | + 'createtime' => time() | ||
59 | + ]; | ||
29 | 60 | ||
61 | + Db::startTrans(); | ||
62 | + try { | ||
63 | + $this->save($data); | ||
64 | + $study->save(['earn_score' => $sum2],['id'=>$stu['id']]); | ||
65 | + $team->save(['score' => $sum1,'updatetime' => time()],['title'=>$stu['team']]); | ||
66 | + foreach ($list as $key => $value){ | ||
67 | + $ronda_score = new RadarScore(); | ||
68 | + $res = $ronda_score->where(['study_id'=>$stu['id'],'radar_id'=>$value['radar']])->find(); | ||
69 | + if (empty($res)){ | ||
70 | + $resc = [ | ||
71 | + 'study_id'=>$stu['id'], | ||
72 | + 'radar_id'=>$value['radar'], | ||
73 | + 'campus_id'=>$xm['campus_ids'], | ||
74 | + 'score'=>$value['score'], | ||
75 | + 'createtime'=>time() | ||
76 | + ]; | ||
77 | + $ronda_score->save($resc); | ||
78 | + }else{ | ||
79 | + $ronda_score->where(['study_id'=>$stu['id'],'radar_id'=>$value['radar']])->update(['updatetime'=>time(), | ||
80 | + 'score'=>$res['score']+$value['score']]); | ||
81 | + } | ||
82 | + } | ||
83 | + Db::commit(); | ||
84 | + } catch (Exception $e) { | ||
85 | + Db::rollback(); | ||
86 | + $e->getMessage(); | ||
87 | + } | ||
30 | } | 88 | } |
31 | 89 | ||
32 | } | 90 | } |
-
请 注册 或 登录 后发表评论