| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Traits;
- use App\OwnerBillReport;
- use App\OwnerBillReportArchive;
- use Illuminate\Http\Request;
- use Illuminate\Support\Collection;
- trait SettlementBillTrait
- {
- /**
- * @param $year
- * @param $month
- * @param $owner_id
- * @return array
- */
- public function getRequestParams($year, $month, $owner_id): array
- {
- $permittingOwnerIds = app('UserService')->getPermittingOwnerIds(auth()->user());
- if (is_null($year)) {
- $year = now()->subMonth()->year;
- }
- if (is_null($month)) {
- $month = now()->subMonth()->month;
- }
- $counting_month = \Carbon\Carbon::parse($year . '-' . $month . '-' . '01')->toDateString();
- if (is_null($owner_id)) {
- $owner_id = $permittingOwnerIds[0];
- }
- return array($permittingOwnerIds, $counting_month, $owner_id);
- }
- /**
- * @param Request $request
- * @param $counting_month
- * @param $owner_id
- * @return Collection|\Tightenco\Collect\Support\Collection
- */
- public function buildRequest(Request $request, $counting_month,$owner_id)
- {
- $request = $request->all();
- $request['year'] = \Carbon\Carbon::parse($counting_month)->year;
- $request['month'] = \Carbon\Carbon::parse($counting_month)->month;
- $request['owner_id'] = $owner_id;
- return collect($request);
- }
- public function confirmBill(Request $request): \Illuminate\Http\RedirectResponse
- {
- 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', '确认成功');
- }
- }
|