UserCouponController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 = ['categoryCouponLists'];
  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. /**
  41. * 商品可领取优惠券列表
  42. * @return \think\response\Json
  43. */
  44. public function categoryCouponLists()
  45. {
  46. $params = (new UserCouponValidate())->goCheck('category',[
  47. 'user_id'=>$this->userId
  48. ]);
  49. $result = UserCouponLogic::categoryCouponLists($params);
  50. if (false === $result) {
  51. return $this->fail(UserCouponLogic::getError());
  52. }
  53. return $this->data($result);
  54. }
  55. /**
  56. * 订单可用优惠券
  57. * @return \think\response\Json
  58. */
  59. public function categoryWithAmountLists()
  60. {
  61. $params = (new UserCouponValidate())->goCheck('categoryWithAmountList',[
  62. 'user_id'=>$this->userId
  63. ]);
  64. $result = UserCouponLogic::categoryWithAmountLists($params);
  65. if (false === $result) {
  66. return $this->fail(UserCouponLogic::getError());
  67. }
  68. return $this->data($result);
  69. }
  70. }