Browse Source

红娘直播任务

master
张彭杰 2 weeks ago
parent
commit
e50ab97e1e
2 changed files with 82 additions and 10 deletions
  1. 24
      dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/virtualaccount/VirtualAccountApplicationService.java
  2. 68
      dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/virtualaccount/CostIMGiftRewardDomainService.java

24
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.aggregate.walletaccount.valueobj.WalletAccountRecord;
import com.qniao.dam.domain.service.virtualaccount.ConsumeVirtualAccountDomainService; import com.qniao.dam.domain.service.virtualaccount.ConsumeVirtualAccountDomainService;
import com.qniao.dam.domain.service.virtualaccount.CostGiftRewardDomainService; 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.domain.service.virtualaccount.SettleOneOnOneRtcDomainService;
import com.qniao.dam.domian.aggregate.order.constant.OrderBelongingEnum; import com.qniao.dam.domian.aggregate.order.constant.OrderBelongingEnum;
import com.qniao.dam.domian.aggregate.order.constant.OrderStatusEnum; import com.qniao.dam.domian.aggregate.order.constant.OrderStatusEnum;
@ -82,6 +83,8 @@ public class VirtualAccountApplicationService extends BaseApplicationService {
@Resource @Resource
private CostGiftRewardDomainService costGiftRewardDomainService; private CostGiftRewardDomainService costGiftRewardDomainService;
@Resource @Resource
private CostIMGiftRewardDomainService costIMGiftRewardDomainService;
@Resource
private ProductQueryService productQueryService; private ProductQueryService productQueryService;
@Resource @Resource
private RewardConfigQueryService rewardConfigQueryService; private RewardConfigQueryService rewardConfigQueryService;
@ -123,7 +126,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService {
if (VirtualAccountTradeTypeEnum.CONNECT_CHANNEL.equals(dto.getTradeType())) { if (VirtualAccountTradeTypeEnum.CONNECT_CHANNEL.equals(dto.getTradeType())) {
RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH); RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH);
BigDecimal worthReward = BigDecimal.valueOf(productSpec.getUnitSellingPrice().intValue()).multiply(new BigDecimal(worthRewardConfig.getValue())); 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()); ProductSpec productSpec = productSpecDao.selectById(dto.getProductSpecId());
Integer costBalance = productSpec.getUnitSellingPrice().intValue() * dto.getQuantity(); Integer costBalance = productSpec.getUnitSellingPrice().intValue() * dto.getQuantity();
if (virtualAccount != null && virtualAccount.getBalance() >= costBalance) { 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); vo.setCostBalance(costBalance);
} }
@ -200,7 +203,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService {
//收益信息 //收益信息
RevenueReward revenueReward = revenueRewardQueryService.queryByUserId(appId, toUserId); RevenueReward revenueReward = revenueRewardQueryService.queryByUserId(appId, toUserId);
if (Objects.isNull(revenueReward)) { if (Objects.isNull(revenueReward)) {
revenueReward = RevenueReward.initUser(appId,toUserId);
revenueReward = RevenueReward.initUser(appId, toUserId);
} }
RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH); RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH);
RewardConfig giftRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.CHAT_PROFIT_BY_GIFT); 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()); WalletAccountRecord walletAccountRecord = WalletAccountRecord.build(TradeTypeEnum.IM_GIFT_REWARD, revenue, true, originalBalance, walletAccount.getTotalBalance());
walletAccount.setRecordList(Collections.singletonList(walletAccountRecord)); walletAccount.setRecordList(Collections.singletonList(walletAccountRecord));
costGiftRewardDomainService.handle(order, virtualAccount, costBalance, revenueReward, walletAccount);
List<BaseDomainEvent> eventList = costIMGiftRewardDomainService.handle(order, virtualAccount, costBalance, revenueReward, walletAccount);
this.sendEvent(eventList);
vo.setSuccess(true); vo.setSuccess(true);
return vo; return vo;
} }
@ -237,10 +241,10 @@ public class VirtualAccountApplicationService extends BaseApplicationService {
if (virtualAccount != null && virtualAccount.getBalance() >= costBalance) { if (virtualAccount != null && virtualAccount.getBalance() >= costBalance) {
if (dto.getDirection() == 1) { 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 { } 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); vo.setCostBalance(costBalance);
@ -268,7 +272,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService {
//收益信息 //收益信息
RevenueReward toRevenueReward = revenueRewardQueryService.queryByUserId(appId, toUserId); RevenueReward toRevenueReward = revenueRewardQueryService.queryByUserId(appId, toUserId);
if (Objects.isNull(toRevenueReward)) { if (Objects.isNull(toRevenueReward)) {
toRevenueReward = RevenueReward.initUser(appId,toUserId);
toRevenueReward = RevenueReward.initUser(appId, toUserId);
} }
RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH); RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH);
//营收额 todo //营收额 todo
@ -289,7 +293,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService {
//收益信息 //收益信息
RevenueReward anchorRevenueReward = revenueRewardQueryService.queryByUserId(appId, anchorId); RevenueReward anchorRevenueReward = revenueRewardQueryService.queryByUserId(appId, anchorId);
if (Objects.isNull(anchorRevenueReward)) { if (Objects.isNull(anchorRevenueReward)) {
anchorRevenueReward = RevenueReward.initUser(appId,anchorId);
anchorRevenueReward = RevenueReward.initUser(appId, anchorId);
} }
//营收额 //营收额
BigDecimal giftRewardPct = rewardConfigQueryService.queryMatchmakerChannelGiftPct(anchorId, channelCreatorTodayCrossMicCount); BigDecimal giftRewardPct = rewardConfigQueryService.queryMatchmakerChannelGiftPct(anchorId, channelCreatorTodayCrossMicCount);
@ -337,7 +341,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService {
//收益信息 //收益信息
RevenueReward revenueReward = revenueRewardQueryService.queryByUserId(appId, toUserId); RevenueReward revenueReward = revenueRewardQueryService.queryByUserId(appId, toUserId);
if (Objects.isNull(revenueReward)) { if (Objects.isNull(revenueReward)) {
revenueReward = RevenueReward.initUser(appId,toUserId);
revenueReward = RevenueReward.initUser(appId, toUserId);
} }
RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH); RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH);
//营收额 todo //营收额 todo
@ -475,7 +479,7 @@ public class VirtualAccountApplicationService extends BaseApplicationService {
RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH); RewardConfig worthRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.VIRTUAL_ACCOUNT_WORTH);
RewardConfig rtcRewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.RTC_PROFIT_BY_ONE_ON_ONE); 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); income = rtcRewardConfig.calculateReward(income);
if (RtcChannelTypeEnum.ONE_ON_ONE_VOICE.equals(dto.getRtcChannelType())) { if (RtcChannelTypeEnum.ONE_ON_ONE_VOICE.equals(dto.getRtcChannelType())) {

68
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<BaseDomainEvent> handle(Order order,
VirtualAccount virtualAccount,
Integer costBalance,
RevenueReward revenueReward,
WalletAccount walletAccount) {
List<BaseDomainEvent> 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;
}
}
Loading…
Cancel
Save