Browse Source

商城代码,地址id回显和提示库存不足

chenguo 15 hours ago
parent
commit
c162c733f9

+ 5 - 148
fs-service/src/main/java/com/fs/hisStore/domain/FsUserAddressScrm.java

@@ -1,9 +1,11 @@
 package com.fs.hisStore.domain;
 
+import com.alibaba.fastjson.annotation.JSONField;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fs.common.annotation.Excel;
 import com.fs.common.core.domain.BaseEntity;
+import lombok.Data;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 
@@ -14,6 +16,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
  * @date 2022-03-15
  */
 @TableName("fs_user_address")
+@Data
 public class FsUserAddressScrm extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
@@ -22,6 +25,8 @@ public class FsUserAddressScrm extends BaseEntity
     @TableField("address_id")
     private Long id;
 
+    private Long addressId;
+
     /** 用户id */
     @Excel(name = "用户id")
     private Long userId;
@@ -75,152 +80,4 @@ public class FsUserAddressScrm extends BaseEntity
     @Excel(name = "是否删除")
     private Integer isDel;
 
-    public void setId(Long id)
-    {
-        this.id = id;
-    }
-
-    public Long getId()
-    {
-        return id;
-    }
-    public void setUserId(Long userId)
-    {
-        this.userId = userId;
-    }
-
-    public Long getUserId()
-    {
-        return userId;
-    }
-    public void setRealName(String realName)
-    {
-        this.realName = realName.trim();
-    }
-
-    public String getRealName()
-    {
-        return realName;
-    }
-    public void setPhone(String phone)
-    {
-        this.phone = phone.trim();
-    }
-
-    public String getPhone()
-    {
-        return phone;
-    }
-    public void setProvince(String province)
-    {
-        this.province = province;
-    }
-
-    public String getProvince()
-    {
-        return province;
-    }
-    public void setCity(String city)
-    {
-        this.city = city;
-    }
-
-    public String getCity()
-    {
-        return city;
-    }
-    public void setCityId(String cityId)
-    {
-        this.cityId = cityId;
-    }
-
-    public String getCityId()
-    {
-        return cityId;
-    }
-    public void setDistrict(String district)
-    {
-        this.district = district;
-    }
-
-    public String getDistrict()
-    {
-        return district;
-    }
-    public void setDetail(String detail)
-    {
-        this.detail = detail.trim();
-    }
-
-    public String getDetail()
-    {
-        return detail;
-    }
-    public void setPostCode(String postCode)
-    {
-        this.postCode = postCode;
-    }
-
-    public String getPostCode()
-    {
-        return postCode;
-    }
-    public void setLongitude(String longitude)
-    {
-        this.longitude = longitude;
-    }
-
-    public String getLongitude()
-    {
-        return longitude;
-    }
-    public void setLatitude(String latitude)
-    {
-        this.latitude = latitude;
-    }
-
-    public String getLatitude()
-    {
-        return latitude;
-    }
-    public void setIsDefault(Integer isDefault)
-    {
-        this.isDefault = isDefault;
-    }
-
-    public Integer getIsDefault()
-    {
-        return isDefault;
-    }
-    public void setIsDel(Integer isDel)
-    {
-        this.isDel = isDel;
-    }
-
-    public Integer getIsDel()
-    {
-        return isDel;
-    }
-
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("id", getId())
-            .append("userId", getUserId())
-            .append("realName", getRealName())
-            .append("phone", getPhone())
-            .append("province", getProvince())
-            .append("city", getCity())
-            .append("cityId", getCityId())
-            .append("district", getDistrict())
-            .append("detail", getDetail())
-            .append("postCode", getPostCode())
-            .append("longitude", getLongitude())
-            .append("latitude", getLatitude())
-            .append("isDefault", getIsDefault())
-            .append("isDel", getIsDel())
-            .append("createTime", getCreateTime())
-            .append("updateTime", getUpdateTime())
-            .toString();
-    }
 }

+ 9 - 9
fs-service/src/main/java/com/fs/hisStore/mapper/FsUserAddressScrmMapper.java

@@ -7,15 +7,15 @@ import org.apache.ibatis.annotations.Update;
 
 /**
  * 用户地址Mapper接口
- * 
+ *
  * @author fs
  * @date 2022-03-15
  */
