OwnerStoreFeeDetail.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 OwnerStoreFeeDetail extends Model
  7. {
  8. use ModelLogChanging;
  9. public $fillable = [
  10. 'owner_fee_detail_id',
  11. 'unit_id',
  12. 'unit_price', //单价
  13. 'amount', //数量
  14. 'owner_id', //货主
  15. 'fee',//费用
  16. 'commodity_id',
  17. 'packing_material_fee',//包材费
  18. 'tax_fee',//税费
  19. 'sku',//sku
  20. 'barcode',//条码
  21. 'work_name',//作业名称
  22. 'asn_code',//asn号
  23. ];
  24. public function ownerFeeDetail(): BelongsTo
  25. {
  26. return $this->belongsTo(OwnerFeeDetail::class);
  27. }
  28. public function unit(): BelongsTo
  29. {
  30. return $this->belongsTo(Unit::class);
  31. }
  32. public function getPriceAttribute(): string
  33. {
  34. return $this->unit_price . '/' . $this->unit->name;
  35. }
  36. public function owner(): BelongsTo
  37. {
  38. return $this->belongsTo(Owner::class);
  39. }
  40. public function commodity(): BelongsTo
  41. {
  42. return $this->belongsTo(Commodity::class);
  43. }
  44. /**
  45. * 根据插入数组构建查询数组
  46. * @param $data
  47. * @return array
  48. */
  49. public static function buildSelectData($data): array
  50. {
  51. return [
  52. 'owner_fee_detail_id' => $data['owner_fee_detail_id'] ?? '',
  53. 'unit_id' => $data['unit_id'] ?? '',
  54. 'owner_id' => $data['owner_id'] ?? '',
  55. 'commodity_id' => $data['commodity_id'] ?? '',
  56. 'sku' => $data['sku'] ?? '',
  57. 'barcode' => $data['barcode'] ?? '',
  58. 'work_name' => $data['work_name'] ?? '',
  59. 'asn_code' => $data['asn_code'] ?? '',
  60. ];
  61. }
  62. }