|
@@ -3,7 +3,10 @@ |
|
@@ -3,7 +3,10 @@ |
3
|
namespace app\common\model;
|
3
|
namespace app\common\model;
|
4
|
|
4
|
|
5
|
use think\Db;
|
5
|
use think\Db;
|
|
|
6
|
+use think\db\exception\DataNotFoundException;
|
|
|
7
|
+use think\db\exception\ModelNotFoundException;
|
6
|
use think\Exception;
|
8
|
use think\Exception;
|
|
|
9
|
+use think\exception\DbException;
|
7
|
use think\Model;
|
10
|
use think\Model;
|
8
|
|
11
|
|
9
|
class StudyScoreLog extends Model
|
12
|
class StudyScoreLog extends Model
|
|
@@ -22,30 +25,30 @@ class StudyScoreLog extends Model |
|
@@ -22,30 +25,30 @@ class StudyScoreLog extends Model |
22
|
|
25
|
|
23
|
|
26
|
|
24
|
//加分
|
27
|
//加分
|
25
|
- public function addScore($id,$unique){
|
28
|
+ public function addScore($id, $unique)
|
|
|
29
|
+ {
|
26
|
$study = new Study();
|
30
|
$study = new Study();
|
27
|
$team = new Team();
|
31
|
$team = new Team();
|
28
|
$item = new Item();
|
32
|
$item = new Item();
|
29
|
- $stu = $study->where('unique',$unique)->find()->toArray();
|
|
|
30
|
- $xm = $item->where('id',$id)->find()->toArray();
|
33
|
+ $stu = $study->where('unique', $unique)->find()->toArray();
|
|
|
34
|
+ $xm = $item->where('id', $id)->find()->toArray();
|
31
|
$team = $team->where('title', $stu['team'])->field('title,score')->find();
|
35
|
$team = $team->where('title', $stu['team'])->field('title,score')->find();
|
32
|
- $radar = explode(',',$xm['radar_ids']);
|
|
|
33
|
- $score = explode(',',$xm['score']);
|
36
|
+ $radar = explode(',', $xm['radar_ids']);
|
|
|
37
|
+ $score = explode(',', $xm['score']);
|
34
|
$sum_score = 0;
|
38
|
$sum_score = 0;
|
35
|
$list = [];
|
39
|
$list = [];
|
36
|
foreach ($score as $k) {
|
40
|
foreach ($score as $k) {
|
37
|
$sum_score += $k;
|
41
|
$sum_score += $k;
|
38
|
}
|
42
|
}
|
39
|
//halt($sum_score);
|
43
|
//halt($sum_score);
|
40
|
- foreach ($radar as $k1 => $v1){
|
|
|
41
|
- foreach ($score as $k2 => $v2){
|
|
|
42
|
- if ($k1 == $k2){
|
44
|
+ foreach ($radar as $k1 => $v1) {
|
|
|
45
|
+ foreach ($score as $k2 => $v2) {
|
|
|
46
|
+ if ($k1 == $k2) {
|
43
|
$list[$k1]['radar'] = $v1;
|
47
|
$list[$k1]['radar'] = $v1;
|
44
|
$list[$k1]['score'] = $v2;
|
48
|
$list[$k1]['score'] = $v2;
|
45
|
}
|
49
|
}
|
46
|
}
|
50
|
}
|
47
|
}
|
51
|
}
|
48
|
- //halt($list);
|
|
|
49
|
$sum1 = $team['score'] + $sum_score; //合计战队总分
|
52
|
$sum1 = $team['score'] + $sum_score; //合计战队总分
|
50
|
$sum2 = $stu['earn_score'] + $sum_score; //合计个人总分
|
53
|
$sum2 = $stu['earn_score'] + $sum_score; //合计个人总分
|
51
|
$data = [
|
54
|
$data = [
|
|
@@ -57,34 +60,33 @@ class StudyScoreLog extends Model |
|
@@ -57,34 +60,33 @@ class StudyScoreLog extends Model |
57
|
'memo' => $stu['name'] . '参加' . $xm['title'] . '加分',
|
60
|
'memo' => $stu['name'] . '参加' . $xm['title'] . '加分',
|
58
|
'createtime' => time()
|
61
|
'createtime' => time()
|
59
|
];
|
62
|
];
|
60
|
-
|
|
|
61
|
Db::startTrans();
|
63
|
Db::startTrans();
|
62
|
try {
|
64
|
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){
|
65
|
+ $this->allowField(true)->save($data);
|
|
|
66
|
+ $study->save(['earn_score' => $sum2], ['id' => $stu['id']]);
|
|
|
67
|
+ $team->save(['score' => $sum1, 'updatetime' => time()], ['title' => $stu['team']]);
|
|
|
68
|
+ foreach ($list as $key => $value) {
|
67
|
$ronda_score = new RadarScore();
|
69
|
$ronda_score = new RadarScore();
|
68
|
- $res = $ronda_score->where(['study_id'=>$stu['id'],'radar_id'=>$value['radar']])->find();
|
|
|
69
|
- if (empty($res)){
|
70
|
+
|
|
|
71
|
+ $res = $ronda_score->where(['study_id' => $stu['id'], 'radar_id' => $value['radar']])->find();
|
|
|
72
|
+ if (empty($res)) {
|
70
|
$resc = [
|
73
|
$resc = [
|
71
|
- 'study_id'=>$stu['id'],
|
|
|
72
|
- 'radar_id'=>$value['radar'],
|
|
|
73
|
- 'campus_id'=>$xm['campus_ids'],
|
|
|
74
|
- 'score'=>$value['score'],
|
|
|
75
|
- 'createtime'=>time()
|
74
|
+ 'study_id' => $stu['id'],
|
|
|
75
|
+ 'radar_id' => $value['radar'],
|
|
|
76
|
+ 'campus_ids' => $xm['campus_ids'],
|
|
|
77
|
+ 'score' => $value['score'],
|
|
|
78
|
+ 'createtime' => time()
|
76
|
];
|
79
|
];
|
77
|
$ronda_score->save($resc);
|
80
|
$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
|
+ } else {
|
|
|
82
|
+ $ronda_score->where(['study_id' => $stu['id'], 'radar_id' => $value['radar']])->update(['updatetime' => time(),
|
|
|
83
|
+ 'score' => $res['score'] + $value['score']]);
|
81
|
}
|
84
|
}
|
82
|
}
|
85
|
}
|
83
|
Db::commit();
|
86
|
Db::commit();
|
84
|
} catch (Exception $e) {
|
87
|
} catch (Exception $e) {
|
85
|
Db::rollback();
|
88
|
Db::rollback();
|
86
|
- $e->getMessage();
|
|
|
87
|
- }
|
|
|
88
|
}
|
89
|
}
|
89
|
|
90
|
|
|
|
91
|
+ }
|
90
|
} |
92
|
} |