作者 邓超

x

... ... @@ -90,7 +90,11 @@ function start(){
}else{
$result = \Lib\Mail\MailFun::sendEmail($data['maildata'],$email);
// 更新状态
\Model\sendJobsSql::upStatus($data['id'],2,db());
db()->update(\Model\sendJobsSql::$table,[
'status' => 2,
'success' => $result[0] ? $data['total'] : 0,
'error' => $result[0] ? 0 : $data['total'],
],dbWhere(['id'=>$data['id']]));
// 插入紫薯精
db()->insert(\Model\sendJobStatusSql::$table,[
'job_id' => $data['id'],
... ... @@ -105,10 +109,15 @@ function start(){
$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());
$total = db()->first(\Model\sendJobStatusSql::countSum($data['id']));
if($total){
// 更新状态
db()->update(\Model\sendJobsSql::$table,[
'status' => $total['t'] == $data['total'] ? 2 : 0,
'success' => $total['s'],
'error' => $total['e'],
],dbWhere(['id'=>$data['id']]));
}
}
... ...
... ... @@ -41,6 +41,45 @@ class Job extends Base {
}
public function stop(){
$id = app()->request('id',0,'intval');
$ret = db()->update(sendJobsSql::$table,[
'status' => 3
],dbWhere([
'id' => $id,
'email_id' => $this->getEmails('id')
]));
if($ret){
return ['status'=>200];
}
app()->e('send_job_stop_error');
}
/**
* @throws \Lib\Err
* @author:dc
* @time 2023/4/17 17:03
*/
public function start(){
$id = app()->request('id',0,'intval');
$ret = db()->update(sendJobsSql::$table,[
'status' => 0
],dbWhere([
'id' => $id,
'email_id' => $this->getEmails('id')
]));
if($ret){
return ['status'=>200];
}
app()->e('send_job_start_error');
}
... ...
... ... @@ -93,7 +93,8 @@ return [
'folder_not_allowed_to_delete' => '此文件夹不允许删除',
'send_job_start_error' => '开始执行任务失败',
'send_job_stop_error' => '暂停任务失败'
... ...
... ... @@ -31,5 +31,17 @@ class sendJobStatusSql {
}
/**
* @param int $job_id
* @return string
* @author:dc
* @time 2023/4/17 17:25
*/
public static function countSum(int $job_id){
$sucees = "(select count(*) from `".self::$table."` where `job_id` = {$job_id} and `status` = 1) as s";
$error = "(select count(*) from `".self::$table."` where `job_id` = {$job_id} and `status` = 0) as e";
return "select count(*) as t,{$sucees},{$error} from `".self::$table."` where `job_id` = {$job_id} ";
}
}
... ...
... ... @@ -37,6 +37,10 @@ return [
// 发送任务
'job' => [\Controller\Job::class, 'index'],
// 暂停任务
'job/stop' => [\Controller\Job::class, 'stop'],
// 开始任务
'job/start' => [\Controller\Job::class, 'start'],
... ...