123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/8/6
- * Time: 9:16 PM
- */
- namespace App\Repositories;
- use App\Models\Bike;
- use phpDocumentor\Reflection\Types\Integer;
- class BikeRepository extends BaseRepository
- {
- private static $filed = [
- 'name',
- 'area_fence',
- 'customer_service_time',
- 'customer_service_phone',
- 'status'
- ];
- public function __construct(Bike $model)
- {
- $this->model = $model;
- }
- public function all()
- {
- return $this->model->active()->get();
- }
- public function byBikeNo($bike_no)
- {
- return $this->model->where('bike_no', $bike_no)->first();
- }
- /**
- * 根据bike_no获取车的id
- * @param $bike_no
- * @return mixed
- * User: Mead
- */
- public function byBikeNoGetId($bike_no)
- {
- return $this->model->where('bike_no', $bike_no)->value('id');
- }
- /**
- * 判断车是否可骑
- * User: Mead
- */
- public function isBikeCanRide($bike_id)
- {
- return $this->model->where('id', $bike_id)->bikeCanRide()->exists();
- }
- /**
- * 通过no判断车是否可骑
- * User: Mead
- */
- public function byNoIsBikeCanRide($bike_id)
- {
- return $this->model->where('bike_no', $bike_id)->bikeCanRide()->exists();
- }
- /**
- * 将车的状态修改为骑行中
- * User: Mead
- */
- public function byIdUpdateRideOk($bike_id)
- {
- return $this->model->where('id', $bike_id)->update([
- 'is_riding' => Bike::RIDING_YES
- ]);
- }
- /**
- * 将车的状态修改为未骑行中
- * User: Mead
- */
- public function byIdUpdateRideNO($bike_id)
- {
- return $this->model->where('id', $bike_id)->update([
- 'is_riding' => Bike::RIDING_NO,
- 'last_use_bike_end_time' => date('Y-m-d H:i:s')
- ]);
- }
- /**
- * 获取车的最后定位
- * @param $id
- * @return mixed
- * User: Mead
- */
- public function byIdGetLastLocation($id)
- {
- $location = $this->model->where('id', $id)->value('last_location');
- return json_decode($location, true);
- }
- /**
- * 通过bike_no 获取车的 box_no
- * @param $bike_no
- * @return mixed
- * User: Mead
- */
- public function byNoGetBoxNO($bike_no)
- {
- return $this->model->where('bike_no', $bike_no)->value('box_no');
- }
- /**
- * 通过box_no 获取蓝牙key
- * @param $box_no
- * @return mixed
- * User: Mead
- */
- public function byBoxNoGetKey($box_no)
- {
- return $this->model->where('box_no', $box_no)->value('blu_ase_key');
- }
- /**
- * 通过
- * @param $bike_no
- * @param $box_no
- * User: Mead
- */
- public function byBoxNoAndBikeNoCheckRide($box_no, $bike_no)
- {
- return $this->model->where('bike_no', $bike_no)->where('box_no', $box_no)->where('is_riding', Bike::RIDING_YES)->exists();
- }
- public function byIdIsCanRentBike($bike_id)
- {
- return $this->model->where('id', $bike_id)->where('is_rent', Bike::RENT_NO)->bikeCanRide()->exists();
- }
- public function byNoIsCanRentBikeGetModel($bike_no)
- {
- return $this->model->where('bike_no', $bike_no)->where('is_rent', Bike::RENT_NO)->bikeCanRide()->first();
- }
- }
|