AreaSettingRepository.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 App\Maps\CacheMap;
  10. use App\Models\AreaSetting;
  11. use Carbon\Carbon;
  12. use Illuminate\Support\Facades\Cache;
  13. class AreaSettingRepository extends BaseRepository
  14. {
  15. public function __construct(AreaSetting $model)
  16. {
  17. $this->model = $model;
  18. }
  19. /**
  20. * 根据area_id 获取区域配置
  21. * @param $area_id
  22. * @return mixed
  23. * User: Mead
  24. */
  25. public function byAreaId($area_id)
  26. {
  27. return $this->model->where('area_id', $area_id)->first();
  28. }
  29. /**
  30. * 根据area_id获取是否全区域可以还车
  31. * @param $area_id
  32. * @return int
  33. */
  34. public function byAreaIdGetIsWholeAreaHuanche($area_id): int
  35. {
  36. return Cache::remember(CacheMap::BY_AREA_ID_GET_IS_WHOLE_AREA_HUANCHE . $area_id, Carbon::now()->addSeconds(CacheMap::CACHE_TIME), function () use ($area_id) {
  37. return $this->model->where('area_id', $area_id)->value('is_whole_area_huanche');
  38. });
  39. }
  40. /**
  41. * 根据area_id获取是否全区域可以还车
  42. * @param $area_id
  43. * @return int
  44. */
  45. public function byAreaIdGetFreeMinute($area_id): int
  46. {
  47. return Cache::remember(CacheMap::BY_AREA_ID_GET_FREE_MINUTE . $area_id, Carbon::now()->addSeconds(CacheMap::CACHE_TIME), function () use ($area_id) {
  48. return $this->model->where('area_id', $area_id)->value('many_minute_free');
  49. });
  50. }
  51. /**
  52. * 根据area_id获取是否全区域可以还车
  53. * @param $area_id
  54. * @return int
  55. */
  56. public function byAreaIdGetBatteryPower($area_id): int
  57. {
  58. return Cache::remember(CacheMap::BY_AREA_ID_GET_BATTERY_POWER . $area_id, Carbon::now()->addSeconds(CacheMap::CACHE_TIME), function () use ($area_id) {
  59. return $this->model->where('area_id', $area_id)->value('power_lower');
  60. });
  61. }
  62. }