Ver código fonte

商品新增vip_promotion属性,更改是否参与vip优惠判断逻辑

codingliang 6 meses atrás
pai
commit
75b6864abf

+ 5 - 0
db/update_251222.sql

@@ -0,0 +1,5 @@
+-- 商品添加参与vip优惠标识 0否 1是
+alter table goods add vip_promotion varchar(1) not null default 0 comment '是否参与vip优惠 0否 1是' after shop_id;
+
+-- 更新商品是否参与vip优惠
+update goods set vip_promotion = 1 where shop_id in (select shop_id from goods_shop where vip_promotion = '1')

+ 6 - 0
src/main/java/com/sqx/modules/goods/controller/GoodsController.java

@@ -211,4 +211,10 @@ public class GoodsController extends AbstractController {
         return goodsService.goodsParticularsPictureList(page,limit,name);
     }
 
+    @ApiOperation(value = "修改商品是否参与vip优惠", notes = "vipPromotion 是否参与vip优惠活动,0否1是")
+    @PutMapping("/vip-promotion/{goodsId}/{vipPromotion}")
+    public Result updateVipPromotion(@PathVariable Long goodsId, @PathVariable String vipPromotion){
+        goodsService.updateVipPromotion(goodsId, vipPromotion);
+        return Result.success();
+    }
 }

+ 1 - 2
src/main/java/com/sqx/modules/goods/controller/GoodsShopController.java

@@ -136,11 +136,10 @@ public class GoodsShopController {
         return Result.success();
     }
 
-    @ApiOperation(value = "修改商是否参与vip优惠", notes = "vipPromotion 是否参与vip优惠活动,0否1是")
+    @ApiOperation(value = "修改商是否参与vip优惠", notes = "vipPromotion 是否参与vip优惠活动,0否1是")
     @PutMapping("/vip-promotion/{shopId}/{vipPromotion}")
     public Result updateVipPromotion(@PathVariable Long shopId, @PathVariable String vipPromotion){
         goodsShopService.updateVipPromotion(shopId, vipPromotion);
         return Result.success();
     }
-
 }

+ 3 - 0
src/main/java/com/sqx/modules/goods/entity/Goods.java

@@ -71,6 +71,9 @@ public class Goods implements Serializable {
     @ApiModelProperty("商户id")
     private Long shopId;
 
+    @ApiModelProperty("是否参与vip优惠 0否 1是")
+    private String vipPromotion;
+
     @ApiModelProperty("商户名")
     @TableField(exist = false)
     private String shopName;

+ 14 - 0
src/main/java/com/sqx/modules/goods/service/GoodsService.java

@@ -78,4 +78,18 @@ public interface GoodsService extends IService<Goods> {
     Result selectGoodsClassifyList(Long shopId, Double lng, Double lat);
 
     Result selectSupermarketGoodsList(Long shopId, Integer classifyId, Integer page, Integer limit);
+
+    /**
+     * 更新商铺商品是否为会员商品
+     * @param shopId 商铺id
+     * @param vipPromotion 是否为会员商品 1:是 0:否
+     */
+    void updateGoodsVipPromotionByShopId(Long shopId, String vipPromotion);
+
+    /**
+     * 更新商品是否为会员商品
+     * @param goodsId 商品id
+     * @param vipPromotion 是否为会员商品 1:是 0:否
+     */
+    void updateVipPromotion(Long goodsId, String vipPromotion);
 }

+ 17 - 0
src/main/java/com/sqx/modules/goods/service/impl/GoodsServiceImpl.java

@@ -5,8 +5,10 @@ import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.sqx.common.constant.RedisKey;
@@ -970,4 +972,19 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsDao, Goods> implements Go
         return Result.success().put("data", goodsIPage);
     }
 
+    @Override
+    public void updateGoodsVipPromotionByShopId(Long shopId, String vipPromotion) {
+        LambdaUpdateWrapper<Goods> updateWrapper = Wrappers.lambdaUpdate();
+        updateWrapper.set(Goods::getVipPromotion, vipPromotion)
+                .eq(Goods::getShopId, shopId);
+        goodsDao.update(null, updateWrapper);
+    }
+
+    @Override
+    public void updateVipPromotion(Long goodsId, String vipPromotion) {
+        Goods goods = new Goods();
+        goods.setGoodsId(goodsId);
+        goods.setVipPromotion(StrUtil.equals(vipPromotion,"1") ? "1" : "0");
+        baseMapper.updateById(goods);
+    }
 }

