1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/8/6
- * Time: 9:16 PM
- */
- namespace App\Repositories;
- use Carbon\Carbon;
- use App\Maps\CacheMap;
- use App\Models\Parking;
- use Illuminate\Support\Facades\Cache;
- class ParkingRepository extends BaseRepository
- {
- private static $filed = [
- 'name',
- 'area_fence',
- 'customer_service_time',
- 'customer_service_phone',
- 'status'
- ];
- public function __construct(Parking $model)
- {
- $this->model = $model;
- }
- public function all()
- {
- return $this->model->active()->get();
- }
- /**
- * 由area_id 获取停车区
- * @param number $area_id
- * @return mixed
- * User: Mead
- */
- public function byAreaIdGetStopSites($area_id)
- {
- return $this->model->where('area_id', $area_id)->where('type', Parking::TYPE_STOP_BIKE)->active()->get();
- }
- /**
- * 根据 area_id 获取停车点和禁停区
- * @param $area_id
- * @return mixed
- */
- public function byAreaIdGetAllStopSites($area_id)
- {
- return Cache::remember(CacheMap::PARkING . $area_id, Carbon::now()->addSeconds(CacheMap::CACHE_TIME), function () use ($area_id) {
- return $this->model->where('area_id', $area_id)->whereIn('type', [Parking::TYPE_STOP_BIKE, Parking::TYPE_NO_STOP_BIKE])->active()->get();
- });
- }
- /**
- * 根据 area_id 获取禁停区
- * @param $area_id
- * @return mixed
- */
- public function byAreaIdGetBanStopSites($area_id)
- {
- return Cache::remember(CacheMap::BAN_PARKING . $area_id, Carbon::now()->addSeconds(CacheMap::CACHE_TIME), function () use ($area_id) {
- return $this->model->where('area_id', $area_id)->where('type', Parking::TYPE_NO_STOP_BIKE)->active()->get();
- });
- }
- }
|