Ver código fonte

溯源码库存校验逻辑、支付日期逻辑、处方药开方展示逻辑代码提交

yjwang 6 dias atrás
pai
commit
1c5a5a7a08

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/domain/FsStoreVerifyCodeScrm.java

@@ -55,5 +55,7 @@ public class FsStoreVerifyCodeScrm extends BaseEntity{
     //是否回收(0否1是)
     private Long isRecycle;
 
+    //购物车ID
+    private Long carId;
 
 }

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStoreCartNumParam.java

@@ -1,6 +1,7 @@
 package com.fs.hisStore.param;
 
 import io.swagger.annotations.ApiModelProperty;
+import io.swagger.models.auth.In;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -21,5 +22,6 @@ public class FsStoreCartNumParam {
     @ApiModelProperty(value = "购物车ID")
     private Long id;
 
+    private Integer type;
 
 }

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStoreCartParam.java

@@ -28,5 +28,7 @@ public class FsStoreCartParam {
     @ApiModelProperty(value = "是否购买")
     private Integer isBuy=0;
 
+    //类型null默认1医药
+    private Integer type;
 
 }

+ 56 - 12
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreCartScrmServiceImpl.java

@@ -3,6 +3,7 @@ package com.fs.hisStore.service.impl;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fs.common.core.domain.R;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
@@ -13,15 +14,9 @@ import com.fs.erp.service.IErpGoodsService;
 import com.fs.his.utils.ConfigUtil;
 import com.fs.hisStore.config.FsErpConfig;
 import com.fs.hisStore.config.MedicalMallConfig;
-import com.fs.hisStore.domain.FsStoreCartScrm;
-import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
-import com.fs.hisStore.domain.FsStoreProductGroupScrm;
-import com.fs.hisStore.domain.FsStoreScrm;
+import com.fs.hisStore.domain.*;
 import com.fs.hisStore.dto.StoreProductGroupDTO;
-import com.fs.hisStore.mapper.FsStoreCartScrmMapper;
-import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
-import com.fs.hisStore.mapper.FsStoreProductGroupScrmMapper;
-import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
+import com.fs.hisStore.mapper.*;
 import com.fs.hisStore.param.FsStoreCartCountParam;
 import com.fs.hisStore.param.FsStoreCartDelParam;
 import com.fs.hisStore.param.FsStoreCartNumParam;
@@ -35,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 import com.fs.hisStore.vo.FsStoreCartGroupStoreVO;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -74,6 +70,9 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
     @Autowired
     private ISysConfigService configService;
 