+ 6 - 0
src/main/java/com/sqx/modules/goods/service/impl/GoodsShopServiceImpl.java

@@ -35,6 +35,7 @@ import com.sqx.modules.goods.entity.Goods;
 import com.sqx.modules.goods.entity.GoodsShop;
 import com.sqx.modules.goods.entity.GoodsShopRelevancy;
 import com.sqx.modules.goods.service.GoodsAttrService;
+import com.sqx.modules.goods.service.GoodsService;
 import com.sqx.modules.goods.service.GoodsShopService;
 import com.sqx.modules.goods.vo.GoodsShopVo;
 import com.sqx.modules.integral.entity.UserIntegral;
@@ -102,6 +103,8 @@ public class GoodsShopServiceImpl extends ServiceImpl<GoodsShopDao, GoodsShop> i
     private UserIntegralService userIntegralService;
     @Autowired
     private UserMoneyDetailsService userMoneyDetailsService;
+    @Autowired
+    private GoodsService goodsService;
 
 
     @Override
@@ -612,11 +615,14 @@ public class GoodsShopServiceImpl extends ServiceImpl<GoodsShopDao, GoodsShop> i
     }
 
     @Override
+    @Transactional
     public void updateVipPromotion(Long shopId, String vipPromotion) {
         GoodsShop goodsShop = new GoodsShop();
         goodsShop.setShopId(shopId);
         goodsShop.setVipPromotion(StrUtil.equals(vipPromotion,"1") ? "1" : "0");
         baseMapper.updateById(goodsShop);
+
+        goodsService.updateGoodsVipPromotionByShopId(shopId, goodsShop.getVipPromotion());
     }
 
     @Override

+ 94 - 0
src/main/java/com/sqx/modules/member/VipPromotionUtil.java

@@ -0,0 +1,94 @@
+package com.sqx.modules.member;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.sqx.common.utils.Constant;
+import com.sqx.modules.app.entity.UserEntity;
+import com.sqx.modules.common.entity.CommonInfo;
+import com.sqx.modules.common.service.CommonInfoService;
+import com.sqx.modules.goods.entity.Goods;
+import com.sqx.modules.goods.entity.GoodsShop;
+import com.sqx.modules.member.vo.VipReduceVO;
+import com.sqx.modules.order.entity.TbOrder;
+import com.sqx.modules.order.service.AppOrderService;
+import com.sqx.modules.utils.VipExpirationUtil;
+import lombok.RequiredArgsConstructor;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * vip优惠工具类
+ * @author codingliang
+ * @date 2025-12-22
+ */
+@RequiredArgsConstructor
+public class VipPromotionUtil {
+
+    private final AppOrderService appOrderService;
+    private final CommonInfoService commonInfoService;
+
+    /**
+     * 查询用户是否可以立减
+     * @param order 订单信息,需要设置originGoodsList原始商品信息
+     * @param goodsShop 店铺信息
+     * @param user 用户信息
+     * @return VipReduceVO
+     */
+    public VipReduceVO getCanReduce(TbOrder order, GoodsShop goodsShop, UserEntity user) {
+        // 参与会员活动的商品id
+        List<Long> vipGoodsIdList = order.getOriginGoodsList().stream().filter(e -> StrUtil.equals(e.getVipPromotion(), Constant.YES)).map(Goods::getGoodsId)
+                .collect(Collectors.toList());
+
+        // 计算参与会员活动的商品总价
+        BigDecimal vipGoodsTotalPrice = order.getOrderGoodsList().stream()
+                .filter(orderGoods -> vipGoodsIdList.contains(orderGoods.getGoodsId()))
+                .map(orderGoods -> orderGoods.getGoodsPrice().multiply(new BigDecimal(orderGoods.getGoodsNum())))
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+        // 判断订单是否达到会员立减最低金额(元)
+        CommonInfo vipPromotionMinAmount = commonInfoService.findOne(446);
+        if (vipGoodsTotalPrice.compareTo(new BigDecimal(vipPromotionMinAmount.getValue())) < 0) {
+            return VipReduceVO.builder().reduceAmount(BigDecimal.ZERO)
+                    .canReduceFlag(Constant.NO)
+                    .vipReduceDesc("订单金额未达到会员立减金额")
+                    .build();
+        }
+
+        // 查询店铺是否参与会员立减
+        if (!StrUtil.equals(goodsShop.getVipPromotion(), Constant.YES)) {
+            return VipReduceVO.builder()
+                    .reduceAmount(BigDecimal.ZERO)
+                    .canReduceFlag(Constant.NO)
+                    .vipReduceDesc("店铺未参与会员立减")
+                    .build();
+        }
+        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(user.getUserId());
+        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();
+    }
+}

