Browse Source

新政策

master
张彭杰 11 months ago
parent
commit
35ddaad363
11 changed files with 310 additions and 35 deletions
  1. 14
      dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/rewardconfig/constant/RewardTypeEnum.java
  2. 45
      dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/ffpm/entity/FranchiseFeeProfitManagement.java
  3. 7
      dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/entity/RevenueReward.java
  4. 126
      dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/revenuereward/RevenueRewardEventHandler.java
  5. 26
      dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/ffpm/FranchiseFeeProfitManagementApplicationService.java
  6. 31
      dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/ffpm/FranchiseFeeProfitManagementAggregate.java
  7. 12
      dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/ffpm/repository/FranchiseFeeProfitManagementRepository.java
  8. 12
      dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/ffpm/FranchiseFeeProfitManagementDao.java
  9. 41
      dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/FranchiseFeeProfitManagementRepositoryImpl.java
  10. 8
      dating-agency-mall-server/src/main/java/com/qniao/dam/query/ffpm/FranchiseFeeProfitManagementQueryService.java
  11. 23
      dating-agency-mall-server/src/main/java/com/qniao/dam/query/ffpm/impl/FranchiseFeeProfitManagementQueryServiceImpl.java

14
dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/rewardconfig/constant/RewardTypeEnum.java

@ -117,7 +117,17 @@ public enum RewardTypeEnum {
NON_OPERATING_PIPELINE_REVENUE(502, "非经营性质管道收益"),
SERVICE_PROVIDER_RECOVERY_PCT(503, "服务商回本百分比");
SERVICE_PROVIDER_RECOVERY_HALF_PCT(503, "服务商回本一半百分比"),
SERVICE_PROVIDER_RECOVERY_ALL_PCT(504, "服务商全回本百分比"),
SERVICE_PROVIDER_MANAGEMENT_FEE(505, "服务商管理费"),
OPERATING_RECOMMEND_100(506, "营性质推荐收益-100%"),
OPERATING_RECOMMEND_50(507, "营性质推荐收益-50%"),
OPERATING_RECOMMEND_20(508, "营性质推荐收益-20%");
@EnumValue
@JsonValue
@ -138,4 +148,4 @@ public enum RewardTypeEnum {
}
return null;
}
}
}

45
dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/ffpm/entity/FranchiseFeeProfitManagement.java

