| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Services;
- use App\OwnerFeeDetail;
- use App\Traits\ServiceAppAop;
- use App\OwnerLogisticFeeDetail;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Builder;
- 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 array
- */
- public function getDetails(string $owner_id, string $start, string $end): array
- {
- $ownerFeeDetailIds = OwnerFeeDetail::query()->selectRaw('id')
- ->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())->pluck('id');
- $ownerLogisticFeeDetails = OwnerLogisticFeeDetail::query()->with(['ownerFeeDetail.logistic', 'ownerFeeDetailLogistic'])->whereIn('owner_fee_detail_id', $ownerFeeDetailIds)->paginate();
- dd($ownerLogisticFeeDetails);
- // $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 ?? '',//续重价格
- ];
- }
- return $result;
- }
- }
|