+ 8 - 7
src/main/java/com/sqx/modules/member/controller/app/AppVipController.java

@@ -3,16 +3,17 @@ package com.sqx.modules.member.controller.app;
 import cn.hutool.core.bean.BeanUtil;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.app.annotation.Login;
-import com.sqx.modules.member.dto.CanReduceQueryDTO;
 import com.sqx.modules.member.service.VipService;
 import com.sqx.modules.member.vo.VipReduceVO;
 import com.sqx.modules.pay.vo.PayTransactionsVO;
 import icu.xuyijie.secureapi.annotation.DecryptParam;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
-import org.springframework.web.bind.annotation.*;
-
-import javax.validation.Valid;
+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;
 
 /**
  * @author codingliang
@@ -27,9 +28,9 @@ public class AppVipController {
 
     @Login
     @ApiOperation(value = "获取用户是否可以会员立减")
-    @GetMapping(value = "get-can-reduce")
-    public Result getCanReduce(@RequestAttribute("userId") Long userId, @Valid CanReduceQueryDTO canReduceQueryDTO){
-        VipReduceVO vipReduceVO = vipService.getVipReduceInfo(userId, canReduceQueryDTO);
+    @GetMapping(value = "get-can-reduce/{orderId}")
+    public Result getCanReduce(@RequestAttribute("userId") Long userId, @PathVariable("orderId") Long orderId){
+        VipReduceVO vipReduceVO = vipService.getVipReduceInfo(userId, orderId);
         return Result.success().put("data", vipReduceVO);
     }
 

+ 0 - 27
src/main/java/com/sqx/modules/member/dto/CanReduceQueryDTO.java

@@ -1,27 +0,0 @@
-package com.sqx.modules.member.dto;
-
-import lombok.Data;
-
-import javax.validation.constraints.NotNull;
-import java.math.BigDecimal;
-
-/**
- * 查询是否可以减免参数
- * @author codingliang
- * @date 2025-11-30
- */
-@Data
-public class CanReduceQueryDTO {
-
-    /**
-     * 店铺id
-     */
-    @NotNull(message = "店铺id不能为空")
-    private Long shopId;
-
-    /**
-     * 订单原始价格
-     */
-    @NotNull(message = "订单原始价格不能为空")
-    private BigDecimal originalPrice;
-}

+ 4 - 6
src/main/java/com/sqx/modules/member/service/VipService.java

@@ -1,12 +1,9 @@
 package com.sqx.modules.member.service;
 
-import com.sqx.modules.member.dto.CanReduceQueryDTO;
 import com.sqx.modules.member.vo.VipReduceVO;
 import com.sqx.modules.pay.entity.PayDetails;
 import com.sqx.modules.pay.vo.PayTransactionsVO;
 
-import javax.validation.Valid;
-
 public interface VipService {
 
     /**
@@ -32,9 +29,10 @@ public interface VipService {
 
      /**
       * 获取用户是否可以会员立减
-      * @param userId 用户id
-      * @param canReduceQueryDTO 查询是否可以减免参数
+      *
+      * @param userId  用户id
+      * @param orderId 订单id
       * @return vip 立减信息
       */
-    VipReduceVO getVipReduceInfo(Long userId, @Valid CanReduceQueryDTO canReduceQueryDTO);
+    VipReduceVO getVipReduceInfo(Long userId, Long orderId);
 }

