StoreCouponUserRepository.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\store\coupon;
  12. use app\common\dao\store\coupon\StoreCouponUserDao;
  13. use app\common\repositories\BaseRepository;
  14. use think\db\exception\DataNotFoundException;
  15. use think\db\exception\DbException;
  16. use think\db\exception\ModelNotFoundException;
  17. /**
  18. * Class StoreCouponUserRepository
  19. * @package app\common\repositories\store\coupon
  20. * @author xaboy
  21. * @day 2020-05-14
  22. * @mixin StoreCouponUserDao
  23. */
  24. class StoreCouponUserRepository extends BaseRepository
  25. {
  26. /**
  27. * @var StoreCouponUserDao
  28. */
  29. protected $dao;
  30. /**
  31. * StoreCouponUserRepository constructor.
  32. * @param StoreCouponUserDao $dao
  33. */
  34. public function __construct(StoreCouponUserDao $dao)
  35. {
  36. $this->dao = $dao;
  37. //TODO 检查过期优惠券
  38. $dao->failCoupon();
  39. }
  40. /**
  41. * @param $where
  42. * @param $page
  43. * @param $limit
  44. * @return array
  45. * @throws DataNotFoundException
  46. * @throws DbException
  47. * @throws ModelNotFoundException
  48. * @author xaboy
  49. * @day 2020/6/3
  50. */
  51. public function userList(array $where, $page, $limit)
  52. {
  53. $query = $this->dao->search($where);
  54. $count = $query->count();
  55. $list = $query->with(['coupon' => function ($query) {
  56. $query->field('coupon_id,type');
  57. }])->page($page, $limit)->select();
  58. return compact('count', 'list');
  59. }
  60. /**
  61. * @param array $where
  62. * @param $page
  63. * @param $limit
  64. * @return array
  65. * @throws DataNotFoundException
  66. * @throws DbException
  67. * @throws ModelNotFoundException
  68. * @author xaboy
  69. * @day 2020/6/3
  70. */
  71. public function getList(array $where, $page, $limit)
  72. {
  73. $query = $this->dao->search($where);
  74. $count = $query->count();
  75. $list = $query->with(['user' => function ($query) {
  76. $query->field('avatar,uid,nickname,user_type');
  77. }])->page($page, $limit)->select();
  78. return compact('count', 'list');
  79. }
  80. }