Browse Source

1.修复供货和进货的逻辑,供货会把商品详情放到nfs里,形成txt问题,进货的时候又进行解析
2.图片进行补全

zhangwl 21 hours ago
parent
commit
ad97781bcb

+ 7 - 0
src/main/java/zs/payment/mapper/flymall/B2cGoodsSpuInOnlineMapper.java

@@ -42,4 +42,11 @@ public interface B2cGoodsSpuInOnlineMapper extends BaseMapper<B2cGoodsSpuInOnlin
      */
     @Select("SELECT COUNT(*) FROM b2c_shipping_status WHERE shop_id = #{shopId} AND is_default = 1")
     int countDefaultShipping(@Param("shopId") Integer shopId);
+
+    /**
+     * 查重:该企悦商品是否已在云商城供货(对应PHP getYmallQiyungoods → qiyungoods接口)
+     * 按 goodsid + shop_id 查有效供货记录(is_del=0),软删除记录不算,允许停供后重新供货
+     */
+    @Select("SELECT COUNT(*) FROM b2c_goods_spu_in_online WHERE goodsid = #{goodsid} AND shop_id = #{shopId} AND is_del = 0")
+    int countSuppliedByGoodsid(@Param("goodsid") Integer goodsid, @Param("shopId") Integer shopId);
 }

+ 52 - 12
src/main/java/zs/payment/service/commodity/impl/CommodityProcureServiceImpl.java

@@ -130,6 +130,10 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
     private static final Pattern IMG_SRC_PATTERN =
             Pattern.compile("<img[^>]*?src\\s*=\\s*[\"']([^\"']+)[\"']", Pattern.CASE_INSENSITIVE);
 
+    /** 提取 PHP 序列化数组中的字符串值 s:len:"value";(对应 PHP unserialize(thumb_url)) */
+    private static final Pattern PHP_SERIALIZE_STR_PATTERN =
+            Pattern.compile("s:\\d+:\"(.*?)\";", Pattern.DOTALL);
+
     private static final BigDecimal HUNDRED = new BigDecimal("100");
     private static final BigDecimal COMMISSION_DEFAULT_RATE = new BigDecimal("0.01");
     private static final Integer JD_SHOP_ID = 11507;
@@ -282,6 +286,7 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
         if (keyWord != null && !keyWord.trim().isEmpty()) {
             criteria.and("gd_name").regex(".*" + keyWord.trim() + ".*", "i");
         }
+//        criteria.and("gd_id").is(430184);
 
         Query query = new Query(criteria);
         // 只查gd_id字段,提高查询效率
@@ -824,6 +829,8 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
                 .eq(ImsEweiShopGoods::getMerchid, 0)
                 .eq(ImsEweiShopGoods::getDeleted, 0)
                 .gt(ImsEweiShopGoods::getCostprice, 0)
+                //库存要大于0
+                .gt(ImsEweiShopGoods::getTotal,0)
                 .ne(ImsEweiShopGoods::getCatchSource, "xinglian");
         // 关键字过滤(商品ID或标题模糊匹配)
         if (req.getKeyword() != null && !req.getKeyword().trim().isEmpty()) {
@@ -831,7 +838,7 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
             goodsQuery.and(w -> w.eq(ImsEweiShopGoods::getId, kw)
                     .or().like(ImsEweiShopGoods::getTitle, kw));
         }
-
+//        goodsQuery.last("limit 1");
         List<ImsEweiShopGoods> items = goodsService.list(goodsQuery);
 
         int submitCount = 0;
@@ -868,8 +875,9 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
     private void supplyGoodsToMall(ImsEweiShopGoods item, Integer storeid, Integer cate, Integer uniacid) {
         Long goodsId = item.getId();
 
-        // 【Bug修复】查重前置:是否已在云商城供货(通过gd_id判断),避免无效查询
-        if (item.getGdId() != null && item.getGdId() > 0) {
+        // 查重前置:是否已在云商城供货(对齐PHP getYmallQiyungoods,查云商城侧 goodsid+shop_id 有效记录)
+        // 注意:不能用本地 gd_id>0 判断——停供只软删云商城记录、不清本地 gd_id,那样会误拦「停供后重新供货」
+        if (b2cGoodsSpuInOnlineMapper.countSuppliedByGoodsid(item.getId().intValue(), storeid) > 0) {
             throw new ApiException("商品已经供货");
         }
 
@@ -929,21 +937,53 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
      * 构建商品图片列表:thumb首图 + thumb_url扩展图
      */
     private List<String> buildGoodsImages(ImsEweiShopGoods item, Long goodsId) {
-        List<String> imgsInfo = new ArrayList<>();
-        if (item.getThumb() != null) {
-            imgsInfo.add(item.getThumb());
+        // 对齐 PHP supply():先解析 thumb_url 扩展图并转全路径,再用主图 thumb 覆盖下标 0
+        List<String> imgsInfo = parseThumbUrl(item.getThumbUrl(), goodsId);
+        for (int i = 0; i < imgsInfo.size(); i++) {
+            imgsInfo.set(i, toMedia(imgsInfo.get(i)));
+        }
+        String mainThumb = toMedia(item.getThumb());
+        if (StringUtils.isNotBlank(mainThumb)) {
+            if (imgsInfo.isEmpty()) {
+                imgsInfo.add(mainThumb);
+            } else {
+                // PHP:$thumb_url[0] = 主图,扩展图的原下标 0 被覆盖丢弃
+                imgsInfo.set(0, mainThumb);
+            }
         }
-        if (item.getThumbUrl() != null && !item.getThumbUrl().isEmpty()) {
+        return imgsInfo;
+    }
+
+    /**
+     * 解析 ims_ewei_shop_goods.thumb_url(对应 PHP unserialize):
+     * 兼容 JSON 数组与 PHP 序列化数组两种存储格式,返回相对/全路径图片列表。
+     */
+    private List<String> parseThumbUrl(String thumbUrl, Long goodsId) {
+        List<String> list = new ArrayList<>();
+        if (StringUtils.isBlank(thumbUrl)) {
+            return list;
+        }
+        String s = thumbUrl.trim();
+        if (s.startsWith("[")) {
             try {
-                List<String> extraImgs = JSON.parseArray(item.getThumbUrl(), String.class);
-                if (extraImgs != null) {
-                    imgsInfo.addAll(extraImgs);
+                List<String> arr = JSON.parseArray(s, String.class);
+                if (arr != null) {
+                    list.addAll(arr);
                 }
             } catch (Exception e) {
-                log.warn("thumb_url解析失败 goodsId={}", goodsId, e);
+                log.warn("thumb_url(JSON)解析失败 goodsId={}, thumbUrl={}", goodsId, thumbUrl, e);
             }
+            return list;
         }
-        return imgsInfo;
+        if (s.startsWith("a:")) {
+            Matcher m = PHP_SERIALIZE_STR_PATTERN.matcher(s);
+            while (m.find()) {
+                list.add(m.group(1));
+            }
+            return list;
+        }
+        log.warn("thumb_url未知格式,已忽略 goodsId={}, thumbUrl={}", goodsId, thumbUrl);
+        return list;
     }
 
     /**