作者 邓超

x

@@ -90,7 +90,11 @@ function start(){ @@ -90,7 +90,11 @@ function start(){
90 }else{ 90 }else{
91 $result = \Lib\Mail\MailFun::sendEmail($data['maildata'],$email); 91 $result = \Lib\Mail\MailFun::sendEmail($data['maildata'],$email);
92 // 更新状态 92 // 更新状态
93 - \Model\sendJobsSql::upStatus($data['id'],2,db()); 93 + db()->update(\Model\sendJobsSql::$table,[
  94 + 'status' => 2,
  95 + 'success' => $result[0] ? $data['total'] : 0,
  96 + 'error' => $result[0] ? 0 : $data['total'],
  97 + ],dbWhere(['id'=>$data['id']]));
94 // 插入紫薯精 98 // 插入紫薯精
95 db()->insert(\Model\sendJobStatusSql::$table,[ 99 db()->insert(\Model\sendJobStatusSql::$table,[
96 'job_id' => $data['id'], 100 'job_id' => $data['id'],
@@ -105,10 +109,15 @@ function start(){ @@ -105,10 +109,15 @@ function start(){
105 $cNum--; 109 $cNum--;
106 // 验证是否完成 110 // 验证是否完成
107 if($data['maildata']['massSuit']??0){ 111 if($data['maildata']['massSuit']??0){
108 - $total = db()->count(\Model\sendJobStatusSql::count($data['id']));  
109 - 112 + $total = db()->first(\Model\sendJobStatusSql::countSum($data['id']));
  113 + if($total){
110 // 更新状态 114 // 更新状态
111 - \Model\sendJobsSql::upStatus($data['id'],$total == $data['total'] ? 2 : 0,db()); 115 + db()->update(\Model\sendJobsSql::$table,[
  116 + 'status' => $total['t'] == $data['total'] ? 2 : 0,
  117 + 'success' => $total['s'],
  118 + 'error' => $total['e'],
  119 + ],dbWhere(['id'=>$data['id']]));
  120 + }
112 121
113 } 122 }
114 123
@@ -41,6 +41,45 @@ class Job extends Base { @@ -41,6 +41,45 @@ class Job extends Base {
41 } 41 }
42 42
43 43
  44 + public function stop(){
  45 + $id = app()->request('id',0,'intval');
  46 +
  47 + $ret = db()->update(sendJobsSql::$table,[
  48 + 'status' => 3
  49 + ],dbWhere([
  50 + 'id' => $id,
  51 + 'email_id' => $this->getEmails('id')
  52 + ]));
  53 +
  54 + if($ret){
  55 + return ['status'=>200];
  56 + }
  57 +
  58 + app()->e('send_job_stop_error');
  59 + }
  60 +
  61 + /**
  62 + * @throws \Lib\Err
  63 + * @author:dc
  64 + * @time 2023/4/17 17:03
  65 + */
  66 + public function start(){
  67 + $id = app()->request('id',0,'intval');
  68 +
  69 + $ret = db()->update(sendJobsSql::$table,[
  70 + 'status' => 0
  71 + ],dbWhere([
  72 + 'id' => $id,
  73 + 'email_id' => $this->getEmails('id')
  74 + ]));
  75 +
  76 + if($ret){
  77 + return ['status'=>200];
  78 + }
  79 +
  80 + app()->e('send_job_start_error');
  81 +
  82 + }
44 83
45 84
46 85
@@ -93,7 +93,8 @@ return [ @@ -93,7 +93,8 @@ return [
93 'folder_not_allowed_to_delete' => '此文件夹不允许删除', 93 'folder_not_allowed_to_delete' => '此文件夹不允许删除',
94 94
95 95
96 - 96 + 'send_job_start_error' => '开始执行任务失败',
  97 + 'send_job_stop_error' => '暂停任务失败'
97 98
98 99
99 100
@@ -31,5 +31,17 @@ class sendJobStatusSql { @@ -31,5 +31,17 @@ class sendJobStatusSql {
31 } 31 }
32 32
33 33
  34 + /**
  35 + * @param int $job_id
  36 + * @return string
  37 + * @author:dc
  38 + * @time 2023/4/17 17:25
  39 + */
  40 + public static function countSum(int $job_id){
  41 + $sucees = "(select count(*) from `".self::$table."` where `job_id` = {$job_id} and `status` = 1) as s";
  42 + $error = "(select count(*) from `".self::$table."` where `job_id` = {$job_id} and `status` = 0) as e";
  43 + return "select count(*) as t,{$sucees},{$error} from `".self::$table."` where `job_id` = {$job_id} ";
  44 + }
  45 +
34 46
35 } 47 }
@@ -37,6 +37,10 @@ return [ @@ -37,6 +37,10 @@ return [
37 37
38 // 发送任务 38 // 发送任务
39 'job' => [\Controller\Job::class, 'index'], 39 'job' => [\Controller\Job::class, 'index'],
  40 + // 暂停任务
  41 + 'job/stop' => [\Controller\Job::class, 'stop'],
  42 + // 开始任务
  43 + 'job/start' => [\Controller\Job::class, 'start'],
40 44
41 45
42 46