OrderRepository.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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\Order;
  10. use Carbon\Carbon;
  11. class OrderRepository extends BaseRepository
  12. {
  13. public function __construct(Order $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', [Order::STATUS_RIDE_BIKE, Order::STATUS_CLOSE_BIKE, Order::STATUS_PAUSE_BIKE])->exists();
  26. }
  27. /**
  28. * 检查用户是否有骑行时订单并获取no(不包含锁车状态)
  29. * @param $user_id
  30. * @return mixed
  31. * User: Mead
  32. */
  33. public function byUserIdCheckIsExistRideOrderWithNo($user_id)
  34. {
  35. return $this->model->where('user_id', $user_id)->whereIn('status', [Order::STATUS_RIDE_BIKE, Order::STATUS_PAUSE_BIKE])->value('no');
  36. }
  37. /**
  38. * 检查用户是否有为支付的订单
  39. * @param $user_id
  40. * @return mixed
  41. * User: Mead
  42. */
  43. public function byUserIdCheckIsExistNoPayOrder($user_id)
  44. {
  45. return $this->model->where('user_id', $user_id)->where('status', Order::STATUS_CLOSE_BIKE)->where('pay_status', Order::PAY_STATUS_NO)->exists();
  46. }
  47. /**
  48. * 检查用户是否有为支付的订单并获取no
  49. * @param $user_id
  50. * @return mixed
  51. * User: Mead
  52. */
  53. public function byUserIdCheckIsExistNoPayOrderWithNo($user_id)
  54. {
  55. return $this->model->where('user_id', $user_id)->where('status', Order::STATUS_CLOSE_BIKE)->where('pay_status', Order::PAY_STATUS_NO)->value('no');
  56. }
  57. /**
  58. * 根据订单号获取model
  59. * @param $order_no
  60. * @return mixed
  61. * User: Mead
  62. */
  63. public function byNo($order_no)
  64. {
  65. return $this->model->where('no', $order_no)->first();
  66. }
  67. /**
  68. * 根据用户id和订单号获取订单
  69. * @param $order_no
  70. * @param $user_id
  71. * @return mixed
  72. * User: Mead
  73. */
  74. public function byNoAndUserId($order_no, $user_id)
  75. {
  76. return $this->model->where('no', $order_no)->where('user_id', $user_id)->first();
  77. }
  78. /**
  79. * 根据订单号获取骑行状态(骑行中,临时停车中)
  80. * @param $order_no
  81. * @return mixed
  82. * User: Mead
  83. */
  84. public function byNoGetRideOrder($order_no)
  85. {
  86. return $this->model->where('no', $order_no)->whereIn('status', [Order::STATUS_RIDE_BIKE, Order::STATUS_PAUSE_BIKE])->first();
  87. }
  88. /**
  89. * 检查用户是否恶意关锁
  90. * @param $user_id
  91. * @return bool
  92. * User: Mead
  93. */
  94. public function checkUserMoreCloseOrder($user_id)
  95. {
  96. $num = $this->model->where('user_id', $user_id)->whereDate('created_at', date('Y-m-d'))->where('status', Order::STATUS_CLOSE_ORDER)->count();
  97. return ($num > 5);
  98. }
  99. /**
  100. *
  101. * @param $order_no
  102. * @param $bike_no
  103. * @param $user_id
  104. * @return mixed
  105. * User: Mead
  106. */
  107. public function checkUserIsRetryOpenLock($order_no, $bike_no, $user_id)
  108. {
  109. 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();
  110. }
  111. /**
  112. * 通过车的中控id,获取订单
  113. * @param $box_no
  114. * User: Mead
  115. */
  116. public function byBikeNoGetRideOrder($bike_no)
  117. {
  118. return $this->model->where('bike_no', $bike_no)->whereIn('status', [Order::STATUS_RIDE_BIKE, Order::STATUS_PAUSE_BIKE])->orderBy('id', 'desc')->first();
  119. }
  120. /**
  121. * 根据用户id 查询今日订单次数
  122. * @param $user_id
  123. *
  124. * */
  125. public function getTodayOrderNum($user_id)
  126. {
  127. return $this->model->where('created_at', '>', Carbon::today())->where('user_id', $user_id)->count();
  128. }
  129. }