正在显示
5 个修改的文件
包含
71 行增加
和
6 行删除
@@ -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 | - | ||
110 | - // 更新状态 | ||
111 | - \Model\sendJobsSql::upStatus($data['id'],$total == $data['total'] ? 2 : 0,db()); | 112 | + $total = db()->first(\Model\sendJobStatusSql::countSum($data['id'])); |
113 | + if($total){ | ||
114 | + // 更新状态 | ||
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 |
@@ -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 |
-
请 注册 或 登录 后发表评论