|
|
@ -0,0 +1,108 @@ |
|
|
|
|
|
package com.qniao.dam.application.handler.siteactivity; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.externalorder.entity.ExternalOrderRel; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.order.entity.Order; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.revenuereward.entity.RevenueReward; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.revenuereward.valueobj.RevenueRewardAssociateOrderRecord; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.revenuereward.valueobj.RevenueRewardRecord; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.rewardconfig.entity.RewardConfig; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.walletaccount.entity.WalletAccount; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.walletaccount.valueobj.WalletAccountRecord; |
|
|
|
|
|
import com.qniao.dam.domain.service.revenuereward.AcquireRevenueRewardDomainService; |
|
|
|
|
|
import com.qniao.dam.domian.aggregate.externalorder.constant.ExternalOrderTypeEnum; |
|
|
|
|
|
import com.qniao.dam.domian.aggregate.rewardconfig.constant.RewardTypeEnum; |
|
|
|
|
|
import com.qniao.dam.domian.aggregate.siteactivity.event.SiteActivityParticipantSettledMQ; |
|
|
|
|
|
import com.qniao.dam.domian.aggregate.walletaccount.constant.IdentityTypeEnum; |
|
|
|
|
|
import com.qniao.dam.domian.aggregate.walletaccount.constant.TradeSceneEnum; |
|
|
|
|
|
import com.qniao.dam.domian.aggregate.walletaccount.constant.TradeTypeEnum; |
|
|
|
|
|
import com.qniao.dam.infrastructure.constant.MqExchange; |
|
|
|
|
|
import com.qniao.dam.infrastructure.constant.MqQueue; |
|
|
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.ExternalOrderRelDao; |
|
|
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.MarriageInformationDao; |
|
|
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.MatchmakerDao; |
|
|
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.OrderDao; |
|
|
|
|
|
import com.qniao.dam.query.revenuereward.RevenueRewardQueryService; |
|
|
|
|
|
import com.qniao.dam.query.rewardconfig.RewardConfigQueryService; |
|
|
|
|
|
import com.qniao.dam.query.walletaccount.WalletAccountQueryService; |
|
|
|
|
|
import com.qniao.das.domian.aggregate.marriageinformation.MarriageInformation; |
|
|
|
|
|
import com.qniao.dau.domain.aggregate.matchmaker.entity.Matchmaker; |
|
|
|
|
|
import com.qniao.domain.BaseApplicationService; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.springframework.amqp.core.ExchangeTypes; |
|
|
|
|
|
import org.springframework.amqp.rabbit.annotation.Exchange; |
|
|
|
|
|
import org.springframework.amqp.rabbit.annotation.Queue; |
|
|
|
|
|
import org.springframework.amqp.rabbit.annotation.QueueBinding; |
|
|
|
|
|
import org.springframework.amqp.rabbit.annotation.RabbitListener; |
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
|
|
@Slf4j |
|
|
|
|
|
public class SiteActivityEventHandler extends BaseApplicationService { |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private ExternalOrderRelDao externalOrderRelDao; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private RewardConfigQueryService rewardConfigQueryService; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private RevenueRewardQueryService revenueRewardQueryService; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private OrderDao orderDao; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private MatchmakerDao matchmakerDao; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private MarriageInformationDao marriageInformationDao; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private WalletAccountQueryService walletAccountQueryService; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private AcquireRevenueRewardDomainService acquireRevenueRewardDomainService; |
|
|
|
|
|
|
|
|
|
|
|
@RabbitListener(bindings = @QueueBinding(value = @Queue(MqQueue.SITE_ACTIVITY_PARTICIPANT_SETTLED), |
|
|
|
|
|
exchange = @Exchange(value = MqExchange.SITE_ACTIVITY_PARTICIPANT_SETTLED, |
|
|
|
|
|
type = ExchangeTypes.FANOUT))) |
|
|
|
|
|
public void handle(SiteActivityParticipantSettledMQ mq) { |
|
|
|
|
|
try { |
|
|
|
|
|
//线下活动参入结算事件 |
|
|
|
|
|
ExternalOrderRel externalOrderRel = externalOrderRelDao.queryCompletedBy(mq.getSiteActivityId(), mq.getReceiveUserId(), |
|
|
|
|
|
mq.getReceiveMiId(), ExternalOrderTypeEnum.SITE_ACTIVITY); |
|
|
|
|
|
if (Objects.nonNull(externalOrderRel)) { |
|
|
|
|
|
Order order = orderDao.selectById(externalOrderRel.getOrderId()); |
|
|
|
|
|
RewardConfig rewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.PLATFORM_SERVICE_FEE); |
|
|
|
|
|
if (Objects.nonNull(rewardConfig)) { |
|
|
|
|
|
Matchmaker matchmaker = matchmakerDao.selectById(mq.getInviteMatchmakerId()); |
|
|
|
|
|
MarriageInformation marriageInformation = marriageInformationDao.selectById(mq.getReceiveMiId()); |
|
|
|
|
|
//收益信息 |
|
|
|
|
|
RevenueReward revenueReward = revenueRewardQueryService.queryByUserId(matchmaker.getUserId()); |
|
|
|
|
|
if (Objects.isNull(revenueReward)) { |
|
|
|
|
|
revenueReward = RevenueReward.initUser(matchmaker.getUserId()); |
|
|
|
|
|
} |
|
|
|
|
|
//营收额 |
|
|
|
|
|
BigDecimal earnings = rewardConfig.calculateReward(order.getSettlementAmount()); |
|
|
|
|
|
|
|
|
|
|
|
RevenueRewardRecord revenueRewardRecord = RevenueRewardRecord.build(TradeTypeEnum.SITE_ACTIVITY_INVITE_FEE, TradeSceneEnum.ONLINE, |
|
|
|
|
|
earnings, new BigDecimal(rewardConfig.getValue()), BigDecimal.ZERO, earnings, order.getSettlementAmount()); |
|
|
|
|
|
revenueRewardRecord.handleContent(Arrays.asList(marriageInformation.getNickName(), mq.getSiteActivityName())); |
|
|
|
|
|
RevenueRewardAssociateOrderRecord associateOrderRecord = RevenueRewardAssociateOrderRecord.build(order.getId(), order.getSettlementAmount()); |
|
|
|
|
|
revenueRewardRecord.setAssociateOrderRecordList(Collections.singletonList(associateOrderRecord)); |
|
|
|
|
|
revenueReward.setRecordList(Collections.singletonList(revenueRewardRecord)); |
|
|
|
|
|
|
|
|
|
|
|
//钱包 |
|
|
|
|
|
WalletAccount walletAccount = walletAccountQueryService.queryByType(matchmaker.getUserId(), IdentityTypeEnum.INDIVIDUAL); |
|
|
|
|
|
BigDecimal originalBalance = walletAccount.getTotalBalance(); |
|
|
|
|
|
walletAccount.setAvailableBalance(walletAccount.getAvailableBalance().add(earnings)); |
|
|
|
|
|
walletAccount.setTotalBalance(walletAccount.getAvailableBalance().add(walletAccount.getFrozenBalance())); |
|
|
|
|
|
WalletAccountRecord walletAccountRecord = WalletAccountRecord.build(TradeTypeEnum.SITE_ACTIVITY_INVITE_FEE, earnings, true, originalBalance, walletAccount.getTotalBalance()); |
|
|
|
|
|
walletAccount.setRecordList(Collections.singletonList(walletAccountRecord)); |
|
|
|
|
|
acquireRevenueRewardDomainService.handle(revenueReward, walletAccount); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("线下活动参入结算事件处理异常", e); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |