OwnerStoreOutFeeDetailService.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace App\Services;
  3. use App\Interfaces\SettlementBillDetailInterface;
  4. use App\OwnerFeeDetail;
  5. use App\OwnerFeeOperation;
  6. use App\OwnerPriceOperation;
  7. use App\Traits\ServiceAppAop;
  8. use App\OwnerStoreOutFeeDetail;
  9. use App\Traits\SettlementBillServiceTrait;
  10. use Illuminate\Contracts\Pagination\LengthAwarePaginator;
  11. use Illuminate\Database\Eloquent\Builder;
  12. use Illuminate\Database\Eloquent\Collection;
  13. class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
  14. {
  15. const TYPE = '出库费-明细';
  16. use ServiceAppAop;
  17. use SettlementBillServiceTrait;
  18. protected $modelClass = OwnerStoreOutFeeDetail::class;
  19. /**
  20. * 详情的查询不管是否却认都是原始数据且分页
  21. * @param array $kvPairs
  22. * @return LengthAwarePaginator
  23. */
  24. public function get(array $kvPairs): LengthAwarePaginator
  25. {
  26. return $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
  27. }
  28. public function getSql($owner_id, $counting_month): Builder
  29. {
  30. list($start, $end) = $this->getStartAndEnd($counting_month);
  31. $OwnerPriceOperationQuery = OwnerPriceOperation::query()
  32. ->select('id')
  33. ->where('operation_type', '出库');
  34. return OwnerFeeOperation::query()
  35. ->with(['details','model','commodity.barcodes'])
  36. ->whereIn('model_id', $OwnerPriceOperationQuery)
  37. ->whereBetween('worked_at', [$start, $end])
  38. ->where('owner_id', $owner_id);
  39. }
  40. public function switchType($type)
  41. {
  42. // TODO: Implement switchType() method.
  43. }
  44. public function buildExport($details): array
  45. {
  46. $result = [];
  47. foreach ($details as $detail) {
  48. $result[] = [
  49. $detail->ownerFeeDetail->worked_at,
  50. $detail->work_name,
  51. $detail->source_bill,
  52. $detail->ownerFeeDetail->operation_bill,
  53. $detail->sku,
  54. $detail->barcode,
  55. $detail->commodity->name ?? '',
  56. $detail->amount,
  57. $detail->unit_price,
  58. $detail->price_remark,
  59. $detail->fee,
  60. ];
  61. }
  62. return $result;
  63. }
  64. public function add(array $model)
  65. {
  66. // TODO: Implement add() method.
  67. }
  68. /**
  69. * 查询指定货主 月份 按照货主 计费模型汇总的 作业费(出入库费)和税费
  70. * @param $owner_id
  71. * @param $counting_month
  72. * @return Builder[]|Collection
  73. */
  74. public function getTotalFee($owner_id, $counting_month)
  75. {
  76. list($start, $end) = $this->getStartAndEnd($counting_month);
  77. return OwnerFeeDetail::query()
  78. ->selectRaw("owner_price_operation_id,
  79. sum(work_fee) as work_fee,
  80. sum(work_tax_fee) as work_tax_fee
  81. ")
  82. ->where('owner_id', $owner_id)
  83. ->whereBetween('created_at', [$start, $end])
  84. ->groupBy('owner_id', 'owner_price_operation_id')
  85. ->get();
  86. }
  87. }