UserCouponController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 (false !== $result) {
  35. return $this->success('领取成功'.implode('\n',$result), [], 1, 1);
  36. }
  37. return $this->fail(UserCouponLogic::getError());
  38. }
  39. public function categoryCouponLists()
  40. {
  41. $params = (new UserCouponValidate())->goCheck('category',[
  42. 'user_id'=>$this->userId
  43. ]);
  44. $result = UserCouponLogic::categoryCouponLists($params);
  45. if (false === $result) {
  46. return $this->fail(UserCouponLogic::getError());
  47. }
  48. return $this->data($result);
  49. }
  50. public function categoryWithAmountLists()
  51. {
  52. $params = (new UserCouponValidate())->goCheck('categoryWithAmountList',[
  53. 'user_id'=>$this->userId
  54. ]);
  55. $result = UserCouponLogic::categoryWithAmountLists($params);
  56. if (false === $result) {
  57. return $this->fail(UserCouponLogic::getError());
  58. }
  59. return $this->data($result);
  60. }
  61. }