OwnerSundryFeeDetail.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App;
  3. use App\Traits\ModelLogChanging;
  4. use App\Traits\ModelTimeFormat;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. use Illuminate\Database\Eloquent\Relations\HasOne;
  8. use Illuminate\Database\Eloquent\SoftDeletes;
  9. class OwnerSundryFeeDetail extends Model
  10. {
  11. use ModelLogChanging;
  12. use ModelTimeFormat;
  13. use SoftDeletes;
  14. protected $fillable = ['type', 'fee_explain', 'remark', 'fee', 'changable', 'owner_id', 'logistic_number', 'logistic_id', 'amount', 'price',];
  15. static public $enums = [
  16. 'type' => [
  17. '' => 0,
  18. '材料' => 1,
  19. '垫付' => 2,
  20. '人工' => 3,
  21. '其他' => 4,
  22. ],
  23. 'changable' => [
  24. '' => 0,
  25. '未冻结' => 1,
  26. '已冻结' => 2,
  27. ],
  28. ];
  29. function __construct(array $attributes = [])
  30. {
  31. foreach (self::$enums as &$enum) {
  32. $enum = $enum + array_flip($enum);
  33. }
  34. parent::__construct($attributes);
  35. }
  36. public function getTypeAttribute($value)
  37. {
  38. if (!$value) return '';
  39. return self::$enums['type'][$value];
  40. }
  41. public function setTypeAttribute($value)
  42. {
  43. if (!$value) return 0;
  44. $this->attributes['type'] = self::$enums['type'][$value];
  45. }
  46. public function getRouteKey()
  47. {
  48. return 'id';
  49. }
  50. public function owner(): BelongsTo
  51. {
  52. return $this->belongsTo(Owner::class);
  53. }
  54. public function logistic(): BelongsTo
  55. {
  56. return $this->belongsTo(Logistic::class);
  57. }
  58. public function scopeFilter($query, $filters)
  59. {
  60. return $filters->apply($query);
  61. }
  62. }