CouponRepository.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. *
  4. *
  5. * @category xxx
  6. * @package PSR
  7. * @subpackage Documentation\API
  8. * @author xxx <xxx@xxx.com>
  9. * @license GPL https://xxx.com
  10. * @link https://xxx.com
  11. * @ctime: 2020/4/16 9:36
  12. */
  13. namespace App\Repositories;
  14. use App\Models\Coupon;
  15. class CouponRepository extends BaseRepository
  16. {
  17. public function __construct(Coupon $coupon)
  18. {
  19. $this->model = $coupon;
  20. }
  21. /**
  22. * 根据获取区域的配置优惠券
  23. * @param $user_id
  24. * Author: Mead
  25. */
  26. public function getNewUserCoupons($area_id = 0)
  27. {
  28. if ($area_id) {
  29. $coupons = $this->model->query()->where('area_id', $area_id)->where('site', Coupon::SITE_NEW_USER)->where('status', Coupon::STATUS_OK)->orderBy('area_id')->get();
  30. if ($coupons) {
  31. return $coupons;
  32. }
  33. }
  34. $coupons = $coupons = $this->model->query()->where('area_id', 0)->where('site', Coupon::SITE_NEW_USER)->where('status', Coupon::STATUS_OK)->orderBy('area_id')->get();
  35. return $coupons;
  36. }
  37. /**
  38. * @param $ids
  39. * Author: Mead
  40. */
  41. public function byIdsGetNewUserCoupons($ids)
  42. {
  43. if (is_string($ids)) {
  44. $ids = str2arr($ids);
  45. }
  46. return $this->model->query()->whereIn('id', $ids)->where('site', Coupon::SITE_NEW_USER)->where('status', Coupon::STATUS_OK)->get();
  47. }
  48. }