OwnerStoreOutFeeDetailService.php 2.6 KB

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