|
@@ -778,6 +778,33 @@ public class ProductOrderService {
|
|
|
log.error("商品赠送会员失败: orderNo={}", orderNo, e);
|
|
log.error("商品赠送会员失败: orderNo={}", orderNo, e);
|
|
|
// 不阻塞支付流程
|
|
// 不阻塞支付流程
|
|
|
}
|
|
}
|
|
|
|
|
+ // 发放订单赠品(CF值 + 实物库存扣减)
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<ProductOrderGift> pendingGifts = productOrderGiftMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<ProductOrderGift>()
|
|
|
|
|
+ .eq(ProductOrderGift::getOrderId, order.getId())
|
|
|
|
|
+ .eq(ProductOrderGift::getFulfilled, 0));
|
|
|
|
|
+ for (ProductOrderGift gift : pendingGifts) {
|
|
|
|
|
+ if ("cf".equals(gift.getGiftType()) && gift.getCfValue() != null && gift.getCfValue() > 0) {
|
|
|
|
|
+ platformPointsService.earn(order.getBuyerId(), gift.getCfValue(),
|
|
|
|
|
+ "product_gift", order.getId(),
|
|
|
|
|
+ "购买商品赠品: " + (gift.getGiftProductName() != null ? gift.getGiftProductName() : "CF值"));
|
|
|
|
|
+ } else if ("product".equals(gift.getGiftType()) && gift.getGiftProductId() != null) {
|
|
|
|
|
+ int qty = gift.getQuantity() != null ? gift.getQuantity() : 1;
|
|
|
|
|
+ boolean stockOk = productService.decreaseStock(gift.getGiftProductId(), qty);
|
|
|
|
|
+ if (!stockOk) {
|
|
|
|
|
+ log.error("赠品库存扣减失败: orderNo={}, giftProductId={}", orderNo, gift.getGiftProductId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ inventoryService.recordOutbound(gift.getGiftProductId(), null, qty,
|
|
|
|
|
+ "gift", order.getId(), null, "商品赠品:" + orderNo);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ gift.setFulfilled(1);
|
|
|
|
|
+ productOrderGiftMapper.updateById(gift);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("订单{}赠品发放异常: {}", orderNo, e.getMessage());
|
|
|
|
|
+ }
|
|
|
// 触发通关解锁刷新:购物成功(PURCHASE 关卡)
|
|
// 触发通关解锁刷新:购物成功(PURCHASE 关卡)
|
|
|
try {
|
|
try {
|
|
|
if (order.getFamilyId() != null) {
|
|
if (order.getFamilyId() != null) {
|