MyCoupon.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /**
  16. * 用户优惠券
  17. * Class Coupon
  18. * @package app\api\controller
  19. */
  20. class MyCoupon extends Controller
  21. {
  22. /**
  23. * 用户优惠券列表
  24. * @return \think\response\Json
  25. * @throws \cores\exception\BaseException
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function list(): \think\response\Json
  29. {
  30. $userId = UserService::getCurrentLoginUserId();
  31. $model = new UserCouponModel;
  32. $list = $model->getList($userId, $this->request->param());
  33. return $this->renderSuccess(compact('list'));
  34. }
  35. /**
  36. * 领取优惠券
  37. * @param int $couponId
  38. * @return \think\response\Json
  39. * @throws \cores\exception\BaseException
  40. */
  41. public function receive(int $couponId): \think\response\Json
  42. {
  43. $model = new UserCouponModel;
  44. if ($model->receive($couponId)) {
  45. return $this->renderSuccess([], '领取成功');
  46. }
  47. return $this->renderError($model->getError() ?: '领取失败');
  48. }
  49. }