退款问题
This commit is contained in:
1 parent
7fb7feea3f
commit
816ea8ecf3
1 file changed
+35
-20
+35
-20
@@ -4647,6 +4647,9 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
|
||||
HardParentCarEntity parentCar = hardCarService.getParentCarById(order.getParentCarId());
|
||||
boolean dailyMenu = isDailyMenuParentCar(parentCar);
|
||||
// App 预约(RESERVE)走线上 ONLINE;安卓机等线下订单走 OFFLINE。退款必须与下单同通道,否则剩余对不上。
|
||||
boolean onlineChannel = dailyMenu
|
||||
&& Objects.equals(order.getOrderType(), HardOrderTypeEnum.RESERVE.getType());
|
||||
LocalDate mealDate = order.getApptUseDate();
|
||||
Integer hourType = parseHourType(order.getHourType());
|
||||
Map<Long, Integer> inventorySnapshot = new LinkedHashMap<>();
|
||||
@@ -4655,8 +4658,9 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
if (mealDate == null || hourType == null) {
|
||||
throw new I18nBizException(ErrorCodes.HARD_CANTEEN_SPU_BAD);
|
||||
}
|
||||
R<List<DailyMenuAppVO>> menuResult = remoteDailyMenuService.getCanteenList(
|
||||
mealDate.toString(), hourType, null, order.getMerchantId());
|
||||
R<List<DailyMenuAppVO>> menuResult = onlineChannel
|
||||
? remoteDailyMenuService.listForOrderValidate(mealDate.toString(), hourType, order.getMerchantId())
|
||||
: remoteDailyMenuService.getCanteenList(mealDate.toString(), hourType, null, order.getMerchantId());
|
||||
if (menuResult == null || !menuResult.isOk() || menuResult.getData() == null) {
|
||||
throw new I18nBizException(menuResult == null ? ErrorCodes.HARD_CANTEEN_STOCK_NO_RESP
|
||||
: ErrorCodes.HARD_CANTEEN_STOCK_QUERY_FAIL);
|
||||
@@ -4670,13 +4674,21 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
if (row == null) {
|
||||
throw new I18nBizException(ErrorCodes.HARD_CANTEEN_SPU_BAD);
|
||||
}
|
||||
int offlineRemain = row.getRemainOfflineStock() != null ? row.getRemainOfflineStock()
|
||||
: (row.getStock() != null ? row.getStock()
|
||||
: (row.getOfflineStock() != null ? row.getOfflineStock() : 0));
|
||||
if (entry.getValue() < 0 && offlineRemain < Math.abs(entry.getValue())) {
|
||||
int channelRemain;
|
||||
if (onlineChannel) {
|
||||
channelRemain = row.getRemainOnlineStock() != null ? row.getRemainOnlineStock()
|
||||
: (row.getStock() != null ? row.getStock()
|
||||
: (row.getOnlineStock() == null ? 0 : row.getOnlineStock()));
|
||||
}
|
||||
else {
|
||||
channelRemain = row.getRemainOfflineStock() != null ? row.getRemainOfflineStock()
|
||||
: (row.getStock() != null ? row.getStock()
|
||||
: (row.getOfflineStock() != null ? row.getOfflineStock() : 0));
|
||||
}
|
||||
if (entry.getValue() < 0 && channelRemain < Math.abs(entry.getValue())) {
|
||||
throw new I18nBizException(ErrorCodes.HARD_PRODUCT_STOCK_LOW, row.getName());
|
||||
}
|
||||
inventorySnapshot.put(entry.getKey(), offlineRemain);
|
||||
inventorySnapshot.put(entry.getKey(), channelRemain);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -4718,10 +4730,11 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
? "HARD_DAILY_MENU_ORDER:" + order.getId()
|
||||
: "HARD_DAILY_MENU_AFTER_SALE:" + afterSaleId;
|
||||
if (dailyMenu) {
|
||||
registerCanteenDailyOfflineInventoryRollback(stockChanges, inventorySnapshot, resolvedInventoryBizId,
|
||||
order.getMerchantId(), mealDate, hourType);
|
||||
applyCanteenDailyOfflineInventoryChange(stockChanges, inventorySnapshot, resolvedInventoryBizId, "APPLY",
|
||||
order.getMerchantId(), mealDate, hourType);
|
||||
String stockChannel = onlineChannel ? "ONLINE" : "OFFLINE";
|
||||
registerCanteenDailyChannelInventoryRollback(stockChanges, inventorySnapshot, resolvedInventoryBizId,
|
||||
order.getMerchantId(), mealDate, hourType, stockChannel);
|
||||
applyCanteenDailyChannelInventoryChange(stockChanges, inventorySnapshot, resolvedInventoryBizId, "APPLY",
|
||||
order.getMerchantId(), mealDate, hourType, stockChannel);
|
||||
}
|
||||
else {
|
||||
registerCanteenSpuInventoryRollback(stockChanges, inventorySnapshot, resolvedInventoryBizId);
|
||||
@@ -4799,14 +4812,14 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
}
|
||||
}
|
||||
|
||||
/** 安卓机/线下每日菜谱:仍调原 updateSkuStockIdempotent,补 OFFLINE 通道参数。 */
|
||||
private void applyCanteenDailyOfflineInventoryChange(Map<Long, Integer> stockChanges,
|
||||
/** 每日菜谱分池:按 ONLINE/OFFLINE 改写 daily_menu.*_sold(配额不动)。 */
|
||||
private void applyCanteenDailyChannelInventoryChange(Map<Long, Integer> stockChanges,
|
||||
Map<Long, Integer> inventorySnapshot, String inventoryBizId, String operation, Long merchantId,
|
||||
LocalDate mealDate, Integer hourType) {
|
||||
LocalDate mealDate, Integer hourType, String stockChannel) {
|
||||
CanteenSpuUpdateStockReqDTO dto = new CanteenSpuUpdateStockReqDTO();
|
||||
dto.setBizId(inventoryBizId);
|
||||
dto.setOperation(operation);
|
||||
dto.setStockChannel("OFFLINE");
|
||||
dto.setStockChannel(stockChannel);
|
||||
dto.setMerchantId(merchantId);
|
||||
dto.setItems(stockChanges.entrySet().stream().map(entry -> {
|
||||
CanteenSpuUpdateStockReqDTO.Item item = new CanteenSpuUpdateStockReqDTO.Item();
|
||||
@@ -4829,14 +4842,15 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCanteenDailyOfflineInventoryRollback(Map<Long, Integer> stockChanges,
|
||||
private void registerCanteenDailyChannelInventoryRollback(Map<Long, Integer> stockChanges,
|
||||
Map<Long, Integer> inventorySnapshot, String inventoryBizId, Long merchantId, LocalDate mealDate,
|
||||
Integer hourType) {
|
||||
Integer hourType, String stockChannel) {
|
||||
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
throw new I18nBizException(ErrorCodes.HARD_STOCK_TX_STATE_BAD);
|
||||
}
|
||||
Map<Long, Integer> rollbackChanges = Map.copyOf(stockChanges);
|
||||
Map<Long, Integer> rollbackSnapshot = Map.copyOf(inventorySnapshot);
|
||||
String channel = stockChannel;
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
public void afterCompletion(int status) {
|
||||
@@ -4844,11 +4858,12 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
return;
|
||||
}
|
||||
try {
|
||||
applyCanteenDailyOfflineInventoryChange(rollbackChanges, rollbackSnapshot, inventoryBizId,
|
||||
"ROLLBACK", merchantId, mealDate, hourType);
|
||||
applyCanteenDailyChannelInventoryChange(rollbackChanges, rollbackSnapshot, inventoryBizId,
|
||||
"ROLLBACK", merchantId, mealDate, hourType, channel);
|
||||
}
|
||||
catch (Exception compensationException) {
|
||||
log.error("|{}|每日菜谱线下库存回滚失败,inventoryBizId:|{}|", TAG, inventoryBizId, compensationException);
|
||||
log.error("|{}|每日菜谱{}库存回滚失败,inventoryBizId:|{}|", TAG, channel, inventoryBizId,
|
||||
compensationException);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user