WorkOrderProcessLog.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. 'indemnity', // 赔偿金
  15. 'creator_id', // 创建人
  16. 'remark', // 描述
  17. ];
  18. static public $enums = [
  19. 'type' => [
  20. '' => 0,
  21. '宝时' => 1,
  22. '承运商' => 2,
  23. ],
  24. 'is_indemnity' => [
  25. '' => 0,
  26. '是' => 1,
  27. '否' => 2,
  28. ],
  29. ];
  30. function __construct(array $attributes = [])
  31. {
  32. foreach (self::$enums as &$enum) {
  33. $enum = $enum + array_flip($enum);
  34. }
  35. parent::__construct($attributes);
  36. }
  37. public function getTypeAttribute($value)
  38. {
  39. if (!$value) return '';
  40. return self::$enums['type'][$value];
  41. }
  42. public function setTypeAttribute($value)
  43. {
  44. if (!$value) return ;
  45. if (is_numeric($value)) {
  46. $this->attributes['type'] = $value;
  47. } else {
  48. $this->attributes['type'] = self::$enums['type'][$value];
  49. }
  50. }
  51. public function getIsIndemnityAttribute($value)
  52. {
  53. if (!$value) return '';
  54. return self::$enums['is_indemnity'][$value];
  55. }
  56. public function setIsIndemnityAttribute($value)
  57. {
  58. if (!$value) return ;
  59. if (is_numeric($value)) {
  60. $this->attributes['is_indemnity'] = $value;
  61. } else {
  62. $this->attributes['is_indemnity'] = self::$enums['is_indemnity'][$value];
  63. }
  64. }
  65. public function workOrder(): BelongsTo
  66. {
  67. return $this->belongsTo(WorkOrder::class);
  68. }
  69. public function creator(): BelongsTo
  70. {
  71. return $this->belongsTo(User::class);
  72. }
  73. }