StoreCouponUser.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\marketing;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\activity\coupon\StoreCouponIssueServices;
  14. use app\services\activity\coupon\StoreCouponUserServices;
  15. use think\facade\App;
  16. /**
  17. * 优惠券发放记录控制器
  18. * Class StoreCategory
  19. * @package app\admin\controller\system
  20. */
  21. class StoreCouponUser extends AuthController
  22. {
  23. public function __construct(App $app, StoreCouponUserServices $services)
  24. {
  25. parent::__construct($app);
  26. $this->services = $services;
  27. }
  28. /**
  29. * 用户领取记录
  30. * @return mixed
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\DbException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. */
  35. public function index()
  36. {
  37. $where = $this->request->getMore([
  38. ['status', ''],
  39. ['coupon_title', ''],
  40. ['nickname', ''],
  41. ]);
  42. $list = $this->services->systemPage($where);
  43. return app('json')->success($list);
  44. }
  45. /**
  46. * 发放优惠券到指定个人
  47. * @return mixed
  48. */
  49. public function grant()
  50. {
  51. $data = $this->request->postMore([
  52. ['id', 0],
  53. ['uid', '']
  54. ]);
  55. if (!$data['id']) return app('json')->fail(100100);
  56. /** @var StoreCouponIssueServices $issueService */
  57. $issueService = app()->make(StoreCouponIssueServices::class);
  58. $coupon = $issueService->get($data['id']);
  59. if (!$coupon) {
  60. return app('json')->fail(100026);
  61. } else {
  62. $coupon = $coupon->toArray();
  63. }
  64. $user = explode(',', $data['uid']);
  65. if (!$issueService->setCoupon($coupon, $user))
  66. return app('json')->fail(100031);
  67. else
  68. return app('json')->success(100030);
  69. }
  70. }