archiveService = app('OwnerBillReportArchiveService'); $this->service = app('OwnerSundryFeeDetailService'); $this->middleware('auth'); } public function index(Request $request) { $paginateParams = $request->input(); list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); $owner_sundry_fee_details = $this->service->get([ 'counting_month' => $counting_month, 'owner_id' => $owner_id, 'paginateParams' => $paginateParams, ]); $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get(); $owner = Owner::query()->selectRaw("name,id")->find($owner_id); $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE); $request = $this->buildRequest($request, $counting_month); return view('finance.settlementBills.ownerSundryFee.index', compact('owner_sundry_fee_details', 'paginateParams', 'owners', 'owner', 'request', 'isArchived')); } /** * @param Request $request * @return RedirectResponse */ public function confirmBill(Request $request): RedirectResponse { list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); $billReport = OwnerBillReport::query() ->select('id') ->where('owner_id', $owner_id) ->where('counting_month', $counting_month) ->firstOr(function () { return new OwnerBillReport(); }); 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' => [], ]); return back()->with('success', '确认成功'); } public function export(Request $request) { list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); $query = $this->service->getSql($owner_id, $counting_month); if (!$request->exists('checkAllSign')) { $query->whereIn('id', explode(',', $request['data'])); } $details = $query->get(); $row = ['货主', '日期', '作业类型', '费用描述', '快递单号', '承运商', '数量', '单价', '收费金额', '备注']; $json = []; foreach ($details as $detail) { $json[] = [ $detail->owner->name ?? '', $detail->created_at ?? '', $detail->type ?? '', $detail->fee_explain ?? '', $detail->logistic_name ?? '', $detail->logistic->name ?? '', $detail->amount ?? '', $detail->price ?? '', $detail->fee ?? '', $detail->remark ?? '', ]; } return Export::make($row, $json, "杂项费"); } }