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