123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace App\Repositories;
- use App\Models\CardRiding;
- use Illuminate\Database\Eloquent\Builder;
- class CardRidingRepository extends BaseRepository
- {
- public function __construct(CardRiding $model)
- {
- $this->model = $model;
- }
- /**
- * 根据区域id获取可用骑行卡列表
- *
- * @param $area_id integer
- *
- * @return collection
- * */
- public function byAreaIdGetCardRidings($area_id)
- {
- return $this->model->query()
- ->with(['areaRidingCard'])
- ->whereHas('areaRidingCard', function (Builder $query) use ($area_id) {
- $query->where('area_id', $area_id);
- }, '>', 0)
- ->where('status', CardRiding::STATUS_OK)
- ->orderBy('price')
- ->get();
- }
- public function byAreaIdIsExists($area_id)
- {
- return $this->model->query()
- ->with(['areaRidingCard'])
- ->whereHas('areaRidingCard', function (Builder $query) use ($area_id) {
- return $query->where('area_id', $area_id);
- }, '>', 0)
- ->where('status', CardRiding::STATUS_OK)
- ->exists();
- }
- /**
- * 判断骑行卡是否启用
- *
- * @param $id integer
- *
- * @return bool true表示可用 false不可用
- *
- * */
- public function isStatusOK($id)
- {
- $cardRiding = $this->model->query()->where('id', $id)->where('status', CardRiding::STATUS_OK)->first();
- if (empty($cardRiding)) return false;
- return true;
- }
- }
|