WorkOrderProcessLog.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 getIndemnitorAttribute($value)
  72. {
  73. if (!$value) return '';
  74. return self::$enums['indemnitor'][$value];
  75. }
  76. public function setIndemnitorAttribute($value)
  77. {
  78. if (!$value) return ;
  79. if (is_numeric($value)) {
  80. $this->attributes['indemnitor'] = $value;
  81. } else {
  82. $this->attributes['indemnitor'] = self::$enums['indemnitor'][$value];
  83. }
  84. }
  85. public function workOrder(): BelongsTo
  86. {
  87. return $this->belongsTo(WorkOrder::class);
  88. }
  89. public function creator(): BelongsTo
  90. {
  91. return $this->belongsTo(User::class);
  92. }
  93. public function isLogisticLog(): bool
  94. {
  95. return $this->type == "承运商";
  96. }
  97. public function isBaoShiLog(): bool
  98. {
  99. return $this->type == "宝时";
  100. }
  101. }