| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- namespace App\Http\Controllers;
- use App\Owner;
- use App\OwnerBillReport;
- use App\OwnerBillReportArchive;
- use App\Services\OwnerBillReportArchiveService;
- use App\Services\OwnerLogisticFeeReportService;
- use App\Services\UserService;
- use App\Traits\SettlementBillTrait;
- use Illuminate\Http\RedirectResponse;
- use Illuminate\Http\Request;
- use Illuminate\Pagination\LengthAwarePaginator;
- use Oursdreams\Export\Export;
- class SettlementBillExpressFeeReportController extends Controller
- {
- use SettlementBillTrait;
- /* @var OwnerLogisticFeeReportService $service */
- private $service;
- /* @var UserService $userService */
- private $userService;
- /** @var $archiveService OwnerBillReportArchiveService */
- private $archiveService;
- /**
- * Display a listing of the resource.
- */
- public function index(Request $request)
- {
- $paginateParams = $request->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', '确认成功');
- }
- }
|