123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace App\Repositories;
- use App\Models\RentOrder;
- use Carbon\Carbon;
- class RentOrderRepository extends BaseRepository
- {
- public function __construct(RentOrder $model)
- {
- $this->model = $model;
- }
-
- public function byUserIdCheckIsExistRideOrder($user_id)
- {
- return $this->model->where('user_id', $user_id)->whereIn('status', [RentOrder::STATUS_RENT_BIKE, RentOrder::STATUS_CLOSE_RENT_BIKE])->exists();
- }
-
- public function checkUserIsRetryOpenLock($order_no, $bike_no, $user_id)
- {
- return $this->model->where('no', $order_no)->where('user_id', $user_id)->where('bike_no', $bike_no)->select(['start_use_bike_time', 'bike_id', 'end_use_bike_time'])->first();
- }
-
- public function byUserIdCheckIsExistRentOrderWithNo($user_id)
- {
- return $this->model->where('user_id', $user_id)->where('status', RentOrder::STATUS_RENT_BIKE)->value('no');
- }
-
- public function byUserIdCheckIsExistNoPayOrder($user_id)
- {
- return $this->model->where('user_id', $user_id)->where('status', RentOrder::STATUS_CLOSE_RENT_BIKE)->where('pay_status', RentOrder::PAY_STATUS_NO)->exists();
- }
-
- public function byUserIdCheckIsExistNoPayOrderWithNo($user_id)
- {
- return $this->model->where('user_id', $user_id)->where('status', RentOrder::STATUS_CLOSE_RENT_BIKE)->where('pay_status', RentOrder::PAY_STATUS_NO)->value('no');
- }
-
- public function byNo($order_no)
- {
- return $this->model->where('no', $order_no)->first();
- }
-
- public function byNoAndUserId($order_no, $user_id)
- {
- return $this->model->where('no', $order_no)->where('user_id', $user_id)->first();
- }
-
- public function byNoGetRideOrder($no)
- {
- return $this->model->where('no', $no)->where('status', RentOrder::STATUS_RENT_BIKE)->first();
- }
-
- public function checkUserMoreCloseOrder($user_id)
- {
- $num = $this->model->where('user_id', $user_id)->where('created_at', now())->where('status', RentOrder::STATUS_CLOSE_ORDER)->count();
- return $num > 5;
- }
- }
|