|
@@ -29,11 +29,18 @@ function start(){ |
|
@@ -29,11 +29,18 @@ function start(){ |
29
|
$data['maildata'] = json_decode($data['maildata'],true);
|
29
|
$data['maildata'] = json_decode($data['maildata'],true);
|
30
|
// 查询邮箱
|
30
|
// 查询邮箱
|
31
|
$email = db()->first(\Model\emailSql::first($data['email_id']));
|
31
|
$email = db()->first(\Model\emailSql::first($data['email_id']));
|
|
|
32
|
+ // 更新状态
|
|
|
33
|
+ \Model\sendJobsSql::upStatus($data['id'],1,db());
|
32
|
// 是否是单发送
|
34
|
// 是否是单发送
|
33
|
if($data['maildata']['massSuit']??0){
|
35
|
if($data['maildata']['massSuit']??0){
|
34
|
$tos = $data['maildata']['tos'];
|
36
|
$tos = $data['maildata']['tos'];
|
35
|
foreach ($tos as $to){
|
37
|
foreach ($tos as $to){
|
36
|
|
38
|
|
|
|
39
|
+ // 是否暂停
|
|
|
40
|
+ if(db()->value(\Model\sendJobsSql::isStatus($data['id'])) === 3){
|
|
|
41
|
+ break;
|
|
|
42
|
+ }
|
|
|
43
|
+
|
37
|
// 是否已发送过了
|
44
|
// 是否已发送过了
|
38
|
if(db()->count(\Model\sendJobStatusSql::count($data['id'],$to['email']))){
|
45
|
if(db()->count(\Model\sendJobStatusSql::count($data['id'],$to['email']))){
|
39
|
continue;
|
46
|
continue;
|
|
@@ -56,30 +63,34 @@ function start(){ |
|
@@ -56,30 +63,34 @@ function start(){ |
56
|
if($data['maildata']['masssuit_interval_send']??[]){
|
63
|
if($data['maildata']['masssuit_interval_send']??[]){
|
57
|
$time = rand($data['maildata']['masssuit_interval_send']['start'],$data['maildata']['masssuit_interval_send']['end']);
|
64
|
$time = rand($data['maildata']['masssuit_interval_send']['start'],$data['maildata']['masssuit_interval_send']['end']);
|
58
|
if($time){
|
65
|
if($time){
|
|
|
66
|
+ $block = false;
|
59
|
while (true){
|
67
|
while (true){
|
60
|
// 没5秒循环一次
|
68
|
// 没5秒循环一次
|
61
|
if(redis()->get('send_job_is_stop')=='stop'){
|
69
|
if(redis()->get('send_job_is_stop')=='stop'){
|
|
|
70
|
+ $block = true;
|
62
|
break;
|
71
|
break;
|
63
|
}
|
72
|
}
|
64
|
$time-=5;
|
73
|
$time-=5;
|
65
|
co::sleep(5);
|
74
|
co::sleep(5);
|
66
|
// 执行下一次了
|
75
|
// 执行下一次了
|
67
|
if (!$time){
|
76
|
if (!$time){
|
|
|
77
|
+ $block = true;
|
68
|
break;
|
78
|
break;
|
69
|
}
|
79
|
}
|
70
|
}
|
80
|
}
|
|
|
81
|
+
|
|
|
82
|
+ if($block){
|
|
|
83
|
+ break;
|
|
|
84
|
+ }
|
71
|
}
|
85
|
}
|
72
|
}
|
86
|
}
|
73
|
|
87
|
|
74
|
}
|
88
|
}
|
75
|
|
89
|
|
76
|
- // 更新状态
|
|
|
77
|
- \Model\sendJobsSql::upStatus($data['id'],1,db());
|
|
|
78
|
-
|
|
|
79
|
}else{
|
90
|
}else{
|
80
|
$result = \Lib\Mail\MailFun::sendEmail($data['maildata'],$email);
|
91
|
$result = \Lib\Mail\MailFun::sendEmail($data['maildata'],$email);
|
81
|
// 更新状态
|
92
|
// 更新状态
|
82
|
- \Model\sendJobsSql::upStatus($data['id'],1,db());
|
93
|
+ \Model\sendJobsSql::upStatus($data['id'],2,db());
|
83
|
// 插入紫薯精
|
94
|
// 插入紫薯精
|
84
|
db()->insert(\Model\sendJobStatusSql::$table,[
|
95
|
db()->insert(\Model\sendJobStatusSql::$table,[
|
85
|
'job_id' => $data['id'],
|
96
|
'job_id' => $data['id'],
|
|
@@ -92,12 +103,23 @@ function start(){ |
|
@@ -92,12 +103,23 @@ function start(){ |
92
|
// 协程结束后
|
103
|
// 协程结束后
|
93
|
co::defer(function ($id) use(&$cNum,$data){
|
104
|
co::defer(function ($id) use(&$cNum,$data){
|
94
|
$cNum--;
|
105
|
$cNum--;
|
|
|
106
|
+ // 验证是否完成
|
|
|
107
|
+ if($data['maildata']['massSuit']??0){
|
|
|
108
|
+ $total = db()->count(\Model\sendJobStatusSql::count($data['id']));
|
|
|
109
|
+
|
|
|
110
|
+ // 更新状态
|
|
|
111
|
+ \Model\sendJobsSql::upStatus($data['id'],$total == $data['total'] ? 2 : 0,db());
|
|
|
112
|
+
|
|
|
113
|
+ }
|
|
|
114
|
+
|
95
|
// 写入日志
|
115
|
// 写入日志
|
96
|
\Lib\Log::getInstance()->write();
|
116
|
\Lib\Log::getInstance()->write();
|
|
|
117
|
+
|
97
|
// 结束后要关闭数据库链接,不然链接一直暂用
|
118
|
// 结束后要关闭数据库链接,不然链接一直暂用
|
98
|
db()->close();
|
119
|
db()->close();
|
99
|
// 删除占用
|
120
|
// 删除占用
|
100
|
redis()->delete('send_job_run_id_'.$data['id']);
|
121
|
redis()->delete('send_job_run_id_'.$data['id']);
|
|
|
122
|
+
|
101
|
redis()->close();
|
123
|
redis()->close();
|
102
|
});
|
124
|
});
|
103
|
|
125
|
|