MyCoupon.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\api\controller;
  13. use app\api\model\UserCoupon as UserCouponModel;
  14. use app\api\service\User as UserService;
  15. use app\common\exception\BaseException;
  16. /**
  17. * 用户优惠券
  18. * Class Coupon
  19. * @package app\api\controller
  20. */
  21. class MyCoupon extends Controller
  22. {
  23. /**
  24. * 用户优惠券列表
  25. * @return mixed
  26. * @throws BaseException
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\DbException
  29. * @throws \think\db\exception\ModelNotFoundException
  30. */
  31. public function list()
  32. {
  33. $userId = UserService::getCurrentLoginUserId();
  34. $model = new UserCouponModel;
  35. $list = $model->getList($userId, $this->request->param());
  36. return $this->renderSuccess(compact('list'));
  37. }
  38. /**
  39. * 领取优惠券
  40. * @param int $couponId
  41. * @return array|\think\response\Json
  42. * @throws BaseException
  43. */
  44. public function receive(int $couponId)
  45. {
  46. $model = new UserCouponModel;
  47. if ($model->receive($couponId)) {
  48. return $this->renderSuccess([], '领取成功');
  49. }
  50. return $this->renderError($model->getError() ?: '领取失败');
  51. }
  52. }