+    @Autowired
+    private FsStoreVerifyCodeScrmMapper verifyCodeScrmMapper;
+
 
 
     /**
@@ -192,6 +191,11 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
                         .build();
                 storeCart.setCreateTime(new Date());
                 checkProductStock(cartParam.getProductId(),storeCart.getProductAttrValueId());
+                if(cartParam.getType() == 1){//加入校验
+                    if(checkCarNumber(storeCart.getProductId(),storeCart.getCartNum())){
+                        return R.error("商品数量大于库存数量!");
+                    }
+                }
                 fsStoreCartMapper.insertFsStoreCart(storeCart);
                 return R.ok().put("id",storeCart.getId());
             }
@@ -200,6 +204,11 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
                 storeCart.setCartNum(cartParam.getCartNum() + cart.get(0).getCartNum());
                 storeCart.setUpdateTime(new Date());
                 checkProductStock(cartParam.getProductId(),storeCart.getProductAttrValueId());
+                if(cartParam.getType() == 1){//加入校验
+                    if(checkCarNumber(storeCart.getProductId(),storeCart.getCartNum())){
+                        return R.error("商品数量大于库存数量!");
+                    }
+                }
                 fsStoreCartMapper.updateFsStoreCart(storeCart);
                 return R.ok().put("id",storeCart.getId());
             }
@@ -221,13 +230,34 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public R changeNum(long userId, FsStoreCartNumParam cartParam) {
-        FsStoreCartScrm cart=fsStoreCartMapper.selectFsStoreCartById(cartParam.getId());
-        checkProductStock(cart.getProductId(),cart.getProductAttrValueId());
-        cart.setCartNum(cartParam.getNumber());
+        FsStoreCartScrm cart = fsStoreCartMapper.selectFsStoreCartById(cartParam.getId());
+        if (cart == null) {
+            return R.error("购物车商品不存在!");
+        }
+        int targetNum = cartParam.getNumber();
+        if(cartParam.getType() != null){
+            checkProductStock(cart.getProductId(), cart.getProductAttrValueId());
+        }else {
+            Integer availableStock = verifyCodeScrmMapper.selectCount(
+                    new LambdaQueryWrapper<FsStoreVerifyCodeScrm>()
+                            .eq(FsStoreVerifyCodeScrm::getProductId, cart.getProductId())
+                            .eq(FsStoreVerifyCodeScrm::getOutboundStatus, 0L)
+                            .eq(FsStoreVerifyCodeScrm::getIsDel, 0L)
+                            .last("FOR UPDATE")
+            );
+            if (targetNum > availableStock) {
+                FsStoreProductScrm product = fsStoreProductMapper.selectFsStoreProductById(cart.getProductId());
+                return R.error("商品" + product.getProductName() + ":库存不足!当前可用库存:" + availableStock);
+            }
+        }
+
+        cart.setCartNum(targetNum);
         cart.setUpdateTime(new Date());
         fsStoreCartMapper.updateFsStoreCart(cart);
-        return R.ok();
+
+        return R.ok("购物车数量修改成功");
     }
 
     @Override
@@ -383,5 +413,19 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
         return goodsService;
     }
 
+    //校验购物车数量
+    public boolean checkCarNumber(Long productId,Integer num){
+        Integer availableStock = verifyCodeScrmMapper.selectCount(
+                new LambdaQueryWrapper<FsStoreVerifyCodeScrm>()
+                        .eq(FsStoreVerifyCodeScrm::getProductId, productId)
+                        .eq(FsStoreVerifyCodeScrm::getOutboundStatus, 0L)
+                        .eq(FsStoreVerifyCodeScrm::getIsDel, 0L)
+                        .last("FOR UPDATE")
+        );
+        if (num > availableStock) {
+            return true;
+        }
+        return false;
+    }
 
 }

+ 2 - 0
fs-service/src/main/resources/mapper/hisStore/FsStoreVerifyCodeScrmMapper.xml

@@ -89,6 +89,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="storeId != null">store_id = #{storeId} ,</if>
             <if test="isRecycle != null">is_recycle = #{isRecycle} ,
             </if>
+            <if test="carId != null">car_id = #{carId} ,
+            </if>
             </trim>
         where id = #{id}
     </update>

+ 8 - 2
fs-user-app/src/main/java/com/fs/app/controller/store/StoreOrderScrmController.java

@@ -205,8 +205,11 @@ public class StoreOrderScrmController extends AppBaseController {
         List<FsStoreOrderItemVO> list=itemService.selectFsStoreOrderItemListByOrderId(orderId);
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(order.getCreateTime());
-        String json=configService.selectConfigByKey("his.store");
+        String json=configService.selectConfigByKey("store.config");
         StoreConfig config=JSONUtil.toBean(json,StoreConfig.class);
+        if(order.getIsPrescribe() != null && order.getIsPrescribe() == 1){
+            config.setUnPayTime(4320);
+        }
         calendar.add(Calendar.MINUTE,config.getUnPayTime());
         SimpleDateFormat format = new   SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String payLimitTime = format.format(calendar.getTime() );
@@ -269,10 +272,13 @@ public class StoreOrderScrmController extends AppBaseController {
         order.setUserPhone(ParseUtils.parsePhone(order.getUserPhone()));
         order.setUserAddress(ParseUtils.parseIdCard(order.getUserAddress()));
 
-        String json=configService.selectConfigByKey("his.store");
+        String json=configService.selectConfigByKey("store.config");
         StoreConfig config=JSONUtil.toBean(json,StoreConfig.class);
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(order.getCreateTime());
+       if(order.getIsPrescribe() != null && order.getIsPrescribe() == 1){
+           config.setUnPayTime(4320);
+       }
         calendar.add(Calendar.MINUTE,config.getUnPayTime());
         SimpleDateFormat format = new   SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String payLimitTime = format.format(calendar.getTime() );