From 19849d2b9d9f92ecfc9440928353d3404d236199 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Thu, 7 Apr 2022 13:37:21 +0800 Subject: [PATCH] 1 --- application/api/job/domail.php | 93 ++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 31 deletions(-) diff --git a/application/api/job/domail.php b/application/api/job/domail.php index 72b6a71..4f755e6 100644 --- a/application/api/job/domail.php +++ b/application/api/job/domail.php @@ -2,6 +2,7 @@ namespace app\api\job; +use Exception; use think\Db; use think\Log; use think\queue\Job; @@ -13,37 +14,71 @@ class domail { // $job->delete(); // 发送邮件 - $isJobDone = $this->doTask($data); - // 删除 - $job->delete(); - //入库 - $this->insertData($data,$isJobDone); - - } - - - /** - * 发送邮件 - * @param $data - * @return array - */ - public function doTask($data){ - if(isset($data['attachment_url']) && !empty($data['attachment_url']) ){ - $res = sendEmail($data['email'],$data['title'],$data['from_name'],$data['content'],$data['sendEmail'],$data['sendPassword'],$data['attachment_url']); - }else{ - $res = sendEmail($data['email'],$data['title'],$data['from_name'],$data['content'],$data['sendEmail'],$data['sendPassword']); + try{ + $this->send($data); + $job->delete(); + // $isJobDone = $this->doTask($data); + }catch(Exception $e){ + $this->addErrMsg($data); + $job->delete(); } - return $res; + + // 删除 + // $job->delete(); + //入库 + // $this->insertData($data,$isJobDone); + } + // /** + // * 发送邮件 + // * @param $data + // * @return array + // */ + // public function doTask($data){ + // if(isset($data['attachment_url']) && !empty($data['attachment_url']) ){ + // $res = sendEmail($data['email'],$data['title'],$data['from_name'],$data['content'],$data['sendEmail'],$data['sendPassword'],$data['attachment_url']); + // }else{ + // $res = sendEmail($data['email'],$data['title'],$data['from_name'],$data['content'],$data['sendEmail'],$data['sendPassword']); + // } + // return $res; + // } + + + // /** + // * email记录入库 + // * @param $data + // * @param $isJobDone + // */ + // public function insertData($data,$isJobDone) + // { + // $insert = [ + // 'title' => $data['title'], + // 'content' => $data['content'], + // 'recive_id' => $data['user_id'], + // 'recive_email' => $data['email'], + // 'journal_id' => $data['journal_id'], + // 'journal_email' => $data['sendEmail'], + // 'journal_password' => $data['sendPassword'], + // 'create_time' => time() + // ]; + // if (isset($data['attachment_url']) && !empty($data['attachment_url'])) { + // $insert['is_attachment'] = 1; + // $insert['attachment_url'] = $data['attachment_url']; + // } + // if($isJobDone['status']==0){ + // $insert['is_success'] = 0; + // $insert['fail_reason'] = $isJobDone['data']; + // } + // Db::name('email')->insert($insert); + // } + + /** - * email记录入库 - * @param $data - * @param $isJobDone + * 添加邮件错误记录 */ - public function insertData($data,$isJobDone) - { + private function addErrMsg($data){ $insert = [ 'title' => $data['title'], 'content' => $data['content'], @@ -58,15 +93,11 @@ class domail { $insert['is_attachment'] = 1; $insert['attachment_url'] = $data['attachment_url']; } - if($isJobDone['status']==0){ - $insert['is_success'] = 0; - $insert['fail_reason'] = $isJobDone['data']; - } + $insert['is_success'] = 0; + $insert['fail_reason'] = "system error at push email queue!"; Db::name('email')->insert($insert); } - - /** * 发送邮件的逻辑 * @param type $data