ParkingRepository.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/8/6
  6. * Time: 9:16 PM
  7. */
  8. namespace App\Repositories;
  9. use Carbon\Carbon;
  10. use App\Maps\CacheMap;
  11. use App\Models\Parking;
  12. use Illuminate\Support\Facades\Cache;
  13. class ParkingRepository extends BaseRepository
  14. {
  15. private static $filed = [
  16. 'name',
  17. 'area_fence',
  18. 'customer_service_time',
  19. 'customer_service_phone',
  20. 'status'
  21. ];
  22. public function __construct(Parking $model)
  23. {
  24. $this->model = $model;
  25. }
  26. public function all()
  27. {
  28. return $this->model->active()->get();
  29. }
  30. /**
  31. * 由area_id 获取停车区
  32. * @param number $area_id
  33. * @return mixed
  34. * User: Mead
  35. */
  36. public function byAreaIdGetStopSites($area_id)
  37. {
  38. return $this->model->where('area_id', $area_id)->where('type', Parking::TYPE_STOP_BIKE)->active()->get();
  39. }
  40. /**
  41. * 根据 area_id 获取停车点和禁停区
  42. * @param $area_id
  43. * @return mixed
  44. */
  45. public function byAreaIdGetAllStopSites($area_id)
  46. {
  47. return Cache::remember(CacheMap::PARkING . $area_id, Carbon::now()->addSeconds(CacheMap::CACHE_TIME), function () use ($area_id) {
  48. return $this->model->where('area_id', $area_id)->whereIn('type', [Parking::TYPE_STOP_BIKE, Parking::TYPE_NO_STOP_BIKE])->active()->get();
  49. });
  50. }
  51. /**
  52. * 根据 area_id 获取禁停区
  53. * @param $area_id
  54. * @return mixed
  55. */
  56. public function byAreaIdGetBanStopSites($area_id)
  57. {
  58. return Cache::remember(CacheMap::BAN_PARKING . $area_id, Carbon::now()->addSeconds(CacheMap::CACHE_TIME), function () use ($area_id) {
  59. return $this->model->where('area_id', $area_id)->where('type', Parking::TYPE_NO_STOP_BIKE)->active()->get();
  60. });
  61. }
  62. }