作者 lyh

gx数据

@@ -31,13 +31,18 @@ class SendAutoEmail extends Command @@ -31,13 +31,18 @@ class SendAutoEmail extends Command
31 { 31 {
32 $autoEmailLogModel = new AutoEmailLog(); 32 $autoEmailLogModel = new AutoEmailLog();
33 $list = $autoEmailLogModel->list(['status'=>AutoEmailLog::STATUS_PENDING],'id',['*'],'asc',100); 33 $list = $autoEmailLogModel->list(['status'=>AutoEmailLog::STATUS_PENDING],'id',['*'],'asc',100);
34 - if(empty($list)){  
35 - sleep(10);  
36 - }else{ 34 + if(!empty($list)){
37 $ids = array_column($list,'id'); 35 $ids = array_column($list,'id');
38 $autoEmailLogModel->edit(['status'=>AutoEmailLog::STATUS_ON],['id'=>['in',$ids]]); 36 $autoEmailLogModel->edit(['status'=>AutoEmailLog::STATUS_ON],['id'=>['in',$ids]]);
39 foreach ($list as $value) { 37 foreach ($list as $value) {
40 - $this->toQueue($value); 38 + $this->output('开始执行任务:' . $value['id']);
  39 + $smtpModel = new Smtp();
  40 + $smtpInfo = $smtpModel->read(['project_id'=>$value['project_id']]);
  41 + if($smtpInfo === false){
  42 + $this->output('任务:' . $smtpInfo['id'] . '失败,未配置SMTP');
  43 + continue;
  44 + }
  45 + $this->toQueue($value,$smtpInfo);
41 } 46 }
42 } 47 }
43 return true; 48 return true;
@@ -50,14 +55,7 @@ class SendAutoEmail extends Command @@ -50,14 +55,7 @@ class SendAutoEmail extends Command
50 * @method :post 55 * @method :post
51 * @time :2024/12/30 15:43 56 * @time :2024/12/30 15:43
52 */ 57 */
53 - public function toQueue($info){  
54 - $this->output('开始执行任务:' . $info['id']);  
55 - $smtpModel = new Smtp();  
56 - $smtpInfo = $smtpModel->read(['project_id'=>$info['project_id']]);  
57 - if($smtpInfo === false){  
58 - $this->output('任务:' . $smtpInfo['id'] . '失败,未配置SMTP');  
59 - return false;  
60 - } 58 + public function toQueue($info,$smtpInfo){
61 Config::set('mail.mailers.smtp.host', $smtpInfo['host']); 59 Config::set('mail.mailers.smtp.host', $smtpInfo['host']);
62 Config::set('mail.mailers.smtp.username', $smtpInfo['email']); 60 Config::set('mail.mailers.smtp.username', $smtpInfo['email']);
63 Config::set('mail.mailers.smtp.password', $smtpInfo['password']); 61 Config::set('mail.mailers.smtp.password', $smtpInfo['password']);