SettlementBillTrait.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Traits;
  3. use App\OwnerBillReport;
  4. use App\OwnerBillReportArchive;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Collection;
  7. trait SettlementBillTrait
  8. {
  9. /**
  10. * @param $year
  11. * @param $month
  12. * @param $owner_id
  13. * @return array
  14. */
  15. public function getRequestParams($year, $month, $owner_id): array
  16. {
  17. $permittingOwnerIds = app('UserService')->getPermittingOwnerIds(auth()->user());
  18. if (is_null($year)) {
  19. $year = now()->subMonth()->year;
  20. }
  21. if (is_null($month)) {
  22. $month = now()->subMonth()->month;
  23. }
  24. $counting_month = \Carbon\Carbon::parse($year . '-' . $month . '-' . '01')->toDateString();
  25. if (is_null($owner_id)) {
  26. $owner_id = $permittingOwnerIds[0];
  27. }
  28. return array($permittingOwnerIds, $counting_month, $owner_id);
  29. }
  30. /**
  31. * @param Request $request
  32. * @param $counting_month
  33. * @param $owner_id
  34. * @return Collection|\Tightenco\Collect\Support\Collection
  35. */
  36. public function buildRequest(Request $request, $counting_month,$owner_id)
  37. {
  38. $request = $request->all();
  39. $request['year'] = \Carbon\Carbon::parse($counting_month)->year;
  40. $request['month'] = \Carbon\Carbon::parse($counting_month)->month;
  41. $request['owner_id'] = $owner_id;
  42. return collect($request);
  43. }
  44. public function confirmBill(Request $request): \Illuminate\Http\RedirectResponse
  45. {
  46. list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
  47. $this->service->confirmBill($counting_month, $owner_id);
  48. return back()->with('success', '确认成功');
  49. }
  50. }