input(); list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); list($reports, $recordTotal) = $this->service->get([ 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'paginateParams' => $paginateParams, 'type' => $this->service::TYPE, ]); $reportPaginator = null; if ($reports instanceof LengthAwarePaginator) { $reportPaginator = $reports; $reports = collect($reportPaginator->items()); } $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, OwnerBillReportArchive::$enums['type']['快递费-合计']); $request = $this->buildRequest($request, $counting_month,$owner_id); return view('finance.settlementBills.expressFee.report.index', compact('reports', 'recordTotal', 'paginateParams', 'owners', 'owner', 'isArchived', 'request', 'reportPaginator')); } public function export(Request $request) { $this->archiveService = app('OwnerBillReportArchiveService'); list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); if ($this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE) == 1) { //已确认账单导出 list($reports, $recordTotal) = $this->service->get([ 'owner_id' => $owner_id, 'counting_month' => $counting_month, 'type' => $this->service::TYPE, ]); } else { //未确认账单导出 $query = $this->service->getSql($owner_id, $counting_month); if (!$request->exists('checkAllSign')) { $query->whereIn('id', explode(',', $request['data'])); } $reports = $query->get(); } $json = []; foreach ($reports as $report) { $json[] = [ $report['logistic']['name'] ?? '', $report['province']['name'], $report['initial_weight'], $report['initial_amount'], $report['additional_weight'], $report['additional_amount'], $report['fee'], ]; } $row = ['快递公司', '地区', '首重', '订单数', '续重', '续重合计', '(省份)合计']; return Export::make($row, $json, "快递费用合计"); } /** * @param $year * @param $month * @param $owner_id * @return array */ private function getRequestParams($year, $month, $owner_id): array { $this->service = app('OwnerLogisticFeeReportService'); $this->userService = app('UserService'); $permittingOwnerIds = app("OwnerService")->getIdArr(); 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 Request $request * @return RedirectResponse */ public function confirmBill(Request $request):RedirectResponse { $this->service = app('OwnerLogisticFeeReportService'); list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id); $this->service->confirmBill($counting_month, $owner_id); return back()->with('success', '确认成功'); } }