WorkOrderProcessLog.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Traits\ModelLogChanging;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. class WorkOrderProcessLog extends Model
  7. {
  8. use ModelLogChanging;
  9. //
  10. protected $fillable = [
  11. 'work_order_id', // 工单
  12. 'type', // 处理类型 0 无 1宝时 2 承运商
  13. 'is_indemnity', // 是否赔偿 0 无 1是 2否
  14. 'indemnitor', // 赔偿人 0 无 1宝时 2承运商
  15. 'indemnity', // 赔偿金
  16. 'creator_id', // 创建人
  17. 'remark', // 描述
  18. ];
  19. static public $enums = [
  20. 'type' => [
  21. '' => 0,
  22. '宝时' => 1,
  23. '承运商' => 2,
  24. ],
  25. 'is_indemnity' => [
  26. '' => 0,
  27. '是' => 1,
  28. '否' => 2,
  29. ],
  30. 'indemnitor'=> [
  31. '' => 0,
  32. '宝时' => 1,
  33. '承运商' => 2,
  34. ],
  35. ];
  36. function __construct(array $attributes = [])
  37. {
  38. foreach (self::$enums as &$enum) {
  39. $enum = $enum + array_flip($enum);
  40. }
  41. parent::__construct($attributes);
  42. }
  43. public function getTypeAttribute($value)
  44. {
  45. if (!$value) return '';
  46. return self::$enums['type'][$value];
  47. }
  48. public function setTypeAttribute($value)
  49. {
  50. if (!$value) return ;
  51. if (is_numeric($value)) {
  52. $this->attributes['type'] = $value;
  53. } else {
  54. $this->attributes['type'] = self::$enums['type'][$value];
  55. }
  56. }
  57. public function getIsIndemnityAttribute($value)
  58. {
  59. if (!$value) return '';
  60. return self::$enums['is_indemnity'][$value];
  61. }
  62. public function setIsIndemnityAttribute($value)
  63. {
  64. if (!$value) return ;
  65. if (is_numeric($value)) {
  66. $this->attributes['is_indemnity'] = $value;
  67. } else {
  68. $this->attributes['is_indemnity'] = self::$enums['is_indemnity'][$value];
  69. }
  70. }
  71. public function workOrder(): BelongsTo
  72. {
  73. return $this->belongsTo(WorkOrder::class);
  74. }
  75. public function creator(): BelongsTo
  76. {
  77. return $this->belongsTo(User::class);
  78. }
  79. }