WorkOrderLog.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 ModelLogChanging;
  10. use ModelTimeFormat;
  11. protected $fillable = ['work_order_id','content','type','creator_id'];
  12. static public $enums = [
  13. 'type' => [
  14. '' => 0,
  15. '创建' => 1,
  16. '处理' => 2,
  17. '完结' => 3,
  18. ],
  19. ];
  20. function __construct(array $attributes = [])
  21. {
  22. foreach (self::$enums as &$enum) {
  23. $enum = $enum + array_flip($enum);
  24. }
  25. parent::__construct($attributes);
  26. }
  27. public function getTypeAttribute($value)
  28. {
  29. if (!$value) return '';
  30. return self::$enums['type'][$value];
  31. }
  32. public function setTypeAttribute($value)
  33. {
  34. if (!$value) return;
  35. if (is_numeric($value)) {
  36. $this->attributes['type'] = $value;
  37. } else {
  38. $this->attributes['type'] = self::$enums['type'][$value];
  39. }
  40. }
  41. public function workOrder(): BelongsTo
  42. {
  43. return $this->belongsTo(WorkOrder::class);
  44. }
  45. public function creator(): BelongsTo
  46. {
  47. return $this->belongsTo(User::class);
  48. }
  49. }