StoreCouponUserRepository.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\common\repositories\store\coupon;
  3. use app\common\dao\store\coupon\StoreCouponUserDao;
  4. use app\common\repositories\BaseRepository;
  5. use think\db\exception\DataNotFoundException;
  6. use think\db\exception\DbException;
  7. use think\db\exception\ModelNotFoundException;
  8. /**
  9. * Class StoreCouponUserRepository
  10. * @package app\common\repositories\store\coupon
  11. * @author zfy
  12. * @day 2020-05-14
  13. * @mixin StoreCouponUserDao
  14. */
  15. class StoreCouponUserRepository extends BaseRepository
  16. {
  17. /**
  18. * @var StoreCouponUserDao
  19. */
  20. protected $dao;
  21. /**
  22. * StoreCouponUserRepository constructor.
  23. * @param StoreCouponUserDao $dao
  24. */
  25. public function __construct(StoreCouponUserDao $dao)
  26. {
  27. $this->dao = $dao;
  28. //TODO 检查过期优惠券
  29. $dao->failCoupon();
  30. }
  31. /**
  32. * @param $where
  33. * @param $page
  34. * @param $limit
  35. * @return array
  36. * @throws DataNotFoundException
  37. * @throws DbException
  38. * @throws ModelNotFoundException
  39. * @author zfy
  40. * @day 2020/6/3
  41. */
  42. public function userList(array $where, $page, $limit)
  43. {
  44. $query = $this->dao->search($where);
  45. $count = $query->count();
  46. $list = $query->with(['coupon' => function ($query) {
  47. $query->field('coupon_id,type');
  48. }])->page($page, $limit)->select();
  49. return compact('count', 'list');
  50. }
  51. /**
  52. * @param array $where
  53. * @param $page
  54. * @param $limit
  55. * @return array
  56. * @throws DataNotFoundException
  57. * @throws DbException
  58. * @throws ModelNotFoundException
  59. * @author zfy
  60. * @day 2020/6/3
  61. */
  62. public function getList(array $where, $page, $limit)
  63. {
  64. $query = $this->dao->search($where);
  65. $count = $query->count();
  66. $list = $query->with(['user' => function ($query) {
  67. $query->field('avatar,uid,nickname,user_type');
  68. }])->page($page, $limit)->select();
  69. return compact('count', 'list');
  70. }
  71. }