service = app('OwnerLogisticFeeReportService'); $this->userService = app('UserService'); $permittingOwnerIds = $this->userService->getPermittingOwnerIds(auth()->user()); if (is_null($year)) { $year = now()->subMonth()->year; } if (is_null($month)) { $month = now()->subMonth()->month; } $counting_month = $year . '-' . $month . '-' . '01'; if (is_null($owner_id)) { $owner_id = $permittingOwnerIds[0]; } return array($permittingOwnerIds, $counting_month, $owner_id); } /** * @param $owner_id * @param $counting_month * @return array */ public function get($owner_id, $counting_month): array { $this->archiveService = app('OwnerBillReportArchiveService'); $archived = $this->archiveService->getSql(\Carbon\Carbon::parse($counting_month)->toDateString(), $owner_id, \App\OwnerBillReportArchive::$enums['type']['仓储费'])->first(); if ($archived ?? false) { $areaReports = collect($archived->information['areaReports']); $billReport = collect($archived->information['billReport']); $price = $archived->information['price']; } else { $areaReports = OwnerAreaReport::query() ->with('ownerStoragePriceModel:id,using_type,price') ->where('owner_id', $owner_id) ->where('counting_month', $counting_month) ->get(); $billReport = OwnerBillReport::query() ->select(['storage_fee', 'id']) ->where('owner_id', $owner_id) ->where('counting_month', $counting_month) ->firstOr(function () { return new OwnerBillReport(); }); $totalArea = $areaReports->reduce(function ($carry, $areaReport) { return $carry + $areaReport->accounting_area; }, 0); try { $price = number_format(($billReport->storage_fee ?? 0) / $totalArea, 3); } catch (\Exception $e) { $price = 0; } } return array($areaReports, $billReport, $price); } }