+ 7 - 52
src/main/java/com/sqx/modules/member/service/impl/VipServiceImpl.java

@@ -14,7 +14,7 @@ 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.CanReduceQueryDTO;
+import com.sqx.modules.member.VipPromotionUtil;
 import com.sqx.modules.member.dto.VipPromoRecordDTO;
 import com.sqx.modules.member.entity.VipPromoCode;
 import com.sqx.modules.member.service.VipPromoCodeService;
@@ -34,7 +34,6 @@ import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.validation.Valid;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 
@@ -55,6 +54,7 @@ public class VipServiceImpl implements VipService {
     private final VipPromoRecordService vipPromoRecordService;
     private final UserMoneyService userMoneyService;
     private final GoodsShopService goodsShopService;
+    private final AppOrderService orderService;
     private final AppOrderService appOrderService;
 
 
@@ -149,58 +149,13 @@ public class VipServiceImpl implements VipService {
     }
 
     @Override
-    public VipReduceVO getVipReduceInfo(Long userId, @Valid CanReduceQueryDTO canReduceQueryDTO) {
-        // 查询订单原始金额是否达到会员立减金额
-        CommonInfo vipPromotionMinAmount = commonInfoService.findOne(446);
-        if (canReduceQueryDTO.getOriginalPrice().compareTo(new BigDecimal(vipPromotionMinAmount.getValue())) < 0) {
-            return VipReduceVO.builder().reduceAmount(BigDecimal.ZERO)
-                    .canReduceFlag(Constant.NO)
-                    .vipReduceDesc("订单金额未达到会员立减金额")
-                    .build();
-        }
-
-        // 查询店铺是否参与会员立减
-        GoodsShop goodsShop = goodsShopService.getById(canReduceQueryDTO.getShopId());
-        if (ObjectUtil.isNull(goodsShop)) {
-            throw new SqxException("无效的店铺id!");
-        }
-        String goodsShopVipPromotion = goodsShop.getVipPromotion();
-        if (!StrUtil.equals(goodsShopVipPromotion, Constant.YES)) {
-            return VipReduceVO.builder()
-                    .reduceAmount(BigDecimal.ZERO)
-                    .canReduceFlag(Constant.NO)
-                    .vipReduceDesc("店铺未参与会员立减")
-                    .build();
-        }
-
-        // 查询用户是否为会员
+    public VipReduceVO getVipReduceInfo(Long userId, Long orderId) {
+        TbOrder order = orderService.getByIdWithGoods(orderId);
         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();
-        }
+        GoodsShop goodsShop = goodsShopService.getById(order.getShopId());
 
-        // 会员每单立减金额(元)
-        CommonInfo vipPromotionAmount = commonInfoService.findOne(444);
-        BigDecimal vipPromotionAmountDecimal = new BigDecimal(vipPromotionAmount.getValue());
-        return  VipReduceVO.builder().reduceAmount(vipPromotionAmountDecimal)
-                .canReduceFlag(Constant.YES)
-                .vipReduceDesc("会员每单立减金额" + vipPromotionAmountDecimal + "元")
-                .build();
+        VipPromotionUtil vipPromotionUtil = new VipPromotionUtil(appOrderService, commonInfoService);
+        return vipPromotionUtil.getCanReduce(order, goodsShop, user);
     }
 
     private void afterPaySuccess(Long userId) {

+ 6 - 0
src/main/java/com/sqx/modules/order/entity/TbOrder.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.sqx.modules.goods.entity.Goods;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
@@ -183,9 +184,14 @@ public class TbOrder implements Serializable {
     @TableField(exist = false)
     private String shopTypeName;
 
+    @ApiModelProperty("订单商品列表")
     @TableField(exist = false)
     private List<OrderGoods> orderGoodsList;
 
+    @ApiModelProperty("原始商品信息列表")
+    @TableField(exist = false)
+    private List<Goods> originGoodsList;
+
     @TableField(exist = false)
     private String avatar;
 

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

@@ -212,4 +212,11 @@ public interface AppOrderService extends IService<TbOrder> {
       * @return 店铺id-订单完成数量映射
       */
     Map<Long, Integer> countFinishByShopIdWithLast30Days();
+
+    /**
+     * 根据订单id查询订单信息,包含订单商品信息
+     * @param orderId 订单id
+     * @return 订单信息
+     */
+    TbOrder getByIdWithGoods(Long orderId);
 }

+ 61 - 58
src/main/java/com/sqx/modules/order/service/impl/AppAppOrderServiceImpl.java

@@ -67,6 +67,8 @@ import com.sqx.modules.goods.service.GoodsShopService;
 import com.sqx.modules.integral.dao.UserIntegralDao;
 import com.sqx.modules.integral.dao.UserIntegralDetailsDao;
 import com.sqx.modules.integral.entity.UserIntegralDetails;
+import com.sqx.modules.member.VipPromotionUtil;
+import com.sqx.modules.member.vo.VipReduceVO;
 import com.sqx.modules.message.dao.MessageInfoDao;
 import com.sqx.modules.message.entity.MessageInfo;
 import com.sqx.modules.order.controller.query.GoodsSkuQuery;
@@ -103,7 +105,6 @@ import com.sqx.modules.shop.service.ShopTypeService;
 import com.sqx.modules.sys.entity.SysUserEntity;
 import com.sqx.modules.sys.service.SysUserService;
 import com.sqx.modules.utils.SenInfoCheckUtil;
-import com.sqx.modules.utils.VipExpirationUtil;
 import com.sqx.modules.utils.excel.EasyExcelUtil;
 import com.sqx.modules.utils.excel.ExcelData;
 import com.sqx.modules.utils.fieYun.FeiYunUtils;
@@ -1263,30 +1264,7 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
     }
 
     private void checkOrderGoods(TbOrder order) {
-        Long orderId = order.getOrderId();
-        // 获取订单商品信息
-        List<OrderGoods> orderGoodsList = orderGoodsDao.selectList(
-                new QueryWrapper<OrderGoods>()
-                        .eq("order_id", orderId));
-        for (int b = 0; b < orderGoodsList.size(); b++) {
-            OrderGoods orderGoods = orderGoodsList.get(b);
-            Long goodsId = orderGoods.getGoodsId();
-            Goods goods = goodsDao.selectById(goodsId);
-            if (goods == null || goods.getStatus().equals(1)) {
-                // TODO ??感觉有问题??
-                orderGoodsDao.deleteById(orderGoods.getId());
-                throw new SqxException("商品:" + orderGoods.getGoodsName() + ",不存在,请刷新后重试!");
-            }
-
-            GoodsShopRelevancy goodsShopRelevancy = goodsShopRelevancyDao.selectOne(
-                    new QueryWrapper<GoodsShopRelevancy>()
-                            .eq("goods_id", goodsId)
-                            .eq("shop_id", order.getShopId()));
-            int i = goodsShopRelevancyDao.selectGoodsCount(orderId, goodsId);
-            if (goodsShopRelevancy.getInventory() < i) {
-                throw new SqxException("库存不足");
-            }
-        }
+        checkAndFillGoodsInfo(order);
     }
 
     @Override
@@ -3014,6 +2992,49 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
                 ));
     }
 
