| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Services;
- use App\Logistic;
- use App\OwnerFeeDetail;
- use App\Traits\ServiceAppAop;
- use App\OwnerLogisticFeeDetail;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Pagination\LengthAwarePaginator;
- use Illuminate\Support\Collection;
- class OwnerLogisticFeeDetailService
- {
- use ServiceAppAop;
- /**
- * @var $modelClass OwnerLogisticFeeDetail
- */
- protected $modelClass = OwnerLogisticFeeDetail::class;
- //插入数据 ServiceAppAop的 insert 方法 支持批量
- /**
- * 根据货主查询 和时间段查询
- * @param string $owner_id
- * @param string $start
- * @param string $end
- * @return LengthAwarePaginator
- */
- public function getDetails(string $owner_id, string $start, string $end, $paginateParams): LengthAwarePaginator
- {
- $logistic_ids = Logistic::query()->selectRaw('id')->where('type', '快递');
- $ownerFeeDetailQuery = OwnerFeeDetail::query()->selectRaw('id')
- ->where('type', '发货')
- ->where('outer_table_name', 'orders')
- ->whereIn('logistic_id', $logistic_ids)
- ->where('owner_id', $owner_id)
- ->where('worked_at', '>=', Carbon::parse($start)->startOfDay())
- ->where('worked_at', '<=', Carbon::parse($end)->endOfDay());
- $ownerLogisticFeeDetails = OwnerLogisticFeeDetail::query()->with([
- 'ownerFeeDetail:id,province,weight,logistic_fee',
- 'ownerFeeDetailLogistic:id,weight,logistic_fee,logistic_bill',
- 'logistic:id,name'
- ])
- ->whereIn('owner_fee_detail_id', $ownerFeeDetailQuery)
- ->orderBy('logistic_id')
- ->paginate($paginateParams['paginate'] ?? 50);
- $items = [];
- foreach ($ownerLogisticFeeDetails as $ownerLogisticFeeDetail) {
- $items[] = [
- 'logistic_name' => $ownerLogisticFeeDetail->logistic->name ?? '',//快递公司
- 'province' => $ownerLogisticFeeDetail->province,//省份
- 'logistic_bill' => $ownerLogisticFeeDetail->logistic_bill ?? '',//快递单号
- 'weight' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->weight ?? $ownerLogisticFeeDetail->ownerFeeDetail->weight ?? '0.00',//重量
- 'logistic_fee' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->logistic_fee ?? $ownerLogisticFeeDetail->ownerFeeDetail->logistic_fee ?? '0.00',//快递费
- 'initial_weight_price' => $ownerLogisticFeeDetail->initial_weight_price ?? '',//首重价格
- 'additional_price' => $ownerLogisticFeeDetail->additional_price ?? '',//续重价格
- ];
- }
- return new LengthAwarePaginator(
- $items,
- $ownerLogisticFeeDetails->total(),
- $ownerLogisticFeeDetails->perPage(),
- $ownerLogisticFeeDetails->currentPage(),
- ["path" => $ownerLogisticFeeDetails->path(), "pageName" => "page"]
- );
- }
- }
|