OwnerStoreOutFeeDetailService.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. // $row = ['作业时间', '作业名称', '上游单号', '订单号', '商家编码', '商品条码', '商品名称', '商品数量', '单价', '价格描述', '合计'];
  49. $result[] = [
  50. $detail->worked_at ?? '',
  51. $detail->model->name ?? '',
  52. $detail->source_number,
  53. $detail->doc_number ?? '',
  54. $detail->commodity->sku ?? '',
  55. $detail->source_number ?? '',
  56. $detail->commodity->name ?? '',
  57. $detail->details[0]->amount ?? '',
  58. $detail->details[0]->price ?? '',
  59. $detail->fee_description ?? '',
  60. $detail->fee ?? '',
  61. ];
  62. }
  63. return $result;
  64. }
  65. public function add(array $model)
  66. {
  67. // TODO: Implement add() method.
  68. }
  69. /**
  70. * 查询指定货主 月份 按照货主 计费模型汇总的 作业费(出入库费)和税费
  71. * @param $owner_id
  72. * @param $counting_month
  73. * @return Builder[]|Collection
  74. */
  75. public function getTotalFee($owner_id, $counting_month)
  76. {
  77. list($start, $end) = $this->getStartAndEnd($counting_month);
  78. return OwnerFeeDetail::query()
  79. ->selectRaw("owner_price_operation_id,
  80. sum(work_fee) as work_fee,
  81. sum(work_tax_fee) as work_tax_fee
  82. ")
  83. ->where('owner_id', $owner_id)
  84. ->whereBetween('created_at', [$start, $end])
  85. ->groupBy('owner_id', 'owner_price_operation_id')
  86. ->get();
  87. }
  88. }