OwnerStoreOutFeeDetailService.php 2.9 KB

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