优化禁止退货的方法

This commit is contained in:
Jack 2025-10-20 22:15:35 +08:00
parent 66498ff82d
commit 2471d2b4c2

View File

@ -2099,49 +2099,29 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
* @return boolean true表示禁止退货false表示允许退货
*/
public boolean ifDenyReturn(ShopOrderInfo shopOrderInfo, ShopOrderItem shopOrderItem, ShopProductIndex shopProductIndex) {
// 参数校验
// 1. 参数校验
if (shopOrderItem == null) {
log.warn("订单商品数据为空");
log.warn("[是否禁止退货] 订单商品数据为空");
return true;
}
if (shopOrderInfo == null) {
log.warn("订单信息为空");
return true;
}
// 获取商品索引信息
ShopProductIndex productIndex = shopProductIndex;
if (productIndex == null) {
productIndex = shopProductIndexService.get(shopOrderItem.getProduct_id());
}
if (productIndex == null) {
log.warn("商品索引信息不存在product_id: {}", shopOrderItem.getProduct_id());
log.warn("[是否禁止退货] 订单信息为空");
return true;
}
String orderId = shopOrderInfo.getOrder_id();
// 1. 检查商品是否设置了禁止退货标识
String contractTypeIdsStr = productIndex.getContract_type_ids();
if (StrUtil.isNotBlank(contractTypeIdsStr)) {
try {
List<Integer> contractTypeIds = Convert.toList(Integer.class, contractTypeIdsStr);
if (contractTypeIds != null && contractTypeIds.contains(StateCode.CONTRACT_TYPE_DENY_RETURN)) {
log.debug("商品设置了禁止退货标识order_id: {}, product_id: {}", orderId, shopOrderItem.getProduct_id());
Integer orderStateId = shopOrderInfo.getOrder_state_id();
if (StrUtil.isBlank(orderId) || CheckUtil.isEmpty(orderStateId)) {
log.warn("[是否禁止退货] 订单ID或订单状态为空");
return true;
}
} catch (Exception e) {
log.error("解析商品保障类型失败order_id: {}, product_id: {}", orderId, shopOrderItem.getProduct_id(), e);
}
}
// 2. 检查订单状态是否为已收货或已完成
Integer orderStateId = shopOrderInfo.getOrder_state_id();
if (ObjectUtil.equal(orderStateId, StateCode.ORDER_STATE_RECEIVED) ||
ObjectUtil.equal(orderStateId, StateCode.ORDER_STATE_FINISH)) {
// 2. 先判断整个订单是否可以退货订单级别检查
// 2.1 检查订单状态是否为已收货或已完成
if (orderStateId.intValue() == StateCode.ORDER_STATE_RECEIVED ||
orderStateId.intValue() == StateCode.ORDER_STATE_FINISH) {
try {
// 获取可提现时间戳
Long withdrawTime = shopOrderBaseService.getWithdrawTime();
@ -2149,33 +2129,60 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
// 检查是否超过退货期限
if (orderDealTime != null && withdrawTime.compareTo(orderDealTime) > 0) {
log.debug("订单已超过退货期限order_id: {}, product_id: {}", orderId, shopOrderItem.getProduct_id());
log.debug("[是否禁止退货] 订单已超过退货期限order_id: {}", orderId);
return true;
}
} catch (Exception e) {
log.error("检查订单退货期限时发生异常order_id: {}, product_id: {}", orderId, shopOrderItem.getProduct_id(), e);
log.error("[是否禁止退货] 检查订单退货期限时发生异常order_id: {}", orderId, e);
}
}
// 3. 检查拉卡拉分账订单是否已提现
// 2.2 检查拉卡拉分账订单是否已提现
try {
if (lklOrderSeparateService != null && lklOrderDrawService != null) {
boolean isSeparated = lklOrderSeparateService.isOrderSeparated(orderId);
boolean isDrawn = lklOrderDrawService.isOrderDrawed(orderId);
if (isSeparated && isDrawn) {
log.debug("拉卡拉分账订单已提现不允许退货order_id: {}, product_id: {}", orderId, shopOrderItem.getProduct_id());
log.debug("[是否禁止退货] 拉卡拉分账订单已提现不允许退货order_id: {}", orderId);
return true;
}
}
} catch (Exception e) {
log.error("检查拉卡拉分账状态时发生异常order_id: {}, product_id: {}", orderId, shopOrderItem.getProduct_id(), e);
log.error("[是否禁止退货] 检查拉卡拉分账状态时发生异常order_id: {}", orderId, e);
}
// 3. 再判断具体商品是否可以退货商品级别检查
// 获取商品索引信息
ShopProductIndex productIndex = shopProductIndex;
if (productIndex == null) {
productIndex = shopProductIndexService.get(shopOrderItem.getProduct_id());
}
if (productIndex == null) {
log.warn("[是否禁止退货] 商品索引信息不存在product_id: {}", shopOrderItem.getProduct_id());
return true;
}
// 3.1 检查商品是否设置了禁止退货标识
String contractTypeIdsStr = productIndex.getContract_type_ids();
if (StrUtil.isNotBlank(contractTypeIdsStr)) {
try {
List<Integer> contractTypeIds = Convert.toList(Integer.class, contractTypeIdsStr);
if (contractTypeIds != null && contractTypeIds.contains(StateCode.CONTRACT_TYPE_DENY_RETURN)) {
log.debug("[是否禁止退货] 商品设置了禁止退货标识order_id: {}, product_id: {}", orderId, shopOrderItem.getProduct_id());
return true;
}
} catch (Exception e) {
log.error("[是否禁止退货] 解析商品保障类型失败order_id: {}, product_id: {}", orderId, shopOrderItem.getProduct_id(), e);
}
}
// 默认允许退货
return false;
}
/**
* 判断订单中某个商品是否禁止退货
* <p>
@ -2207,7 +2214,7 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
public boolean isOrderDenyReturn(String orderId) {
// 参数校验
if (StrUtil.isBlank(orderId)) {
log.warn("订单ID为空无法判断退货状态");
log.warn("[订单是否禁止退货]订单ID为空无法判断退货状态");
return true;
}
@ -2215,7 +2222,7 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
// 获取订单信息
ShopOrderInfo shopOrderInfo = shopOrderInfoService.get(orderId);
if (shopOrderInfo == null) {
log.error("订单信息不存在订单ID: {}", orderId);
log.error("[订单是否禁止退货]订单信息不存在订单ID: {}", orderId);
return true;
}
@ -2230,7 +2237,7 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
// 如果订单成交时间早于可提现时间说明已过退货期
if (orderDealTime != null && withdrawTime.compareTo(orderDealTime) > 0) {
log.debug("订单[{}]已过退货期,不允许退货", orderId);
log.debug("[订单是否禁止退货]订单[{}]已过退货期,不允许退货", orderId);
return true;
}
}
@ -2238,7 +2245,7 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
// 检查拉卡拉分账和提现状态
if (lklOrderSeparateService.isOrderSeparated(orderId) &&
lklOrderDrawService.isOrderDrawed(orderId)) {
log.debug("订单[{}]已提现,不允许退货", orderId);
log.debug("[订单是否禁止退货]订单[{}]已提现,不允许退货", orderId);
return true;
}
@ -2246,7 +2253,7 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl<ShopOrderReturnM
return false;
} catch (Exception e) {
log.error("查询订单[{}]退货状态异常", orderId, e);
log.error("[订单是否禁止退货]查询订单[{}]退货状态异常", orderId, e);
return true;
}
}