|
|
@@ -58,6 +58,7 @@ import com.etotem.cfc.dto.MembershipLevelDTO;
|
|
|
import com.etotem.cfc.service.EnergyService;
|
|
|
import com.etotem.cfc.service.UnlockGateService;
|
|
|
import com.etotem.cfc.service.UserService;
|
|
|
+import com.etotem.cfc.service.GiftMembershipProgressService;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -141,6 +142,9 @@ public class ProductOrderService {
|
|
|
@Resource
|
|
|
private ProductGiftRuleService productGiftRuleService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private GiftMembershipProgressService giftMembershipProgressService;
|
|
|
+
|
|
|
@Resource
|
|
|
private MembershipService membershipService;
|
|
|
|
|
|
@@ -232,6 +236,8 @@ public class ProductOrderService {
|
|
|
int discountAmount = dto.getDiscountAmount() != null ? dto.getDiscountAmount() : 0;
|
|
|
int moneyAmount = order.getTotalAmount() - pointsCost - discountAmount;
|
|
|
order.setMoneyAmount(moneyAmount > 0 ? moneyAmount : 0);
|
|
|
+ order.setGiftAmount(productGiftRuleService.getActiveByProductId(product.getId()) != null
|
|
|
+ ? product.getPrice() * dto.getQuantity() : 0);
|
|
|
order.setStatus("pending");
|
|
|
order.setPaymentMethod(dto.getPaymentMethod() != null ? dto.getPaymentMethod() : "wechat");
|
|
|
order.setRemark(dto.getRemark());
|
|
|
@@ -452,6 +458,7 @@ public class ProductOrderService {
|
|
|
private Result<ProductOrderDTO> createMultiItem(CreateProductOrderDTO dto, Long buyerId) {
|
|
|
int totalAmount = 0;
|
|
|
int totalQuantity = 0;
|
|
|
+ int giftAmount = 0;
|
|
|
OrderItemVO firstItem = dto.getItems().get(0);
|
|
|
Product firstProduct = null;
|
|
|
int firstUnitPrice = 0;
|
|
|
@@ -505,6 +512,10 @@ public class ProductOrderService {
|
|
|
}
|
|
|
totalAmount += unitPrice * item.getQuantity();
|
|
|
totalQuantity += item.getQuantity();
|
|
|
+ // 送会员商品:累计原价金额(用于赠送会员额度判定)
|
|
|
+ if (product != null && productGiftRuleService.getActiveByProductId(product.getId()) != null) {
|
|
|
+ giftAmount += unitPrice * item.getQuantity();
|
|
|
+ }
|
|
|
if (firstProduct == null) {
|
|
|
firstProduct = product;
|
|
|
firstUnitPrice = unitPrice;
|
|
|
@@ -522,6 +533,7 @@ public class ProductOrderService {
|
|
|
order.setQuantity(totalQuantity);
|
|
|
order.setUnitPrice(firstUnitPrice);
|
|
|
order.setTotalAmount(totalAmount);
|
|
|
+ order.setGiftAmount(giftAmount > 0 ? giftAmount : 0);
|
|
|
order.setPointsUsed(dto.getPointsUsed() != null ? dto.getPointsUsed() : 0);
|
|
|
int pointsCost = dto.getPointsUsed() != null ? dto.getPointsUsed() : 0;
|
|
|
order.setPointsCost(pointsCost);
|
|
|
@@ -800,21 +812,17 @@ public class ProductOrderService {
|
|
|
log.error("发放测评额度失败: orderNo={}", orderNo, e);
|
|
|
// 不阻塞支付流程
|
|
|
}
|
|
|
- // 商品赠送会员:原价购买且配置赠送规则时,支付成功后自动赠送会员
|
|
|
+ // 赠送会员:原价支付时,送会员商品金额累计到家庭进度,达到阈值自动赠送会员
|
|
|
try {
|
|
|
- if (paidProduct != null) {
|
|
|
- ProductGiftRule giftRule = productGiftRuleService.getActiveByProductId(paidProduct.getId());
|
|
|
- if (giftRule != null) {
|
|
|
- // 原价判定:无积分抵扣、无优惠券、无折扣
|
|
|
- boolean fullPrice = (order.getPointsUsed() == null || order.getPointsUsed() == 0)
|
|
|
- && order.getCouponId() == null
|
|
|
- && (order.getDiscountAmount() == null || order.getDiscountAmount() == 0);
|
|
|
- if (fullPrice && order.getFamilyId() != null) {
|
|
|
- boolean granted = membershipService.grantMembershipByGift(
|
|
|
- order.getFamilyId(), order.getBuyerId(), giftRule.getLevelCode(),
|
|
|
- order.getOrderNo(), order.getTransactionId());
|
|
|
- log.info("商品订单{}赠送会员{}结果={}", orderNo, giftRule.getLevelCode(), granted);
|
|
|
- }
|
|
|
+ if (order.getGiftAmount() != null && order.getGiftAmount() > 0 && order.getFamilyId() != null) {
|
|
|
+ // 原价判定:无积分抵扣、无优惠券、无折扣
|
|
|
+ boolean fullPrice = (order.getPointsUsed() == null || order.getPointsUsed() == 0)
|
|
|
+ && order.getCouponId() == null
|
|
|
+ && (order.getDiscountAmount() == null || order.getDiscountAmount() == 0);
|
|
|
+ if (fullPrice) {
|
|
|
+ boolean granted = giftMembershipProgressService.accumulate(
|
|
|
+ order.getFamilyId(), order.getBuyerId(), order.getGiftAmount());
|
|
|
+ log.info("商品订单{}累计送会员金额={}, 触发赠送={}", orderNo, order.getGiftAmount(), granted);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|