Coupon.php 2.6 KB

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