userExpireWarning.php 940 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Mail;
  3. use App\Models\NotificationLog;
  4. use Exception;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Mail\Mailable;
  8. use Illuminate\Queue\SerializesModels;
  9. class userExpireWarning extends Mailable implements ShouldQueue
  10. {
  11. use Queueable, SerializesModels;
  12. protected $id; // 邮件记录ID
  13. protected $lastCanUseDays; // 剩余可用天数
  14. public function __construct($id, $lastCanUseDays)
  15. {
  16. $this->id = $id;
  17. $this->lastCanUseDays = $lastCanUseDays;
  18. }
  19. public function build(): userExpireWarning
  20. {
  21. return $this->view('emails.userExpireWarning')->subject('账号过期提醒')->with(['lastCanUseDays' => $this->lastCanUseDays]);
  22. }
  23. // 发件失败处理
  24. public function failed(Exception $e): void
  25. {
  26. NotificationLog::whereId($this->id)->update(['status' => -1, 'error' => $e->getMessage()]);
  27. }
  28. }