userExpireWarning.php 873 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Mail;
  3. use App\Http\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()
  20. {
  21. return $this->view('emails.userExpireWarning')->subject('账号过期提醒')->with([
  22. 'lastCanUseDays' => $this->lastCanUseDays
  23. ]);
  24. }
  25. // 发件失败处理
  26. public function failed(Exception $e)
  27. {
  28. NotificationLog::query()->whereId($this->id)->update(['status' => -1, 'error' => $e->getMessage()]);
  29. }
  30. }