-public interface FsUserAddressScrmMapper 
+public interface FsUserAddressScrmMapper
 {
     /**
      * 查询用户地址
-     * 
+     *
      * @param id 用户地址ID
      * @return 用户地址
      */
@@ -23,7 +23,7 @@ public interface FsUserAddressScrmMapper
 
     /**
      * 查询用户地址列表
-     * 
+     *
      * @param fsUserAddress 用户地址
      * @return 用户地址集合
      */
@@ -31,7 +31,7 @@ public interface FsUserAddressScrmMapper
 
     /**
      * 新增用户地址
-     * 
+     *
      * @param fsUserAddress 用户地址
      * @return 结果
      */
@@ -39,7 +39,7 @@ public interface FsUserAddressScrmMapper
 
     /**
      * 修改用户地址
-     * 
+     *
      * @param fsUserAddress 用户地址
      * @return 结果
      */
@@ -47,7 +47,7 @@ public interface FsUserAddressScrmMapper
 
     /**
      * 删除用户地址
-     * 
+     *
      * @param id 用户地址ID
      * @return 结果
      */
@@ -55,12 +55,12 @@ public interface FsUserAddressScrmMapper
 
     /**
      * 批量删除用户地址
-     * 
+     *
      * @param ids 需要删除的数据ID
      * @return 结果
      */
     public int deleteFsUserAddressByIds(Long[] ids);
-    @Select("select * from fs_user_address where user_id=#{uid} and is_default=1 and is_del=0 limit 1")
+
     FsUserAddressScrm selectFsUserAddressByDefaultAddress(long uid);
     @Update("update fs_user_address set is_default=0 where user_id=#{userId}")
     int clearIsDefalut(long userId);

+ 64 - 66
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreCartScrmServiceImpl.java

@@ -222,84 +222,82 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
     @Override
     public void checkProductStock(Long productId, Long productAttrValueId) {
         IErpGoodsService goodsService = getErpService();
-        if(goodsService == null){
-            log.info("未找到erp服务");
-            throw new CustomException("未找到erp服务");
-        }
-        log.info("检查库存 {} {}",productId,productAttrValueId);
-        FsStoreProductAttrValueScrm productAttrValue=valueMapper.selectFsStoreProductAttrValueById(productAttrValueId);
-        if(StringUtils.isEmpty(productAttrValue.getGroupBarCode())){
-            //单品
-            ErpGoodsStockQueryRequert queryRequert = new ErpGoodsStockQueryRequert();
-            queryRequert.setBarcode(productAttrValue.getBarCode());
-            ErpGoodsStockQueryResponse goodsStock = goodsService.getGoodsStock(queryRequert);
-            if(goodsStock != null && goodsStock.getStocks() != null && !goodsStock.getStocks().isEmpty()){
-
-                int stocks = Integer.valueOf(goodsStock.getStocks().get(0).getSalable_qty());
-
-                if(stocks<=0){
-                    productAttrValue.setStock(0);
-                    valueMapper.updateFsStoreProductAttrValue(productAttrValue);
-                    fsStoreProductMapper.updateStock(productId);
-                    throw new CustomException("库存不足");
+        if(goodsService != null){
+            log.info("检查库存 {} {}",productId,productAttrValueId);
+            FsStoreProductAttrValueScrm productAttrValue=valueMapper.selectFsStoreProductAttrValueById(productAttrValueId);
+            if(StringUtils.isEmpty(productAttrValue.getGroupBarCode())){
+                //单品
+                ErpGoodsStockQueryRequert queryRequert = new ErpGoodsStockQueryRequert();
+                queryRequert.setBarcode(productAttrValue.getBarCode());
+                ErpGoodsStockQueryResponse goodsStock = goodsService.getGoodsStock(queryRequert);
+                if(goodsStock != null && goodsStock.getStocks() != null && !goodsStock.getStocks().isEmpty()){
+
+                    int stocks = Integer.valueOf(goodsStock.getStocks().get(0).getSalable_qty());
+
+                    if(stocks<=0){
+                        productAttrValue.setStock(0);
+                        valueMapper.updateFsStoreProductAttrValue(productAttrValue);
+                        fsStoreProductMapper.updateStock(productId);
+                        throw new CustomException("库存不足");
+                    }
+                    else{
+                        //更新库存
+                        productAttrValue.setStock(stocks);
+                        valueMapper.updateFsStoreProductAttrValue(productAttrValue);
+                        fsStoreProductMapper.updateStock(productId);
+                        return;
+                    }
+
                 }
                 else{
-                    //更新库存
-                    productAttrValue.setStock(stocks);
-                    valueMapper.updateFsStoreProductAttrValue(productAttrValue);
-                    fsStoreProductMapper.updateStock(productId);
-                    return;
+                    throw new CustomException("未获取到库存");
                 }
 
             }
             else{
-                throw new CustomException("未获取到库存");
-            }
-
-        }
-        else{
-            //组合码
-            FsStoreProductGroupScrm group=productGroupMapper.selectFsStoreProductGroupByBarCode(productAttrValue.getGroupBarCode());
-            if(group!=null){
-                Integer totalStock=0;
-                JSONArray jsonArray= JSONUtil.parseArray(group.getProducts());
-                List<StoreProductGroupDTO> productGroupDTOS=JSONUtil.toList(jsonArray, StoreProductGroupDTO.class);
-                if(productGroupDTOS!=null){
-                    for(StoreProductGroupDTO dto:productGroupDTOS){
-                        FsStoreProductAttrValueScrm attrValue=valueMapper.selectFsStoreProductAttrValueById(dto.getId());
-                        ErpGoodsStockQueryRequert queryRequert = new ErpGoodsStockQueryRequert();
-                        queryRequert.setBarcode(attrValue.getGroupBarCode());
-                        ErpGoodsStockQueryResponse goodsStock = goodsService.getGoodsStock(queryRequert);
-                        if(goodsStock != null && goodsStock.getStocks() != null && !goodsStock.getStocks().isEmpty()){
-                            int stocks = Integer.valueOf(goodsStock.getStocks().get(0).getSalable_qty());
-
-
-                            if(stocks<=0){
-                                attrValue.setStock(0);
-                                valueMapper.updateFsStoreProductAttrValue(attrValue);
-                                fsStoreProductMapper.updateStock(productId);
-                                throw new CustomException("库存不足");
+                //组合码
+                FsStoreProductGroupScrm group=productGroupMapper.selectFsStoreProductGroupByBarCode(productAttrValue.getGroupBarCode());
+                if(group!=null){
+                    Integer totalStock=0;
+                    JSONArray jsonArray= JSONUtil.parseArray(group.getProducts());
+                    List<StoreProductGroupDTO> productGroupDTOS=JSONUtil.toList(jsonArray, StoreProductGroupDTO.class);
+                    if(productGroupDTOS!=null){
+                        for(StoreProductGroupDTO dto:productGroupDTOS){
+                            FsStoreProductAttrValueScrm attrValue=valueMapper.selectFsStoreProductAttrValueById(dto.getId());
+                            ErpGoodsStockQueryRequert queryRequert = new ErpGoodsStockQueryRequert();
+                            queryRequert.setBarcode(attrValue.getGroupBarCode());
+                            ErpGoodsStockQueryResponse goodsStock = goodsService.getGoodsStock(queryRequert);
+                            if(goodsStock != null && goodsStock.getStocks() != null && !goodsStock.getStocks().isEmpty()){
+                                int stocks = Integer.valueOf(goodsStock.getStocks().get(0).getSalable_qty());
+
+
+                                if(stocks<=0){
+                                    attrValue.setStock(0);
+                                    valueMapper.updateFsStoreProductAttrValue(attrValue);
+                                    fsStoreProductMapper.updateStock(productId);
+                                    throw new CustomException("库存不足");
+                                }
+                                else{
+                                    //更新库存
+                                    attrValue.setStock(stocks);
+                                    valueMapper.updateFsStoreProductAttrValue(attrValue);
+                                    fsStoreProductMapper.updateStock(productId);
+                                }
+                                totalStock+=stocks;
                             }
-                            else{
-                                //更新库存
-                                attrValue.setStock(stocks);
-                                valueMapper.updateFsStoreProductAttrValue(attrValue);
-                                fsStoreProductMapper.updateStock(productId);
-                            }
-                            totalStock+=stocks;
                         }
                     }
+                    productAttrValue.setStock(totalStock);
+                    valueMapper.updateFsStoreProductAttrValue(productAttrValue);
+                    fsStoreProductMapper.updateStock(productId);
                 }
-                productAttrValue.setStock(totalStock);
-                valueMapper.updateFsStoreProductAttrValue(productAttrValue);
-                fsStoreProductMapper.updateStock(productId);
-            }
 
+            }
+        }
+        int stock=valueMapper.selectFsStoreProductStockById(productAttrValueId);
+        if (stock < 1) {
+            throw new CustomException("库存不足");
         }
-//        int stock=valueMapper.selectFsStoreProductStockById(productAttrValueId);
-//        if (stock < cartNum) {
-//            throw new CustomException(product.getProductName() + "库存不足");
-//        }
     }
 
 

+ 5 - 0
fs-service/src/main/resources/mapper/hisStore/FsUserAddressScrmMapper.xml

@@ -27,6 +27,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select address_id, user_id, real_name, phone, province, city, city_ids, district, detail, post_code, longitude, latitude, is_default, is_del, create_time, update_time from fs_user_address
     </sql>
 
+    <select id="selectFsUserAddressByDefaultAddress" parameterType="Long" resultMap="FsUserAddressResult">
+        <include refid="selectFsUserAddressVo"/>
+        where user_id = #{uid} and is_default = 1 and is_del = 0 limit 1
+    </select>
+
     <select id="selectFsUserAddressList" parameterType="FsUserAddressScrm" resultMap="FsUserAddressResult">
         <include refid="selectFsUserAddressVo"/>
         <where>