WorkOrderProcessLog.php 2.9 KB

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