作者 邓超

1

@@ -10,6 +10,7 @@ use Model\bodySql; @@ -10,6 +10,7 @@ use Model\bodySql;
10 use Model\emailSql; 10 use Model\emailSql;
11 use Model\folderSql; 11 use Model\folderSql;
12 use Model\listsSql; 12 use Model\listsSql;
  13 +use Model\sendJobsSql;
13 use PHPMailer\PHPMailer\PHPMailer; 14 use PHPMailer\PHPMailer\PHPMailer;
14 use PHPMailer\PHPMailer\SMTP; 15 use PHPMailer\PHPMailer\SMTP;
15 16
@@ -228,9 +229,19 @@ class Home extends Base { @@ -228,9 +229,19 @@ class Home extends Base {
228 $sendData['priority'] = $formData['priority']??3;// 是否紧急邮件 229 $sendData['priority'] = $formData['priority']??3;// 是否紧急邮件
229 $sendData['subject'] = $formData['subject'];// //Content 主题,标题 230 $sendData['subject'] = $formData['subject'];// //Content 主题,标题
230 $sendData['body'] = $formData['body']; 231 $sendData['body'] = $formData['body'];
  232 + // 不重要的信息
  233 + $sendData['jobName'] = $formData['jobName']??'';//任务标题
  234 + $sendData['massSuit'] = $formData['massSuit']??0;// 是否是群发单显
231 235
232 // 定时发送时间 236 // 定时发送时间
233 - $timer = strtotime(app()->request('timerValue','2023-04-10')); 237 + $timer = app()->request('timerValue',0);
  238 + if(is_numeric($timer) && $timer){
  239 + $timer = time()+$timer;
  240 + }else if (is_string($timer)){
  241 + $timer = strtotime($timer);
  242 + }else{
  243 + $timer = 0;
  244 + }
234 // 是否存草稿 245 // 是否存草稿
235 if(app()->request('saveType')=='draft'){ 246 if(app()->request('saveType')=='draft'){
236 // 保存 247 // 保存
@@ -242,15 +253,37 @@ class Home extends Base { @@ -242,15 +253,37 @@ class Home extends Base {
242 app()->e('save_draft_error'); 253 app()->e('save_draft_error');
243 254
244 } 255 }
245 - // 定时发送  
246 - else if(app()->request('timer') && $timer > time()){ 256 + // 定时发送 或者是单条发送
  257 + else if((app()->request('timer') && $timer > time()) || $sendData['massSuit']){
247 258
248 - }else{  
249 - // 发送  
250 -// $result = MailFun::sendEmail($sendData,$email);  
251 -// if($result[0]){  
252 -// app()->_json(['messageId' => $result[1]]);  
253 -// } 259 + if($sendData['massSuit']){
  260 + // 每次发送间隔的时间
  261 + $sendData['masssuit_interval_send'] = app()->request('masssuit_interval_send');
  262 + $sendData['masssuit_interval_send']['start'] = intval($sendData['masssuit_interval_send']['start']??0);
  263 + $sendData['masssuit_interval_send']['end'] = intval($sendData['masssuit_interval_send']['end']??1);
  264 + }
  265 +
  266 + // 插入任务
  267 + $job_id = db()->insert(sendJobsSql::$table,[
  268 + 'email_id' => $email['id'],
  269 + 'maildata' => $sendData,
  270 + 'title' => $sendData['jobName'] ? : $sendData['subject'],
  271 + 'total' => count($sendData['tos']),
  272 + 'send_time' => $timer
  273 + ]);
  274 + if($job_id){
  275 + // 返回任务id
  276 + app()->_json(['job_id'=>$job_id]);
  277 + }
  278 +
  279 + app()->e('send_timer_job_error');
  280 + }
  281 + else{
  282 + // 立即发送
  283 + $result = MailFun::sendEmail($sendData,$email);
  284 + if($result[0]){
  285 + app()->_json(['messageId' => $result[1]]);
  286 + }
254 // 错误 287 // 错误
255 app()->e($result[1]); 288 app()->e($result[1]);
256 } 289 }
@@ -490,7 +523,9 @@ class Home extends Base { @@ -490,7 +523,9 @@ class Home extends Base {
490 523
491 if($data){ 524 if($data){
492 $sync_num = 0; 525 $sync_num = 0;
493 - $data['to_name'] = json_decode($data['to_name']??"[]",true); 526 + $data['to_name'] = $data['to_name'] ? json_decode($data['to_name'],true) : [];
  527 + $data['cc'] = $data['cc'] ? json_decode($data['cc'],true) : [];
  528 + $data['bcc'] = $data['bcc'] ? json_decode($data['bcc'],true) : [];
494 529
495 HOME_INFO_BODY: 530 HOME_INFO_BODY:
496 $body = db()->first(bodySql::first($id)); 531 $body = db()->first(bodySql::first($id));
@@ -551,9 +586,15 @@ class Home extends Base { @@ -551,9 +586,15 @@ class Home extends Base {
551 return [ 586 return [
552 'data' => $data 587 'data' => $data
553 ]; 588 ];
  589 + }// 草稿
  590 + else if(!$data['uid'] && $data['draft']){
  591 + $data['body'] = [];
  592 + return [
  593 + 'data' => $data
  594 + ];
554 } 595 }
555 // 循环几次 596 // 循环几次
556 - if($sync_num < 1){ 597 + if($data['uid']&&$sync_num < 1){
557 $mail = new Mail($email['email'],base64_decode($email['password']),$email['imap']); 598 $mail = new Mail($email['email'],base64_decode($email['password']),$email['imap']);
558 599
559 if($mail->login()){ 600 if($mail->login()){
@@ -86,6 +86,8 @@ return [ @@ -86,6 +86,8 @@ return [
86 86
87 'save_draft_error' => '草稿保存失败', 87 'save_draft_error' => '草稿保存失败',
88 88
  89 + 'send_timer_job_error' => '延迟发送失败',
  90 +
89 91
90 92
91 93
@@ -122,6 +122,12 @@ class listsSql { @@ -122,6 +122,12 @@ class listsSql {
122 'email_id' => $email['id'], 122 'email_id' => $email['id'],
123 'is_file' => $data['attachment'] ? 1 : 0, //是否附件 123 'is_file' => $data['attachment'] ? 1 : 0, //是否附件
124 'description' => mb_substr(strip_tags($data['body']),0,150), //是否附件 124 'description' => mb_substr(strip_tags($data['body']),0,150), //是否附件
  125 + 'references' => [
  126 + 'receipt' => $data['receipt'],
  127 + 'priority' => $data['priority'],
  128 + 'massSuit' => $data['massSuit']?1:0,
  129 + 'jobName' => $data['jobName']??'',
  130 + ]
125 ]; 131 ];
126 $draftData['to'] = $data['tos'][0]['email']; 132 $draftData['to'] = $data['tos'][0]['email'];
127 $draftData['to_name'] = $data['tos']; 133 $draftData['to_name'] = $data['tos'];
@@ -154,6 +160,8 @@ class listsSql { @@ -154,6 +160,8 @@ class listsSql {
154 ]; 160 ];
155 161
156 foreach ($data['attachment'] as $da){ 162 foreach ($data['attachment'] as $da){
  163 + $da['name'] = base64_encode($da['name']);
  164 + $da['filename'] = base64_encode($da['filename']);
157 $draftBody[] = $da; 165 $draftBody[] = $da;
158 } 166 }
159 167
@@ -15,7 +15,7 @@ class sendJobsSql { @@ -15,7 +15,7 @@ class sendJobsSql {
15 * 表 15 * 表
16 * @var string 16 * @var string
17 */ 17 */
18 - public static $table = 'lists'; 18 + public static $table = 'send_jobs';
19 19
20 20
21 21