|
@@ -758,7 +758,16 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
payPrice = BigDecimal.ZERO;
|
|
payPrice = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- payPrice = subtractAutoPromotionDiscount(uid, carts, null, param.getCouponUserId(), payPrice);
|
|
|
|
|
|
|
+ // 制单改过价的跳过满减计算,避免重复优惠
|
|
|
|
|
+ boolean skipPromotion = false;
|
|
|
|
|
+ if (StringUtils.isNotEmpty(param.getCreateOrderKey())) {
|
|
|
|
|
+ Boolean isAdjusted = redisCache.getCacheObject("createOrderIsAdjusted:" + param.getCreateOrderKey());
|
|
|
|
|
+ skipPromotion = (isAdjusted != null && isAdjusted);
|
|
|
|
|
+ }
|
|
|
|
|
+ PromotionApplyResult promotionResult = skipPromotion
|
|
|
|
|
+ ? new PromotionApplyResult(payPrice, BigDecimal.ZERO)
|
|
|
|
|
+ : applyAutoPromotionDiscount(uid, carts, null, param.getCouponUserId(), payPrice);
|
|
|
|
|
+ payPrice = promotionResult.getPayPrice();
|
|
|
|
|
|
|
|
//优惠券
|
|
//优惠券
|
|
|
if (param.getCouponUserId() != null) {
|
|
if (param.getCouponUserId() != null) {
|
|
@@ -778,6 +787,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
.usedIntegral(usedIntegral)
|
|
.usedIntegral(usedIntegral)
|
|
|
.payIntegral(priceGroup.getPayIntegral())
|
|
.payIntegral(priceGroup.getPayIntegral())
|
|
|
.serviceFee(serviceFee)
|
|
.serviceFee(serviceFee)
|
|
|
|
|
+ .promotionDiscountAmount(promotionResult.getPromotionDiscountAmount())
|
|
|
.build();
|
|
.build();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -906,7 +916,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
storeOrder.setServiceFee(config.getServiceFee());
|
|
storeOrder.setServiceFee(config.getServiceFee());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- applyPromotionFields(storeOrder, carts, userId, param.getCouponUserId(), param.getStoreId());
|
|
|
|
|
|
|
+ FsStorePromotionComputeResultVO promotionResult = applyPromotionFields(storeOrder, carts, userId, param.getCouponUserId(), param.getStoreId());
|
|
|
|
|
|
|
|
//后台制单处理
|
|
//后台制单处理
|
|
|
if (param.getPayPrice() != null && param.getPayPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
if (param.getPayPrice() != null && param.getPayPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
@@ -971,8 +981,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if (flag == 0) {
|
|
if (flag == 0) {
|
|
|
return R.error("订单创建失败");
|
|
return R.error("订单创建失败");
|
|
|
}
|
|
}
|
|
|
- promotionComputeService.recordPendingUsage(storeOrder,
|
|
|
|
|
- promotionComputeService.autoApplyBestPromotion(userId, carts, param.getStoreId(), param.getCouponUserId()));
|
|
|
|
|
|
|
+ promotionComputeService.recordPendingUsage(storeOrder, promotionResult);
|
|
|
if (!isPay && storeOrder.getCompanyId() != null) {
|
|
if (!isPay && storeOrder.getCompanyId() != null) {
|
|
|
// 添加订单审核
|
|
// 添加订单审核
|
|
|
addOrderAudit(storeOrder);
|
|
addOrderAudit(storeOrder);
|
|
@@ -1091,6 +1100,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
redisCache.deleteObject("createOrderKey:" + createOrderKey);
|
|
redisCache.deleteObject("createOrderKey:" + createOrderKey);
|
|
|
redisCache.deleteObject("orderCarts:" + createOrderKey);
|
|
redisCache.deleteObject("orderCarts:" + createOrderKey);
|
|
|
redisCache.deleteObject("createOrderMoney:" + createOrderKey);
|
|
redisCache.deleteObject("createOrderMoney:" + createOrderKey);
|
|
|
|
|
+ redisCache.deleteObject("createOrderIsAdjusted:" + createOrderKey);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//货到付款自定义金额 key改为id存储
|
|
//货到付款自定义金额 key改为id存储
|
|
@@ -1457,8 +1467,11 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
try {
|
|
try {
|
|
|
JSONObject js = JSON.parseObject(itemList.get(0).getJsonInfo());
|
|
JSONObject js = JSON.parseObject(itemList.get(0).getJsonInfo());
|
|
|
String productName = js.getString("productName");
|
|
String productName = js.getString("productName");
|
|
|
- if (StringUtils.isNotEmpty(productName)) {
|
|
|
|
|
|
|
+ String commonName = js.getString("commonName");
|
|
|
|
|
+ if (StringUtils.isNotEmpty(productName) && !productName.equals("-")) {
|
|
|
itemDesc = productName;
|
|
itemDesc = productName;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ itemDesc = commonName;
|
|
|
}
|
|
}
|
|
|
} catch (Exception ignore) {
|
|
} catch (Exception ignore) {
|
|
|
}
|
|
}
|
|
@@ -3017,6 +3030,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
}
|
|
}
|
|
|
redisCache.setCacheObject("orderKey:" + uuid, carts.stream().map(c->c.getId().toString()).collect(Collectors.joining(",")) , 24, TimeUnit.HOURS);//处理订单过期问题
|
|
redisCache.setCacheObject("orderKey:" + uuid, carts.stream().map(c->c.getId().toString()).collect(Collectors.joining(",")) , 24, TimeUnit.HOURS);//处理订单过期问题
|
|
|
redisCache.setCacheObject("createOrderMoney:" + uuid, totalMoney, 24, TimeUnit.HOURS);
|
|
redisCache.setCacheObject("createOrderMoney:" + uuid, totalMoney, 24, TimeUnit.HOURS);
|
|
|
|
|
+ redisCache.setCacheObject("createOrderIsAdjusted:" + uuid, false, 24, TimeUnit.HOURS);
|
|
|
return R.ok().put("orderKey", uuid).put("carts", carts);
|
|
return R.ok().put("orderKey", uuid).put("carts", carts);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -3033,7 +3047,21 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if (StringUtils.isEmpty(key)) {
|
|
if (StringUtils.isEmpty(key)) {
|
|
|
throw new CustomException("订单已过期", 501);
|
|
throw new CustomException("订单已过期", 501);
|
|
|
}
|
|
}
|
|
|
- return R.ok().put("carts", carts).put("totalMoney", money).put("payType", payType);
|
|
|
|
|
|
|
+ // 计算满减活动优惠(改过价则跳过,避免重复优惠)
|
|
|
|
|
+ BigDecimal promotionDiscountAmount = BigDecimal.ZERO;
|
|
|
|
|
+ BigDecimal payPrice = money != null ? money : BigDecimal.ZERO;
|
|
|
|
|
+ Boolean isAdjusted = redisCache.getCacheObject("createOrderIsAdjusted:" + createOrderKey);
|
|
|
|
|
+ if ((isAdjusted == null || !isAdjusted) && CollectionUtils.isNotEmpty(carts) && key.contains("-")) {
|
|
|
|
|
+ Long userId = Long.parseLong(key.substring(key.indexOf("-") + 1));
|
|
|
|
|
+ PromotionApplyResult promotionResult = this.applyAutoPromotionDiscount(userId, carts, null, null, payPrice);
|
|
|
|
|
+ payPrice = promotionResult.getPayPrice();
|
|
|
|
|
+ promotionDiscountAmount = promotionResult.getPromotionDiscountAmount();
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok()
|
|
|
|
|
+ .put("carts", carts)
|
|
|
|
|
+ .put("totalMoney", payPrice)
|
|
|
|
|
+ .put("payType", payType)
|
|
|
|
|
+ .put("promotionDiscountAmount", promotionDiscountAmount);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -3200,16 +3228,26 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
preparedPriceChange.setCreateBy(userId.toString());//创建人
|
|
preparedPriceChange.setCreateBy(userId.toString());//创建人
|
|
|
preparedPriceChange.setCreateOrderKey(createOrderKey);//唯一key
|
|
preparedPriceChange.setCreateOrderKey(createOrderKey);//唯一key
|
|
|
preparedPriceChange.setCartIds(carts.stream().map(c -> c.getId().toString()).collect(Collectors.joining(",")));//购物车IDs
|
|
preparedPriceChange.setCartIds(carts.stream().map(c -> c.getId().toString()).collect(Collectors.joining(",")));//购物车IDs
|
|
|
|
|
+ // 捕获满减活动ID,用于后续分享时校验活动是否进行中
|
|
|
|
|
+ if (key.contains("-")) {
|
|
|
|
|
+ Long cartUserId = Long.parseLong(key.substring(key.indexOf("-") + 1));
|
|
|
|
|
+ FsStorePromotionComputeResultVO promotion = promotionComputeService.autoApplyBestPromotion(cartUserId, carts, null, null);
|
|
|
|
|
+ if (promotion != null && promotion.getPromotionActivityId() != null) {
|
|
|
|
|
+ preparedPriceChange.setPromotionActivityId(promotion.getPromotionActivityId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
fsStorePreparedPriceChangeService.insertFsStorePreparedPriceChange(preparedPriceChange);
|
|
fsStorePreparedPriceChangeService.insertFsStorePreparedPriceChange(preparedPriceChange);
|
|
|
|
|
|
|
|
//缓存半小时
|
|
//缓存半小时
|
|
|
redisCache.setCacheObject("createOrderMoney:" + createOrderKey, money, 30, TimeUnit.MINUTES);
|
|
redisCache.setCacheObject("createOrderMoney:" + createOrderKey, money, 30, TimeUnit.MINUTES);
|
|
|
redisCache.setCacheObject("createOrderAmount:" + createOrderKey, payAmount, 30, TimeUnit.MINUTES);//物流代收自定义金额
|
|
redisCache.setCacheObject("createOrderAmount:" + createOrderKey, payAmount, 30, TimeUnit.MINUTES);//物流代收自定义金额
|
|
|
redisCache.setCacheObject("createOrderPayType:" + createOrderKey, payType, 30, TimeUnit.MINUTES);//支付类型 1-全付款 3-物流代收(货到付款)
|
|
redisCache.setCacheObject("createOrderPayType:" + createOrderKey, payType, 30, TimeUnit.MINUTES);//支付类型 1-全付款 3-物流代收(货到付款)
|
|
|
|
|
+ redisCache.setCacheObject("createOrderIsAdjusted:" + createOrderKey, true, 30, TimeUnit.MINUTES);//改价标记,避免重复计算活动优惠
|
|
|
} else {
|
|
} else {
|
|
|
redisCache.setCacheObject("createOrderMoney:" + createOrderKey, money, 24, TimeUnit.HOURS);
|
|
redisCache.setCacheObject("createOrderMoney:" + createOrderKey, money, 24, TimeUnit.HOURS);
|
|
|
redisCache.setCacheObject("createOrderAmount:" + createOrderKey, payAmount, 24, TimeUnit.HOURS);//物流代收自定义金额
|
|
redisCache.setCacheObject("createOrderAmount:" + createOrderKey, payAmount, 24, TimeUnit.HOURS);//物流代收自定义金额
|
|
|
redisCache.setCacheObject("createOrderPayType:" + createOrderKey, payType, 24, TimeUnit.HOURS);//支付类型 1-全付款 3-物流代收(货到付款)
|
|
redisCache.setCacheObject("createOrderPayType:" + createOrderKey, payType, 24, TimeUnit.HOURS);//支付类型 1-全付款 3-物流代收(货到付款)
|
|
|
|
|
+ redisCache.setCacheObject("createOrderIsAdjusted:" + createOrderKey, true, 24, TimeUnit.HOURS);//改价标记,避免重复计算活动优惠
|
|
|
}
|
|
}
|
|
|
return R.ok().put("disabled", config.getIsPreparedPriceChange() != null && config.getIsPreparedPriceChange());
|
|
return R.ok().put("disabled", config.getIsPreparedPriceChange() != null && config.getIsPreparedPriceChange());
|
|
|
}
|
|
}
|
|
@@ -5289,45 +5327,106 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
@Transactional
|
|
@Transactional
|
|
|
@Synchronized
|
|
@Synchronized
|
|
|
public String payConfirmMultiStore(Integer type, Long orderId, String payCode, String tradeNo, String bankTransactionId, String bankSerialNo) {
|
|
public String payConfirmMultiStore(Integer type, Long orderId, String payCode, String tradeNo, String bankTransactionId, String bankSerialNo) {
|
|
|
- //支付订单
|
|
|
|
|
-// FsStoreOrder order = null;
|
|
|
|
|
try {
|
|
try {
|
|
|
List<FsStoreOrderScrm> orders = new ArrayList<>();
|
|
List<FsStoreOrderScrm> orders = new ArrayList<>();
|
|
|
if (type.equals(1)) {
|
|
if (type.equals(1)) {
|
|
|
List<FsStorePaymentScrm> storePayments = paymentService.selectFsStorePaymentByPaymentCode(payCode);
|
|
List<FsStorePaymentScrm> storePayments = paymentService.selectFsStorePaymentByPaymentCode(payCode);
|
|
|
- if (storePayments != null && !storePayments.isEmpty()) {
|
|
|
|
|
- for (FsStorePaymentScrm storePayment : storePayments) {
|
|
|
|
|
- if (storePayment == null || !storePayment.getStatus().equals(0)) {
|
|
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
- return "";
|
|
|
|
|
- }
|
|
|
|
|
- storePayment.setStatus(1);
|
|
|
|
|
- storePayment.setPayTime(new Date());
|
|
|
|
|
- storePayment.setTradeNo(tradeNo);
|
|
|
|
|
- storePayment.setBankSerialNo(bankSerialNo);
|
|
|
|
|
- storePayment.setBankTransactionId(bankTransactionId);
|
|
|
|
|
- paymentService.updateFsStorePayment(storePayment);
|
|
|
|
|
- if (storePayment.getBusinessOrderId() != null && storePayment.getBusinessOrderId().length() > 30) {
|
|
|
|
|
- orders.addAll(fsStoreOrderMapper.getStoreOrderByCombinationId(storePayment.getBusinessOrderId()));
|
|
|
|
|
- } else {
|
|
|
|
|
- orders.add(fsStoreOrderMapper.selectFsStoreOrderById(storePayment.getOrderId()));
|
|
|
|
|
|
|
+ if (storePayments == null || storePayments.isEmpty()) {
|
|
|
|
|
+ logger.warn("payConfirmMultiStore: 未找到支付记录, payCode={}", payCode);
|
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ // 【关键修复】第一步:先加载并校验所有订单状态,避免 payment 已更新但 order 更新失败
|
|
|
|
|
+ boolean allPaymentAlreadyPaid = true;
|
|
|
|
|
+ for (FsStorePaymentScrm storePayment : storePayments) {
|
|
|
|
|
+ if (storePayment == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 检查 payment 是否已处理(幂等判断)
|
|
|
|
|
+ if (storePayment.getStatus() != null && !storePayment.getStatus().equals(0)) {
|
|
|
|
|
+ // payment 已经是非待支付状态,不再更新 payment,但仍需校验订单
|
|
|
|
|
+ logger.info("payConfirmMultiStore: payment已处理, paymentId={}, status={}, payCode={}",
|
|
|
|
|
+ storePayment.getPaymentId(), storePayment.getStatus(), payCode);
|
|
|
|
|
+ allPaymentAlreadyPaid = allPaymentAlreadyPaid && true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ allPaymentAlreadyPaid = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 加载关联订单
|
|
|
|
|
+ if (storePayment.getBusinessOrderId() != null && storePayment.getBusinessOrderId().length() > 30) {
|
|
|
|
|
+ orders.addAll(fsStoreOrderMapper.getStoreOrderByCombinationId(storePayment.getBusinessOrderId()));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderById(storePayment.getOrderId());
|
|
|
|
|
+ if (order != null) {
|
|
|
|
|
+ orders.add(order);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (orders.isEmpty()) {
|
|
|
|
|
+ logger.warn("payConfirmMultiStore: 未找到关联订单, payCode={}", payCode);
|
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ // 【关键修复】第二步:校验订单状态,跳过已支付的订单
|
|
|
for (FsStoreOrderScrm order : orders) {
|
|
for (FsStoreOrderScrm order : orders) {
|
|
|
- if (order != null && !order.getStatus().equals(OrderInfoEnum.STATUS_0.getValue())) {
|
|
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
- return "";
|
|
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- if (order != null && !order.getPaid().equals(0)) {
|
|
|
|
|
|
|
+ // 如果订单已经支付完成,跳过(幂等)
|
|
|
|
|
+ if (order.getPaid() != null && order.getPaid().equals(OrderInfoEnum.PAY_STATUS_1.getValue())
|
|
|
|
|
+ && order.getStatus() != null && order.getStatus().equals(OrderInfoEnum.STATUS_1.getValue())) {
|
|
|
|
|
+ logger.info("payConfirmMultiStore: 订单已支付,跳过, orderId={}, orderCode={}", order.getId(), order.getOrderCode());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 订单状态不是待支付且也不是已支付,说明订单状态异常
|
|
|
|
|
+ if (order.getStatus() != null && !order.getStatus().equals(OrderInfoEnum.STATUS_0.getValue())
|
|
|
|
|
+ && !order.getStatus().equals(OrderInfoEnum.STATUS_1.getValue())) {
|
|
|
|
|
+ logger.error("payConfirmMultiStore: 订单状态异常, orderId={}, status={}, orderCode={}",
|
|
|
|
|
+ order.getId(), order.getStatus(), order.getOrderCode());
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return "";
|
|
return "";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 【关键修复】第三步:先更新订单状态,再更新 payment(保证订单优先落库)
|
|
|
|
|
+ for (FsStoreOrderScrm order : orders) {
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 跳过的已支付订单
|
|
|
|
|
+ if (order.getPaid() != null && order.getPaid().equals(OrderInfoEnum.PAY_STATUS_1.getValue())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
|
|
+ storeOrder.setId(order.getId());
|
|
|
|
|
+ storeOrder.setPaid(OrderInfoEnum.PAY_STATUS_1.getValue());
|
|
|
|
|
+ storeOrder.setStatus(OrderInfoEnum.STATUS_1.getValue());
|
|
|
|
|
+ storeOrder.setPayTime(new Date());
|
|
|
|
|
+ fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
|
|
|
|
|
+
|
|
|
|
|
+ // 增加状态日志
|
|
|
|
|
+ orderStatusService.create(order.getId(), OrderLogEnum.PAY_ORDER_SUCCESS.getValue(),
|
|
|
|
|
+ OrderLogEnum.PAY_ORDER_SUCCESS.getDesc());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 【关键修复】第四步:更新 payment 状态(订单已落库,payment 更新即使异常也有 orders 兜底)
|
|
|
|
|
+ for (FsStorePaymentScrm storePayment : storePayments) {
|
|
|
|
|
+ if (storePayment == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (storePayment.getStatus() != null && storePayment.getStatus().equals(0)) {
|
|
|
|
|
+ storePayment.setStatus(1);
|
|
|
|
|
+ storePayment.setPayTime(new Date());
|
|
|
|
|
+ storePayment.setTradeNo(tradeNo);
|
|
|
|
|
+ storePayment.setBankSerialNo(bankSerialNo);
|
|
|
|
|
+ storePayment.setBankTransactionId(bankTransactionId);
|
|
|
|
|
+ paymentService.updateFsStorePayment(storePayment);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
} else if (type.equals(2)) {
|
|
} else if (type.equals(2)) {
|
|
|
//货到付款
|
|
//货到付款
|
|
|
FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderById(orderId);
|
|
FsStoreOrderScrm order = fsStoreOrderMapper.selectFsStoreOrderById(orderId);
|
|
@@ -5336,55 +5435,58 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
return "";
|
|
return "";
|
|
|
}
|
|
}
|
|
|
orders.add(order);
|
|
orders.add(order);
|
|
|
|
|
+
|
|
|
|
|
+ FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
|
|
+ storeOrder.setId(order.getId());
|
|
|
|
|
+ storeOrder.setPaid(OrderInfoEnum.PAY_STATUS_1.getValue());
|
|
|
|
|
+ storeOrder.setStatus(OrderInfoEnum.STATUS_1.getValue());
|
|
|
|
|
+ storeOrder.setPayTime(new Date());
|
|
|
|
|
+ fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
|
|
|
|
|
+
|
|
|
|
|
+ orderStatusService.create(order.getId(), OrderLogEnum.PAY_ORDER_SUCCESS.getValue(),
|
|
|
|
|
+ OrderLogEnum.PAY_ORDER_SUCCESS.getDesc());
|
|
|
}
|
|
}
|
|
|
- //写入公司佣金
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //第五步:OMS推送、佣金等后置处理(非关键路径,异常不影响订单支付状态)
|
|
|
if (orders.size() > 0) {
|
|
if (orders.size() > 0) {
|
|
|
for (FsStoreOrderScrm order : orders) {
|
|
for (FsStoreOrderScrm order : orders) {
|
|
|
- if (order.getCompanyId() != null && order.getCompanyId() > 0) {
|
|
|
|
|
- companyService.addCompanyTuiMoney(order);
|
|
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (order.getCompanyId() != null && order.getCompanyId() > 0) {
|
|
|
|
|
+ companyService.addCompanyTuiMoney(order);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("payConfirmMultiStore 公司佣金处理失败, orderId={}", order.getId(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ userService.incPayCount(order.getUserId());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("payConfirmMultiStore 用户购买次数增加失败, orderId={}", order.getId(), e);
|
|
|
}
|
|
}
|
|
|
- //增加用户购买次数
|
|
|
|
|
- userService.incPayCount(order.getUserId());
|
|
|
|
|
- //增加状态
|
|
|
|
|
- orderStatusService.create(order.getId(), OrderLogEnum.PAY_ORDER_SUCCESS.getValue(),
|
|
|
|
|
- OrderLogEnum.PAY_ORDER_SUCCESS.getDesc());
|
|
|
|
|
- // FsUser user=userService.selectFsUserById(order.getUserId());
|
|
|
|
|
- // //增加流水
|
|
|
|
|
- // String payTypeMsg = PayTypeEnum.WEIXIN.getDesc();
|
|
|
|
|
- // billService.addBill(user.getUserId(),
|
|
|
|
|
- // BillDetailEnum.CATEGORY_1.getValue(),
|
|
|
|
|
- // 0,
|
|
|
|
|
- // BillDetailEnum.TYPE_1.getDesc(),
|
|
|
|
|
- // order.getPayPrice().doubleValue(), user.getNowMoney().doubleValue(),
|
|
|
|
|
- // payTypeMsg + order.getPayPrice() + "元购买商品",order.getId().toString());
|
|
|
|
|
-
|
|
|
|
|
- FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
|
|
- storeOrder.setId(order.getId());
|
|
|
|
|
- storeOrder.setPaid(OrderInfoEnum.PAY_STATUS_1.getValue());
|
|
|
|
|
- storeOrder.setStatus(OrderInfoEnum.STATUS_1.getValue());
|
|
|
|
|
- storeOrder.setPayTime(new Date());
|
|
|
|
|
- fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
|
|
|
|
|
try {
|
|
try {
|
|
|
//非处方直接提交OMS
|
|
//非处方直接提交OMS
|
|
|
if (order.getIsPrescribe() != null && order.getIsPrescribe().equals(0)) {
|
|
if (order.getIsPrescribe() != null && order.getIsPrescribe().equals(0)) {
|
|
|
createOmsOrder(order.getId());
|
|
createOmsOrder(order.getId());
|
|
|
} else if (order.getIsPrescribe() != null && order.getIsPrescribe().equals(1)) {
|
|
} else if (order.getIsPrescribe() != null && order.getIsPrescribe().equals(1)) {
|
|
|
- //是否已开方
|
|
|
|
|
FsPrescribeScrm prescribe = prescribeService.selectFsPrescribeByOrderId(order.getId());
|
|
FsPrescribeScrm prescribe = prescribeService.selectFsPrescribeByOrderId(order.getId());
|
|
|
if (prescribe != null && prescribe.getStatus() == 1) {
|
|
if (prescribe != null && prescribe.getStatus() == 1) {
|
|
|
createOmsOrder(order.getId());
|
|
createOmsOrder(order.getId());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- // 预防支付成功但上传聚水潭失败导致支付状态未改变
|
|
|
|
|
logger.error("payConfirmMultiStore 创建ERP订单失败, orderId={}, orderCode={}", order.getId(), order.getOrderCode(), e);
|
|
logger.error("payConfirmMultiStore 创建ERP订单失败, orderId={}, orderCode={}", order.getId(), order.getOrderCode(), e);
|
|
|
}
|
|
}
|
|
|
- //处理佣金 套餐不分佣金
|
|
|
|
|
- if (order.getIsPackage() != 1 && order.getTuiUserId() != null && order.getTuiUserId() > 0) {
|
|
|
|
|
- FsStoreOrderItemScrm orderItemMap = new FsStoreOrderItemScrm();
|
|
|
|
|
- orderItemMap.setOrderId(order.getId());
|
|
|
|
|
- List<FsStoreOrderItemScrm> items = storeOrderItemService.selectFsStoreOrderItemList(orderItemMap);
|
|
|
|
|
- userService.addTuiMoney(order, items);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (order.getIsPackage() != 1 && order.getTuiUserId() != null && order.getTuiUserId() > 0) {
|
|
|
|
|
+ FsStoreOrderItemScrm orderItemMap = new FsStoreOrderItemScrm();
|
|
|
|
|
+ orderItemMap.setOrderId(order.getId());
|
|
|
|
|
+ List<FsStoreOrderItemScrm> items = storeOrderItemService.selectFsStoreOrderItemList(orderItemMap);
|
|
|
|
|
+ userService.addTuiMoney(order, items);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("payConfirmMultiStore 佣金处理失败, orderId={}", order.getId(), e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -5398,35 +5500,48 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public String payRemainConfirmMultiStore(String payCode, String tradeNo, String bankTransactionId, String bankSerialNo) {
|
|
public String payRemainConfirmMultiStore(String payCode, String tradeNo, String bankTransactionId, String bankSerialNo) {
|
|
|
- //支付订单
|
|
|
|
|
-// FsStoreOrder order = null;
|
|
|
|
|
String orderIds = "";
|
|
String orderIds = "";
|
|
|
List<FsStorePaymentScrm> storePayments = paymentService.selectFsStorePaymentByPaymentCode(payCode);
|
|
List<FsStorePaymentScrm> storePayments = paymentService.selectFsStorePaymentByPaymentCode(payCode);
|
|
|
- if (storePayments != null && !storePayments.isEmpty()) {
|
|
|
|
|
- for (int i = 0; i < storePayments.size(); i++) {
|
|
|
|
|
- if (storePayments.get(i) == null || !storePayments.get(i).getStatus().equals(0)) {
|
|
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
- return "";
|
|
|
|
|
- }
|
|
|
|
|
- storePayments.get(i).setStatus(1);
|
|
|
|
|
- storePayments.get(i).setPayTime(new Date());
|
|
|
|
|
- storePayments.get(i).setTradeNo(tradeNo);
|
|
|
|
|
- storePayments.get(i).setBankSerialNo(bankSerialNo);
|
|
|
|
|
- storePayments.get(i).setBankTransactionId(bankTransactionId);
|
|
|
|
|
- storePayments.get(i).setIsPayRemain(1);
|
|
|
|
|
- paymentService.updateFsStorePayment(storePayments.get(i));
|
|
|
|
|
- if (i == 0) {
|
|
|
|
|
- orderIds = orderIds + (storePayments.get(i).getOrderId());
|
|
|
|
|
- } else {
|
|
|
|
|
- orderIds = orderIds + "," + storePayments.get(i).getOrderId();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (storePayments == null || storePayments.isEmpty()) {
|
|
|
|
|
+ logger.warn("payRemainConfirmMultiStore: 未找到支付记录, payCode={}", payCode);
|
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 【修复】先收集 orderIds 并校验订单
|
|
|
|
|
+ for (int i = 0; i < storePayments.size(); i++) {
|
|
|
|
|
+ FsStorePaymentScrm sp = storePayments.get(i);
|
|
|
|
|
+ if (sp == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 幂等:payment已经处理过则跳过payment更新,但订单仍需校验
|
|
|
|
|
+ if (sp.getStatus() != null && !sp.getStatus().equals(0) && sp.getIsPayRemain() != null && sp.getIsPayRemain().equals(1)) {
|
|
|
|
|
+ logger.info("payRemainConfirmMultiStore: payment已处理, paymentId={}, payCode={}", sp.getPaymentId(), payCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (i == 0) {
|
|
|
|
|
+ orderIds = orderIds + (sp.getOrderId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ orderIds = orderIds + "," + sp.getOrderId();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// order = fsStoreOrderMapper.selectFsStoreOrderById(storePayment.getOrderId());
|
|
|
|
|
|
|
+ if (StringUtils.isBlank(orderIds)) {
|
|
|
|
|
+ logger.warn("payRemainConfirmMultiStore: orderIds为空, payCode={}", payCode);
|
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 【修复】先更新订单状态
|
|
|
List<FsStoreOrderScrm> orders = fsStoreOrderMapper.selectFsStoreOrderByOrderIds(orderIds);
|
|
List<FsStoreOrderScrm> orders = fsStoreOrderMapper.selectFsStoreOrderByOrderIds(orderIds);
|
|
|
for (FsStoreOrderScrm order : orders) {
|
|
for (FsStoreOrderScrm order : orders) {
|
|
|
- //增加状态
|
|
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 幂等:已支付尾款的订单跳过
|
|
|
|
|
+ if (order.getIsPayRemain() != null && order.getIsPayRemain().equals(1)) {
|
|
|
|
|
+ logger.info("payRemainConfirmMultiStore: 订单已支付尾款,跳过, orderId={}", order.getId());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
orderStatusService.create(order.getId(), OrderLogEnum.PAY_REMAIN_ORDER_SUCCESS.getValue(),
|
|
orderStatusService.create(order.getId(), OrderLogEnum.PAY_REMAIN_ORDER_SUCCESS.getValue(),
|
|
|
OrderLogEnum.PAY_REMAIN_ORDER_SUCCESS.getDesc());
|
|
OrderLogEnum.PAY_REMAIN_ORDER_SUCCESS.getDesc());
|
|
|
|
|
|
|
@@ -5436,6 +5551,21 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
|
|
fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 【修复】订单已落库后再更新 payment
|
|
|
|
|
+ for (FsStorePaymentScrm storePayment : storePayments) {
|
|
|
|
|
+ if (storePayment == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (storePayment.getStatus() != null && storePayment.getStatus().equals(0)) {
|
|
|
|
|
+ storePayment.setStatus(1);
|
|
|
|
|
+ storePayment.setPayTime(new Date());
|
|
|
|
|
+ storePayment.setTradeNo(tradeNo);
|
|
|
|
|
+ storePayment.setBankSerialNo(bankSerialNo);
|
|
|
|
|
+ storePayment.setBankTransactionId(bankTransactionId);
|
|
|
|
|
+ storePayment.setIsPayRemain(1);
|
|
|
|
|
+ paymentService.updateFsStorePayment(storePayment);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return "success";
|
|
return "success";
|
|
|
}
|
|
}
|
|
@@ -5603,7 +5733,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
storeOrder.setShippingType(1);
|
|
storeOrder.setShippingType(1);
|
|
|
storeOrder.setCreateTime(new Date());
|
|
storeOrder.setCreateTime(new Date());
|
|
|
storeOrder.setStatus(0);
|
|
storeOrder.setStatus(0);
|
|
|
- applyPromotionFields(storeOrder, carts, userId, param.getCouponUserId(), param.getStoreId());
|
|
|
|
|
|
|
+ FsStorePromotionComputeResultVO promotionResult = applyPromotionFields(storeOrder, carts, userId, param.getCouponUserId(), param.getStoreId());
|
|
|
//后台制单处理
|
|
//后台制单处理
|
|
|
if (param.getPayPrice() != null && param.getPayPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
if (param.getPayPrice() != null && param.getPayPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
storeOrder.setPayPrice(param.getPayPrice());
|
|
storeOrder.setPayPrice(param.getPayPrice());
|
|
@@ -5635,8 +5765,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if (flag == 0) {
|
|
if (flag == 0) {
|
|
|
return R.error("订单创建失败");
|
|
return R.error("订单创建失败");
|
|
|
}
|
|
}
|
|
|
- promotionComputeService.recordPendingUsage(storeOrder,
|
|
|
|
|
- promotionComputeService.autoApplyBestPromotion(userId, carts, param.getStoreId(), param.getCouponUserId()));
|
|
|
|
|
|
|
+ promotionComputeService.recordPendingUsage(storeOrder, promotionResult);
|
|
|
//收款单更新
|
|
//收款单更新
|
|
|
// if(param.getPaymentId()!=null&¶m.getPaymentId()>0){
|
|
// if(param.getPaymentId()!=null&¶m.getPaymentId()>0){
|
|
|
// FsStorePayment payment=new FsStorePayment();
|
|
// FsStorePayment payment=new FsStorePayment();
|
|
@@ -5769,6 +5898,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
redisCache.deleteObject("createOrderKey:" + param.getCreateOrderKey());
|
|
redisCache.deleteObject("createOrderKey:" + param.getCreateOrderKey());
|
|
|
redisCache.deleteObject("orderCarts:" + param.getCreateOrderKey());
|
|
redisCache.deleteObject("orderCarts:" + param.getCreateOrderKey());
|
|
|
redisCache.deleteObject("createOrderMoney:" + param.getCreateOrderKey());
|
|
redisCache.deleteObject("createOrderMoney:" + param.getCreateOrderKey());
|
|
|
|
|
+ redisCache.deleteObject("createOrderIsAdjusted:" + param.getCreateOrderKey());
|
|
|
redisCache.deleteObject("createOrderMoneyDetails:" + param.getCreateOrderKey());
|
|
redisCache.deleteObject("createOrderMoneyDetails:" + param.getCreateOrderKey());
|
|
|
}
|
|
}
|
|
|
redisCache.setCacheObject("orderAmount:" + storeOrder.getId(), storeOrder.getPayMoney(), 24, TimeUnit.HOURS);//物流代收自定义金额
|
|
redisCache.setCacheObject("orderAmount:" + storeOrder.getId(), storeOrder.getPayMoney(), 24, TimeUnit.HOURS);//物流代收自定义金额
|
|
@@ -5791,6 +5921,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
BigDecimal payIntegralTotal = BigDecimal.ZERO;
|
|
BigDecimal payIntegralTotal = BigDecimal.ZERO;
|
|
|
BigDecimal payPostageTotal = BigDecimal.ZERO;
|
|
BigDecimal payPostageTotal = BigDecimal.ZERO;
|
|
|
BigDecimal deductionPriceTotal = BigDecimal.ZERO;
|
|
BigDecimal deductionPriceTotal = BigDecimal.ZERO;
|
|
|
|
|
+ BigDecimal promotionDiscountTotal = BigDecimal.ZERO;
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> createOrderKeys = null;
|
|
List<String> createOrderKeys = null;
|
|
@@ -5816,6 +5947,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
payIntegralTotal = NumberUtil.add(payIntegralTotal, dto.getPayIntegral());
|
|
payIntegralTotal = NumberUtil.add(payIntegralTotal, dto.getPayIntegral());
|
|
|
payPostageTotal = NumberUtil.add(payPostageTotal, dto.getPayPostage());
|
|
payPostageTotal = NumberUtil.add(payPostageTotal, dto.getPayPostage());
|
|
|
deductionPriceTotal = NumberUtil.add(deductionPriceTotal, dto.getDeductionPrice());
|
|
deductionPriceTotal = NumberUtil.add(deductionPriceTotal, dto.getDeductionPrice());
|
|
|
|
|
+ if (dto.getPromotionDiscountAmount() != null) {
|
|
|
|
|
+ promotionDiscountTotal = NumberUtil.add(promotionDiscountTotal, dto.getPromotionDiscountAmount());
|
|
|
|
|
+ }
|
|
|
dtos.add(dto);
|
|
dtos.add(dto);
|
|
|
}
|
|
}
|
|
|
//
|
|
//
|
|
@@ -5826,6 +5960,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
.deductionPrice(deductionPriceTotal)
|
|
.deductionPrice(deductionPriceTotal)
|
|
|
.usedIntegral(usedIntegralTotal)
|
|
.usedIntegral(usedIntegralTotal)
|
|
|
.payIntegral(payIntegralTotal)
|
|
.payIntegral(payIntegralTotal)
|
|
|
|
|
+ .promotionDiscountAmount(promotionDiscountTotal)
|
|
|
.build());
|
|
.build());
|
|
|
return dtos;
|
|
return dtos;
|
|
|
}
|
|
}
|
|
@@ -6157,7 +6292,20 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
payPrice = BigDecimal.ZERO;
|
|
payPrice = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- payPrice = subtractAutoPromotionDiscount(uid, carts, null, param.getCouponUserId(), payPrice);
|
|
|
|
|
|
|
+ // 制单改过价的只算活动优惠金额供展示,不参与 payPrice 扣减
|
|
|
|
|
+ boolean skipPromotion = false;
|
|
|
|
|
+ if (StringUtils.isNotEmpty(param.getCreateOrderKey())) {
|
|
|
|
|
+ Boolean isAdjusted = redisCache.getCacheObject("createOrderIsAdjusted:" + param.getCreateOrderKey());
|
|
|
|
|
+ skipPromotion = (isAdjusted != null && isAdjusted);
|
|
|
|
|
+ }
|
|
|
|
|
+ PromotionApplyResult promotionResult;
|
|
|
|
|
+ if (skipPromotion) {
|
|
|
|
|
+ BigDecimal displayDiscountAmount = getPromotionDiscountAmount(uid, carts, null, param.getCouponUserId());
|
|
|
|
|
+ promotionResult = new PromotionApplyResult(payPrice, displayDiscountAmount);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ promotionResult = applyAutoPromotionDiscount(uid, carts, null, param.getCouponUserId(), payPrice);
|
|
|
|
|
+ }
|
|
|
|
|
+ payPrice = promotionResult.getPayPrice();
|
|
|
|
|
|
|
|
//优惠券
|
|
//优惠券
|
|
|
if (param.getCouponUserId() != null) {
|
|
if (param.getCouponUserId() != null) {
|
|
@@ -6176,41 +6324,83 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
.deductionPrice(deductionPrice)
|
|
.deductionPrice(deductionPrice)
|
|
|
.usedIntegral(usedIntegral)
|
|
.usedIntegral(usedIntegral)
|
|
|
.payIntegral(priceGroup.getPayIntegral())
|
|
.payIntegral(priceGroup.getPayIntegral())
|
|
|
|
|
+ .promotionDiscountAmount(promotionResult.getPromotionDiscountAmount())
|
|
|
.build();
|
|
.build();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 积分之后、优惠券之前:自动匹配满减/折扣并扣减 */
|
|
/** 积分之后、优惠券之前:自动匹配满减/折扣并扣减 */
|
|
|
- private BigDecimal subtractAutoPromotionDiscount(long uid,
|
|
|
|
|
- List<FsStoreCartQueryVO> carts,
|
|
|
|
|
- Long storeId,
|
|
|
|
|
- Long couponUserId,
|
|
|
|
|
- BigDecimal payPrice) {
|
|
|
|
|
|
|
+ private PromotionApplyResult applyAutoPromotionDiscount(long uid,
|
|
|
|
|
+ List<FsStoreCartQueryVO> carts,
|
|
|
|
|
+ Long storeId,
|
|
|
|
|
+ Long couponUserId,
|
|
|
|
|
+ BigDecimal payPrice) {
|
|
|
|
|
+ FsStorePromotionComputeResultVO promotion = promotionComputeService.autoApplyBestPromotion(
|
|
|
|
|
+ uid, carts, storeId, couponUserId);
|
|
|
|
|
+ BigDecimal promotionDiscountAmount = BigDecimal.ZERO;
|
|
|
|
|
+ if (promotion != null && promotion.getPromotionDiscountAmount() != null
|
|
|
|
|
+ && promotion.getPromotionDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ promotionDiscountAmount = promotion.getPromotionDiscountAmount();
|
|
|
|
|
+ payPrice = NumberUtil.sub(payPrice, promotionDiscountAmount);
|
|
|
|
|
+ if (payPrice.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
|
+ payPrice = BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return new PromotionApplyResult(payPrice, promotionDiscountAmount);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 仅获取活动优惠金额(不参与 payPrice 扣减),用于制单改价后 computedMultiStore 前端展示 */
|
|
|
|
|
+ private BigDecimal getPromotionDiscountAmount(long uid, List<FsStoreCartQueryVO> carts,
|
|
|
|
|
+ Long storeId, Long couponUserId) {
|
|
|
FsStorePromotionComputeResultVO promotion = promotionComputeService.autoApplyBestPromotion(
|
|
FsStorePromotionComputeResultVO promotion = promotionComputeService.autoApplyBestPromotion(
|
|
|
uid, carts, storeId, couponUserId);
|
|
uid, carts, storeId, couponUserId);
|
|
|
- if (promotion == null || promotion.getPromotionDiscountAmount() == null) {
|
|
|
|
|
|
|
+ if (promotion != null && promotion.getPromotionDiscountAmount() != null
|
|
|
|
|
+ && promotion.getPromotionDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ return promotion.getPromotionDiscountAmount();
|
|
|
|
|
+ }
|
|
|
|
|
+ return BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static class PromotionApplyResult {
|
|
|
|
|
+ private final BigDecimal payPrice;
|
|
|
|
|
+ private final BigDecimal promotionDiscountAmount;
|
|
|
|
|
+
|
|
|
|
|
+ private PromotionApplyResult(BigDecimal payPrice, BigDecimal promotionDiscountAmount) {
|
|
|
|
|
+ this.payPrice = payPrice;
|
|
|
|
|
+ this.promotionDiscountAmount = promotionDiscountAmount;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private BigDecimal getPayPrice() {
|
|
|
return payPrice;
|
|
return payPrice;
|
|
|
}
|
|
}
|
|
|
- BigDecimal newPayPrice = NumberUtil.sub(payPrice, promotion.getPromotionDiscountAmount());
|
|
|
|
|
- return newPayPrice.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : newPayPrice;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private BigDecimal getPromotionDiscountAmount() {
|
|
|
|
|
+ return promotionDiscountAmount;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void applyPromotionFields(FsStoreOrderScrm storeOrder,
|
|
|
|
|
- List<FsStoreCartQueryVO> carts,
|
|
|
|
|
- long userId,
|
|
|
|
|
- Long couponUserId,
|
|
|
|
|
- Long storeId) {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算并应用满减活动优惠到订单对象(不持久化),返回计算结果供后续复用
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return 活动计算结果,无活动或无优惠时返回 null
|
|
|
|
|
+ */
|
|
|
|
|
+ private FsStorePromotionComputeResultVO applyPromotionFields(FsStoreOrderScrm storeOrder,
|
|
|
|
|
+ List<FsStoreCartQueryVO> carts,
|
|
|
|
|
+ long userId,
|
|
|
|
|
+ Long couponUserId,
|
|
|
|
|
+ Long storeId) {
|
|
|
if (storeOrder == null) {
|
|
if (storeOrder == null) {
|
|
|
- return;
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
FsStorePromotionComputeResultVO promotion = promotionComputeService.autoApplyBestPromotion(
|
|
FsStorePromotionComputeResultVO promotion = promotionComputeService.autoApplyBestPromotion(
|
|
|
userId, carts, storeId, couponUserId);
|
|
userId, carts, storeId, couponUserId);
|
|
|
if (promotion == null || promotion.getPromotionDiscountAmount() == null
|
|
if (promotion == null || promotion.getPromotionDiscountAmount() == null
|
|
|
|| promotion.getPromotionDiscountAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|| promotion.getPromotionDiscountAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- return;
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
storeOrder.setPromotionActivityId(promotion.getPromotionActivityId());
|
|
storeOrder.setPromotionActivityId(promotion.getPromotionActivityId());
|
|
|
storeOrder.setPromotionTierId(promotion.getPromotionTierId());
|
|
storeOrder.setPromotionTierId(promotion.getPromotionTierId());
|
|
|
storeOrder.setPromotionDiscountAmount(promotion.getPromotionDiscountAmount());
|
|
storeOrder.setPromotionDiscountAmount(promotion.getPromotionDiscountAmount());
|
|
|
|
|
+ return promotion;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|