Ticket.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Models;
  3. use Auth;
  4. use Illuminate\Database\Eloquent\Builder;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\Relations\HasOne;
  7. /**
  8. * 工单
  9. *
  10. * @property int $id
  11. * @property int $user_id 用户ID
  12. * @property int $admin_id 管理员ID
  13. * @property string $title 标题
  14. * @property string $content 内容
  15. * @property int $status 状态:0-待处理、1-已处理未关闭、2-已关闭
  16. * @property \Illuminate\Support\Carbon $created_at 创建时间
  17. * @property \Illuminate\Support\Carbon $updated_at 最后更新时间
  18. * @property-read \App\Models\User|null $admin
  19. * @property-read string $status_label
  20. * @property-read \App\Models\User|null $user
  21. * @method static Builder|Ticket newModelQuery()
  22. * @method static Builder|Ticket newQuery()
  23. * @method static Builder|Ticket query()
  24. * @method static Builder|Ticket uid()
  25. * @method static Builder|Ticket whereAdminId($value)
  26. * @method static Builder|Ticket whereContent($value)
  27. * @method static Builder|Ticket whereCreatedAt($value)
  28. * @method static Builder|Ticket whereId($value)
  29. * @method static Builder|Ticket whereStatus($value)
  30. * @method static Builder|Ticket whereTitle($value)
  31. * @method static Builder|Ticket whereUpdatedAt($value)
  32. * @method static Builder|Ticket whereUserId($value)
  33. * @mixin \Eloquent
  34. */
  35. class Ticket extends Model {
  36. protected $table = 'ticket';
  37. public function scopeUid($query) {
  38. return $query->whereUserId(Auth::id());
  39. }
  40. public function user(): HasOne {
  41. return $this->hasOne(User::class, 'id', 'user_id');
  42. }
  43. public function admin(): HasOne {
  44. return $this->hasOne(User::class, 'id', 'admin_id');
  45. }
  46. public function getStatusLabelAttribute(): string {
  47. switch($this->attributes['status']){
  48. case 0:
  49. $status_label = '<span class="badge badge-lg badge-success">'.trans('home.ticket_table_status_wait').'</span>';
  50. break;
  51. case 1:
  52. $status_label = '<span class="badge badge-lg badge-danger">'.trans('home.ticket_table_status_reply').'</span>';
  53. break;
  54. case 2:
  55. $status_label = '<span class="badge badge-lg badge-default">'.trans('home.ticket_table_status_close').'</span>';
  56. break;
  57. default:
  58. $status_label = '<span class="badge badge-lg badge-default"> 未知 </span>';
  59. }
  60. return $status_label;
  61. }
  62. }