1
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user