OwnerLogisticFeeDetailService.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 Carbon\Carbon;
  8. use Illuminate\Database\Eloquent\Builder;
  9. use Illuminate\Pagination\LengthAwarePaginator;
  10. use Illuminate\Support\Collection;
  11. class OwnerLogisticFeeDetailService
  12. {
  13. use ServiceAppAop;
  14. /**
  15. * @var $modelClass OwnerLogisticFeeDetail
  16. */
  17. protected $modelClass = OwnerLogisticFeeDetail::class;
  18. //插入数据 ServiceAppAop的 insert 方法 支持批量
  19. /**
  20. * 根据货主查询 和时间段查询
  21. * @param string $owner_id
  22. * @param string $start
  23. * @param string $end
  24. * @return LengthAwarePaginator
  25. */
  26. public function getDetails(string $owner_id, string $start, string $end, $paginateParams): LengthAwarePaginator
  27. {
  28. $logistic_ids = Logistic::query()->selectRaw('id')->where('type', '快递');
  29. $ownerFeeDetailQuery = OwnerFeeDetail::query()->selectRaw('id')
  30. ->where('type', '发货')
  31. ->where('outer_table_name', 'orders')
  32. ->whereIn('logistic_id', $logistic_ids)
  33. ->where('owner_id', $owner_id)
  34. ->where('worked_at', '>=', Carbon::parse($start)->startOfDay())
  35. ->where('worked_at', '<=', Carbon::parse($end)->endOfDay());
  36. $ownerLogisticFeeDetails = OwnerLogisticFeeDetail::query()->with([
  37. 'ownerFeeDetail:id,province,weight,logistic_fee',
  38. 'ownerFeeDetailLogistic:id,weight,logistic_fee,logistic_bill',
  39. 'logistic:id,name'
  40. ])
  41. ->whereIn('owner_fee_detail_id', $ownerFeeDetailQuery)
  42. ->orderBy('logistic_id')
  43. ->paginate($paginateParams['paginate'] ?? 50);
  44. $items = [];
  45. foreach ($ownerLogisticFeeDetails as $ownerLogisticFeeDetail) {
  46. $items[] = [
  47. 'logistic_name' => $ownerLogisticFeeDetail->logistic->name ?? '',//快递公司
  48. 'province' => $ownerLogisticFeeDetail->province,//省份
  49. 'logistic_bill' => $ownerLogisticFeeDetail->logistic_bill ?? '',//快递单号
  50. 'weight' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->weight ?? $ownerLogisticFeeDetail->ownerFeeDetail->weight ?? '0.00',//重量
  51. 'logistic_fee' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->logistic_fee ?? $ownerLogisticFeeDetail->ownerFeeDetail->logistic_fee ?? '0.00',//快递费
  52. 'initial_weight_price' => $ownerLogisticFeeDetail->initial_weight_price ?? '',//首重价格
  53. 'additional_price' => $ownerLogisticFeeDetail->additional_price ?? '',//续重价格
  54. ];
  55. }
  56. return new LengthAwarePaginator(
  57. $items,
  58. $ownerLogisticFeeDetails->total(),
  59. $ownerLogisticFeeDetails->perPage(),
  60. $ownerLogisticFeeDetails->currentPage(),
  61. ["path" => $ownerLogisticFeeDetails->path(), "pageName" => "page"]
  62. );
  63. }
  64. }