WorkOrderLog.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App;
  3. use App\Traits\ModelTimeFormat;
  4. use Illuminate\Database\Eloquent\Model;
  5. use App\Traits\ModelLogChanging;
  6. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. class WorkOrderLog extends Model
  8. {
  9. use ModelTimeFormat;
  10. protected $fillable = [
  11. 'work_order_id',
  12. 'work_order_detail_id',
  13. 'content',
  14. 'type', // 记录类型
  15. 'creator_id', // 创建人
  16. 'tag', // 标记
  17. ];
  18. static public $enums = [
  19. 'type' => [
  20. '' => 0,
  21. '创建' => 1,
  22. '处理' => 2,
  23. '终审' => 3,
  24. '完结' => 4,
  25. ],
  26. 'tag' => [
  27. '创建' => 0,
  28. '完结' => 1,
  29. '标记' => 2,
  30. ],
  31. ];
  32. function __construct(array $attributes = [])
  33. {
  34. foreach (self::$enums as &$enum) {
  35. $enum = $enum + array_flip($enum);
  36. }
  37. parent::__construct($attributes);
  38. }
  39. public function getTypeAttribute($value)
  40. {
  41. if (!$value) return '';
  42. return self::$enums['type'][$value];
  43. }
  44. public function setTypeAttribute($value)
  45. {
  46. if (!$value) return;
  47. if (is_numeric($value)) {
  48. $this->attributes['type'] = $value;
  49. } else {
  50. $this->attributes['type'] = self::$enums['type'][$value];
  51. }
  52. }
  53. public function getTagAttribute($value)
  54. {
  55. if (!$value) return '';
  56. return self::$enums['tag'][$value];
  57. }
  58. public function setTagAttribute($value)
  59. {
  60. if (!$value) return;
  61. if (is_numeric($value)) {
  62. $this->attributes['tag'] = $value;
  63. } else {
  64. $this->attributes['tag'] = self::$enums['tag'][$value];
  65. }
  66. }
  67. public function creator(): BelongsTo
  68. {
  69. return $this->belongsTo(User::class);
  70. }
  71. }