@ -0,0 +1,45 @@
package com.qniao.dam.domain.aggregate.ffpm.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.qniao.dam.domian.aggregate.walletaccount.constant.IdentityTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.qniao.domain.Entity;
/**
* 入驻费分佣管理
*
* @date 2025/04/22
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("da_franchise_fee_profit_management")
public class FranchiseFeeProfitManagement extends Entity<FranchiseFeeProfitManagement> {
@ApiModelProperty("用户唯一标识")
private Long userId;
@ApiModelProperty("组织唯一标识")
private Long orgId;
@ApiModelProperty("身份类型(个人、组织)")
private IdentityTypeEnum identityType;
@ApiModelProperty("是否完成分润")
private Boolean isFinish;
@ApiModelProperty("关联订单ID")
private Long associatedOrderId;
public static FranchiseFeeProfitManagement initOrg(Long orgId,
Long associatedOrderId) {
FranchiseFeeProfitManagement management = new FranchiseFeeProfitManagement();
management.setOrgId(orgId);
management.setIdentityType(IdentityTypeEnum.ORGANIZATION);
management.setIsFinish(false);
management.setAssociatedOrderId(associatedOrderId);
return management;
}
}

7
dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/revenuereward/entity/RevenueReward.java

@ -31,8 +31,11 @@ public class RevenueReward extends Entity<RevenueReward> {
@ApiModelProperty("已回本金额")
private BigDecimal recoveredAmount;
@ApiModelProperty("回本要求")
private Boolean recoveryRequirement;
@ApiModelProperty("回本一半要求")
private Boolean halfRecoveryRequirement;
@ApiModelProperty("全回本要求")
private Boolean allRecoveryRequirement;
@ApiModelProperty("收益记录")
private transient List<RevenueRewardRecord> recordList;

126
dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/revenuereward/RevenueRewardEventHandler.java

@ -2,11 +2,14 @@ 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.ffpm.FranchiseFeeProfitManagementAggregate;
import com.qniao.dam.domain.aggregate.ffpm.entity.FranchiseFeeProfitManagement;
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.RevenueRewardRecoveryRequirementFilledEvent;
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;
@ -17,6 +20,7 @@ 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.ffpm.FranchiseFeeProfitManagementQueryService;
import com.qniao.dam.query.operationcenter.OperationCenterQueryService;
import com.qniao.dam.query.revenuereward.RevenueRewardQueryService;
import com.qniao.dam.query.rewardconfig.RewardConfigQueryService;
@ -63,6 +67,10 @@ public class RevenueRewardEventHandler extends BaseApplicationService {
private StoreQueryService storeQueryService;
@Resource
private OperationCenterQueryService operationCenterQueryService;
@Resource
private FranchiseFeeProfitManagementAggregate franchiseFeeProfitManagementAggregate;
@Resource
private FranchiseFeeProfitManagementQueryService franchiseFeeProfitManagementQueryService;
@RabbitListener(bindings = @QueueBinding(value = @Queue(MqQueue.STORE_CREATED),
exchange = @Exchange(value = MqExchange.STORE_CREATED,
@ -74,31 +82,22 @@ public class RevenueRewardEventHandler extends BaseApplicationService {
//经营性质推荐
//推荐服务商回本前 100%获得
//推荐服务商回本后 先提取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);
if (!revenueReward.getAllRecoveryRequirement()) {
//推荐服务商回本前 100%获得
handleServiceProviderManagementFee(mq.getRecommendServiceProviderOrgId(), mq.getStoreName(), mq.getFranchiseFee(), RewardTypeEnum.OPERATING_RECOMMEND_100);
} else {
//推荐服务商回本后 先提取50%,剩余20需要被推荐服务商回本50%后才能提取
handleServiceProviderManagementFee(mq.getRecommendServiceProviderOrgId(), mq.getStoreName(), mq.getFranchiseFee(), RewardTypeEnum.OPERATING_RECOMMEND_50);
//补充 入驻费分佣管理
FranchiseFeeProfitManagement franchiseFeeProfitManagement = FranchiseFeeProfitManagement.initOrg(mq.getOrgId(), null);
franchiseFeeProfitManagementAggregate.create(franchiseFeeProfitManagement);
}
//发送事件 检查是否满足回本要求
RevenueRewardUpdatedEvent event = new RevenueRewardUpdatedEvent(revenueReward.getId());
this.sendEvent(event);
} else {
//非经营性质推荐
handleServiceProviderManagementFee(mq.getRecommendServiceProviderOrgId(), mq.getStoreName(), mq.getFranchiseFee(), RewardTypeEnum.NON_OPERATING_RECOMMEND);
//运营中心收益处理
handleServiceProviderManagementFee(mq.getOperationCenterOrgId(), mq.getStoreName(), mq.getFranchiseFee(), RewardTypeEnum.SERVICE_PROVIDER_MANAGEMENT_FEE);
}
}
} catch (Exception e) {
@ -106,12 +105,40 @@ public class RevenueRewardEventHandler extends BaseApplicationService {
}
}
private void handleServiceProviderManagementFee(Long orgId,
String serviceProviderName,
BigDecimal franchiseFee,
RewardTypeEnum rewardType) {
//服务商管理费
RewardConfig rewardConfig = rewardConfigQueryService.queryByRewardType(rewardType);
RevenueReward revenueReward = revenueRewardQueryService.queryByOrgId(orgId);
BigDecimal revenue = RewardConfig.calculatePct(franchiseFee, new BigDecimal(rewardConfig.getValue()));
//线下收益
RevenueRewardRecord revenueRewardRecord = RevenueRewardRecord.build(TradeTypeEnum.SERVICE_PROVIDER_RECOMMEND_FEE, TradeSceneEnum.OFFLINE,
revenue, new BigDecimal(rewardConfig.getValue()), BigDecimal.ZERO, revenue, franchiseFee);
revenueRewardRecord.handleContent(Collections.singletonList(serviceProviderName));
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.getAllRecoveryRequirement()) {
revenueRewardApplicationService.pipeLineRevenue(orgId, revenueRewardRecord, TradeSceneEnum.OFFLINE);
}
//发送事件 检查是否满足回本要求
RevenueRewardUpdatedEvent reEvent = new RevenueRewardUpdatedEvent(revenueReward.getId());
this.sendEvent(reEvent);
}
@Subscribe
private void handle(RevenueRewardUpdatedEvent event) {
try {
RevenueReward revenueReward = revenueRewardDao.selectById(event.getId());
//满足回本条件处理 服务商
if (IdentityTypeEnum.ORGANIZATION.equals(revenueReward.getIdentityType()) && !revenueReward.getRecoveryRequirement()) {
if (IdentityTypeEnum.ORGANIZATION.equals(revenueReward.getIdentityType()) && (!revenueReward.getHalfRecoveryRequirement() || !revenueReward.getAllRecoveryRequirement())) {
BigDecimal franchiseFee = null;
Organization organization = organizationDao.selectById(revenueReward.getOrgId());
if (OrganizationTypeEnum.OPERATION_CENTER.equals(organization.getType())) {
@ -122,13 +149,24 @@ public class RevenueRewardEventHandler extends BaseApplicationService {
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);
if (!revenueReward.getHalfRecoveryRequirement()) {
RewardConfig rewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.SERVICE_PROVIDER_RECOVERY_HALF_PCT);
BigDecimal recoveredAmount = rewardConfig.calculateReward(franchiseFee);
if (Objects.nonNull(revenueReward.getRecoveredAmount()) && revenueReward.getRecoveredAmount().compareTo(recoveredAmount) > 0) {
//达到回本一半条件
revenueReward.setHalfRecoveryRequirement(true);
BaseDomainEvent filledEvent = revenueRewardAggregate.fillRecoveryRequirement(revenueReward);
this.sendEvent(filledEvent);
}
}
if (!revenueReward.getAllRecoveryRequirement()) {
RewardConfig rewardConfig = rewardConfigQueryService.queryByRewardType(RewardTypeEnum.SERVICE_PROVIDER_RECOVERY_ALL_PCT);
BigDecimal recoveredAmount = rewardConfig.calculateReward(franchiseFee);
if (Objects.nonNull(revenueReward.getRecoveredAmount()) && revenueReward.getRecoveredAmount().compareTo(recoveredAmount) > 0) {
//达到全回本条件
revenueReward.setAllRecoveryRequirement(true);
revenueRewardAggregate.fillRecoveryRequirement(revenueReward);
}
}
}
}
@ -136,4 +174,30 @@ public class RevenueRewardEventHandler extends BaseApplicationService {
log.error("收益信息更新事件处理异常", e);
}
}
@Subscribe
private void handle(RevenueRewardRecoveryRequirementFilledEvent event) {
try {
//回本一半后直推推荐的区域服务商可以拿到剩余20%的入驻费
RevenueReward revenueReward = revenueRewardDao.selectById(event.getId());
FranchiseFeeProfitManagement franchiseFeeProfitManagement = franchiseFeeProfitManagementQueryService.queryByOrg(revenueReward.getOrgId());
if (Objects.nonNull(franchiseFeeProfitManagement) && !franchiseFeeProfitManagement.getIsFinish()) {
Organization organization = organizationDao.selectById(revenueReward.getOrgId());
Long recommendServiceProviderOrgId = null;
BigDecimal franchiseFee = null;
if (OrganizationTypeEnum.OPERATION_CENTER.equals(organization.getType())) {
OperationCenter operationCenter = operationCenterQueryService.queryByOrg(revenueReward.getOrgId());
franchiseFee = operationCenter.getFranchiseFee();
recommendServiceProviderOrgId = operationCenter.getRecommendServiceProviderOrgId();
} else if (OrganizationTypeEnum.STORE.equals(organization.getType())) {
Store store = storeQueryService.queryByOrg(revenueReward.getOrgId());
franchiseFee = store.getFranchiseFee();
recommendServiceProviderOrgId = store.getRecommendServiceProviderOrgId();
}
handleServiceProviderManagementFee(recommendServiceProviderOrgId, organization.getFullName(), franchiseFee, RewardTypeEnum.OPERATING_RECOMMEND_20);
}
} catch (Exception e) {
log.error("服务商回本事件处理异常");
}
}
}

26
dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/ffpm/FranchiseFeeProfitManagementApplicationService.java

@ -0,0 +1,26 @@
package com.qniao.dam.application.service.ffpm;
import com.qniao.dam.domain.aggregate.ffpm.FranchiseFeeProfitManagementAggregate;
import com.qniao.dam.domain.aggregate.ffpm.entity.FranchiseFeeProfitManagement;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class FranchiseFeeProfitManagementApplicationService {
@Resource
private FranchiseFeeProfitManagementAggregate franchiseFeeProfitManagementAggregate;
public void create(FranchiseFeeProfitManagement franchiseFeeProfitManagement) {
franchiseFeeProfitManagementAggregate.create(franchiseFeeProfitManagement);
}
public void edit(FranchiseFeeProfitManagement franchiseFeeProfitManagement) {
franchiseFeeProfitManagementAggregate.edit(franchiseFeeProfitManagement);
}
public void delete(Long id) {
franchiseFeeProfitManagementAggregate.delete(id);
}
}

31
dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/ffpm/FranchiseFeeProfitManagementAggregate.java

@ -0,0 +1,31 @@
package com.qniao.dam.domain.aggregate.ffpm;
import com.qniao.dam.domain.aggregate.ffpm.entity.FranchiseFeeProfitManagement;
import com.qniao.dam.domain.aggregate.ffpm.repository.FranchiseFeeProfitManagementRepository;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* 入驻费分佣管理
*
* @date 2025/04/22
*/
@Service
public class FranchiseFeeProfitManagementAggregate {
@Resource
private FranchiseFeeProfitManagementRepository repository;
public void create(FranchiseFeeProfitManagement entity) {
repository.save(entity);
}
public void edit(FranchiseFeeProfitManagement entity) {
repository.save(entity);
}
public void delete(Long id) {
repository.delete(id);
}
}

