middleware('auth'); } public function index(Request $request) { $this->service = app('OwnerStoreFeeReportService'); $this->archiveService = app('OwnerBillReportArchiveService'); list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id); list($reports, $totalAmount, $totalFee, $newFee, $backFee) = $this->service->get([ 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, ]); $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); return view('finance.settlementBills.storeFee.report.index', compact('reports', 'owners', 'owner', 'isArchived', 'request', 'reports', 'totalAmount', 'totalFee', 'newFee', 'backFee')); } public function confirmBill(Request $request) { $this->service = app('OwnerStoreFeeReportService'); $this->archiveService = app('OwnerBillReportArchiveService'); list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id); $billReport = OwnerBillReport::query() ->select('storage_fee', 'id') ->where('owner_id', $owner_id) ->where('counting_month', $counting_month) ->firstOr(function () { return new OwnerBillReport(); }); list($reports, $totalAmount, $totalFee, $newFee, $backFee) = $this->service->get([ 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, ]); OwnerBillReportArchive::query()->create([ 'owner_bill_report_id' => $billReport->id ?? null, 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, 'archiver_id' => auth()->id(), 'archived_at' => now(), 'information' => [ 'reports' => $reports, 'totalAmount' => $totalAmount, 'totalFee' => $totalFee, 'newFee' => $newFee, 'backFee' => $backFee, ], ]); return back()->with('success', '确认成功'); } public function export(Request $request) { $this->service = app('OwnerStoreFeeReportService'); $this->archiveService = app('OwnerBillReportArchiveService'); list($permittingOwnerIds, $counting_month, $owner_id) = $this->service->getRequestParams($request->year, $request->month, $request->owner_id); list($reports, $totalAmount, $totalFee, $newFee, $backFee) = $this->service->get([ 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, ]); $json = []; foreach ($reports as $report) { $json[] = [ $report['type'], $report['unit_price'], $report['amount'], $report['type'] == '新品入库' ? $newFee : $backFee, ]; } $row = ['名称', '单价', '数量', '合计']; return Export::make($row, $json, "入库费合计"); } }