CardRidingRepository.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\CardRiding;
  4. use Illuminate\Database\Eloquent\Builder;
  5. class CardRidingRepository extends BaseRepository
  6. {
  7. public function __construct(CardRiding $model)
  8. {
  9. $this->model = $model;
  10. }
  11. /**
  12. * 根据区域id获取可用骑行卡列表
  13. *
  14. * @param $area_id integer
  15. *
  16. * @return collection
  17. * */
  18. public function byAreaIdGetCardRidings($area_id)
  19. {
  20. return $this->model->query()
  21. ->with(['areaRidingCard'])
  22. ->whereHas('areaRidingCard', function (Builder $query) use ($area_id) {
  23. $query->where('area_id', $area_id);
  24. }, '>', 0)
  25. ->where('status', CardRiding::STATUS_OK)
  26. ->orderBy('price')
  27. ->get();
  28. }
  29. /**
  30. * 判断骑行卡是否启用
  31. *
  32. * @param $id integer
  33. *
  34. * @return bool true表示可用 false不可用
  35. *
  36. * */
  37. public function isStatusOK($id)
  38. {
  39. $cardRiding = $this->model->query()->where('id', $id)->where('status', CardRiding::STATUS_OK)->first();
  40. if (empty($cardRiding)) return false;
  41. return true;
  42. }
  43. }