OwnerBillReportArchive.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. '杂项费' => 11,
  32. '卸货费' => 12,
  33. ],
  34. ];
  35. function __construct(array $attributes = [])
  36. {
  37. foreach (self::$enums as &$enum) {
  38. $enum=$enum+array_flip($enum);
  39. }
  40. parent::__construct($attributes);
  41. }
  42. public function getTypeAttribute($value)
  43. {
  44. if (!$value) return '';
  45. return self::$enums['type'][$value];
  46. }
  47. public function setTypeAttribute($value)
  48. {
  49. if (!$value) return 0;
  50. $this->attributes['type'] = self::$enums['type'][$value];
  51. }
  52. public function ownerBillReport(): BelongsTo
  53. {
  54. return $this->belongsTo(OwnerBillReport::class);
  55. }
  56. public function owner(): BelongsTo
  57. {
  58. return $this->belongsTo(Owner::class);
  59. }
  60. }