Browse Source

使用java代码替换php的判断配送方式的接口

zhangwl 1 month ago
parent
commit
9326dff9c5

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

@@ -35,4 +35,11 @@ public interface B2cGoodsSpuInOnlineMapper extends BaseMapper<B2cGoodsSpuInOnlin
      */
      */
     @Select("SELECT cate_id, cate_name, pt_id, parent_id, level FROM b2c_product_category WHERE cate_id = #{cateId} LIMIT 1")
     @Select("SELECT cate_id, cate_name, pt_id, parent_id, level FROM b2c_product_category WHERE cate_id = #{cateId} LIMIT 1")
     Map<String, Object> findCategoryByCateId(@Param("cateId") Integer cateId);
     Map<String, Object> findCategoryByCateId(@Param("cateId") Integer cateId);
+
+    /**
+     * 检查店铺是否存在默认配送方式(对应PHP checkExpress → checkShippingList)
+     * 查询b2c_shipping_status表中是否有is_default=1的记录
+     */
+    @Select("SELECT COUNT(*) FROM b2c_shipping_status WHERE shop_id = #{shopId} AND is_default = 1")
+    int countDefaultShipping(@Param("shopId") Integer shopId);
 }
 }

+ 5 - 18
src/main/java/zs/payment/service/commodity/impl/CommodityProcureServiceImpl.java

@@ -732,24 +732,11 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
             throw new ApiException("店铺不存在!");
             throw new ApiException("店铺不存在!");
         }
         }
 
 
-        // 2. 判断在云商城中是否有配送方式
-        String checkExpressUrl = mallHost + "/checkExpress?shop_id=" + apply.getStoreid();
-        try {
-            String expressResp = HttpUtil.restTemplateGet(checkExpressUrl, null);
-            log.info("配送方式查询 storeid={}, url={}, resp={}", apply.getStoreid(), checkExpressUrl, expressResp);
-            JSONObject expressJson = JSON.parseObject(expressResp);
-            if (expressJson == null || expressJson.getIntValue("head") != 200) {
-                throw new ApiException("配送方式查询失败!");
-            }
-            if (expressJson.getJSONObject("result") != null
-                    && expressJson.getJSONObject("result").getIntValue("hasExpress") == 2) {
-                throw new ApiException("请添加配送方式!");
-            }
-        } catch (ApiException e) {
-            throw e;
-        } catch (Exception e) {
-            log.error("配送方式查询异常 storeid={}", apply.getStoreid(), e);
-            throw new ApiException("配送方式查询失败!");
+        // 2. 判断在云商城中是否有配送方式(替换原 PHP checkExpress 接口,直连BD查询)
+        // 对应PHP逻辑:查询b2c_shipping_status表是否存在is_default=1的配送方式
+        int defaultShippingCount = b2cGoodsSpuInOnlineMapper.countDefaultShipping(apply.getStoreid());
+        if (defaultShippingCount <= 0) {
+            throw new ApiException("请添加配送方式!");
         }
         }
 
 
         // 3. 供货时品类必填
         // 3. 供货时品类必填