service = app('OwnerStoreFeeReportService'); $this->archiveService = app('OwnerBillReportArchiveService'); } public function index(Request $request) { list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); list($reports, $totalAmount, $totalFee, $owner_price_operation_fees) = $this->service->get([ 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, ]); $owner_price_operation_fees = $this->buildOwnerPriceOperationFees($reports, $owner_price_operation_fees); $owner = Owner::query()->selectRaw("name,id")->find($owner_id); $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get(); $this->archiveService = app('OwnerBillReportArchiveService'); $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE); $request = $this->buildRequest($request, $counting_month, $owner_id); return view('finance.settlementBills.storeFee.report.index', compact('owners', 'owner', 'isArchived', 'request', 'totalAmount', 'totalFee', 'owner_price_operation_fees')); } public function export(Request $request) { $this->service = app('OwnerStoreFeeReportService'); $this->archiveService = app('OwnerBillReportArchiveService'); list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); list($reports, $totalAmount, $totalFee, $owner_price_operation_fees) = $this->service->get([ 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, ]); $json = []; foreach ($reports as $report) { $operation = $owner_price_operation_fees->firstWhere('work_name', $report['work_name']); $json[] = [ $report['work_name'], $report['unit_price'], $report['amount'], $operation['fee'], ]; } $row = ['名称', '单价', '数量', '合计']; return Export::make($row, $json, "入库费合计"); } /** * @param $reports * @param $owner_price_operation_fees * @return \Illuminate\Support\Collection|Collection */ private function buildOwnerPriceOperationFees($reports, $owner_price_operation_fees) { $result = []; $reports = $reports->groupBy('work_name'); foreach ($owner_price_operation_fees as $price_operation) { $price_operation['data'] = $reports[$price_operation['work_name']]; $result[] = $price_operation; } return collect($result); } }