Bläddra i källkod

bugfix:805 团购管理库存为0状态修改为售罄

qxy 1 månad sedan
förälder
incheckning
f7ee0376c6

+ 19 - 0
alien-entity/src/main/java/shop/alien/mapper/LifeGroupBuyMainMapper.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
 import shop.alien.entity.store.LifeGroupBuyMain;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import shop.alien.entity.store.vo.LifeGroupBuyThaliVo;
@@ -28,6 +29,24 @@ public interface LifeGroupBuyMainMapper extends BaseMapper<LifeGroupBuyMain> {
             "        coupon_id,delete_flag,created_time,updated_time,created_user_id,\n" +
             "        updated_user_id from life_group_buy_main ${ew.customSqlSegment}")
     IPage<LifeGroupBuyThaliVo> selectPageByThaliVo(IPage<LifeGroupBuyThaliVo> lifeGroupBuyThaliVoIPage,@Param(Constants.WRAPPER) QueryWrapper<LifeGroupBuyThaliVo> queryWrapper);
+
+
+    @Update("UPDATE life_group_buy_main\n" +
+            "SET \n" +
+            "  status = CASE \n" +
+            "    WHEN (inventory_num - #{buyCount}) = 0 THEN #{soldOutStatus}  \n" +
+            "    ELSE status \n" +
+            "  END,\n" +
+            "  inventory_num = inventory_num - #{buyCount}\n" +
+            "WHERE \n" +
+            "   id = #{couponId}\n" +
+            "\t AND inventory_num >= #{buyCount}"
+    )
+    int deductInventoryAtomically(
+            @Param("couponId") Integer couponId,
+            @Param("buyCount") int buyCount,
+            @Param("soldOutStatus") int soldOutStatus
+    );
 }
 
 

+ 10 - 6
alien-store/src/main/java/shop/alien/store/service/impl/LifeGroupBuyServiceImpl.java

@@ -132,12 +132,16 @@ public class LifeGroupBuyServiceImpl extends ServiceImpl<LifeGroupBuyMainMapper,
     @Override
     public IPage<LifeGroupBuyThaliVo> getThaliList(int page, int size, String storeId, String status, String groupName, String groupType) {
         QueryWrapper<LifeGroupBuyThaliVo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq(StringUtils.isNotEmpty(storeId), "store_id", storeId)
-                .eq(StringUtils.isNotEmpty(status), "status", status)
-                .eq(StringUtils.isNotEmpty(groupType), "group_type", groupType)
-                .like(StringUtils.isNotEmpty(groupName), "group_name", groupName)
-                .eq("delete_flag", 0)
-                .orderByDesc("created_time");
+        queryWrapper.eq(StringUtils.isNotEmpty(storeId), "store_id", storeId);
+        if(status.equals("8")){
+            queryWrapper.in(StringUtils.isNotEmpty(status), "status", 2, 6);
+        }else{
+            queryWrapper.eq(StringUtils.isNotEmpty(status), "status", status);
+        }
+        queryWrapper.eq(StringUtils.isNotEmpty(groupType), "group_type", groupType);
+        queryWrapper.like(StringUtils.isNotEmpty(groupName), "group_name", groupName);
+        queryWrapper.eq("delete_flag", 0);
+        queryWrapper.orderByDesc("created_time");
         IPage<LifeGroupBuyThaliVo> lifeGroupBuyThaliVoIPage = new Page<>(page, size);
         IPage<LifeGroupBuyThaliVo> voIPage = lifeGroupBuyMainMapper.selectPageByThaliVo(lifeGroupBuyThaliVoIPage, queryWrapper);
         voIPage.getRecords().forEach(this::getMainImgAndDisableDate);