...
|
...
|
@@ -29,11 +29,18 @@ function start(){ |
|
|
$data['maildata'] = json_decode($data['maildata'],true);
|
|
|
// 查询邮箱
|
|
|
$email = db()->first(\Model\emailSql::first($data['email_id']));
|
|
|
// 更新状态
|
|
|
\Model\sendJobsSql::upStatus($data['id'],1,db());
|
|
|
// 是否是单发送
|
|
|
if($data['maildata']['massSuit']??0){
|
|
|
$tos = $data['maildata']['tos'];
|
|
|
foreach ($tos as $to){
|
|
|
|
|
|
// 是否暂停
|
|
|
if(db()->value(\Model\sendJobsSql::isStatus($data['id'])) === 3){
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
// 是否已发送过了
|
|
|
if(db()->count(\Model\sendJobStatusSql::count($data['id'],$to['email']))){
|
|
|
continue;
|
...
|
...
|
@@ -56,30 +63,34 @@ function start(){ |
|
|
if($data['maildata']['masssuit_interval_send']??[]){
|
|
|
$time = rand($data['maildata']['masssuit_interval_send']['start'],$data['maildata']['masssuit_interval_send']['end']);
|
|
|
if($time){
|
|
|
$block = false;
|
|
|
while (true){
|
|
|
// 没5秒循环一次
|
|
|
if(redis()->get('send_job_is_stop')=='stop'){
|
|
|
$block = true;
|
|
|
break;
|
|
|
}
|
|
|
$time-=5;
|
|
|
co::sleep(5);
|
|
|
// 执行下一次了
|
|
|
if (!$time){
|
|
|
$block = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if($block){
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 更新状态
|
|
|
\Model\sendJobsSql::upStatus($data['id'],1,db());
|
|
|
}
|
|
|
|
|
|
}else{
|
|
|
$result = \Lib\Mail\MailFun::sendEmail($data['maildata'],$email);
|
|
|
// 更新状态
|
|
|
\Model\sendJobsSql::upStatus($data['id'],1,db());
|
|
|
\Model\sendJobsSql::upStatus($data['id'],2,db());
|
|
|
// 插入紫薯精
|
|
|
db()->insert(\Model\sendJobStatusSql::$table,[
|
|
|
'job_id' => $data['id'],
|
...
|
...
|
@@ -92,12 +103,23 @@ function start(){ |
|
|
// 协程结束后
|
|
|
co::defer(function ($id) use(&$cNum,$data){
|
|
|
$cNum--;
|
|
|
// 验证是否完成
|
|
|
if($data['maildata']['massSuit']??0){
|
|
|
$total = db()->count(\Model\sendJobStatusSql::count($data['id']));
|
|
|
|
|
|
// 更新状态
|
|
|
\Model\sendJobsSql::upStatus($data['id'],$total == $data['total'] ? 2 : 0,db());
|
|
|
|
|
|
}
|
|
|
|
|
|
// 写入日志
|
|
|
\Lib\Log::getInstance()->write();
|
|
|
|
|
|
// 结束后要关闭数据库链接,不然链接一直暂用
|
|
|
db()->close();
|
|
|
// 删除占用
|
|
|
redis()->delete('send_job_run_id_'.$data['id']);
|
|
|
|
|
|
redis()->close();
|
|
|
});
|
|
|
|
...
|
...
|
|