From 0c0d02b753eddadb29415ca5eac6a5d9f96aab3e Mon Sep 17 00:00:00 2001 From: Derran Date: Mon, 21 Apr 2025 18:12:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E6=94=BF=E7=AD=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rewardconfig/constant/RewardTypeEnum.java | 4 +- .../walletaccount/constant/TradeTypeEnum.java | 4 + .../revenuereward/entity/RevenueReward.java | 16 ++++ .../valueobj/RevenueRewardRecord.java | 5 + .../RevenueRewardRecoveredRecord.java | 27 ++++++ ...eRewardRecoveryRequirementFilledEvent.java | 15 +++ .../event/RevenueRewardUpdatedEvent.java | 15 +++ .../RevenueRewardEventHandler.java | 93 +++++++++++++++++++ .../RevenueRewardApplicationService.java | 86 +++++++++++++++++ .../revenuereward/RevenueRewardAggregate.java | 7 ++ .../AcquireRevenueRewardDomainService.java | 11 ++- .../RevenueRewardRecoveredRecordDao.java | 7 ++ .../impl/RevenueRewardRepositoryImpl.java | 2 + 13 files changed, 287 insertions(+), 5 deletions(-) create mode 100644 dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/valueobj/RevenueRewardRecoveredRecord.java create mode 100644 dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/revenuereward/event/RevenueRewardRecoveryRequirementFilledEvent.java create mode 100644 dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/revenuereward/event/RevenueRewardUpdatedEvent.java create mode 100644 dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/domain/RevenueRewardRecoveredRecordDao.java diff --git a/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/rewardconfig/constant/RewardTypeEnum.java b/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/rewardconfig/constant/RewardTypeEnum.java index 963fe5a..560f822 100644 --- a/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/rewardconfig/constant/RewardTypeEnum.java +++ b/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/rewardconfig/constant/RewardTypeEnum.java @@ -115,7 +115,9 @@ public enum RewardTypeEnum { //服务商推荐费 NON_OPERATING_RECOMMEND(501, "非经营性质推荐收益"), - NON_OPERATING_PIPELINE_REVENUE(502, "非经营性质管道收益"); + NON_OPERATING_PIPELINE_REVENUE(502, "非经营性质管道收益"), + + SERVICE_PROVIDER_RECOVERY_PCT(503, "服务商回本百分比"); @EnumValue @JsonValue diff --git a/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/walletaccount/constant/TradeTypeEnum.java b/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/walletaccount/constant/TradeTypeEnum.java index e5caba8..fa38919 100644 --- a/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/walletaccount/constant/TradeTypeEnum.java +++ b/dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/walletaccount/constant/TradeTypeEnum.java @@ -24,6 +24,10 @@ public enum TradeTypeEnum { SITE_ACTIVITY_INVITE_FEE(107, "活动邀约佣金"), + SERVICE_PROVIDER_RECOMMEND_FEE(108, "服务商入驻推荐"), + + PIPELINE_REVENUE_FEE(109, "管道收益"), + PLATFORM_SERVICE_FEE(201, "平台服务费"), WITHDRAW(202, "提现"); diff --git a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/entity/RevenueReward.java b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/entity/RevenueReward.java index 17c7989..f83a69e 100644 --- a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/entity/RevenueReward.java +++ b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/entity/RevenueReward.java @@ -2,13 +2,16 @@ package com.qniao.dam.domain.aggregate.revenuereward.entity; import com.baomidou.mybatisplus.annotation.TableName; import com.qniao.dam.domain.aggregate.revenuereward.valueobj.RevenueRewardRecord; +import com.qniao.dam.domain.aggregate.revenuereward.valueobj.RevenueRewardRecoveredRecord; import com.qniao.dam.domian.aggregate.walletaccount.constant.IdentityTypeEnum; import com.qniao.domain.Entity; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import java.math.BigDecimal; import java.util.List; +import java.util.Objects; @Data @@ -25,6 +28,12 @@ public class RevenueReward extends Entity { @ApiModelProperty("身份类型(个人、组织)") private IdentityTypeEnum identityType; + @ApiModelProperty("已回本金额") + private BigDecimal recoveredAmount; + + @ApiModelProperty("回本要求") + private Boolean recoveryRequirement; + @ApiModelProperty("收益记录") private transient List recordList; @@ -41,4 +50,11 @@ public class RevenueReward extends Entity { revenueReward.setIdentityType(IdentityTypeEnum.ORGANIZATION); return revenueReward; } + + public void handleRevenueReward(BigDecimal thisRecoveredAmount) { + if (Objects.isNull(recoveredAmount)) { + recoveredAmount = BigDecimal.ZERO; + } + recoveredAmount = recoveredAmount.add(thisRecoveredAmount); + } } diff --git a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/valueobj/RevenueRewardRecord.java b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/valueobj/RevenueRewardRecord.java index 5982c7d..a8d0a07 100644 --- a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/valueobj/RevenueRewardRecord.java +++ b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/valueobj/RevenueRewardRecord.java @@ -44,6 +44,9 @@ public class RevenueRewardRecord extends ValueObject { @ApiModelProperty("内容") private String content; + @ApiModelProperty("关联的收益记录") + private Long associateRevenueRewardRecordId; + @ApiModelProperty("凭证Url") private String proofUrl; @@ -80,6 +83,8 @@ public class RevenueRewardRecord extends ValueObject { content = StrUtil.format("推荐嘉宾{}见面", elements.toArray()); } else if (TradeTypeEnum.SITE_ACTIVITY_INVITE_FEE.equals(tradeType)) { content = StrUtil.format("推荐{}参与{}", elements.toArray()); + } else if (TradeTypeEnum.SERVICE_PROVIDER_RECOMMEND_FEE.equals(tradeType)) { + content = StrUtil.format("推荐服务商{}入驻平台", elements.toArray()); } } } \ No newline at end of file diff --git a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/valueobj/RevenueRewardRecoveredRecord.java b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/valueobj/RevenueRewardRecoveredRecord.java new file mode 100644 index 0000000..915ff3b --- /dev/null +++ b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/valueobj/RevenueRewardRecoveredRecord.java @@ -0,0 +1,27 @@ +package com.qniao.dam.domain.aggregate.revenuereward.valueobj; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.qniao.domain.ValueObject; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("da_revenue_reward_recovered_record") +public class RevenueRewardRecoveredRecord extends ValueObject { + + @ApiModelProperty("收益标识") + private Long revenueRewardId; + + @ApiModelProperty("收益记录标识") + private Long revenueRewardRecordId; + + public static RevenueRewardRecoveredRecord build(Long revenueRewardId, + Long revenueRewardRecordId) { + RevenueRewardRecoveredRecord recoveredRecord = new RevenueRewardRecoveredRecord(); + recoveredRecord.setRevenueRewardId(revenueRewardId); + recoveredRecord.setRevenueRewardRecordId(revenueRewardRecordId); + return recoveredRecord; + } +} diff --git a/dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/revenuereward/event/RevenueRewardRecoveryRequirementFilledEvent.java b/dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/revenuereward/event/RevenueRewardRecoveryRequirementFilledEvent.java new file mode 100644 index 0000000..f359de3 --- /dev/null +++ b/dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/revenuereward/event/RevenueRewardRecoveryRequirementFilledEvent.java @@ -0,0 +1,15 @@ +package com.qniao.dam.domian.aggregate.revenuereward.event; + +import com.qniao.domain.BaseDomainEvent; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class RevenueRewardRecoveryRequirementFilledEvent extends BaseDomainEvent { + + private Long id; + +} diff --git a/dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/revenuereward/event/RevenueRewardUpdatedEvent.java b/dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/revenuereward/event/RevenueRewardUpdatedEvent.java new file mode 100644 index 0000000..5392b66 --- /dev/null +++ b/dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/revenuereward/event/RevenueRewardUpdatedEvent.java @@ -0,0 +1,15 @@ +package com.qniao.dam.domian.aggregate.revenuereward.event; + +import com.qniao.domain.BaseDomainEvent; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class RevenueRewardUpdatedEvent extends BaseDomainEvent { + + private Long id; + +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/revenuereward/RevenueRewardEventHandler.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/revenuereward/RevenueRewardEventHandler.java index f11917d..499bcb5 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/revenuereward/RevenueRewardEventHandler.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/revenuereward/RevenueRewardEventHandler.java @@ -1,10 +1,33 @@ package com.qniao.dam.application.handler.revenuereward; +import com.google.common.eventbus.Subscribe; +import com.qniao.dam.application.service.revenuereward.RevenueRewardApplicationService; +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.RevenueRewardRecord; +import com.qniao.dam.domain.aggregate.revenuereward.valueobj.RevenueRewardRecoveredRecord; +import com.qniao.dam.domain.aggregate.rewardconfig.entity.RewardConfig; +import com.qniao.dam.domian.aggregate.revenuereward.event.RevenueRewardUpdatedEvent; +import com.qniao.dam.domian.aggregate.rewardconfig.constant.RewardTypeEnum; +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.RevenueRewardDao; +import com.qniao.dam.infrastructure.persistent.dao.domain.RevenueRewardRecoveredRecordDao; +import com.qniao.dam.infrastructure.persistent.dao.org.OrganizationDao; +import com.qniao.dam.query.operationcenter.OperationCenterQueryService; +import com.qniao.dam.query.revenuereward.RevenueRewardQueryService; import com.qniao.dam.query.rewardconfig.RewardConfigQueryService; +import com.qniao.dam.query.store.StoreQueryService; +import com.qniao.dau.domain.aggregate.operationcenter.entity.OperationCenter; +import com.qniao.dau.domain.aggregate.organization.entity.Organization; +import com.qniao.dau.domain.aggregate.store.entity.Store; +import com.qniao.dau.domian.aggregate.organization.constant.OrganizationTypeEnum; import com.qniao.dau.domian.aggregate.store.event.StoreCreatedMQ; import com.qniao.domain.BaseApplicationService; +import com.qniao.domain.BaseDomainEvent; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.core.ExchangeTypes; import org.springframework.amqp.rabbit.annotation.Exchange; @@ -15,6 +38,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.math.BigDecimal; +import java.util.Collections; import java.util.Objects; @Component @@ -23,6 +47,22 @@ public class RevenueRewardEventHandler extends BaseApplicationService { @Resource private RewardConfigQueryService rewardConfigQueryService; + @Resource + private RevenueRewardQueryService revenueRewardQueryService; + @Resource + private RevenueRewardAggregate revenueRewardAggregate; + @Resource + private RevenueRewardRecoveredRecordDao revenueRewardRecoveredRecordDao; + @Resource + private RevenueRewardApplicationService revenueRewardApplicationService; + @Resource + private RevenueRewardDao revenueRewardDao; + @Resource + private OrganizationDao organizationDao; + @Resource + private StoreQueryService storeQueryService; + @Resource + private OperationCenterQueryService operationCenterQueryService; @RabbitListener(bindings = @QueueBinding(value = @Queue(MqQueue.STORE_CREATED), exchange = @Exchange(value = MqExchange.STORE_CREATED, @@ -36,11 +76,64 @@ public class RevenueRewardEventHandler extends BaseApplicationService { //推荐服务商回本后 先提取50%,剩余20需要被推荐服务商回本50%后才能提取 } else { //非经营性质推荐 + RevenueReward revenueReward = revenueRewardQueryService.queryByOrgId(mq.getRecommendServiceProviderOrgId()); //推荐服务商直接拿取20%,被推荐服务商回本后获得1%管道收益 + RewardConfig rewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.NON_OPERATING_RECOMMEND); + //营收额 20%推荐费 + BigDecimal revenue = RewardConfig.calculatePct(mq.getFranchiseFee(), new BigDecimal(rewardConfig.getValue())); + //线下收益 + RevenueRewardRecord revenueRewardRecord = RevenueRewardRecord.build(TradeTypeEnum.SERVICE_PROVIDER_RECOMMEND_FEE, TradeSceneEnum.OFFLINE, + revenue, new BigDecimal(rewardConfig.getValue()), BigDecimal.ZERO, revenue, mq.getFranchiseFee()); + revenueRewardRecord.handleContent(Collections.singletonList(mq.getStoreName())); + revenueReward.setRecordList(Collections.singletonList(revenueRewardRecord)); + //计算本次回本金额 + revenueReward.handleRevenueReward(revenue); + revenueRewardAggregate.save(revenueReward); + //配置回本数据 + RevenueRewardRecoveredRecord recoveredRecord = RevenueRewardRecoveredRecord.build(revenueReward.getId(), revenueRewardRecord.getId()); + revenueRewardRecoveredRecordDao.insert(recoveredRecord); + //补充管道收益 PIPELINE_REVENUE + if (revenueReward.getRecoveryRequirement()) { + revenueRewardApplicationService.pipeLineRevenue(mq.getRecommendServiceProviderOrgId(), revenueRewardRecord, TradeSceneEnum.OFFLINE); + } + //发送事件 检查是否满足回本要求 + RevenueRewardUpdatedEvent event = new RevenueRewardUpdatedEvent(revenueReward.getId()); + this.sendEvent(event); } } } catch (Exception e) { log.error("门店已创建事件处理异常", e); } } + + @Subscribe + private void handle(RevenueRewardUpdatedEvent event) { + try { + RevenueReward revenueReward = revenueRewardDao.selectById(event.getId()); + //满足回本条件处理 服务商 + if (IdentityTypeEnum.ORGANIZATION.equals(revenueReward.getIdentityType()) && !revenueReward.getRecoveryRequirement()) { + BigDecimal franchiseFee = null; + Organization organization = organizationDao.selectById(revenueReward.getOrgId()); + if (OrganizationTypeEnum.OPERATION_CENTER.equals(organization.getType())) { + OperationCenter operationCenter = operationCenterQueryService.queryByOrg(revenueReward.getOrgId()); + franchiseFee = operationCenter.getFranchiseFee(); + } else if (OrganizationTypeEnum.STORE.equals(organization.getType())) { + Store store = storeQueryService.queryByOrg(revenueReward.getOrgId()); + franchiseFee = store.getFranchiseFee(); + } + if (Objects.nonNull(franchiseFee)) { + RewardConfig rewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.SERVICE_PROVIDER_RECOVERY_PCT); + BigDecimal recoveredAmount = rewardConfig.calculateReward(franchiseFee); + if (Objects.nonNull(revenueReward.getRecoveredAmount()) && revenueReward.getRecoveredAmount().compareTo(recoveredAmount) > 0) { + //达到回本条件 + revenueReward.setRecoveryRequirement(true); + BaseDomainEvent filledEvent = revenueRewardAggregate.fillRecoveryRequirement(revenueReward); + this.sendEvent(filledEvent); + } + } + } + } catch (Exception e) { + log.error("收益信息更新事件处理异常", e); + } + } } diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/revenuereward/RevenueRewardApplicationService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/revenuereward/RevenueRewardApplicationService.java index 34e7098..5991175 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/revenuereward/RevenueRewardApplicationService.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/revenuereward/RevenueRewardApplicationService.java @@ -2,17 +2,38 @@ package com.qniao.dam.application.service.revenuereward; 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.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.rewardconfig.constant.RewardTypeEnum; +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.persistent.dao.domain.RevenueRewardRecordDao; +import com.qniao.dam.infrastructure.persistent.dao.org.OrganizationDao; +import com.qniao.dam.query.operationcenter.OperationCenterQueryService; import com.qniao.dam.query.revenuereward.RevenueRewardQueryService; +import com.qniao.dam.query.rewardconfig.RewardConfigQueryService; +import com.qniao.dam.query.store.StoreQueryService; +import com.qniao.dam.query.walletaccount.WalletAccountQueryService; +import com.qniao.dau.domain.aggregate.operationcenter.entity.OperationCenter; +import com.qniao.dau.domain.aggregate.organization.entity.Organization; +import com.qniao.dau.domain.aggregate.store.entity.Store; +import com.qniao.dau.domian.aggregate.organization.constant.OrganizationTypeEnum; import com.qniao.framework.exception.BizException; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Collections; import java.util.Objects; @Service +@Slf4j public class RevenueRewardApplicationService { @Resource @@ -21,6 +42,18 @@ public class RevenueRewardApplicationService { private RevenueRewardAggregate revenueRewardAggregate; @Resource private RevenueRewardRecordDao revenueRewardRecordDao; + @Resource + private OrganizationDao organizationDao; + @Resource + private StoreQueryService storeQueryService; + @Resource + private OperationCenterQueryService operationCenterQueryService; + @Resource + private RewardConfigQueryService rewardConfigQueryService; + @Resource + private WalletAccountQueryService walletAccountQueryService; + @Resource + private AcquireRevenueRewardDomainService acquireRevenueRewardDomainService; public void create(RevenueReward revenueReward) { RevenueReward existRevenueReward = revenueRewardQueryService.queryByUserId(revenueReward.getUserId()); @@ -37,4 +70,57 @@ public class RevenueRewardApplicationService { } revenueRewardRecordDao.updateById(revenueRewardRecord); } + + /** + * 管道收益 + * + * @param serviceProviderOrgId + */ + public void pipeLineRevenue(Long serviceProviderOrgId, + RevenueRewardRecord rewardRecord, + TradeSceneEnum tradeScene) { + try { + Organization organization = organizationDao.selectById(serviceProviderOrgId); + Long recommendServiceProviderOrgId = null; + if (OrganizationTypeEnum.OPERATION_CENTER.equals(organization.getType())) { + //运营中心 + OperationCenter operationCenter = operationCenterQueryService.queryByOrg(serviceProviderOrgId); + recommendServiceProviderOrgId = operationCenter.getRecommendServiceProviderOrgId(); + } else if (OrganizationTypeEnum.STORE.equals(organization.getType())) { + //门店 + Store store = storeQueryService.queryByOrg(serviceProviderOrgId); + if (Objects.nonNull(store.getOperationCenterOrgId()) && Objects.nonNull(store.getRecommendServiceProviderOrgId())) { + //非经营推荐,推荐方可以拿1%的管道收益 + if (!store.getOperationCenterOrgId().equals(store.getRecommendServiceProviderOrgId())) { + recommendServiceProviderOrgId = store.getRecommendServiceProviderOrgId(); + } + } + } + if (Objects.nonNull(recommendServiceProviderOrgId)) { + RewardConfig rewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.NON_OPERATING_PIPELINE_REVENUE); + //营收额 + BigDecimal revenue = rewardConfig.calculateReward(rewardRecord.getEarnings()); + RevenueReward revenueReward = revenueRewardQueryService.queryByOrgId(recommendServiceProviderOrgId); + RevenueRewardRecord revenueRewardRecord = RevenueRewardRecord.build(TradeTypeEnum.PIPELINE_REVENUE_FEE, tradeScene, + revenue, new BigDecimal(rewardConfig.getValue()), BigDecimal.ZERO, revenue, rewardRecord.getEarnings()); + revenueRewardRecord.setContent(revenueRewardRecord.getContent() + "管道收益"); + revenueRewardRecord.setAssociateRevenueRewardRecordId(rewardRecord.getId()); + revenueReward.setRecordList(Collections.singletonList(revenueRewardRecord)); + + WalletAccount walletAccount = null; + if (TradeSceneEnum.ONLINE.equals(tradeScene)) { + //钱包信息 + walletAccount = walletAccountQueryService.queryByType(recommendServiceProviderOrgId, IdentityTypeEnum.ORGANIZATION); + BigDecimal originalBalance = walletAccount.getTotalBalance(); + walletAccount.setAvailableBalance(walletAccount.getAvailableBalance().add(revenue)); + walletAccount.setTotalBalance(walletAccount.getAvailableBalance().add(walletAccount.getFrozenBalance())); + WalletAccountRecord walletAccountRecord = WalletAccountRecord.build(TradeTypeEnum.PIPELINE_REVENUE_FEE, revenue, true, originalBalance, walletAccount.getTotalBalance()); + walletAccount.setRecordList(Collections.singletonList(walletAccountRecord)); + } + acquireRevenueRewardDomainService.handle(revenueReward, walletAccount); + } + } catch (Exception e) { + log.error("管道收益处理异常"); + } + } } diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/RevenueRewardAggregate.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/RevenueRewardAggregate.java index b875515..a04a32a 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/RevenueRewardAggregate.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/RevenueRewardAggregate.java @@ -2,6 +2,8 @@ package com.qniao.dam.domain.aggregate.revenuereward; import com.qniao.dam.domain.aggregate.revenuereward.entity.RevenueReward; import com.qniao.dam.domain.aggregate.revenuereward.repository.RevenueRewardRepository; +import com.qniao.dam.domian.aggregate.revenuereward.event.RevenueRewardRecoveryRequirementFilledEvent; +import com.qniao.domain.BaseDomainEvent; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -15,4 +17,9 @@ public class RevenueRewardAggregate { public void save(RevenueReward revenueReward) { revenueRewardRepository.save(revenueReward); } + + public BaseDomainEvent fillRecoveryRequirement(RevenueReward revenueReward) { + revenueRewardRepository.save(revenueReward); + return new RevenueRewardRecoveryRequirementFilledEvent(revenueReward.getId()); + } } diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/revenuereward/AcquireRevenueRewardDomainService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/revenuereward/AcquireRevenueRewardDomainService.java index 9c51e66..abb290f 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/revenuereward/AcquireRevenueRewardDomainService.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/domain/service/revenuereward/AcquireRevenueRewardDomainService.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Objects; @Service public class AcquireRevenueRewardDomainService { @@ -21,9 +22,11 @@ public class AcquireRevenueRewardDomainService { @Transactional(rollbackFor = Exception.class) public void handle(RevenueReward revenueReward, WalletAccount walletAccount) { revenueRewardAggregate.save(revenueReward); - walletAccount.getRecordList().forEach(record -> { - record.setAssociateId(revenueReward.getRecordList().get(0).getId()); - }); - walletAccountAggregate.save(walletAccount); + if(Objects.nonNull(walletAccount)) { + walletAccount.getRecordList().forEach(record -> { + record.setAssociateId(revenueReward.getRecordList().get(0).getId()); + }); + walletAccountAggregate.save(walletAccount); + } } } diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/domain/RevenueRewardRecoveredRecordDao.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/domain/RevenueRewardRecoveredRecordDao.java new file mode 100644 index 0000000..d323599 --- /dev/null +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/domain/RevenueRewardRecoveredRecordDao.java @@ -0,0 +1,7 @@ +package com.qniao.dam.infrastructure.persistent.dao.domain; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.qniao.dam.domain.aggregate.revenuereward.valueobj.RevenueRewardRecoveredRecord; + +public interface RevenueRewardRecoveredRecordDao extends BaseMapper { +} diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/RevenueRewardRepositoryImpl.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/RevenueRewardRepositoryImpl.java index fb7b0f4..ac2f57e 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/RevenueRewardRepositoryImpl.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/RevenueRewardRepositoryImpl.java @@ -4,9 +4,11 @@ import cn.hutool.core.collection.CollUtil; import com.qniao.dam.domain.aggregate.revenuereward.entity.RevenueReward; import com.qniao.dam.domain.aggregate.revenuereward.repository.RevenueRewardRepository; import com.qniao.dam.domain.aggregate.revenuereward.valueobj.RevenueRewardAssociateOrderRecord; +import com.qniao.dam.domain.aggregate.revenuereward.valueobj.RevenueRewardRecoveredRecord; import com.qniao.dam.infrastructure.persistent.dao.domain.RevenueRewardAssociateOrderRecordDao; import com.qniao.dam.infrastructure.persistent.dao.domain.RevenueRewardDao; import com.qniao.dam.infrastructure.persistent.dao.domain.RevenueRewardRecordDao; +import com.qniao.dam.infrastructure.persistent.dao.domain.RevenueRewardRecoveredRecordDao; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional;