OwnerBillReportArchive.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 OwnerBillReportArchive extends Model
  7. {
  8. use ModelLogChanging;
  9. public $fillable = ['owner_bill_report_id', 'owner_id', 'counting_month', 'type', 'archiver_id', 'archived_at', 'information'];
  10. public $dates = [
  11. 'archived_at',
  12. 'counting_month'
  13. ];
  14. public $casts = [
  15. 'information' => 'array',
  16. ];
  17. public $timestamps = false;
  18. static public $enums = [
  19. 'type' => [
  20. '' => 0,
  21. '仓储费' => 1,
  22. '快递费-明细' => 2,
  23. '快递费-合计' => 3,
  24. '入库费' => 4,
  25. '出库费' => 5,
  26. '物流费' => 6,
  27. '包材费' => 7,
  28. '加工费' => 8,
  29. '杂项' => 9,
  30. '卸货费' => 10,
  31. ],
  32. ];
  33. function __construct(array $attributes = [])
  34. {
  35. foreach (self::$enums as &$enum) {
  36. $enum=$enum+array_flip($enum);
  37. }
  38. parent::__construct($attributes);
  39. }
  40. public function getTypeAttribute($value)
  41. {
  42. if (!$value) return '';
  43. return self::$enums['type'][$value];
  44. }
  45. public function setTypeAttribute($value)
  46. {
  47. if (!$value) return 0;
  48. $this->attributes['type'] = self::$enums['type'][$value];
  49. }
  50. public function ownerBillReport(): BelongsTo
  51. {
  52. return $this->belongsTo(OwnerBillReport::class);
  53. }
  54. public function owner(): BelongsTo
  55. {
  56. return $this->belongsTo(Owner::class);
  57. }
  58. }