12
dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/ffpm/repository/FranchiseFeeProfitManagementRepository.java

@ -0,0 +1,12 @@
package com.qniao.dam.domain.aggregate.ffpm.repository;
import com.qniao.dam.domain.aggregate.ffpm.entity.FranchiseFeeProfitManagement;
import com.qniao.domain.Repository;
/**
* 入驻费分佣管理
*
* @date 2025/04/22
*/
public interface FranchiseFeeProfitManagementRepository extends Repository<FranchiseFeeProfitManagement, Long> {
}

12
dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/ffpm/FranchiseFeeProfitManagementDao.java

@ -0,0 +1,12 @@
package com.qniao.dam.infrastructure.persistent.dao.ffpm;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qniao.dam.domain.aggregate.ffpm.entity.FranchiseFeeProfitManagement;
/**
* 入驻费分佣管理
*
* @date 2025/04/22
*/
public interface FranchiseFeeProfitManagementDao extends BaseMapper<FranchiseFeeProfitManagement> {
}

41
dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/FranchiseFeeProfitManagementRepositoryImpl.java

@ -0,0 +1,41 @@
package com.qniao.dam.infrastructure.persistent.repository.impl;
import com.qniao.dam.domain.aggregate.ffpm.entity.FranchiseFeeProfitManagement;
import com.qniao.dam.domain.aggregate.ffpm.repository.FranchiseFeeProfitManagementRepository;
import com.qniao.dam.infrastructure.persistent.dao.ffpm.FranchiseFeeProfitManagementDao;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Objects;
/**
* 入驻费分佣管理
*
* @date 2025/04/22
*/
@Service
public class FranchiseFeeProfitManagementRepositoryImpl implements FranchiseFeeProfitManagementRepository {
@Resource
private FranchiseFeeProfitManagementDao dao;
@Override
public FranchiseFeeProfitManagement load(Long id) {
return dao.selectById(id);
}
@Override
public Long save(FranchiseFeeProfitManagement entity) {
if (Objects.isNull(entity) || Objects.isNull(dao.selectById(entity.getId()))) {
dao.insert(entity);
} else {
dao.updateById(entity);
}
return entity.getId();
}
@Override
public void delete(Long id) {
dao.deleteById(id);
}
}