+    @Override
+    public TbOrder getByIdWithGoods(Long orderId) {
+        TbOrder order = getById(orderId);
+        return checkAndFillGoodsInfo(order);
+    }
+
+    /**
+     * 检查订单商品信息是否有效,填充订单商品信息
+     * @param order 订单信息
+     * @return 订单信息
+     */
+    private TbOrder checkAndFillGoodsInfo(TbOrder order) {
+        // 获取订单商品信息
+        List<OrderGoods> orderGoodsList = orderGoodsDao.selectList(
+                new QueryWrapper<OrderGoods>()
+                        .eq("order_id", order.getOrderId()));
+        order.setOrderGoodsList(orderGoodsList);
+        List<Goods> goodsList = new ArrayList<>();
+        for (int b = 0; b < orderGoodsList.size(); b++) {
+            OrderGoods orderGoods = orderGoodsList.get(b);
+            Long goodsId = orderGoods.getGoodsId();
+            Goods goods = goodsDao.selectById(goodsId);
+            if (goods == null || goods.getStatus().equals(1)) {
+                orderGoodsDao.deleteById(orderGoods.getId());
+                throw new SqxException("商品:" + orderGoods.getGoodsName() + ",不存在,请刷新后重试!");
+            }
+
+            GoodsShopRelevancy goodsShopRelevancy = goodsShopRelevancyDao.selectOne(
+                    new QueryWrapper<GoodsShopRelevancy>()
+                            .eq("goods_id", goodsId)
+                            .eq("shop_id", order.getShopId()));
+            int i = goodsShopRelevancyDao.selectGoodsCount(order.getOrderId(), goodsId);
+            if (goodsShopRelevancy.getInventory() < i) {
+                throw new SqxException("库存不足");
+            }
+
+            goodsList.add(goods);
+        }
+
+        order.setOriginGoodsList(goodsList);
+        return order;
+    }
+
     /**
      * 更新订单状态和支付顺序
      *
@@ -3040,45 +3061,27 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
      * @param userId 用户id
      */
     private void checkVipPromotion(TbOrder order, GoodsShop goodsShop, Long userId) {
-        // 检查店铺是否支持会员优惠
-        if (!StrUtil.equals(goodsShop.getVipPromotion(), Constant.YES)) {
-            return;
-        }
-
-        // 判断订单是否达到会员立减最低金额(元)
-        CommonInfo vipPromotionMinAmount = commonInfoService.findOne(446);
-        if (order.getPayMoney().compareTo(new BigDecimal(vipPromotionMinAmount.getValue())) < 0) {
+        UserEntity user = userService.getById(userId);
+        VipPromotionUtil vipPromotionUtil = new VipPromotionUtil(this, commonInfoService);
+        VipReduceVO canReduce = vipPromotionUtil.getCanReduce(order, goodsShop, user);
+        if (StrUtil.equals(canReduce.getCanReduceFlag(), Constant.NO)) {
             return;
         }
 
-        // 检查用户是否为会员,且会员是否过期
-        UserEntity user = userService.getById(userId);
-        if(ObjectUtil.isNotNull(user.getIsVip()) && user.getIsVip() == 1 && VipExpirationUtil.isVipValid(user.getVipExpirationTime())) {
-            // 查询用户当天会员优惠单数量
-            int count = getCurDayVipPromotionByUserCount(userId);
-
-            // 会员每天限制优惠单数(单)
-            CommonInfo vipPromotionCount = commonInfoService.findOne(445);
-            if (count >= Integer.parseInt(vipPromotionCount.getValue())) {
-                return;
-            }
+        // 计算订单支付金额,减去会员立减金额
+        BigDecimal payMoney = order.getPayMoney().subtract(canReduce.getReduceAmount());
 
-            // 会员每单立减金额(元)
-            CommonInfo vipPromotionAmount = commonInfoService.findOne(444);
-            BigDecimal payMoney = order.getPayMoney().subtract(new BigDecimal(vipPromotionAmount.getValue()));
-
-            //如果使用红包后,订单价格小于0,则改为0.01元
-            if (payMoney.doubleValue() <= 0) {
-                payMoney = new BigDecimal("0.01");
-            }
+        //如果使用红包后,订单价格小于0,则改为0.01元
+        if (payMoney.doubleValue() <= 0) {
+            payMoney = new BigDecimal("0.01");
+        }
 
-            // 设置订单支付金额
-            order.setPayMoney(payMoney);
+        // 设置订单支付金额
+        order.setPayMoney(payMoney);
 
-            // 订单设置为vip优惠订单
-            order.setVipPromotion(Constant.YES);
+        // 订单设置为vip优惠订单
+        order.setVipPromotion(Constant.YES);
 
-            log.info("preOrder==>[{}],订单参与会员优惠,优惠后金额为:{}元", order.getOrderId(), payMoney);
-        }
+        log.info("preOrder==>[{}],订单参与会员优惠,优惠后金额为:{}元", order.getOrderId(), payMoney);
     }
 }