SendEmailJobs.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Jobs\Manager\Process;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldBeUnique;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use App\Facades\Servers\Logs\Log;
  10. use App\Servers\Email\VerifyCode as EmailVerifyCode;
  11. use App\Models\Manager\Process\SubNoticeLog as SubNoticeLogModel;
  12. /**
  13. * 发送邮件通知队列
  14. * @author 唐远望
  15. * @version 1.0
  16. * @date 2026-04-16
  17. */
  18. class SendEmailJobs implements ShouldQueue
  19. {
  20. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  21. protected $message_data;
  22. protected $company_id;
  23. /**
  24. * Create a new job instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct(array $message_data)
  29. {
  30. $this->message_data = $message_data;
  31. }
  32. /**
  33. * Execute the job.
  34. *
  35. * @return void
  36. */
  37. public function handle()
  38. {
  39. try {
  40. $EmailVerifyCode = new EmailVerifyCode();
  41. $SubNoticeLogModel = new SubNoticeLogModel();
  42. $notice_data_info = $this->message_data['notice_data_info'];
  43. $email_to = $notice_data_info['email'];
  44. $email_content = json_decode($notice_data_info['email_content'], true);
  45. $email_title = $email_content['title'];
  46. $email_content = $email_content['content'];
  47. $res_msg = $EmailVerifyCode->sendSmtpEmail($email_to, $email_title, $email_content);
  48. Log::info('job_send_email', '订阅邮件通知推送队列记录', ['email' => $email_to, 'email_content' => $email_content, 'msg' => $res_msg]);
  49. $SubNoticeLogModel->where(['id' => $notice_data_info['id']])->update(['email_status' => 0]);
  50. } catch (\Exception $e) {
  51. Log::info('job_send_email', '发送邮件通知队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
  52. }
  53. }
  54. public function failed(\Throwable $exception)
  55. {
  56. Log::info('job_send_email', '发送邮件通知队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
  57. }
  58. }