input(); list($permittingOwnerIds, $owner_id, $start, $end) = $this->getRequestParams($request->owner_id, $request->year, $request->month); $details = $this->service->getDetails($owner_id, $start, $end, $paginateParams); $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get(); $owner = Owner::query()->selectRaw("name,id")->find($owner_id); $this->archiveService = app('OwnerBillReportArchiveService'); $isArchived = $this->archiveService->isArchived($start, $owner_id, OwnerBillReportArchive::$enums['type']['快递费-明细']); $request = collect($request->all()); return view('finance.settlementBills.logisticFee.detail.index', compact('details', 'paginateParams', 'owners', 'owner', 'request','isArchived')); } public function export(Request $request) { list($permittingOwnerIds, $owner_id, $start, $end) = $this->getRequestParams($request->owner_id, $request->year, $request->month); $query = $this->service->getSql($owner_id, $start, $end); if (!$request->exists('checkAllSign')) { $query->whereIn('id', explode(',', $request['data'])); } $details = $this->service->buildDetails($query->get()); $json = []; foreach ($details as $detail) { $json[] = array_values($detail); } $row = ['主键', '快递公司', '省份', '快递单号', '重量', '首重价格', '续重价格', '快递费',]; return Export::make($row, $json, "快递费用详情"); } /** * @param $owner_id * @param $year * @param $month * @return array */ private function getRequestParams($owner_id, $year, $month): array { $this->service = app('OwnerLogisticFeeDetailService'); $this->userService = app('UserService'); $permittingOwnerIds = $this->userService->getPermittingOwnerIds(auth()->user()); if (is_null($owner_id)) { $owner_id = $permittingOwnerIds[0]; } if (is_null($year)) { $year = now()->subMonth()->year; } if (is_null($month)) { $month = now()->subMonth()->month; } $day = Carbon::parse($year . '-' . $month . '-01'); return array($permittingOwnerIds, $owner_id, $day->startOfMonth()->toDateString(), $day->endOfMonth()->toDateString()); } /** * 确认账单 * @param Request $request * @return RedirectResponse */ public function confirmBill(Request $request) { $this->service = app('OwnerLogisticFeeDetailService'); $this->archiveService = app('OwnerBillReportArchiveService'); list($permittingOwnerIds, $owner_id, $start, $end) = $this->getRequestParams($request->owner_id, $request->year, $request->month); $billReport = OwnerBillReport::query() ->select('storage_fee', 'id') ->where('owner_id', $owner_id) ->where('counting_month', $start) ->firstOr(function () { return new OwnerBillReport(); }); OwnerBillReportArchive::query()->create([ 'owner_bill_report_id' => $billReport->id ?? null, 'owner_id' => $owner_id, 'counting_mouth' => $start, 'type' => $this->service::TYPE, 'archiver_id' => auth()->id(), 'archived_at' => now(), 'information' => [], ]); return back()->with('success', '确认成功'); } }