Coupon.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\controller\admin\store;
  3. use app\common\repositories\store\coupon\StoreCouponProductRepository;
  4. use app\common\repositories\store\coupon\StoreCouponUserRepository;
  5. use think\App;
  6. use ln\basic\BaseController;
  7. use think\db\exception\DataNotFoundException;
  8. use think\db\exception\DbException;
  9. use think\db\exception\ModelNotFoundException;
  10. use app\common\repositories\store\coupon\StoreCouponRepository;
  11. /**
  12. * Class CouponIssue
  13. * @package app\controller\merchant\store\coupon
  14. * @author xaboy
  15. * @day 2020-05-13
  16. */
  17. class Coupon extends BaseController
  18. {
  19. /**
  20. * @var StoreCouponRepository
  21. */
  22. protected $repository;
  23. /**
  24. * CouponIssue constructor.
  25. * @param App $app
  26. * @param StoreCouponRepository $repository
  27. */
  28. public function __construct(App $app, StoreCouponRepository $repository)
  29. {
  30. parent::__construct($app);
  31. $this->repository = $repository;
  32. }
  33. /**
  34. * @return mixed
  35. * @throws DbException
  36. * @throws DataNotFoundException
  37. * @throws ModelNotFoundException
  38. * @author xaboy
  39. * @day 2020-05-14
  40. */
  41. public function lst()
  42. {
  43. $where = $this->request->params(['is_full_give', 'status', 'is_give_subscribe', 'coupon_name', ['mer_id', null],'is_trader']);
  44. [$page, $limit] = $this->getPage();
  45. return app('json')->success($this->repository->getList($where['mer_id'], $where, $page, $limit));
  46. }
  47. public function detail($id)
  48. {
  49. if (!$this->repository->exists($id))
  50. return app('json')->fail('数据不存在');
  51. $coupon = $this->repository->get($id)->append(['used_num', 'send_num']);
  52. return app('json')->success($coupon->toArray());
  53. }
  54. public function product($id)
  55. {
  56. $merId = $this->request->merId();
  57. if ($merId) {
  58. $exists = app()->make(StoreCouponRepository::class)->merExists($merId, $id);
  59. } else {
  60. $exists = app()->make(StoreCouponRepository::class)->exists($id);
  61. }
  62. if (!$exists) {
  63. return app('json')->fail('优惠券不存在');
  64. }
  65. [$page, $limit] = $this->getPage();
  66. return app('json')->success(app()->make(StoreCouponProductRepository::class)->productList((int)$id, $page, $limit));
  67. }
  68. /**
  69. * @param StoreCouponUserRepository $repository
  70. * @author xaboy
  71. * @day 2020/6/2
  72. */
  73. public function issue(StoreCouponUserRepository $repository)
  74. {
  75. [$page, $limit] = $this->getPage();
  76. $where = $this->request->params(['username', 'coupon_id', 'coupon', 'status', 'mer_id']);
  77. return app('json')->success($repository->getList($where, $page, $limit));
  78. }
  79. }