Prechádzať zdrojové kódy

新增获取用户是否可以会员立减接口

codingliang 7 mesiacov pred
rodič
commit
8b197446ab

+ 12 - 2
src/main/java/com/sqx/modules/member/controller/app/AppVipController.java

@@ -4,10 +4,12 @@ import cn.hutool.core.bean.BeanUtil;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.app.annotation.Login;
 import com.sqx.modules.member.service.VipService;
+import com.sqx.modules.member.vo.VipReduceVO;
 import com.sqx.modules.pay.vo.PayTransactionsVO;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 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.RestController;
@@ -24,7 +26,15 @@ public class AppVipController {
     private final VipService vipService;
 
     @Login
-    @ApiOperation(value = "获取购买vip支付参数", notes = "promoCode 为优惠券码,可选")
+    @ApiOperation(value = "获取用户是否可以会员立减", notes = "shopId 为店铺id")
+    @GetMapping(value = "get-can-reduce/{shopId}")
+    public Result getCanReduce(@RequestAttribute("userId") Long userId, @PathVariable("shopId") Long shopId){
+        VipReduceVO vipReduceVO = vipService.getVipReduceInfo(userId, shopId);
+        return Result.success().put("data", vipReduceVO);
+    }
+
+    @Login
+    @ApiOperation(value = "获取购买vip支付参数", notes = "promoCode 为推荐码,可选")
     @GetMapping(value = "get-pay-param")
     public Result getPayParam(@RequestAttribute("userId") Long userId, String promoCode){
         PayTransactionsVO payParamVO = vipService.getPayParam(userId, promoCode);
@@ -33,7 +43,7 @@ public class AppVipController {
     }
 
     @Login
-    @ApiOperation(value = "余额购买vip", notes = "promoCode 为优惠券码,可选")
+    @ApiOperation(value = "余额购买vip", notes = "promoCode 为推荐码,可选")
     @GetMapping(value = "balance-pay")
     public Result balancePay(@RequestAttribute("userId") Long userId, String promoCode){
         vipService.balancePay(userId, promoCode);

+ 9 - 0
src/main/java/com/sqx/modules/member/service/VipService.java

@@ -1,5 +1,6 @@
 package com.sqx.modules.member.service;
 
+import com.sqx.modules.member.vo.VipReduceVO;
 import com.sqx.modules.pay.entity.PayDetails;
 import com.sqx.modules.pay.vo.PayTransactionsVO;
 
@@ -25,4 +26,12 @@ public interface VipService {
       * @param promoCode 优惠券码,可选
       */
     void balancePay(Long userId, String promoCode);
+
+     /**
+      * 获取用户是否可以会员立减
+      * @param userId 用户id
+      * @param shopId 店铺id
+      * @return vip 立减信息
+      */
+    VipReduceVO getVipReduceInfo(Long userId, Long shopId);
 }

+ 54 - 0
src/main/java/com/sqx/modules/member/service/impl/VipServiceImpl.java

@@ -1,8 +1,10 @@
 package com.sqx.modules.member.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.sqx.common.exception.SqxException;
+import com.sqx.common.utils.Constant;
 import com.sqx.modules.app.bo.UpdateMoneyBO;
 import com.sqx.modules.app.entity.UserEntity;
 import com.sqx.modules.app.service.UserMoneyService;
@@ -10,9 +12,13 @@ import com.sqx.modules.app.service.UserService;
 import com.sqx.modules.common.entity.CommonInfo;
 import com.sqx.modules.common.service.CommonInfoService;
 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.service.VipPromoRecordService;
 import com.sqx.modules.member.service.VipService;
+import com.sqx.modules.member.vo.VipReduceVO;
+import com.sqx.modules.order.service.AppOrderService;
 import com.sqx.modules.pay.dto.GetPayParamDTO;
 import com.sqx.modules.pay.entity.PayDetails;
 import com.sqx.modules.pay.enums.PayChannelEnum;
@@ -42,6 +48,8 @@ public class VipServiceImpl implements VipService {
     private final TbCouponUserService tbCouponUserService;
     private final VipPromoRecordService vipPromoRecordService;
     private final UserMoneyService userMoneyService;
+    private final GoodsShopService goodsShopService;
+    private final AppOrderService appOrderService;
 
     @Override
     public PayTransactionsVO getPayParam(Long userId, String promoCode) {
@@ -128,6 +136,52 @@ public class VipServiceImpl implements VipService {
         afterPaySuccess(userId);
     }
 
+    @Override
+    public VipReduceVO getVipReduceInfo(Long userId, Long shopId) {
+        GoodsShop goodsShop = goodsShopService.getById(shopId);
+        if (ObjectUtil.isNull(goodsShop)) {
+            new SqxException("无效的店铺id!");
+        }
+
+        String goodsShopVipPromotion = goodsShop.getVipPromotion();
+        if (!StrUtil.equals(goodsShopVipPromotion, Constant.YES)) {
+
+            return VipReduceVO.builder()
+                    .reduceAmount(BigDecimal.ZERO)
+                    .canReduceFlag(Constant.NO)
+                    .vipReduceDesc("店铺未参与会员立减")
+                    .build();
+        }
+
+        UserEntity user = userService.getById(userId);
+        String vipFlag = ObjectUtil.isNotNull(user.getIsVip()) && user.getIsVip() == 1 && VipExpirationUtil.isVipValid(user.getVipExpirationTime())
+                ? Constant.YES : Constant.NO;
+        if (!StrUtil.equals(vipFlag, Constant.YES)) {
+            return VipReduceVO.builder().reduceAmount(BigDecimal.ZERO)
+                    .canReduceFlag(Constant.NO)
+                    .vipReduceDesc("用户非会员,不能立减")
+                    .build();
+        }
+
+        int count = appOrderService.getCurDayVipPromotionByUserCount(userId);
+        // 会员每天限制优惠单数(单)
+        CommonInfo vipPromotionCount = commonInfoService.findOne(445);
+        if (count >= Integer.parseInt(vipPromotionCount.getValue())) {
+            return VipReduceVO.builder().reduceAmount(BigDecimal.ZERO)
+                    .canReduceFlag(Constant.NO)
+                    .vipReduceDesc("会员当日优惠单数已达上限")
+                    .build();
+        }
+
+        // 会员每单立减金额(元)
+        CommonInfo vipPromotionAmount = commonInfoService.findOne(444);
+        BigDecimal vipPromotionAmountDecimal = new BigDecimal(vipPromotionAmount.getValue());
+        return  VipReduceVO.builder().reduceAmount(vipPromotionAmountDecimal)
+                .canReduceFlag(Constant.YES)
+                .vipReduceDesc("会员每单立减金额" + vipPromotionAmountDecimal + "元")
+                .build();
+    }
+
     private void afterPaySuccess(Long userId) {
         // 会员期限(天)
         CommonInfo vipExpirationDays = commonInfoService.findOne(314);

+ 26 - 0
src/main/java/com/sqx/modules/member/vo/VipReduceVO.java

@@ -0,0 +1,26 @@
+package com.sqx.modules.member.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Builder;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * vip 立减信息
+ * @author codingliang
+ * @date 2025-11-16
+ */
+@Data
+@Builder
+public class VipReduceVO {
+
+    @ApiModelProperty(value = "用户是否可以会员立减")
+    private String canReduceFlag;
+
+    @ApiModelProperty(value = "立减金额")
+    private BigDecimal reduceAmount;
+
+    @ApiModelProperty(value = "立减描述")
+    private String vipReduceDesc;
+}

+ 7 - 0
src/main/java/com/sqx/modules/order/service/AppOrderService.java

@@ -198,4 +198,11 @@ public interface AppOrderService extends IService<TbOrder> {
      * @param query 查询参数
      */
     void exportGoodsSkuSalesCount(GoodsSkuQuery query);
+
+     /**
+     * 查询用户当天会员优惠单数量
+     * @param userId 用户id
+     * @return 会员优惠单数量
+     */
+    int getCurDayVipPromotionByUserCount(Long userId);
 }

+ 14 - 13
src/main/java/com/sqx/modules/order/service/impl/AppAppOrderServiceImpl.java

@@ -2973,6 +2973,20 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         EasyExcelUtil.exportExcel(records, GoodsSkuSalesCountVO.class, "sku销售记录", "sheet1");
     }
 
+    @Override
+    public int getCurDayVipPromotionByUserCount(Long userId) {
+        // 查询用户当天会员优惠单数量
+        QueryWrapper<TbOrder> wrapper = new QueryWrapper<>();
+        wrapper.eq("user_id", userId)
+                .eq("vip_promotion", Constant.YES)
+                .eq("is_pay", Constant.YES)
+                // 8商家拒绝接单 5订单已取消 不纳入统计
+                .notIn("status", "5", "8")
+                .ge("pay_time", LocalDateTime.now().toLocalDate().atStartOfDay())
+                .le("pay_time", LocalDateTime.now().toLocalDate().atTime(23, 59, 59));
+        return count(wrapper);
+    }
+
     /**
      * 更新订单状态和支付顺序
      *
@@ -3035,17 +3049,4 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
             log.info("preOrder==>[{}],订单参与会员优惠,优惠后金额为:{}元", order.getOrderId(), payMoney);
         }
     }
-
-    private int getCurDayVipPromotionByUserCount(Long userId) {
-        // 查询用户当天会员优惠单数量
-        QueryWrapper<TbOrder> wrapper = new QueryWrapper<>();
-        wrapper.eq("user_id", userId)
-                .eq("vip_promotion", Constant.YES)
-                .eq("is_pay", Constant.YES)
-                // 8商家拒绝接单 5订单已取消 不纳入统计
-                .notIn("status", "5", "8")
-                .ge("pay_time", LocalDateTime.now().toLocalDate().atStartOfDay())
-                .le("pay_time", LocalDateTime.now().toLocalDate().atTime(23, 59, 59));
-        return count(wrapper);
-    }
 }