SendController.class.php
2.76 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
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 17/7/25
* Time: 11:57
*/
namespace Apicp\Controller\Customtask;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\TaskHelper;
use Common\Service\CustomtaskContentService;
use Common\Service\CustomtaskCronService;
use Common\Service\CustomtaskService;
class SendController extends \Apicp\Controller\AbstractController
{
/**
* Send
* @author tangxingguo
* @desc 立刻发布常规任务接口
* @param Int customtask_id 常规任务ID
*/
public function Index_post()
{
// 验证规则
$rules = [
'customtask_id' => 'require|integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$customtaskId = $validate->postData['customtask_id'];
// 取数据
$customtaskServ = new CustomtaskService();
$customtaskInfo = $customtaskServ->get($customtaskId);
if (empty($customtaskInfo)) {
E('_ERR_CUSTOMTASK_NOT_FOUND');
}
// 任务必须为草稿和未开始开可以发布
if (!in_array($customtaskInfo['task_status'], [Constant::CUSTOMTASK_STATUS_DRAFT, Constant::CUSTOMTASK_STATUS_UNSTART])) {
E('_ERR_DAILYTASK_STATUS_NOT_SEND');
}
// 任务结束时间不能小于当前时间
if ($customtaskInfo['end_time'] < MILLI_TIME) {
E('_ERR_CUSTOMTASK_END_TIME_LT_TIME');
}
// 检查任务内容状态
$taskHelper = &TaskHelper::instance();
$ContentServ = new CustomtaskContentService();
list($dels) = $ContentServ->contentStatus($customtaskId);
if (!empty($dels)) {
// 存在任务内容被删除
$titles = implode(',', array_column($dels, 'title'));
E($titles . '被删除');
} else {
// 立即发送
if ($customtaskInfo['start_time'] <= MILLI_TIME) {
$taskHelper->sendCustomtask($customtaskId);
} else {
// 修改状态为未开始
if ($customtaskInfo['start_time'] > MILLI_TIME) {
$customtaskServ->update($customtaskId, ['task_status' => Constant::CUSTOMTASK_STATUS_UNSTART]);
}
// 定时发送的计划任务
$cronServ = new CustomtaskCronService();
$cronServ->sendCustomtask($customtaskInfo);
// 定时结束的计划任务
$cronServ->stopCustomtask($customtaskInfo);
}
// 更新参与人数
list($userTotal) = $taskHelper->getCustomtaskUserData($customtaskId);
$customtaskServ->update($customtaskId, ['user_total' => count($userTotal)]);
}
}
}