RentOrderRepository.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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\RentOrder;
  10. use Carbon\Carbon;
  11. class RentOrderRepository extends BaseRepository
  12. {
  13. public function __construct(RentOrder $model)
  14. {
  15. $this->model = $model;
  16. }
  17. /**
  18. * 检查用户是否有租车的订单
  19. * @param $user_id
  20. * @return mixed
  21. * User: Mead
  22. */
  23. public function byUserIdCheckIsExistRideOrder($user_id)
  24. {
  25. return $this->model->where('user_id', $user_id)->whereIn('status', [RentOrder::STATUS_RENT_BIKE, RentOrder::STATUS_CLOSE_RENT_BIKE])->exists();
  26. }
  27. /**
  28. *
  29. * @param $order_no
  30. * @param $bike_no
  31. * @param $user_id
  32. * @return mixed
  33. * User: Fx
  34. */
  35. public function checkUserIsRetryOpenLock($order_no, $bike_no, $user_id)
  36. {
  37. 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();
  38. }
  39. /**
  40. * 检查用户是否有租车的订单并获取no
  41. * @param $user_id
  42. * @return mixed
  43. * User: Mead
  44. */
  45. public function byUserIdCheckIsExistRentOrderWithNo($user_id)
  46. {
  47. return $this->model->where('user_id', $user_id)->where('status', RentOrder::STATUS_RENT_BIKE)->value('no');
  48. }
  49. /**
  50. * 检查用户是否有为支付的订单
  51. * @param $user_id
  52. * @return mixed
  53. * User: Mead
  54. */
  55. public function byUserIdCheckIsExistNoPayOrder($user_id)
  56. {
  57. return $this->model->where('user_id', $user_id)->where('status', RentOrder::STATUS_CLOSE_RENT_BIKE)->where('pay_status', RentOrder::PAY_STATUS_NO)->exists();
  58. }
  59. /**
  60. * 检查用户是否有为支付的订单并获取no
  61. * @param $user_id
  62. * @return mixed
  63. * User: Mead
  64. */
  65. public function byUserIdCheckIsExistNoPayOrderWithNo($user_id)
  66. {
  67. return $this->model->where('user_id', $user_id)->where('status', RentOrder::STATUS_CLOSE_RENT_BIKE)->where('pay_status', RentOrder::PAY_STATUS_NO)->value('no');
  68. }
  69. /**
  70. * 根据订单号获取model
  71. * @param $order_no
  72. * @return mixed
  73. * User: Mead
  74. */
  75. public function byNo($order_no)
  76. {
  77. return $this->model->where('no', $order_no)->first();
  78. }
  79. /**
  80. * 根据用户id和订单号获取订单
  81. * @param $order_no
  82. * @param $user_id
  83. * @return mixed
  84. * User: Mead
  85. */
  86. public function byNoAndUserId($order_no, $user_id)
  87. {
  88. return $this->model->where('no', $order_no)->where('user_id', $user_id)->first();
  89. }
  90. /**
  91. * 根据订单获取租车的订单
  92. * User: Mead
  93. */
  94. public function byNoGetRideOrder($no)
  95. {
  96. return $this->model->where('no', $no)->where('status', RentOrder::STATUS_RENT_BIKE)->first();
  97. }
  98. /**
  99. * 检查用户是否恶意
  100. * @param $user_id
  101. * User: Mead
  102. */
  103. public function checkUserMoreCloseOrder($user_id)
  104. {
  105. $num = $this->model->where('user_id', $user_id)->where('created_at', now())->where('status', RentOrder::STATUS_CLOSE_ORDER)->count();
  106. return $num > 5;
  107. }
  108. }