OwnerBillReportArchive.php 1.6 KB

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