|
|
|
@ -1,9 +1,12 @@ |
|
|
|
package com.qniao.dam.application.handler.revenuereward; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.google.common.eventbus.Subscribe; |
|
|
|
import com.qniao.dam.application.service.revenuereward.RevenueRewardApplicationService; |
|
|
|
import com.qniao.dam.application.service.reward.RewardApplicationService; |
|
|
|
import com.qniao.dam.domain.aggregate.ffpm.FranchiseFeeProfitManagementAggregate; |
|
|
|
import com.qniao.dam.domain.aggregate.ffpm.entity.FranchiseFeeProfitManagement; |
|
|
|
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.RevenueRewardRecord; |
|
|
|
@ -18,14 +21,17 @@ 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.OrderDao; |
|
|
|
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.domain.StoreDao; |
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.org.OrganizationDao; |
|
|
|
import com.qniao.dam.query.ffpm.FranchiseFeeProfitManagementQueryService; |
|
|
|
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.das.domian.aggregate.mntp.event.MatchmakerNoviceTaskProgressFinishedMQ; |
|
|
|
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; |
|
|
|
@ -45,6 +51,7 @@ import org.springframework.stereotype.Component; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
@Component |
|
|
|
@ -56,6 +63,8 @@ public class RevenueRewardEventHandler extends BaseApplicationService { |
|
|
|
@Resource |
|
|
|
private RevenueRewardQueryService revenueRewardQueryService; |
|
|
|
@Resource |
|
|
|
private OrderDao orderDao; |
|
|
|
@Resource |
|
|
|
private RevenueRewardAggregate revenueRewardAggregate; |
|
|
|
@Resource |
|
|
|
private RevenueRewardRecoveredRecordDao revenueRewardRecoveredRecordDao; |
|
|
|
@ -73,6 +82,10 @@ public class RevenueRewardEventHandler extends BaseApplicationService { |
|
|
|
private FranchiseFeeProfitManagementAggregate franchiseFeeProfitManagementAggregate; |
|
|
|
@Resource |
|
|
|
private FranchiseFeeProfitManagementQueryService franchiseFeeProfitManagementQueryService; |
|
|
|
@Resource |
|
|
|
private RewardApplicationService rewardApplicationService; |
|
|
|
@Resource |
|
|
|
private StoreDao storeDao; |
|
|
|
|
|
|
|
@RabbitListener(bindings = @QueueBinding(value = @Queue(MqQueue.OPERATION_CENTER_CREATED), |
|
|
|
exchange = @Exchange(value = MqExchange.OPERATION_CENTER_CREATED, |
|
|
|
@ -150,7 +163,7 @@ public class RevenueRewardEventHandler extends BaseApplicationService { |
|
|
|
revenueRewardRecoveredRecordDao.insert(recoveredRecord); |
|
|
|
//补充管道收益 PIPELINE_REVENUE 全回本后才有管道收益 |
|
|
|
if (revenueReward.getAllRecoveryRequirement()) { |
|
|
|
revenueRewardApplicationService.pipeLineRevenue(orgId, revenueRewardRecord, TradeSceneEnum.OFFLINE,revenueRewardRecord.getContent()); |
|
|
|
revenueRewardApplicationService.pipeLineRevenue(orgId, revenueRewardRecord, TradeSceneEnum.OFFLINE, revenueRewardRecord.getContent()); |
|
|
|
} |
|
|
|
//发送事件 检查是否满足回本要求 |
|
|
|
RevenueRewardUpdatedEvent reEvent = new RevenueRewardUpdatedEvent(revenueReward.getId()); |
|
|
|
@ -224,4 +237,59 @@ public class RevenueRewardEventHandler extends BaseApplicationService { |
|
|
|
log.error("服务商回本事件处理异常"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 新手任务完成 |
|
|
|
* |
|
|
|
* @param mq |
|
|
|
*/ |
|
|
|
@RabbitListener(bindings = @QueueBinding(value = @Queue(MqQueue.OPERATION_CENTER_CREATED), |
|
|
|
exchange = @Exchange(value = MqExchange.OPERATION_CENTER_CREATED, |
|
|
|
type = ExchangeTypes.FANOUT))) |
|
|
|
public void handle(MatchmakerNoviceTaskProgressFinishedMQ mq) { |
|
|
|
try { |
|
|
|
//红娘新手任务完成, 卡在平台的加盟收益要分润出去 |
|
|
|
//将新手任务阶段的红娘入驻的分佣分给站点,最后红娘的额外奖励由站点支付 |
|
|
|
List<FranchiseFeeProfitManagement> franchiseFeeProfitManagementList = franchiseFeeProfitManagementQueryService |
|
|
|
.listByInitiatorId(mq.getMatchmakerUserId(), IdentityTypeEnum.INDIVIDUAL, false); |
|
|
|
if (CollUtil.isNotEmpty(franchiseFeeProfitManagementList)) { |
|
|
|
//站点分佣金 |
|
|
|
Store store = storeDao.selectById(mq.getStoreId()); |
|
|
|
for (FranchiseFeeProfitManagement franchiseFeeProfitManagement : franchiseFeeProfitManagementList) { |
|
|
|
Order associateOrder = orderDao.selectById(franchiseFeeProfitManagement.getAssociatedOrderId()); |
|
|
|
RevenueReward storeRevenueReward = revenueRewardQueryService.queryByOrgId(store.getOrgId()); |
|
|
|
if (!storeRevenueReward.getAllRecoveryRequirement()) { |
|
|
|
//未回本 拿100% 20%推荐费+50%门店费用+ 30%回本补贴 |
|
|
|
rewardApplicationService.handleStoreRecommendMatchmakerFee(store.getOrgId(), mq.getMatchmakerName(), associateOrder.getSettlementAmount(), RewardTypeEnum.OPERATING_RECOMMEND_50); |
|
|
|
rewardApplicationService.handleStoreRecommendMatchmakerFee(store.getOrgId(), mq.getMatchmakerName(), associateOrder.getSettlementAmount(), RewardTypeEnum.PAYBACK_SUBSIDY_30); |
|
|
|
|
|
|
|
//发送事件 检查是否满足回本要求 |
|
|
|
RevenueReward stRevenueReward = revenueRewardQueryService.queryByOrgId(store.getOrgId()); |
|
|
|
RevenueRewardUpdatedEvent storeReEvent = new RevenueRewardUpdatedEvent(stRevenueReward.getId()); |
|
|
|
handle(storeReEvent); |
|
|
|
} else { |
|
|
|
//回本后 拿70% 20%推荐费+50%门店费用 |
|
|
|
rewardApplicationService.handleStoreRecommendMatchmakerFee(store.getOrgId(), mq.getMatchmakerName(), associateOrder.getSettlementAmount(), RewardTypeEnum.OPERATING_RECOMMEND_50); |
|
|
|
//发送事件 检查是否满足回本要求 |
|
|
|
RevenueReward stRevenueReward = revenueRewardQueryService.queryByOrgId(store.getOrgId()); |
|
|
|
RevenueRewardUpdatedEvent storeReEvent = new RevenueRewardUpdatedEvent(stRevenueReward.getId()); |
|
|
|
handle(storeReEvent); |
|
|
|
|
|
|
|
//区域分润 |
|
|
|
rewardApplicationService.handleStoreRecommendMatchmakerFee(store.getOperationCenterOrgId(), mq.getMatchmakerName(), associateOrder.getSettlementAmount(), RewardTypeEnum.SERVICE_PROVIDER_MANAGEMENT_FEE); |
|
|
|
//发送事件 检查是否满足回本要求 |
|
|
|
RevenueReward operationCenterRevenueReward = revenueRewardQueryService.queryByOrgId(store.getOperationCenterOrgId()); |
|
|
|
RevenueRewardUpdatedEvent operationCenterReEvent = new RevenueRewardUpdatedEvent(operationCenterRevenueReward.getId()); |
|
|
|
handle(operationCenterReEvent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//todo 推荐的红娘不在一个门店中,收益是否归门店 |
|
|
|
//todo 红娘的新手任务奖励 |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("新手任务完成事件处理异常", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |