UpdateCountController.class.php
3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* 更新考试统计接口
*/
namespace Frontend\Controller\Temp;
use Common\Service\PaperService;
use Think\Exception;
class UpdateCountController extends AbstractController
{
public $ep_id = null; // 试卷ID
public $domain = null; // 企业标识
/** @var PaperService 试卷信息表 */
protected $paper_s;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$this->ep_id = I('ep_id', 0, 'intval');
$this->domain = QY_DOMAIN;
// 实例化试卷表
$this->paper_s = new PaperService();
return true;
}
public function Index()
{
$ep_id = $this->ep_id;
$domain = $this->domain;
// 非空判断
if (empty($ep_id)) {
return true;
}
if (empty($domain)) {
return true;
}
// 获取试卷基本详情
$data = $this->paper_s->get($ep_id);
if (empty($data)) {
return true;
}
// 实例化think下的model类
$com_model = new \Think\Model();
$this->paper_s->start_trans();
try {
// 如果是系统阅卷
if ($data['marking_type'] == 1) {
// 将状态为待批阅的答卷修改为已批阅
$sql_one = 'UPDATE `oa_exam_answer_detail` SET `marking_status`=1 WHERE `marking_status`=0 AND ep_id=' . $ep_id . ' AND status<3 AND domain=\'' . $domain . '\'';
$com_model->execute($sql_one);
}
// 将答卷详情表状态为已批阅的统计分数更新到答卷表
$sql_two = 'UPDATE `oa_exam_answer` a INNER JOIN ( SELECT ea_id,sum(my_score) AS score FROM `oa_exam_answer_detail` WHERE `marking_status`=1 AND ep_id=' . $ep_id . ' GROUP BY ea_id )b SET a.my_score =b.score WHERE a.ea_id = b.ea_id AND status<3 AND domain=\'' . $domain . '\'';
$com_model->execute($sql_two);
// 将状态为已批阅且低于及格分数,答卷状态为已通过的答卷修改为未通过
$sql_three = 'UPDATE `oa_exam_answer` b INNER JOIN ( SELECT ea_id,score FROM ( SELECT ea_id,sum(my_score) AS score FROM `oa_exam_answer_detail` WHERE `marking_status`=1 AND `ep_id`=' . $ep_id . ' GROUP BY ea_id ) as a WHERE a.score < ' . $data['pass_score'] . ' ) c SET b.my_is_pass=0 WHERE b.ea_id = c.ea_id AND status<3 AND domain=\'' . $domain . '\'';
$com_model->execute($sql_three);
$this->paper_s->commit();
} catch (Exception $e) {
// 事务回滚
$this->paper_s->rollback();
}
return true;
}
/**
* 重置统计状态
*
* @return bool
*/
public function ResetStatus()
{
$ep_id = $this->ep_id;
$domain = $this->domain;
// 非空判断
if (empty($ep_id)) {
return true;
}
if (empty($domain)) {
return true;
}
// 实例化think下的model类
$com_model = new \Think\Model();
$this->paper_s->start_trans();
try {
// 更新答卷详情表的计划任务字段状态
$sql_one = 'UPDATE `oa_exam_answer_detail` SET `cron_status`=0 WHERE ep_id=' . $ep_id . ' AND cron_status=1 AND status<3 AND domain=\'' . $domain . '\'';
$com_model->execute($sql_one);
// 删除统计表数据
$sql_two = 'DELETE FROM `oa_exam_statistics` WHERE ep_id = ' . $ep_id . ' and status < 3 and domain = \'' . $domain . '\'';
$com_model->execute($sql_two);
$this->paper_s->commit();
} catch (Exception $e) {
// 事务回滚
$this->paper_s->rollback();
}
return true;
}
}