SettlementBillOwnerAreaFeeController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\OwnerAreaReport;
  4. use Illuminate\Http\Request;
  5. /**
  6. * 结算管理-结算账单-仓储费
  7. * Class SettlementBillOwnerAreaFeeController
  8. * @package App\Http\Controllers
  9. */
  10. class SettlementBillOwnerAreaFeeController extends Controller
  11. {
  12. /**
  13. * SettlementBillOwnerAreaFeeController constructor.
  14. */
  15. public function __construct()
  16. {
  17. $this->middleware('auth');
  18. }
  19. public function index(Request $request)
  20. {
  21. list($permittingOwnerIds, $date, $owner_id) = $this->getRequestParams($request);
  22. $owners = \App\Owner::query()->find($permittingOwnerIds);
  23. $owner = \App\Owner::query()->find($owner_id);
  24. $ownerAreas = OwnerAreaReport::query()
  25. ->with('ownerStoragePriceModel:id,using_type')
  26. ->where('owner_id', $owner_id)
  27. ->where('counting_month', $date)
  28. ->get();
  29. $ownerBillReport = \App\OwnerBillReport::query()
  30. ->selectRaw('storage_fee')
  31. ->where('owner_id', $owner_id)
  32. ->where('counting_month', $date)
  33. ->first();
  34. }
  35. /**
  36. * @param Request $request
  37. * @return array
  38. */
  39. private function getRequestParams(Request $request): array
  40. {
  41. $this->service = app('OwnerLogisticFeeReportService');
  42. $this->userService = app('UserService');
  43. $permittingOwnerIds = $this->userService->getPermittingOwnerIds(auth()->user());
  44. if (is_null($request->year) || is_null($request->month)) {
  45. $date = now()->subMonth()->startOfMonth()->toDateString();
  46. } else {
  47. $date = $request->year . '-' . $request->month . '-' . '01';
  48. }
  49. if (is_null($request->owner_id)) {
  50. $owner_id = $permittingOwnerIds[0];
  51. } else {
  52. $owner_id = $request->owner_id;
  53. }
  54. return array($permittingOwnerIds, $date, $owner_id);
  55. }
  56. }