From e50ab97e1eb1df20323bec987928e85df681c5f3 Mon Sep 17 00:00:00 2001 From: Derran Date: Wed, 29 Apr 2026 18:20:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A2=E5=A8=98=E7=9B=B4=E6=92=AD=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VirtualAccountApplicationService.java | 24 ++++--- .../CostIMGiftRewardDomainService.java | 68 +++++++++++++++++++ 2 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/virtualaccount/CostIMGiftRewardDomainService.java diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/virtualaccount/VirtualAccountApplicationService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/virtualaccount/VirtualAccountApplicationService.java index 9c71d92..2a3ba6a 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/virtualaccount/VirtualAccountApplicationService.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/virtualaccount/VirtualAccountApplicationService.java @@ -23,6 +23,7 @@ import com.qniao.dam.domain.aggregate.walletaccount.entity.WalletAccount; import com.qniao.dam.domain.aggregate.walletaccount.valueobj.WalletAccountRecord; import com.qniao.dam.domain.service.virtualaccount.ConsumeVirtualAccountDomainService; import com.qniao.dam.domain.service.virtualaccount.CostGiftRewardDomainService; +import com.qniao.dam.domain.service.virtualaccount.CostIMGiftRewardDomainService; import com.qniao.dam.domain.service.virtualaccount.SettleOneOnOneRtcDomainService; import com.qniao.dam.domian.aggregate.order.constant.OrderBelongingEnum; import com.qniao.dam.domian.aggregate.order.constant.OrderStatusEnum; @@ -82,6 +83,8 @@ public class VirtualAccountApplicationService extends BaseApplicationService { @Resource private CostGiftRewardDomainService costGiftRewardDomainService; @Resource + private CostIMGiftRewardDomainService costIMGiftRewardDomainService; + @Resource private ProductQueryService productQueryService; @Resource private RewardConfigQueryService rewardConfigQueryService; @@ -123,7 +126,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService { if (VirtualAccountTradeTypeEnum.CONNECT_CHANNEL.equals(dto.getTradeType())) { RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH); BigDecimal worthReward = BigDecimal.valueOf(productSpec.getUnitSellingPrice().intValue()).multiply(new BigDecimal(worthRewardConfig.getValue())); - walletAccountApplicationService.handleChannelConnectReward(dto.getAppId(),dto.getAnchorUserId(), dto.getChannelCreatorTodayCrossMicCount(),worthReward); + walletAccountApplicationService.handleChannelConnectReward(dto.getAppId(), dto.getAnchorUserId(), dto.getChannelCreatorTodayCrossMicCount(), worthReward); } } } @@ -176,7 +179,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService { ProductSpec productSpec = productSpecDao.selectById(dto.getProductSpecId()); Integer costBalance = productSpec.getUnitSellingPrice().intValue() * dto.getQuantity(); if (virtualAccount != null && virtualAccount.getBalance() >= costBalance) { - vo = handleIMGiftReward(virtualAccount, dto.getAppId(),dto.getFromUserId(), dto.getToUserId(), productSpec, costBalance, dto.getQuantity()); + vo = handleIMGiftReward(virtualAccount, dto.getAppId(), dto.getFromUserId(), dto.getToUserId(), productSpec, costBalance, dto.getQuantity()); } vo.setCostBalance(costBalance); } @@ -200,7 +203,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService { //收益信息 RevenueReward revenueReward = revenueRewardQueryService.queryByUserId(appId, toUserId); if (Objects.isNull(revenueReward)) { - revenueReward = RevenueReward.initUser(appId,toUserId); + revenueReward = RevenueReward.initUser(appId, toUserId); } RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH); RewardConfig giftRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.CHAT_PROFIT_BY_GIFT); @@ -222,7 +225,8 @@ public class VirtualAccountApplicationService extends BaseApplicationService { WalletAccountRecord walletAccountRecord = WalletAccountRecord.build(TradeTypeEnum.IM_GIFT_REWARD, revenue, true, originalBalance, walletAccount.getTotalBalance()); walletAccount.setRecordList(Collections.singletonList(walletAccountRecord)); - costGiftRewardDomainService.handle(order, virtualAccount, costBalance, revenueReward, walletAccount); + List eventList = costIMGiftRewardDomainService.handle(order, virtualAccount, costBalance, revenueReward, walletAccount); + this.sendEvent(eventList); vo.setSuccess(true); return vo; } @@ -237,10 +241,10 @@ public class VirtualAccountApplicationService extends BaseApplicationService { if (virtualAccount != null && virtualAccount.getBalance() >= costBalance) { if (dto.getDirection() == 1) { //直接送主播 - vo = handleChannelAnchorGiftReward(virtualAccount,dto.getAppId(), dto.getFromUserId(), dto.getChannelCreatorId(), productSpec, costBalance, dto.getQuantity(), dto.getChannelCreatorTodayCrossMicCount()); + vo = handleChannelAnchorGiftReward(virtualAccount, dto.getAppId(), dto.getFromUserId(), dto.getChannelCreatorId(), productSpec, costBalance, dto.getQuantity(), dto.getChannelCreatorTodayCrossMicCount()); } else { //直接送嘉宾 - vo = handleChannelUserGiftReward(virtualAccount, dto.getAppId(),dto.getFromUserId(), dto.getToUserId(), dto.getChannelCreatorId(), productSpec, costBalance, dto.getQuantity(), dto.getChannelCreatorTodayCrossMicCount()); + vo = handleChannelUserGiftReward(virtualAccount, dto.getAppId(), dto.getFromUserId(), dto.getToUserId(), dto.getChannelCreatorId(), productSpec, costBalance, dto.getQuantity(), dto.getChannelCreatorTodayCrossMicCount()); } } vo.setCostBalance(costBalance); @@ -268,7 +272,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService { //收益信息 RevenueReward toRevenueReward = revenueRewardQueryService.queryByUserId(appId, toUserId); if (Objects.isNull(toRevenueReward)) { - toRevenueReward = RevenueReward.initUser(appId,toUserId); + toRevenueReward = RevenueReward.initUser(appId, toUserId); } RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH); //营收额 todo @@ -289,7 +293,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService { //收益信息 RevenueReward anchorRevenueReward = revenueRewardQueryService.queryByUserId(appId, anchorId); if (Objects.isNull(anchorRevenueReward)) { - anchorRevenueReward = RevenueReward.initUser(appId,anchorId); + anchorRevenueReward = RevenueReward.initUser(appId, anchorId); } //营收额 BigDecimal giftRewardPct = rewardConfigQueryService.queryMatchmakerChannelGiftPct(anchorId, channelCreatorTodayCrossMicCount); @@ -337,7 +341,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService { //收益信息 RevenueReward revenueReward = revenueRewardQueryService.queryByUserId(appId, toUserId); if (Objects.isNull(revenueReward)) { - revenueReward = RevenueReward.initUser(appId,toUserId); + revenueReward = RevenueReward.initUser(appId, toUserId); } RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH); //营收额 todo @@ -475,7 +479,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService { RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH); RewardConfig rtcRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.RTC_PROFIT_BY_ONE_ON_ONE); - BigDecimal income = BigDecimal.valueOf(dto.getConsumeBalance()).multiply(new BigDecimal(worthRewardConfig.getValue())); + BigDecimal income = BigDecimal.valueOf(dto.getConsumeBalance()).multiply(new BigDecimal(worthRewardConfig.getValue())); income = rtcRewardConfig.calculateReward(income); if (RtcChannelTypeEnum.ONE_ON_ONE_VOICE.equals(dto.getRtcChannelType())) { diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/virtualaccount/CostIMGiftRewardDomainService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/virtualaccount/CostIMGiftRewardDomainService.java new file mode 100644 index 0000000..ead3317 --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/virtualaccount/CostIMGiftRewardDomainService.java @@ -0,0 +1,68 @@ +package com.qniao.dam.domain.service.virtualaccount; + +import cn.hutool.core.collection.CollUtil; +import com.qniao.dam.domain.aggregate.order.OrderAggregate; +import com.qniao.dam.domain.aggregate.order.entity.Order; +import com.qniao.dam.domain.aggregate.revenuereward.RevenueRewardAggregate; +import com.qniao.dam.domain.aggregate.revenuereward.entity.RevenueReward; +import com.qniao.dam.domain.aggregate.revenuereward.valueobj.RevenueRewardAssociateOrderRecord; +import com.qniao.dam.domain.aggregate.virtualaccount.VirtualAccountAggregate; +import com.qniao.dam.domain.aggregate.virtualaccount.entity.VirtualAccount; +import com.qniao.dam.domain.aggregate.walletaccount.WalletAccountAggregate; +import com.qniao.dam.domain.aggregate.walletaccount.entity.WalletAccount; +import com.qniao.dam.domian.aggregate.revenuereward.event.RevenueRewardRecordCreatedEvent; +import com.qniao.domain.BaseDomainEvent; +import com.qniao.framework.utils.TypeConvertUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +@Service +public class CostIMGiftRewardDomainService { + + + @Resource + private OrderAggregate orderAggregate; + @Resource + private VirtualAccountAggregate virtualAccountAggregate; + @Resource + private RevenueRewardAggregate revenueRewardAggregate; + @Resource + private WalletAccountAggregate walletAccountAggregate; + + @Transactional(rollbackFor = Exception.class) + public List handle(Order order, + VirtualAccount virtualAccount, + Integer costBalance, + RevenueReward revenueReward, + WalletAccount walletAccount) { + List eventList = new ArrayList<>(); + + orderAggregate.complete(order); + + virtualAccountAggregate.costGift(virtualAccount, costBalance,order.getId()); + + RevenueRewardAssociateOrderRecord associateOrderRecord = RevenueRewardAssociateOrderRecord.build(order.getId(), order.getSettlementAmount()); + revenueReward.getRecordList().get(0).setAssociateOrderRecordList(Collections.singletonList(associateOrderRecord)); + revenueRewardAggregate.save(revenueReward); + + if(Objects.nonNull(walletAccount)) { + walletAccount.getRecordList().forEach(record -> { + record.setAssociateId(revenueReward.getRecordList().get(0).getId()); + }); + walletAccountAggregate.save(walletAccount); + } + + if (CollUtil.isNotEmpty(revenueReward.getRecordList())){ + revenueReward.getRecordList().forEach(record -> { + eventList.add(TypeConvertUtils.convert(record, RevenueRewardRecordCreatedEvent.class)); + }); + } + return eventList; + } +}