Преглед на файлове

购买会员新增推荐码校验

codingliang преди 7 месеца
родител
ревизия
6adcf72ad8

+ 5 - 4
src/main/java/com/sqx/modules/member/controller/app/AppVipController.java

@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
@@ -34,18 +35,18 @@ public class AppVipController {
     }
 
     @Login
-    @ApiOperation(value = "获取购买vip支付参数", notes = "promoCode 为推荐码,可选")
+    @ApiOperation(value = "获取购买vip支付参数", notes = "promoCode 为推荐码")
     @GetMapping(value = "get-pay-param")
-    public Result getPayParam(@RequestAttribute("userId") Long userId, String promoCode){
+    public Result getPayParam(@RequestAttribute("userId") Long userId, @RequestParam(value = "promoCode") String promoCode){
         PayTransactionsVO payParamVO = vipService.getPayParam(userId, promoCode);
 
         return Result.success(BeanUtil.beanToMap(payParamVO, false, true));
     }
 
     @Login
-    @ApiOperation(value = "余额购买vip", notes = "promoCode 为推荐码,可选")
+    @ApiOperation(value = "余额购买vip", notes = "promoCode 为推荐码")
     @GetMapping(value = "balance-pay")
-    public Result balancePay(@RequestAttribute("userId") Long userId, String promoCode){
+    public Result balancePay(@RequestAttribute("userId") Long userId, @RequestParam(value = "promoCode") String promoCode){
         vipService.balancePay(userId, promoCode);
         return Result.success();
     }

+ 17 - 8
src/main/java/com/sqx/modules/member/service/impl/VipServiceImpl.java

@@ -15,6 +15,8 @@ import com.sqx.modules.coupon.service.TbCouponUserService;
 import com.sqx.modules.goods.entity.GoodsShop;
 import com.sqx.modules.goods.service.GoodsShopService;
 import com.sqx.modules.member.dto.VipPromoRecordDTO;
+import com.sqx.modules.member.entity.VipPromoCode;
+import com.sqx.modules.member.service.VipPromoCodeService;
 import com.sqx.modules.member.service.VipPromoRecordService;
 import com.sqx.modules.member.service.VipService;
 import com.sqx.modules.member.vo.VipReduceVO;
@@ -46,17 +48,17 @@ public class VipServiceImpl implements VipService {
     private final UserService userService;
     private final CommonInfoService commonInfoService;
     private final TbCouponUserService tbCouponUserService;
+    private final VipPromoCodeService vipPromoCodeService;
     private final VipPromoRecordService vipPromoRecordService;
     private final UserMoneyService userMoneyService;
     private final GoodsShopService goodsShopService;
     private final AppOrderService appOrderService;
 
+
     @Override
     public PayTransactionsVO getPayParam(Long userId, String promoCode) {
         UserEntity user = userService.getById(userId);
-        if(ObjectUtil.isNotNull(user.getIsVip()) && user.getIsVip() == 1 && VipExpirationUtil.isVipValid(user.getVipExpirationTime())) {
-            new SqxException("已经是会员,不能重复购买!");
-        }
+        beforePay(user, promoCode);
 
         // 查询会员价格
         CommonInfo one = commonInfoService.findOne(313);
@@ -82,8 +84,6 @@ public class VipServiceImpl implements VipService {
     public void paySuccess(PayDetails payDetails) {
         Long userId = payDetails.getUserId();
         UserEntity user = userService.getById(userId);
-        // 202511141701426541989257421909929985
-        // 新增会员充值记录
         VipPromoRecordDTO recordDTO = VipPromoRecordDTO.builder()
                 .userId(userId)
                 .userName(user.getNickName())
@@ -103,9 +103,7 @@ public class VipServiceImpl implements VipService {
     @Transactional(rollbackFor = Exception.class)
     public void balancePay(Long userId, String promoCode) {
         UserEntity user = userService.getById(userId);
-        if(ObjectUtil.isNotNull(user.getIsVip()) && user.getIsVip() == 1 && VipExpirationUtil.isVipValid(user.getVipExpirationTime())) {
-            new SqxException("已经是会员,不能重复购买!");
-        }
+        beforePay(user, promoCode);
 
         // 会员价格
         CommonInfo vipPrice = commonInfoService.findOne(313);
@@ -136,6 +134,17 @@ public class VipServiceImpl implements VipService {
         afterPaySuccess(userId);
     }
 
+    private void beforePay(UserEntity user, String promoCode) {
+        if(ObjectUtil.isNotNull(user.getIsVip()) && user.getIsVip() == 1 && VipExpirationUtil.isVipValid(user.getVipExpirationTime())) {
+            new SqxException("已经是会员,不能重复购买!");
+        }
+
+        VipPromoCode vipPromoCode = vipPromoCodeService.getByCode(promoCode);
+        if (ObjectUtil.isNull(vipPromoCode)) {
+            new SqxException("无效的推广码!");
+        }
+    }
+
     @Override
     public VipReduceVO getVipReduceInfo(Long userId, Long shopId) {
         GoodsShop goodsShop = goodsShopService.getById(shopId);