OwnerLogisticFeeDetailService.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Services;
  3. use App\Logistic;
  4. use App\OwnerFeeDetail;
  5. use App\Traits\ServiceAppAop;
  6. use App\OwnerLogisticFeeDetail;
  7. use App\Traits\SettlementBillServiceTrait;
  8. use Carbon\Carbon;
  9. use Illuminate\Database\Eloquent\Builder;
  10. use Illuminate\Pagination\LengthAwarePaginator;
  11. class OwnerLogisticFeeDetailService implements \App\Interfaces\SettlementBillDetailInterface
  12. {
  13. use SettlementBillServiceTrait;
  14. const TYPE = '快递费-明细';
  15. use ServiceAppAop;
  16. /**
  17. * @var $modelClass OwnerLogisticFeeDetail
  18. */
  19. protected $modelClass = OwnerLogisticFeeDetail::class;
  20. /**
  21. * 根据货主查询 和时间段查询
  22. * @param array $kvPairs
  23. * @return LengthAwarePaginator
  24. */
  25. public function get(array $kvPairs): LengthAwarePaginator
  26. {
  27. $ownerLogisticFeeDetails = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50);
  28. $items = $this->buildDetails($ownerLogisticFeeDetails);
  29. return new LengthAwarePaginator(
  30. $items,
  31. $ownerLogisticFeeDetails->total(),
  32. $ownerLogisticFeeDetails->perPage(),
  33. $ownerLogisticFeeDetails->currentPage(),
  34. ["path" => $ownerLogisticFeeDetails->path(), "pageName" => "page"]
  35. );
  36. }
  37. /**
  38. * @param Builder $logistic_ids
  39. * @param string $owner_id
  40. * @param string $start
  41. * @param string $end
  42. * @return Builder
  43. */
  44. private function getOwnerFeeDetailQuery(Builder $logistic_ids, string $owner_id, string $start, string $end): Builder
  45. {
  46. return OwnerFeeDetail::query()->selectRaw('id')
  47. ->where('type', '发货')
  48. ->where('outer_table_name', 'orders')
  49. ->whereIn('logistic_id', $logistic_ids)
  50. ->where('owner_id', $owner_id)
  51. ->where('worked_at', '>=', Carbon::parse($start)->startOfDay())
  52. ->where('worked_at', '<=', Carbon::parse($end)->endOfDay());
  53. }
  54. /**
  55. * @return Builder
  56. */
  57. public function getSql($owner_id, $counting_month): Builder
  58. {
  59. list($start, $end) = $this->getStartAndEnd($counting_month);
  60. return OwnerLogisticFeeDetail::query()->with([
  61. 'ownerFeeDetail:id,province,weight,logistic_fee',
  62. 'ownerFeeDetailLogistic:id,weight,logistic_fee,logistic_bill',
  63. 'logistic:id,name'
  64. ])
  65. ->whereIn('owner_fee_detail_id', $this->getOwnerFeeDetailQuery(Logistic::query()->selectRaw('id')->where('type', '快递'), $owner_id, $start, $end))
  66. ->orderBy('logistic_id');
  67. }
  68. /**
  69. * @param $ownerLogisticFeeDetails
  70. * @return array
  71. */
  72. public function buildDetails($ownerLogisticFeeDetails): array
  73. {
  74. $items = [];
  75. foreach ($ownerLogisticFeeDetails as $ownerLogisticFeeDetail) {
  76. $items[] = [
  77. 'id' => $ownerLogisticFeeDetail->id,
  78. 'logistic_name' => $ownerLogisticFeeDetail->logistic->name ?? '',//快递公司
  79. 'province' => $ownerLogisticFeeDetail->province,//省份
  80. 'logistic_bill' => $ownerLogisticFeeDetail->logistic_bill ?? '',//快递单号
  81. 'weight' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->weight ?? $ownerLogisticFeeDetail->ownerFeeDetail->weight ?? '0.00',//重量
  82. 'initial_weight_price' => $ownerLogisticFeeDetail->initial_weight_price ?? '',//首重价格
  83. 'additional_price' => $ownerLogisticFeeDetail->additional_price ?? '',//续重价格
  84. // 'logistic_fee' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->logistic_fee ?? $ownerLogisticFeeDetail->ownerFeeDetail->logistic_fee ?? '0.00',//快递费
  85. 'logistic_fee' => $ownerLogisticFeeDetail->fee,//快递费
  86. ];
  87. }
  88. return $items;
  89. }
  90. public function switchType($type)
  91. {
  92. }
  93. public function buildExport($details): array
  94. {
  95. }
  96. public function add(array $model)
  97. {
  98. }
  99. public function getTotalFee($owner_id, $counting_month)
  100. {
  101. }
  102. }