|
|
@@ -2,11 +2,13 @@
|
|
|
|
|
|
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
|
|
|
@@ -25,71 +27,45 @@ class OwnerLogisticFeeDetailService
|
|
|
* @param string $owner_id
|
|
|
* @param string $start
|
|
|
* @param string $end
|
|
|
- * @return array
|
|
|
+ * @return LengthAwarePaginator
|
|
|
*/
|
|
|
- public function getDetails(string $owner_id, string $start, string $end): array
|
|
|
+ public function getDetails(string $owner_id, string $start, string $end, $paginateParams): LengthAwarePaginator
|
|
|
{
|
|
|
- $ownerFeeDetailIds = OwnerFeeDetail::query()->selectRaw('id')
|
|
|
+ $logistic_ids = Logistic::query()->selectRaw('id')->where('type', '快递');
|
|
|
+ $ownerFeeDetailQuery = OwnerFeeDetail::query()->selectRaw('id')
|
|
|
->where('type', '发货')
|
|
|
->where('outer_table_name', 'orders')
|
|
|
- ->whereHas('logistic', function (Builder $query) {
|
|
|
- $query->where('type', '快递');
|
|
|
- })
|
|
|
+ ->whereIn('logistic_id', $logistic_ids)
|
|
|
->where('owner_id', $owner_id)
|
|
|
->where('worked_at', '>=', Carbon::parse($start)->startOfDay())
|
|
|
- ->where('worked_at', '<=', Carbon::parse($end)->endOfDay())->pluck('id');
|
|
|
- $ownerLogisticFeeDetails = OwnerLogisticFeeDetail::query()->with(['ownerFeeDetail.logistic', 'ownerFeeDetailLogistic'])->whereIn('owner_fee_detail_id', $ownerFeeDetailIds)->paginate();
|
|
|
- dd($ownerLogisticFeeDetails);
|
|
|
+ ->where('worked_at', '<=', Carbon::parse($end)->endOfDay());
|
|
|
|
|
|
-// $ownerFeeDetails = OwnerFeeDetail::query()
|
|
|
-// ->with(['ownerLogisticFeeDetail:id,logistic_bill,initial_weight_price,additional_price', 'items.logistic:id,name','items.ownerLogisticFeeDetail:id,logistic_bill,initial_weight_price,additional_price', 'logistic:id,name,type'])
|
|
|
-// ->where('type', '发货')
|
|
|
-// ->where('outer_table_name', 'orders')
|
|
|
-// ->whereHas('logistic', function (Builder $query) {
|
|
|
-// $query->where('type', '快递');
|
|
|
-// })
|
|
|
-// ->where('owner_id', $owner_id)
|
|
|
-// ->where('worked_at', '>=', Carbon::parse($start)->startOfDay())
|
|
|
-// ->where('worked_at', '<=', Carbon::parse($end)->endOfDay())
|
|
|
-// ->get();
|
|
|
-// $result = [];
|
|
|
-// foreach ($ownerFeeDetails as $ownerFeeDetail) {
|
|
|
-// if ($ownerFeeDetail->items->count()==0) {//只有一个包裹
|
|
|
-// $result[] = [
|
|
|
-// 'logistic_name' => $ownerFeeDetail->logistic->name ?? '',//快递公司
|
|
|
-// 'province' => $ownerFeeDetail->province,//省份
|
|
|
-// 'logistic_bill' => $ownerFeeDetail->logistic_bill ?? '',//快递单号
|
|
|
-// 'weight' => $ownerFeeDetail->weight,//重量
|
|
|
-// 'logistic_fee' => $ownerFeeDetail->logistic_fee,//快递费
|
|
|
-// 'initial_weight_price' => $ownerFeeDetail->ownerLogisticFeeDetail->initial_weight_price ?? '',//首重价格
|
|
|
-// 'additional_price' => $ownerFeeDetail->ownerLogisticFeeDetail->additional_price ?? '',//续重价格
|
|
|
-// ];
|
|
|
-// } else {//多个包裹
|
|
|
-// foreach ($ownerFeeDetail->items as $ownerFeeDetailLogistic) {
|
|
|
-// $result[] = [
|
|
|
-// 'logistic_name' => $ownerFeeDetail->logistic->name ?? '',//快递公司
|
|
|
-// 'province' => $ownerFeeDetail->province,//省份
|
|
|
-// 'logistic_bill' => $ownerFeeDetailLogistic->logistic_bill,//快递单号
|
|
|
-// 'weight' => $ownerFeeDetailLogistic->weight,//重量
|
|
|
-// 'logistic_fee' => $ownerFeeDetailLogistic->logistic_fee,//快递费
|
|
|
-// 'initial_weight_price' => $ownerFeeDetailLogistic->ownerLogisticFeeDetail->initial_weight_price ?? '',//首重价格
|
|
|
-// 'additional_price' => $ownerFeeDetailLogistic->ownerLogisticFeeDetail->additional_price ?? '',//续重价格
|
|
|
-// ];
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
- $result = [];
|
|
|
- foreach ($ownerLogisticFeeDetails->items() as $ownerLogisticFeeDetail) {
|
|
|
- $result[] = [
|
|
|
- 'logistic_name' => $ownerLogisticFeeDetail->ownerFeeDetail->logistic->name ?? '',//快递公司
|
|
|
- 'province' => $ownerLogisticFeeDetail->ownerFeeDetail->province,//省份
|
|
|
- 'logistic_bill' => $ownerLogisticFeeDetail->logistic_bill ?? '',//快递单号
|
|
|
- 'weight' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->weight,//重量
|
|
|
- 'logistic_fee' => $ownerLogisticFeeDetail->ownerFeeDetailLogistic->logistic_fee,//快递费
|
|
|
- 'initial_weight_price' => $ownerLogisticFeeDetail->initial_weight_price ?? '',//首重价格
|
|
|
- 'additional_price' => $ownerLogisticFeeDetail->additional_price ?? '',//续重价格
|
|
|
- ];
|
|
|
+ $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 $result;
|
|
|
+ return new LengthAwarePaginator(
|
|
|
+ $items,
|
|
|
+ $ownerLogisticFeeDetails->total(),
|
|
|
+ $ownerLogisticFeeDetails->perPage(),
|
|
|
+ $ownerLogisticFeeDetails->currentPage(),
|
|
|
+ ["path" => $ownerLogisticFeeDetails->path(), "pageName" => "page"]
|
|
|
+ );
|
|
|
}
|
|
|
}
|