8
dating-agency-mall-server/src/main/java/com/qniao/dam/query/ffpm/FranchiseFeeProfitManagementQueryService.java

@ -0,0 +1,8 @@
package com.qniao.dam.query.ffpm;
import com.qniao.dam.domain.aggregate.ffpm.entity.FranchiseFeeProfitManagement;
public interface FranchiseFeeProfitManagementQueryService {
FranchiseFeeProfitManagement queryByOrg(Long orgId);
}

23
dating-agency-mall-server/src/main/java/com/qniao/dam/query/ffpm/impl/FranchiseFeeProfitManagementQueryServiceImpl.java

@ -0,0 +1,23 @@
package com.qniao.dam.query.ffpm.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qniao.dam.domain.aggregate.ffpm.entity.FranchiseFeeProfitManagement;
import com.qniao.dam.infrastructure.persistent.dao.ffpm.FranchiseFeeProfitManagementDao;
import com.qniao.dam.query.ffpm.FranchiseFeeProfitManagementQueryService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class FranchiseFeeProfitManagementQueryServiceImpl implements FranchiseFeeProfitManagementQueryService {
@Resource
private FranchiseFeeProfitManagementDao franchiseFeeProfitManagementDao;
@Override
public FranchiseFeeProfitManagement queryByOrg(Long orgId) {
return franchiseFeeProfitManagementDao.selectOne(new LambdaQueryWrapper<FranchiseFeeProfitManagement>()
.eq(FranchiseFeeProfitManagement::getOrgId, orgId)
.last("limit 1"));
}
}
Loading…
Cancel
Save