UserCouponController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\lists\UserCouponLists;
  4. use app\api\logic\UserCouponLogic;
  5. use app\api\validate\UserCouponValidate;
  6. class UserCouponController extends BaseApiController
  7. {
  8. public array $notNeedLogin = ['categoryCouponList'];
  9. /**
  10. * 我的优惠卷列表
  11. * @return \think\response\Json
  12. */
  13. public function lists()
  14. {
  15. $params = (new UserCouponValidate())->goCheck('voucher',[
  16. 'user_id'=>$this->userId
  17. ]);
  18. $result = UserCouponLogic::userCouponList($params);
  19. if (false === $result) {
  20. return $this->fail(UserCouponLogic::getError());
  21. }
  22. return $this->data($result);
  23. }
  24. /**
  25. * 一键领取优惠卷
  26. * @return \think\response\Json
  27. */
  28. public function add()
  29. {
  30. $params = (new UserCouponValidate())->post()->goCheck('add',[
  31. 'user_id'=>$this->userId
  32. ]);
  33. $result = UserCouponLogic::add($params);
  34. if(!empty($result)){
  35. return $this->fail(implode(',',$result));
  36. }else{
  37. return $this->success('领取成功', [], 1, 1);
  38. }
  39. }
  40. public function categoryCouponLists()
  41. {
  42. $params = (new UserCouponValidate())->goCheck('category',[
  43. 'user_id'=>$this->userId
  44. ]);
  45. $result = UserCouponLogic::categoryCouponLists($params);
  46. if (false === $result) {
  47. return $this->fail(UserCouponLogic::getError());
  48. }
  49. return $this->data($result);
  50. }
  51. public function categoryWithAmountLists()
  52. {
  53. $params = (new UserCouponValidate())->goCheck('categoryWithAmountList',[
  54. 'user_id'=>$this->userId
  55. ]);
  56. $result = UserCouponLogic::categoryWithAmountLists($params);
  57. if (false === $result) {
  58. return $this->fail(UserCouponLogic::getError());
  59. }
  60. return $this->data($result);
  61. }
  62. }