getSql($owner_id, $start, $end) ->paginate($paginateParams['paginate'] ?? 50); $items = $this->buildDetails($ownerLogisticFeeDetails); return new LengthAwarePaginator( $items, $ownerLogisticFeeDetails->total(), $ownerLogisticFeeDetails->perPage(), $ownerLogisticFeeDetails->currentPage(), ["path" => $ownerLogisticFeeDetails->path(), "pageName" => "page"] ); } /** * @param Builder $logistic_ids * @param string $owner_id * @param string $start * @param string $end * @return Builder */ private function getOwnerFeeDetailQuery(Builder $logistic_ids, string $owner_id, string $start, string $end): Builder { return 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()); } /** * @param string $owner_id * @param string $start * @param string $end * @return Builder */ public function getSql(string $owner_id, string $start, string $end): Builder { return OwnerLogisticFeeDetail::query()->with([ 'ownerFeeDetail:id,province,weight,logistic_fee', 'ownerFeeDetailLogistic:id,weight,logistic_fee,logistic_bill', 'logistic:id,name' ]) ->whereIn('owner_fee_detail_id', $this->getOwnerFeeDetailQuery(Logistic::query()->selectRaw('id')->where('type', '快递'), $owner_id, $start, $end)) ->orderBy('logistic_id'); } /** * @param $ownerLogisticFeeDetails * @return array */ public function buildDetails($ownerLogisticFeeDetails): array { $items = []; foreach ($ownerLogisticFeeDetails as $ownerLogisticFeeDetail) { $items[] = [ 'id' => $ownerLogisticFeeDetail->id, 'logistic_name' => $ownerLogisticFeeDetail->logistic->name ?? '',//快递公司 'province' => $ownerLogisticFeeDetail->province,//省份 'logistic_bill' => $ownerLogisticFeeDetail->logistic_bill ?? '',//快递单号 'weight' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->weight ?? $ownerLogisticFeeDetail->ownerFeeDetail->weight ?? '0.00',//重量 'initial_weight_price' => $ownerLogisticFeeDetail->initial_weight_price ?? '',//首重价格 'additional_price' => $ownerLogisticFeeDetail->additional_price ?? '',//续重价格 'logistic_fee' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->logistic_fee ?? $ownerLogisticFeeDetail->ownerFeeDetail->logistic_fee ?? '0.00',//快递费 ]; } return $items; } }