StatisticsController.class.php
2.55 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
<?php
/**
* 考试定时任务
* User: heyuelong
* Date: 2017年06月23日16:37:37
*/
namespace Frontend\Controller\Callback;
use Com\Service;
use Common\Service\AnswerDetailService;
use Common\Service\AnswerService;
use Common\Service\PaperService;
use VcySDK\Cron;
class StatisticsController extends AbstractController
{
// 默认执行条数
const LIMIT = 500;
// 锁定计划任务数据状态
const CRON_CLOSE = 3;
/** @var AnswerDetailService */
protected $answer_serv;
/** @var AnswerDetailService */
protected $answer_detail_serv;
/** @var PaperService */
protected $papar_serv;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$this->answer_serv = new AnswerService();
$this->answer_detail_serv = new AnswerDetailService();
$this->papar_serv = new PaperService();
return true;
}
public function Index()
{
// 获取需要发送的试卷id
$back = $this->callBackData;
$ep_id = $back['ep_id'];
if (empty($ep_id)) {
$ep_id = I('get.ep_id');
}
$time = MILLI_TIME - 900000;
$this->answer_detail_serv->update_by_conds(array('cron_status' => self::CRON_CLOSE, 'updated<?' => $time),
array('cron_status' => AnswerService::CRON_UNDO_STATE));
$condition = array(
'cron_status' => AnswerService::CRON_UNDO_STATE,
);
$condition['ep_id'] = $ep_id;
$order_by = array('ead_id' => 'DESC');
$data = $this->answer_detail_serv->list_by_conds($condition, self::LIMIT, $order_by);
// 统计数据处理
if (!empty($data)) {
$ead_ids = array_column($data, 'ead_id');
$this->answer_detail_serv->update_by_conds(array('ead_id' => $ead_ids),
array('cron_status' => self::CRON_CLOSE));
$this->answer_detail_serv->cron_statistics($data, $ep_id);
}
$paper = $this->papar_serv->get($ep_id);
if ($paper['end_time'] < $paper['makeup_end_time']) {
$end_time = $paper['makeup_end_time'];
} else {
$end_time = $paper['end_time'];
}
$del_time = $end_time + 2 * 24 * 60 * 60 * 1000;
if ($del_time < MILLI_TIME && !empty($paper['cron_statistics'])) {
// 考试结束后两天删除统计任务
$cron = new Cron(\VcySDK\Service::instance());
$cron->delete($paper['cron_statistics']);
}
return true;
}
}