Ticket.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Models;
  3. use Auth;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. /**
  7. * 工单
  8. */
  9. class Ticket extends Model
  10. {
  11. protected $table = 'ticket';
  12. public function scopeUid($query)
  13. {
  14. return $query->whereUserId(Auth::id());
  15. }
  16. public function user(): BelongsTo
  17. {
  18. return $this->belongsTo(User::class);
  19. }
  20. public function admin(): BelongsTo
  21. {
  22. return $this->BelongsTo(User::class);
  23. }
  24. public function getStatusLabelAttribute(): string
  25. {
  26. switch ($this->attributes['status']) {
  27. case 0:
  28. $status_label = '<span class="badge badge-lg badge-success">'.trans('home.ticket_table_status_wait').'</span>';
  29. break;
  30. case 1:
  31. $status_label = '<span class="badge badge-lg badge-danger">'.trans('home.ticket_table_status_reply').'</span>';
  32. break;
  33. case 2:
  34. $status_label = '<span class="badge badge-lg badge-default">'.trans('home.ticket_table_status_close').'</span>';
  35. break;
  36. default:
  37. $status_label = '<span class="badge badge-lg badge-default"> 未知 </span>';
  38. }
  39. return $status_label;
  40. }
  41. }