店铺关键字段,同步需要条件才更新

This commit is contained in:
Jack 2025-09-27 19:35:22 +08:00
parent 77fdb27275
commit 22cfe81958
4 changed files with 113 additions and 10 deletions

View File

@ -3199,18 +3199,27 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
// 设置店铺基础信息添加null检查
shopStoreBase.setUser_id(userId);
shopStoreBase.setStore_name(shopMchEntry.getStore_name());
shopStoreBase.setStore_category_id(shopMchEntry.getBiz_category());
shopStoreBase.setStore_2nd_category_id(
shopMchEntry.getBiz_second_category() != null ? shopMchEntry.getBiz_second_category() : 0);
if (CheckUtil.isEmpty(shopStoreBase.getStore_category_id())) {
shopStoreBase.setStore_category_id(shopMchEntry.getBiz_category());
}
if (CheckUtil.isEmpty(shopStoreBase.getStore_2nd_category_id())) {
shopStoreBase.setStore_2nd_category_id(
CheckUtil.isNotEmpty(shopMchEntry.getBiz_second_category()) ? shopMchEntry.getBiz_second_category() : 0);
}
// 计算分账比例
BigDecimal splitRatio = shopMchEntryService.getMchEntryRatioOrDefault(
shopMchEntry.getBiz_category(),
shopMchEntry.getBiz_second_category(),
shopMchEntry.getSplit_ratio(),
new BigDecimal(94));
shopStoreBase.setSplit_ratio(splitRatio);
shopStoreBase.setPacking_fee(BigDecimal.ZERO);
if (CheckUtil.isEmpty(shopStoreBase.getSplit_ratio())) {
shopStoreBase.setSplit_ratio(splitRatio);
}
if (CheckUtil.isEmpty(shopStoreBase.getPacking_fee())) {
shopStoreBase.setPacking_fee(BigDecimal.ZERO);
}
// 处理图片信息
String storeFacadeImage = shopMchEntry.getFront_facade_image();
@ -3222,12 +3231,12 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
// 处理地址信息添加null检查
String storeDistrict = shopMchEntry.getStore_district();
if (storeDistrict != null) {
if (StrUtil.isNotBlank(storeDistrict)) {
shopStoreBase.setStore_district_id(storeDistrict);
}
String storeArea = shopMchEntry.getStore_area();
if (storeArea != null) {
if (StrUtil.isNotBlank(storeArea)) {
shopStoreBase.setStore_area(storeArea);
}

View File

@ -8,10 +8,20 @@
package com.suisung.mall.shop.wechat.controller;
import cn.hutool.json.JSONObject;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.exception.ApiException;
import com.suisung.mall.shop.wechat.service.WxOrderShippingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.util.Pair;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* 小程序发货信息管理服务 前端控制器
*/
@ -19,4 +29,17 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/admin/shop/order-shipping")
public class WxOrderShippingController {
@Resource
private WxOrderShippingService wxOrderShippingService;
@ApiOperation(value = "配置订单详情路径", notes = "配置订单详情路径")
@RequestMapping(value = "/updateOrderDetailPath", method = RequestMethod.POST)
public CommonResult updateOrderDetailPath(@RequestBody JSONObject params) {
Pair<Boolean, String> result = wxOrderShippingService.updateOrderDetailPath(params.getStr("path"));
if (!result.getFirst()) {
throw new ApiException(result.getSecond());
}
return CommonResult.success();
}
}

View File

@ -30,4 +30,11 @@ public interface WxOrderShippingService {
* @return 返回确认收货结果包含成功状态和错误消息
*/
Pair<Boolean, String> notifyConfirmReceive(String orderId);
/**
* 配置订单详情路径
* 参考https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order_center/order_center.html
*/
Pair<Boolean, String> updateOrderDetailPath(String orderId);
}

View File

@ -33,22 +33,23 @@ import org.springframework.web.client.HttpClientErrorException;
import java.util.Date;
/**
* 对接微信订单管理相关接口
*/
@Slf4j
@Service
public class WxOrderShippingServiceImpl implements WxOrderShippingService {
private final String ORDER_DETAIL_PATH = "https://api.weixin.qq.com/wxa/business/shipping";
@Lazy
@Autowired
private WxUtil wxUtil;
@Lazy
@Autowired
private ShopOrderBaseService shopOrderBaseService;
@Lazy
@Autowired
private ShopStoreSfOrderService shopStoreSfOrderService;
@Lazy
@Autowired
private ShopOrderLogisticsService shopOrderLogisticsService;
@ -241,4 +242,67 @@ public class WxOrderShippingServiceImpl implements WxOrderShippingService {
return Pair.of(false, "通知微信确认收货失败: " + e.getMessage());
}
}
/**
* 配置订单详情路径
* 参考https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order_center/order_center.html
*
* @param path 订单详情页面路径
* @return 配置结果包含成功状态和错误消息
*/
@Override
public Pair<Boolean, String> updateOrderDetailPath(String path) {
log.debug("开始配置订单详情路径,路径: {}", path);
if (StrUtil.isBlank(path)) {
log.warn("订单详情路径为空,默认:{}", ORDER_DETAIL_PATH);
// return Pair.of(false, "详情路径 path 不能为空");
path = ORDER_DETAIL_PATH;
}
try {
// 获取微信访问令牌
String accessToken = wxUtil.getAccessToken();
if (StrUtil.isBlank(accessToken)) {
log.error("获取AccessToken失败");
return Pair.of(false, "获取AccessToken失败");
}
// 构造请求参数
JSONObject paramsJSON = new JSONObject()
.set("path", String.format("%s?on=${商品订单号}", path));
// 构造请求URL
String postUrl = "https://api.weixin.qq.com/wxa/sec/order/update_order_detail_path?access_token=" + accessToken;
log.debug("配置订单详情路径请求: {} \n {}", postUrl, paramsJSON);
// 发送请求到微信API
JSONObject respObj = RestTemplateHttpUtil.sendPost(
postUrl,
null, paramsJSON, JSONObject.class
);
// 处理响应结果
if (respObj == null) {
log.error("配置订单详情路径失败,返回结果为空");
return Pair.of(false, "配置订单详情路径失败,返回结果为空");
}
int errCode = respObj.getInt("errcode", -1);
if (errCode != 0) {
String errorMsg = respObj.getStr("errmsg", "未知错误");
log.error("配置订单详情路径失败,错误码: {}, 错误信息: {}", errCode, errorMsg);
return Pair.of(false, "配置订单详情路径失败: " + errorMsg);
}
log.info("配置订单详情路径成功,路径: {}", path);
return Pair.of(true, "配置订单详情路径成功");
} catch (HttpClientErrorException e) {
log.error("HTTP请求错误状态码: {}, 错误信息: {}", e.getStatusCode(), e.getMessage(), e);
return Pair.of(false, "HTTP请求错误: " + e.getMessage());
} catch (Exception e) {
log.error("配置订单详情路径失败,错误信息: {}", e.getMessage(), e);
return Pair.of(false, "配置订单详情路径失败: " + e.getMessage());
}
}
}