OwnerStoreOutFeeDetailService.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. ])
  34. ->where('owner_id', $owner_id)
  35. ->whereBetween('created_at', [$start, $end]);
  36. }
  37. public function switchType($type)
  38. {
  39. // TODO: Implement switchType() method.
  40. }
  41. public function buildExport($details): array
  42. {
  43. $result = [];
  44. foreach ($details as $detail) {
  45. $result[] = [
  46. $detail->ownerFeeDetail->worked_at,
  47. $detail->work_name,
  48. $detail->source_bill,
  49. $detail->ownerFeeDetail->operation_bill,
  50. $detail->sku,
  51. $detail->barcode,
  52. $detail->commodity->name ?? '',
  53. $detail->amount,
  54. $detail->unit_price,
  55. $detail->price_remark,
  56. $detail->fee,
  57. ];
  58. }
  59. return $result;
  60. }
  61. public function add(array $model)
  62. {
  63. // TODO: Implement add() method.
  64. }
  65. /**
  66. * 查询指定货主 月份 按照货主 计费模型汇总的 作业费(出入库费)和税费
  67. * @param $owner_id
  68. * @param $counting_month
  69. * @return Builder[]|Collection
  70. */
  71. public function getTotalFee($owner_id, $counting_month)
  72. {
  73. list($start, $end) = $this->getStartAndEnd($counting_month);
  74. return OwnerFeeDetail::query()
  75. ->selectRaw("owner_price_operation_id,
  76. sum(work_fee) as work_fee,
  77. sum(work_tax_fee) as work_tax_fee
  78. ")
  79. ->where('owner_id', $owner_id)
  80. ->whereBetween('created_at', [$start, $end])
  81. ->groupBy('owner_id', 'owner_price_operation_id')
  82. ->get();
  83. }
  84. }