userTrafficWarning.php 919 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 userTrafficWarning extends Mailable implements ShouldQueue
  10. {
  11. use Queueable, SerializesModels;
  12. protected $id; // 邮件记录ID
  13. protected $usedPercent; // 已使用百分比
  14. public function __construct($id, $usedPercent)
  15. {
  16. $this->id = $id;
  17. $this->usedPercent = $usedPercent;
  18. }
  19. public function build(): userTrafficWarning
  20. {
  21. return $this->view('emails.userTrafficWarning')->subject('流量警告')->with(['usedPercent' => $this->usedPercent]);
  22. }
  23. // 发件失败处理
  24. public function failed(Exception $e): void
  25. {
  26. NotificationLog::whereId($this->id)->update(['status' => -1, 'error' => $e->getMessage()]);
  27. }
  28. }