BikeRepository.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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\Models\Bike;
  10. use phpDocumentor\Reflection\Types\Integer;
  11. class BikeRepository extends BaseRepository
  12. {
  13. private static $filed = [
  14. 'name',
  15. 'area_fence',
  16. 'customer_service_time',
  17. 'customer_service_phone',
  18. 'status'
  19. ];
  20. public function __construct(Bike $model)
  21. {
  22. $this->model = $model;
  23. }
  24. public function all()
  25. {
  26. return $this->model->active()->get();
  27. }
  28. public function byBikeNo($bike_no)
  29. {
  30. return $this->model->where('bike_no', $bike_no)->first();
  31. }
  32. /**
  33. * 根据bike_no获取车的id
  34. * @param $bike_no
  35. * @return mixed
  36. * User: Mead
  37. */
  38. public function byBikeNoGetId($bike_no)
  39. {
  40. return $this->model->where('bike_no', $bike_no)->value('id');
  41. }
  42. /**
  43. * 判断车是否可骑
  44. * User: Mead
  45. */
  46. public function isBikeCanRide($bike_id)
  47. {
  48. return $this->model->where('id', $bike_id)->bikeCanRide()->exists();
  49. }
  50. /**
  51. * 通过no判断车是否可骑
  52. * User: Mead
  53. */
  54. public function byNoIsBikeCanRide($bike_id)
  55. {
  56. return $this->model->where('bike_no', $bike_id)->bikeCanRide()->exists();
  57. }
  58. /**
  59. * 将车的状态修改为骑行中
  60. * User: Mead
  61. */
  62. public function byIdUpdateRideOk($bike_id)
  63. {
  64. return $this->model->where('id', $bike_id)->update([
  65. 'is_riding' => Bike::RIDING_YES
  66. ]);
  67. }
  68. /**
  69. * 将车的状态修改为未骑行中
  70. * User: Mead
  71. */
  72. public function byIdUpdateRideNO($bike_id)
  73. {
  74. return $this->model->where('id', $bike_id)->update([
  75. 'is_riding' => Bike::RIDING_NO,
  76. 'last_use_bike_end_time' => date('Y-m-d H:i:s')
  77. ]);
  78. }
  79. /**
  80. * 获取车的最后定位
  81. * @param $id
  82. * @return mixed
  83. * User: Mead
  84. */
  85. public function byIdGetLastLocation($id)
  86. {
  87. $location = $this->model->where('id', $id)->value('last_location');
  88. return json_decode($location, true);
  89. }
  90. /**
  91. * 通过bike_no 获取车的 box_no
  92. * @param $bike_no
  93. * @return mixed
  94. * User: Mead
  95. */
  96. public function byNoGetBoxNO($bike_no)
  97. {
  98. return $this->model->where('bike_no', $bike_no)->value('box_no');
  99. }
  100. /**
  101. * 通过box_no 获取蓝牙key
  102. * @param $box_no
  103. * @return mixed
  104. * User: Mead
  105. */
  106. public function byBoxNoGetKey($box_no)
  107. {
  108. return $this->model->where('box_no', $box_no)->value('blu_ase_key');
  109. }
  110. /**
  111. * 通过
  112. * @param $bike_no
  113. * @param $box_no
  114. * User: Mead
  115. */
  116. public function byBoxNoAndBikeNoCheckRide($box_no, $bike_no)
  117. {
  118. return $this->model->where('bike_no', $bike_no)->where('box_no', $box_no)->where('is_riding', Bike::RIDING_YES)->exists();
  119. }
  120. public function byIdIsCanRentBike($bike_id)
  121. {
  122. return $this->model->where('id', $bike_id)->where('is_rent', Bike::RENT_NO)->bikeCanRide()->exists();
  123. }
  124. public function byNoIsCanRentBikeGetModel($bike_no)
  125. {
  126. return $this->model->where('bike_no', $bike_no)->where('is_rent', Bike::RENT_NO)->bikeCanRide()->first();
  127. }
  128. }