123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/8/6
- * Time: 9:16 PM
- */
- namespace App\Repositories;
- use App\Models\RentOrder;
- use Carbon\Carbon;
- class RentOrderRepository extends BaseRepository
- {
- public function __construct(RentOrder $model)
- {
- $this->model = $model;
- }
- /**
- * 检查用户是否有租车的订单
- * @param $user_id
- * @return mixed
- * User: Mead
- */
- 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();
- }
- /**
- *
- * @param $order_no
- * @param $bike_no
- * @param $user_id
- * @return mixed
- * User: Fx
- */
- 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();
- }
- /**
- * 检查用户是否有租车的订单并获取no
- * @param $user_id
- * @return mixed
- * User: Mead
- */
- public function byUserIdCheckIsExistRentOrderWithNo($user_id)
- {
- return $this->model->where('user_id', $user_id)->where('status', RentOrder::STATUS_RENT_BIKE)->value('no');
- }
- /**
- * 检查用户是否有为支付的订单
- * @param $user_id
- * @return mixed
- * User: Mead
- */
- 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();
- }
- /**
- * 检查用户是否有为支付的订单并获取no
- * @param $user_id
- * @return mixed
- * User: Mead
- */
- 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');
- }
- /**
- * 根据订单号获取model
- * @param $order_no
- * @return mixed
- * User: Mead
- */
- public function byNo($order_no)
- {
- return $this->model->where('no', $order_no)->first();
- }
- /**
- * 根据用户id和订单号获取订单
- * @param $order_no
- * @param $user_id
- * @return mixed
- * User: Mead
- */
- public function byNoAndUserId($order_no, $user_id)
- {
- return $this->model->where('no', $order_no)->where('user_id', $user_id)->first();
- }
- /**
- * 根据订单获取租车的订单
- * User: Mead
- */
- public function byNoGetRideOrder($no)
- {
- return $this->model->where('no', $no)->where('status', RentOrder::STATUS_RENT_BIKE)->first();
- }
- /**
- * 检查用户是否恶意
- * @param $user_id
- * User: Mead
- */
- 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;
- }
- }
|