Pārlūkot izejas kodu

店铺分销提成

zoujiajian 2 gadi atpakaļ
vecāks
revīzija
9585e4b0f1
22 mainītis faili ar 623 papildinājumiem un 41 dzēšanām
  1. 3 0
      netflix-dao/src/main/java/com/cyksj/mapper/UserMapper.java
  2. 13 0
      netflix-dao/src/main/java/com/cyksj/mapper/shop/YhShopDistributeOrdersDeductPointsRecordMapper.java
  3. 13 0
      netflix-dao/src/main/java/com/cyksj/mapper/shop/YhShopUserDistributeBusinessOrderDonRecordMapper.java
  4. 13 0
      netflix-dao/src/main/java/com/cyksj/mapper/shop/YhShopUserDistributeSharedMapper.java
  5. 22 0
      netflix-dao/src/main/java/com/cyksj/model/entity/YhShopDistributeOrdersDeductPointsRecord.java
  6. 5 0
      netflix-dao/src/main/java/com/cyksj/model/entity/YhShopGoodsRate.java
  7. 77 0
      netflix-dao/src/main/java/com/cyksj/model/entity/YhShopUserDistributeBusinessOrderDonRecord.java
  8. 35 0
      netflix-dao/src/main/java/com/cyksj/model/entity/YhShopUserDistributeShared.java
  9. 8 0
      netflix-dao/src/main/java/com/cyksj/model/manage/entity/YhShopDistributeWaitingSendPoints.java
  10. 10 0
      netflix-service/src/main/java/com/cyksj/service/distribute/UserBusinessFrontService.java
  11. 179 1
      netflix-service/src/main/java/com/cyksj/service/distribute/impl/UserBusinessFrontServiceImpl.java
  12. 1 1
      netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsYhShopCommonServiceImpl.java
  13. 30 8
      netflix-service/src/main/java/com/cyksj/service/mange/impl/CmsOrderDonServiceImpl.java
  14. 4 5
      netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java
  15. 19 0
      netflix-service/src/main/java/com/cyksj/service/shop/YhShopDistributeService.java
  16. 1 1
      netflix-service/src/main/java/com/cyksj/service/shop/YhShopUserPlatDistributeRateService.java
  17. 1 2
      netflix-service/src/main/java/com/cyksj/service/shop/YhShopUserPlatDistributeRateServiceImpl.java
  18. 150 0
      netflix-service/src/main/java/com/cyksj/service/shop/impl/YhShopDistributeServiceImpl.java
  19. 5 0
      netflix-service/src/main/java/com/cyksj/service/user/UserBenefitsService.java
  20. 34 0
      netflix-service/src/main/java/com/cyksj/service/user/impl/UserBenefitsServiceImpl.java
  21. 0 10
      netflix-service/src/main/java/com/cyksj/service/yhShop/YhShopDistributeService.java
  22. 0 13
      netflix-service/src/main/java/com/cyksj/service/yhShop/YhShopDistributeServiceImpl.java

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/mapper/UserMapper.java

@@ -53,4 +53,7 @@ public interface UserMapper extends BaseMapper<User> {
 
     @Update("update user set yhs_money = yhs_money + #{addYhsMoney} where id = #{userId} and yhs_money = #{yhsMoney}")
     Integer addYhsMoney(@Param("userId") Long id, @Param("yhsMoney") BigDecimal yhsMoney, @Param("addYhsMoney") BigDecimal addYhsMoney);
+
+    @Update("update user set yhs_money = yhs_money - #{deductMoney} where id = #{shopUserId} and yhs_money = #{yhsMoney}")
+    Integer subYhShopUserMoney(@Param("shopUserId") Long shopUserId, @Param("yhsMoney") BigDecimal yhsMoney, @Param("deductMoney") BigDecimal deductMoney);
 }

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/shop/YhShopDistributeOrdersDeductPointsRecordMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper.shop;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.YhShopDistributeOrdersDeductPointsRecord;
+
+/*
+ *项目名: yhlxj
+ *文件名: YhShopDistributeOrdersDeductPointsRecordMapper
+ *创建者: JavaZou
+ *创建时间:2023/9/20 16:30
+ */
+public interface YhShopDistributeOrdersDeductPointsRecordMapper extends BaseMapper<YhShopDistributeOrdersDeductPointsRecord> {
+}

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/shop/YhShopUserDistributeBusinessOrderDonRecordMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper.shop;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.YhShopUserDistributeBusinessOrderDonRecord;
+
+/*
+ *项目名: yhlxj
+ *文件名: YhShopUserDistributeBusinessOrderDonRecordMapper
+ *创建者: JavaZou
+ *创建时间:2023/9/20 16:09
+ */
+public interface YhShopUserDistributeBusinessOrderDonRecordMapper extends BaseMapper<YhShopUserDistributeBusinessOrderDonRecord> {
+}

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/shop/YhShopUserDistributeSharedMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper.shop;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.YhShopUserDistributeShared;
+
+/*
+ *项目名: yhlxj
+ *文件名: YhShopUserDistributeSharedMapper
+ *创建者: JavaZou
+ *创建时间:2023/9/20 15:36
+ */
+public interface YhShopUserDistributeSharedMapper extends BaseMapper<YhShopUserDistributeShared> {
+}

+ 22 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/YhShopDistributeOrdersDeductPointsRecord.java

@@ -0,0 +1,22 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/*
+ *项目名: yhlxj
+ *文件名: YhShopDistributeOrdersDeductPointsRecord
+ *创建者: JavaZou
+ *创建时间:2023/9/20 16:29
+ */
+@Getter
+@Setter
+public class YhShopDistributeOrdersDeductPointsRecord extends BaseEntity{
+	private Long shopUserId;
+
+	private Long orderId;
+
+	private BigDecimal deductMoney;
+}

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/YhShopGoodsRate.java

@@ -18,5 +18,10 @@ public class YhShopGoodsRate extends BaseEntity{
 
     private Long skuId;
 
+    /**
+     * 店铺主用户id
+     */
+    private Long userId;
+
     private Integer rate;
 }

+ 77 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/YhShopUserDistributeBusinessOrderDonRecord.java

@@ -0,0 +1,77 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/*
+ *项目名: yhlxj
+ *文件名: YhShopUserDistributeBusinessOrderDonRecord
+ *创建者: JavaZou
+ *创建时间:2023/9/20 16:08
+ */
+
+@Getter
+@Setter
+public class YhShopUserDistributeBusinessOrderDonRecord extends BaseEntity {
+	/**
+	 * 商务id
+	 */
+	private Long businessId;
+
+	/**
+	 * 店铺主user_id
+	 */
+	private Long shopUserId;
+
+	/**
+	 * 产生分销订单用户id
+	 */
+	private Long userId;
+
+	/**
+	 * 首单时 座位id
+	 */
+	private Long preRelationId;
+
+	private Long orderId;
+
+	/**
+	 * 1首单,2续费
+	 */
+	private Integer orderType;
+
+	/**
+	 * 分销比例
+	 */
+	private Integer rate;
+
+	/**
+	 * 提成金额
+	 */
+	private BigDecimal takeMoney;
+
+	/**
+	 * 提成状态
+	 */
+	private Status status;
+
+	/**
+	 * 订单创建时间
+	 */
+	private Date orderCreatedTime;
+
+	@Getter
+	public enum Status {
+		success("成功"),
+		refund("失败"),
+		;
+		String desc;
+
+		Status(String desc) {
+			this.desc = desc;
+		}
+	}
+}

+ 35 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/YhShopUserDistributeShared.java

@@ -0,0 +1,35 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/*
+ *项目名: yhlxj
+ *文件名: YhShopUserDistributeShared
+ *创建者: JavaZou
+ *创建时间:2023/9/20 15:36
+ */
+@Getter
+@Setter
+public class YhShopUserDistributeShared extends BaseEntity{
+	/**
+	 * 被分享人id
+	 */
+	private Long userId;
+
+	/**
+	 * 店铺主user_id
+	 */
+	private Long shopUserId;
+
+	/**
+	 * 邀请方式备注
+	 */
+	private String remark;
+
+	/**
+	 * cps后台自定义推广链接id
+	 */
+	private Long dsPopularizeId;
+}
+

+ 8 - 0
netflix-dao/src/main/java/com/cyksj/model/manage/entity/YhShopDistributeWaitingSendPoints.java

@@ -5,6 +5,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.Date;
 
 /*
  *项目名: yhlxj
@@ -39,6 +40,13 @@ public class YhShopDistributeWaitingSendPoints extends BaseEntity {
 	 */
 	private BigDecimal refundMoney;
 
+	/**
+	 * 提成比例
+	 */
+	private Integer rate;
+
+	private Date sendTime;
+
 	private Status sendStatus;
 
 	public enum Status{

+ 10 - 0
netflix-service/src/main/java/com/cyksj/service/distribute/UserBusinessFrontService.java

@@ -16,4 +16,14 @@ public interface UserBusinessFrontService {
 	 * @param distributeRate      平台分销比例
 	 */
 	void taskDistributeRateBenefits(Long sharedId, Long businessId, Integer goodsType, OrderDon order, Integer distributeRate);
+
+	/**
+	 * 设置店铺商务的 提成
+	 * @param shopUserId 店铺主用户id
+	 * @param businessId
+	 * @param goodsType
+	 * @param order
+	 * @param distributeRate
+	 */
+	void taskYhShopDistributeRateBenefits(Long shopUserId, Long businessId, Integer goodsType, OrderDon order, Integer distributeRate);
 }

+ 179 - 1
netflix-service/src/main/java/com/cyksj/service/distribute/impl/UserBusinessFrontServiceImpl.java

@@ -4,11 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.constant.Constant;
 import com.cyksj.mapper.OrderDonMapper;
-import com.cyksj.mapper.UserRenewChangeTicketRecordMapper;
 import com.cyksj.mapper.UserDistributeSpecialMapper;
+import com.cyksj.mapper.UserRenewChangeTicketRecordMapper;
+import com.cyksj.mapper.YhShopUserDistributeBusinessRateMapper;
 import com.cyksj.mapper.manage.distribute.UserBusinessDefaultRateConfigMapper;
 import com.cyksj.mapper.manage.distribute.UserDistributeBusinessOrderDonRecordMapper;
 import com.cyksj.mapper.manage.distribute.UserDistributeBusinessRateMapper;
+import com.cyksj.mapper.shop.YhShopUserDistributeBusinessOrderDonRecordMapper;
 import com.cyksj.model.entity.*;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.distribute.UserBusinessFrontService;
@@ -46,6 +48,10 @@ public class UserBusinessFrontServiceImpl implements UserBusinessFrontService {
 
 	private final UserDistributeSpecialMapper UserDistributeSpecialMapper;
 
+	private final YhShopUserDistributeBusinessRateMapper yhShopUserDistributeBusinessRateMapper;
+
+	private final YhShopUserDistributeBusinessOrderDonRecordMapper yhShopBusinessOrderDonRecordMapper;
+
 	@Override
 	public void taskDistributeRateBenefits(Long sharedId, Long businessId, Integer goodsType, OrderDon order, Integer distributeRate) {
 		LambdaQueryWrapper<UserDistributeBusinessRate> wrapper = Wrappers.lambdaQuery(UserDistributeBusinessRate.class)
@@ -163,6 +169,117 @@ public class UserBusinessFrontServiceImpl implements UserBusinessFrontService {
 		}
 	}
 
+	/**
+	 * 店铺商务提成
+	 */
+	@Override
+	public void taskYhShopDistributeRateBenefits(Long shopUserId, Long businessId, Integer goodsType, OrderDon order, Integer distributeRate) {
+		LambdaQueryWrapper<YhShopUserDistributeBusinessRate> wrapper = Wrappers.lambdaQuery(YhShopUserDistributeBusinessRate.class)
+				.eq(YhShopUserDistributeBusinessRate::getBusinessId, businessId)
+				.eq(YhShopUserDistributeBusinessRate::getGoodsId, order.getGoodsId())
+				.last("limit 1");
+		//虚拟平台
+		if (goodsType == 1) {
+			wrapper.eq(YhShopUserDistributeBusinessRate::getSkuId, order.getSkuId());
+		}
+		YhShopUserDistributeBusinessRate businessRate = yhShopUserDistributeBusinessRateMapper.selectOne(wrapper);
+		if (businessRate != null) {
+			if (order.getOrderType() == 1) {
+				//实物商务分销提成 无首单
+				if (goodsType != 1) {
+					YhShopUserDistributeBusinessOrderDonRecord record = saveYhShopBusinessTakeMoneyRecord(order, businessId, shopUserId, businessRate.getFirstOrderRate(), null, distributeRate);
+					if (record == null) {
+						return;
+					}
+					yhShopBusinessOrderDonRecordMapper.insert(record);
+					log.info("开始给店铺商务人员:{}分配分销人:{}分销的用户:{}实物:{}提成", businessId, shopUserId, order.getUserId(), order.getId());
+					return;
+				}
+				//首单
+				log.info("店铺商务首单orderId:{}分销分配提成开始", order.getId());
+				//用户之前是否下过单
+				Integer count = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
+						.eq(OrderDon::getUserId, order.getUserId())
+						.ne(OrderDon::getId, order.getId()).notIn(OrderDon::getStatus, Constant.noOrderAllStatus));
+				if (count == 0) {
+					//是否享受过该用户带来的首单 提成
+					YhShopUserDistributeBusinessOrderDonRecord record = yhShopBusinessOrderDonRecordMapper.selectOne(Wrappers.lambdaQuery(YhShopUserDistributeBusinessOrderDonRecord.class)
+							.eq(YhShopUserDistributeBusinessOrderDonRecord::getBusinessId, businessId)
+							.eq(YhShopUserDistributeBusinessOrderDonRecord::getUserId, order.getUserId())
+							.eq(YhShopUserDistributeBusinessOrderDonRecord::getOrderType, 1)
+							.eq(YhShopUserDistributeBusinessOrderDonRecord::getStatus, UserDistributeBusinessOrderDonRecord.Status.success)
+							.last("limit 1"));
+					if (record == null) {
+						try {
+							boolean isSuccess = redisService.setNx(RedisService.key.BUSINESS_FIRST_ORDER_USER_KEY.getNameFormat(order.getUserId()), businessId, RedisService.key.BUSINESS_FIRST_ORDER_USER_KEY.getTimeout());
+							if (isSuccess) {
+								//首单虚物规格 提成
+								record = saveYhShopBusinessTakeMoneyRecord(order, businessId, shopUserId, businessRate.getFirstOrderRate(), null, distributeRate);
+								if (record == null) {
+									return;
+								}
+								yhShopBusinessOrderDonRecordMapper.insert(record);
+								log.info("开始给店铺商务人员:{}分配分销人:{}分销的用户:{}首单:{}提成", businessId, shopUserId, order.getUserId(), order.getId());
+								redisService.del(RedisService.key.BUSINESS_FIRST_ORDER_USER_KEY.getNameFormat(order.getUserId()));
+							}
+						} catch (DuplicateKeyException e) {
+							log.error("店铺商务:{}重复获取分销人:{}分销的用户:{}首单:{}提成", businessId, businessId, order.getUserId(), order.getId());
+						}
+					}
+				}
+			}
+			//续费
+			if (order.getOrderType() == 2) {
+				log.info("店铺商务首单续费分销分配提成开始");
+				//是否享受过该用户首单 提成
+				YhShopUserDistributeBusinessOrderDonRecord record = yhShopBusinessOrderDonRecordMapper.selectOne(Wrappers.lambdaQuery(YhShopUserDistributeBusinessOrderDonRecord.class)
+						.eq(YhShopUserDistributeBusinessOrderDonRecord::getBusinessId, businessId)
+						.eq(YhShopUserDistributeBusinessOrderDonRecord::getUserId, order.getUserId())
+						.eq(YhShopUserDistributeBusinessOrderDonRecord::getOrderType, 1)
+						.eq(YhShopUserDistributeBusinessOrderDonRecord::getStatus, UserDistributeBusinessOrderDonRecord.Status.success)
+						.last("limit 1"));
+				if (record != null) {
+					log.info("开始给店铺商务人员:{}分配用户:{}首单续费提成", businessId, order.getUserId());
+					//是否更换过车票规格座位号
+					Long preRelationId = record.getPreRelationId();
+					Long relationId = order.getRelationId();
+					if (relationId.equals(preRelationId)) {
+						try {
+							//分配首单续费提成
+							record = saveYhShopBusinessTakeMoneyRecord(order, businessId, shopUserId, null, businessRate.getRenewOrderRate(), distributeRate);
+							if (record == null) {
+								return;
+							}
+							yhShopBusinessOrderDonRecordMapper.insert(record);
+							log.info("开始给店铺商务人员:{}分配分销人:{}分销的用户:{}续费首单:{}提成", businessId, shopUserId, order.getUserId(), order.getId());
+						} catch (DuplicateKeyException e) {
+							log.error("店铺商务:{}重复获取分销人:{}分销的用户:{}续费首单:{}提成", businessId, businessId, order.getUserId(), order.getId());
+						}
+					} else {
+						UserRenewChangeTicketRecord renewChangeTicketRecord = renewChangeTicketRecordMapper.selectOne(Wrappers.lambdaQuery(UserRenewChangeTicketRecord.class)
+								.eq(UserRenewChangeTicketRecord::getUserId, order.getUserId())
+								.eq(UserRenewChangeTicketRecord::getAfterRelationId, relationId)
+								.last("limit 1"));
+						if (renewChangeTicketRecord != null && renewChangeTicketRecord.getPreRelationId().equals(preRelationId)) {
+							try {
+								//分配首单续费更换车位后提成
+								record = saveYhShopBusinessTakeMoneyRecord(order, businessId, shopUserId, null, businessRate.getRenewOrderRate(), distributeRate);
+								if (record == null) {
+									return;
+								}
+								yhShopBusinessOrderDonRecordMapper.insert(record);
+								log.info("开始给店铺商务人员:{}分配分销人:{}分销的用户:{}续费首单:{}更换后车位提成", businessId, shopUserId, order.getUserId(), order.getId());
+							} catch (DuplicateKeyException e) {
+								log.error("店铺商务:{}重复获取分销人:{}分销的用户:{}续费首单:{}更换后车位提成", businessId, businessId, order.getUserId(), order.getId());
+							}
+						}
+					}
+
+				}
+			}
+		}
+	}
+
 
 	/**
 	 * 保存商务分配提成记录
@@ -224,4 +341,65 @@ public class UserBusinessFrontServiceImpl implements UserBusinessFrontService {
 		record.setTakeMoney(takeMoney);
 		return record;
 	}
+
+	/**
+	 * 保存店铺商务分配提成记录
+	 */
+	public YhShopUserDistributeBusinessOrderDonRecord saveYhShopBusinessTakeMoneyRecord(OrderDon order, Long businessId, Long shopUserId, Integer firstOrderRate, Integer renewOrderRate, Integer distributeRate) {
+		UserBusinessDefaultRateConfig defaultGoodsRateConfig = defaultRateConfigMapper.selectOne(Wrappers.lambdaQuery(UserBusinessDefaultRateConfig.class)
+				.eq(UserBusinessDefaultRateConfig::getGoodsId, order.getGoodsId()).last("limit 1"));
+		if (defaultGoodsRateConfig == null) {
+			log.info("系统默认商务分销配置未配置,businessId:{},orderId:{}", businessId, order.getId());
+			return null;
+		}
+		YhShopUserDistributeBusinessOrderDonRecord record = new YhShopUserDistributeBusinessOrderDonRecord();
+		record.setBusinessId(businessId);
+		record.setUserId(order.getUserId());
+		record.setShopUserId(shopUserId);
+		record.setOrderType(order.getOrderType());
+		record.setOrderCreatedTime(order.getCreatedTime());
+		record.setOrderId(order.getId());
+		record.setPreRelationId(order.getRelationId());
+		//是否超过默认配置平台比例
+		Integer defaultGoodsRate = defaultGoodsRateConfig.getRate();
+		//首单提成比例
+		BigDecimal orderMoney = order.getMoney();
+		BigDecimal takeMoney = BigDecimal.ZERO;
+		if (firstOrderRate != null) {
+			if (distributeRate > defaultGoodsRate) {
+				if (defaultGoodsRateConfig.getIsPlatPay()) {
+					log.info("首单,平台承担商务businessId:{}配置分销者sharedId:{}超过平台goodsId:{}标准分销比例:{}", businessId, shopUserId, order.getGoodsId(), defaultGoodsRate);
+				} else {
+					firstOrderRate -= distributeRate - defaultGoodsRate;
+					log.info("商务businessId:{}配置分销者sharedId:{}比例超过标准比例,可获取首单提成比例为:{}", businessId, shopUserId, firstOrderRate);
+					if (firstOrderRate <= 0) {
+						log.info("商务businessId:{}获得分销者sharedId:{}首单提成比例不大于0", businessId, shopUserId);
+						return null;
+					}
+				}
+			}
+			record.setRate(firstOrderRate);
+			BigDecimal firstRate = BigDecimal.valueOf(firstOrderRate).divide(BigDecimal.valueOf(100));
+			takeMoney = orderMoney.multiply(firstRate);
+		}
+		if (renewOrderRate != null) {
+			if (distributeRate > defaultGoodsRate) {
+				if (defaultGoodsRateConfig.getIsPlatPay()) {
+					log.info("首单续费,平台承担商务businessId:{}配置分销者sharedId:{}超过平台goodsId:{}标准分销比例:{}", businessId, shopUserId, order.getGoodsId(), defaultGoodsRate);
+				} else {
+					renewOrderRate -= distributeRate - defaultGoodsRate;
+					log.info("商务businessId:{}配置分销者sharedId:{}比例超过标准比例,可获取首单续费提成比例为:{}", businessId, shopUserId, renewOrderRate);
+					if (renewOrderRate <= 0) {
+						log.info("商务businessId:{}获得分销者sharedId:{}首单续费提成比例不大于0", businessId, shopUserId);
+						return null;
+					}
+				}
+			}
+			record.setRate(renewOrderRate);
+			BigDecimal renewRate = BigDecimal.valueOf(renewOrderRate).divide(BigDecimal.valueOf(100));
+			takeMoney = orderMoney.multiply(renewRate);
+		}
+		record.setTakeMoney(takeMoney);
+		return record;
+	}
 }

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsYhShopCommonServiceImpl.java

@@ -15,7 +15,7 @@ import com.cyksj.model.request.DistributeApplyMoneyReq;
 import com.cyksj.model.request.ShopGeneralGoodsRateReq;
 import com.cyksj.model.request.YhShopVerifyReq;
 import com.cyksj.model.views.GoodsDonSkuView;
-import com.cyksj.service.YhShopUserPlatDistributeRateService;
+import com.cyksj.service.shop.YhShopUserPlatDistributeRateService;
 import com.cyksj.service.mange.CmsYhShopCommonService;
 import com.cyksj.service.mange.business.UserBusinessRateService;
 import com.cyksj.service.user.UserBenefitsService;

+ 30 - 8
netflix-service/src/main/java/com/cyksj/service/mange/impl/CmsOrderDonServiceImpl.java

@@ -32,6 +32,7 @@ import com.cyksj.mapper.manage.distribute.UserDistributeBusinessOrderDonRecordMa
 import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
 import com.cyksj.mapper.manage.distribute.equipment.EquipmentUserDistributeTransportBenefitsMapper;
 import com.cyksj.mapper.manage.sys.WorkOrderMapper;
+import com.cyksj.mapper.shop.YhShopUserDistributeBusinessOrderDonRecordMapper;
 import com.cyksj.mapper.stock.GoodsSkuStockRelateMapper;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.excel.ExcelOrderDonInfo;
@@ -51,6 +52,7 @@ import com.cyksj.service.order.UserRealOrderBenefitsService;
 import com.cyksj.service.paypal.PayPalService;
 import com.cyksj.service.relation.GroupRelationClearService;
 import com.cyksj.service.relation.GroupsRelationExpiryRecordService;
+import com.cyksj.service.shop.YhShopDistributeService;
 import com.cyksj.service.stripe.StripeService;
 import com.cyksj.service.user.UserBenefitsService;
 import com.cyksj.service.wechat.WeChatService;
@@ -148,6 +150,9 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
 
     private final GroupsRelationExpiryRecordService groupsRelationExpiryRecordService;
 
+    private final YhShopDistributeService yhShopDistributeService;
+
+    private final YhShopUserDistributeBusinessOrderDonRecordMapper yhShopBusinessOrderDonRecordMapper;
     private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
 
     @Override
@@ -690,15 +695,32 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
                 //余额退款不需要扣除积分
                 //分销提成积分扣除
                 deductDsPoints(orderDon);
+                //店铺 分销提成金额扣除
+                yhShopDistributeService.deductDsMoney(orderDon);
+            }
+
+            if (orderDon.getIsFixedDistribute()) {
+                //商务提成 因订单退款去掉
+                UserDistributeBusinessOrderDonRecord record = businessOrderDonRecordMapper.selectOne(Wrappers.lambdaQuery(UserDistributeBusinessOrderDonRecord.class)
+                        .eq(UserDistributeBusinessOrderDonRecord::getOrderId, orderDon.getId())
+                        .eq(UserDistributeBusinessOrderDonRecord::getStatus, UserDistributeBusinessOrderDonRecord.Status.success)
+                        .last("limit 1"));
+                if (record != null) {
+                    record.setStatus(UserDistributeBusinessOrderDonRecord.Status.refund);
+                    businessOrderDonRecordMapper.updateById(record);
+                }
             }
-            //商务提成 因订单退款去掉
-            UserDistributeBusinessOrderDonRecord record = businessOrderDonRecordMapper.selectOne(Wrappers.lambdaQuery(UserDistributeBusinessOrderDonRecord.class)
-                    .eq(UserDistributeBusinessOrderDonRecord::getOrderId, orderDon.getId())
-                    .eq(UserDistributeBusinessOrderDonRecord::getStatus, UserDistributeBusinessOrderDonRecord.Status.success)
-                    .last("limit 1"));
-            if (record != null) {
-                record.setStatus(UserDistributeBusinessOrderDonRecord.Status.refund);
-                businessOrderDonRecordMapper.updateById(record);
+
+            //店铺商务提成
+            if (orderDon.getYhsId() != null && orderDon.getYhsId() > 0) {
+                YhShopUserDistributeBusinessOrderDonRecord shop_record = yhShopBusinessOrderDonRecordMapper.selectOne(Wrappers.lambdaQuery(YhShopUserDistributeBusinessOrderDonRecord.class)
+                        .eq(YhShopUserDistributeBusinessOrderDonRecord::getOrderId, orderDon.getId())
+                        .eq(YhShopUserDistributeBusinessOrderDonRecord::getStatus, YhShopUserDistributeBusinessOrderDonRecord.Status.success)
+                        .last("limit 1"));
+                if (shop_record != null) {
+                    shop_record.setStatus(YhShopUserDistributeBusinessOrderDonRecord.Status.refund);
+                    yhShopBusinessOrderDonRecordMapper.updateById(shop_record);
+                }
             }
             //是否是优惠加购关联订单
             if (orderDon.getIsDp()) {

+ 4 - 5
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -74,6 +74,7 @@ import com.cyksj.service.pay.AliPayCommonService;
 import com.cyksj.service.relation.GroupRelationClearService;
 import com.cyksj.service.relation.GroupRelationFrontService;
 import com.cyksj.service.relation.GroupsRelationExpiryRecordService;
+import com.cyksj.service.shop.YhShopDistributeService;
 import com.cyksj.service.shop.YhShopFrontService;
 import com.cyksj.service.sys.SysConfigService;
 import com.cyksj.service.telegram.TelegramService;
@@ -223,6 +224,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 
 	private final YhShopFrontService yhShopFrontService;
 
+	private final YhShopDistributeService yhShopDistributeService;
+
 	private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
 
 	@Transactional(rollbackFor = Throwable.class)
@@ -603,7 +606,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			}
 			//店铺分销 存在
 			if (order.getYhsId() != null && order.getYhsId() > 0) {
-				TASK_POOL.execute(() -> yhShopDistributeWaitingSendPointsRecord(order));
+				TASK_POOL.execute(() -> yhShopDistributeService.distributeWaitingSendPointsRecord(order));
 			}
 			if (goodsDon.getType() == 1) {
 				//无车队,新增车队
@@ -652,10 +655,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		}
 	}
 
-	private void yhShopDistributeWaitingSendPointsRecord(OrderDon order) {
-
-	}
-
 	@Override
 	public List<RealGoodsInterestUser> selectNoPaymentRealGoods() {
 		return orderDonMapper.selectNoPaymentRealGoods();

+ 19 - 0
netflix-service/src/main/java/com/cyksj/service/shop/YhShopDistributeService.java

@@ -0,0 +1,19 @@
+package com.cyksj.service.shop;
+
+import com.cyksj.model.entity.OrderDon;
+
+/*
+ *项目名: yhlxj
+ *文件名: YhShopDistributeService
+ *创建者: JavaZou
+ *创建时间:2023/9/20 15:30
+ */
+public interface YhShopDistributeService {
+	void distributeWaitingSendPointsRecord(OrderDon order);
+
+	/**
+	 * 订单退款 扣除分销提成
+	 * @param orderDon
+	 */
+	void deductDsMoney(OrderDon orderDon);
+}

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/YhShopUserPlatDistributeRateService.java → netflix-service/src/main/java/com/cyksj/service/shop/YhShopUserPlatDistributeRateService.java

@@ -1,4 +1,4 @@
-package com.cyksj.service;
+package com.cyksj.service.shop;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.cyksj.model.entity.YhShopUserPlatDistributeRate;

+ 1 - 2
netflix-service/src/main/java/com/cyksj/service/mange/goods/YhShopUserPlatDistributeRateServiceImpl.java → netflix-service/src/main/java/com/cyksj/service/shop/YhShopUserPlatDistributeRateServiceImpl.java

@@ -1,9 +1,8 @@
-package com.cyksj.service.mange.goods;
+package com.cyksj.service.shop;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cyksj.mapper.YhShopUserPlatDistributeRateMapper;
 import com.cyksj.model.entity.YhShopUserPlatDistributeRate;
-import com.cyksj.service.YhShopUserPlatDistributeRateService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 

+ 150 - 0
netflix-service/src/main/java/com/cyksj/service/shop/impl/YhShopDistributeServiceImpl.java

@@ -0,0 +1,150 @@
+package com.cyksj.service.shop.impl;
+
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.mapper.YhShopUserPlatDistributeRateMapper;
+import com.cyksj.mapper.shop.YhShopDistributeWaitingSendPointsMapper;
+import com.cyksj.mapper.shop.YhShopMapper;
+import com.cyksj.mapper.shop.YhShopUserDistributeSharedMapper;
+import com.cyksj.model.entity.DistributeWaitingSendPoints;
+import com.cyksj.model.entity.OrderDon;
+import com.cyksj.model.entity.YhShopUserDistributeShared;
+import com.cyksj.model.entity.YhShopUserPlatDistributeRate;
+import com.cyksj.model.manage.entity.YhShop;
+import com.cyksj.model.manage.entity.YhShopDistributeWaitingSendPoints;
+import com.cyksj.service.distribute.UserBusinessFrontService;
+import com.cyksj.service.shop.YhShopDistributeService;
+import com.cyksj.service.user.UserBenefitsService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.Optional;
+
+/*
+ *项目名: yhlxj
+ *文件名: YhShopDistributeServiceImpl
+ *创建者: JavaZou
+ *创建时间:2023/9/20 15:30
+ */
+@Service
+@RequiredArgsConstructor
+@Slf4j
+public class YhShopDistributeServiceImpl implements YhShopDistributeService {
+	private final YhShopUserDistributeSharedMapper yhShopUserDistributeSharedMapper;
+
+	private final YhShopMapper yhShopMapper;
+
+	private final YhShopUserPlatDistributeRateMapper yhShopUserPlatDistributeRateMapper;
+
+	private final YhShopDistributeWaitingSendPointsMapper yhShopDistributeWaitingSendPointsMapper;
+
+	private final UserBusinessFrontService userBusinessFrontService;
+
+	private final UserBenefitsService userBenefitsService;
+	@Override
+	public void distributeWaitingSendPointsRecord(OrderDon order) {
+		BigDecimal orderMoney = order.getMoney();
+		if (orderMoney.compareTo(BigDecimal.ZERO) == 0) {
+			return;
+		}
+		BigDecimal returnMoney;
+		Long businessId;
+		YhShopUserDistributeShared yhShopUserDistributeShared = yhShopUserDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(YhShopUserDistributeShared.class).eq(YhShopUserDistributeShared::getUserId, order.getUserId()).last("limit 1"));
+		if (yhShopUserDistributeShared != null) {
+			Long shopUserId = yhShopUserDistributeShared.getShopUserId();
+			YhShop yhShop = yhShopMapper.selectById(order.getYhsId());
+			if (yhShop == null) {
+				log.info("订单orderId:{}店铺yhs_id:{}对应的店铺不存在", order.getId(), order.getYhsId());
+				return;
+			}
+			YhShopDistributeWaitingSendPoints distributeWaitingSendPoints = new YhShopDistributeWaitingSendPoints();
+			distributeWaitingSendPoints.setOrderId(order.getId());
+			distributeWaitingSendPoints.setUserId(order.getUserId());
+
+
+			distributeWaitingSendPoints.setShopUserId(shopUserId);
+			//是否配置了对应平台比例
+			YhShopUserPlatDistributeRate yhShopUserPlatDistributeRate = yhShopUserPlatDistributeRateMapper.selectOne(Wrappers.lambdaQuery(YhShopUserPlatDistributeRate.class)
+					.eq(YhShopUserPlatDistributeRate::getUserId, shopUserId)
+					.eq(YhShopUserPlatDistributeRate::getGoodsId, order.getGoodsId()).last("limit 1"));
+			if (yhShopUserPlatDistributeRate == null) {
+				log.info("未配置店铺主userId:{}对应平台goodsId:{}的比例", shopUserId, order.getGoodsId());
+				return;
+			}
+			Integer rate = yhShopUserPlatDistributeRate.getRate();
+			if (rate <= 0) {
+				log.info("配置店铺主userId:{}对应平台goodsId:{}的比例为0", shopUserId, order.getGoodsId());
+				return;
+			}
+			returnMoney = orderMoney.multiply(BigDecimal.valueOf(rate)).divide(BigDecimal.valueOf(100));
+			distributeWaitingSendPoints.setMoney(returnMoney);
+			distributeWaitingSendPoints.setSendStatus(YhShopDistributeWaitingSendPoints.Status.waiting);
+			distributeWaitingSendPoints.setSendTime(DateUtil.offsetDay(order.getPayTime(), 3));
+			distributeWaitingSendPoints.setRate(rate);
+			yhShopDistributeWaitingSendPointsMapper.insert(distributeWaitingSendPoints);
+
+			//对应商务
+			businessId = yhShop.getBusinessId();
+			if (businessId != null) {
+				userBusinessFrontService.taskYhShopDistributeRateBenefits(shopUserId, businessId, 1, order, rate);
+			}
+		}
+	}
+
+	@Override
+	public void deductDsMoney(OrderDon orderDon) {
+		if (orderDon.getYhsId() != null && orderDon.getYhsId() > 0) {
+			YhShopDistributeWaitingSendPoints distributeWaitingSendPoints = yhShopDistributeWaitingSendPointsMapper.selectOne(Wrappers.lambdaQuery(YhShopDistributeWaitingSendPoints.class).eq(YhShopDistributeWaitingSendPoints::getOrderId, orderDon.getId()).last("limit 1"));
+			if (distributeWaitingSendPoints != null) {
+				BigDecimal money = orderDon.getMoney();
+				BigDecimal refundMoney = orderDon.getRefundMoney();
+				//已发送 发送中 部分 全额退款
+				YhShopDistributeWaitingSendPoints.Status sendStatus = distributeWaitingSendPoints.getSendStatus();
+				BigDecimal take_money = distributeWaitingSendPoints.getMoney();
+				if (sendStatus == YhShopDistributeWaitingSendPoints.Status.waiting) {
+					if (refundMoney.compareTo(money) == 0) {
+						//待发送状态 全额退款
+						distributeWaitingSendPoints.setSendStatus(YhShopDistributeWaitingSendPoints.Status.close);
+						distributeWaitingSendPoints.setRefundMoney(take_money);
+						distributeWaitingSendPoints.setMoney(BigDecimal.ZERO);
+						yhShopDistributeWaitingSendPointsMapper.updateById(distributeWaitingSendPoints);
+						return;
+					}
+					Integer rate = distributeWaitingSendPoints.getRate();
+					if (rate > 0) {
+						BigDecimal needDeductMoney = refundMoney.multiply(BigDecimal.valueOf(rate).divide(BigDecimal.valueOf(100)));
+						distributeWaitingSendPoints.setRefundMoney(needDeductMoney);
+						//剩余积分
+						distributeWaitingSendPoints.setMoney(take_money.subtract(needDeductMoney));
+						yhShopDistributeWaitingSendPointsMapper.updateById(distributeWaitingSendPoints);
+					}
+				} else if (sendStatus == YhShopDistributeWaitingSendPoints.Status.success) {
+					//已发送的提成 部分退款 全额退款 需要扣除用户积分
+					//扣除固定推广者积分
+					if (refundMoney.compareTo(money) == 0) {
+						//扣除店铺主 已有的提成金额
+						userBenefitsService.deductYhShopTakeMoney(orderDon.getId(), distributeWaitingSendPoints.getShopUserId(), take_money);
+						distributeWaitingSendPoints.setRefundMoney(take_money);
+						distributeWaitingSendPoints.setMoney(BigDecimal.ZERO);
+						distributeWaitingSendPoints.setSendStatus(YhShopDistributeWaitingSendPoints.Status.close);
+						yhShopDistributeWaitingSendPointsMapper.updateById(distributeWaitingSendPoints);
+						return;
+					}
+					Integer rate = distributeWaitingSendPoints.getRate();
+					if (rate > 0) {
+						BigDecimal needDeductMoney = refundMoney.multiply(BigDecimal.valueOf(rate).divide(BigDecimal.valueOf(100)));
+						//扣除店铺主 已有的提成金额
+						userBenefitsService.deductYhShopTakeMoney(orderDon.getId(), distributeWaitingSendPoints.getShopUserId(), needDeductMoney);
+						//部分退款
+						distributeWaitingSendPoints.setRefundMoney(needDeductMoney);
+						distributeWaitingSendPoints.setMoney(take_money.subtract(needDeductMoney));
+						yhShopDistributeWaitingSendPointsMapper.updateById(distributeWaitingSendPoints);
+					}
+
+				}
+			}
+		}
+	}
+}

+ 5 - 0
netflix-service/src/main/java/com/cyksj/service/user/UserBenefitsService.java

@@ -39,4 +39,9 @@ public interface UserBenefitsService {
 	void recordBalanceBySource(Long userId, BigDecimal balance, UserBalanceSourceRecord.Source source);
 
 	void addYhsMoney(Long userId, BigDecimal money);
+
+	/**
+	 * 扣除店铺主用户 提成金额
+	 */
+	void deductYhShopTakeMoney(Long orderId, Long shopUserId, BigDecimal deductMoney);
 }

+ 34 - 0
netflix-service/src/main/java/com/cyksj/service/user/impl/UserBenefitsServiceImpl.java

@@ -5,9 +5,11 @@ import com.cyksj.common.constant.Constant;
 import com.cyksj.mapper.DistributeOrdersDeductPointsRecordMapper;
 import com.cyksj.mapper.UserBalanceSourceRecordMapper;
 import com.cyksj.mapper.UserMapper;
+import com.cyksj.mapper.shop.YhShopDistributeOrdersDeductPointsRecordMapper;
 import com.cyksj.model.entity.DistributeOrdersDeductPointsRecord;
 import com.cyksj.model.entity.User;
 import com.cyksj.model.entity.UserBalanceSourceRecord;
+import com.cyksj.model.entity.YhShopDistributeOrdersDeductPointsRecord;
 import com.cyksj.service.sms.SmsService;
 import com.cyksj.service.user.UserBenefitsService;
 import lombok.RequiredArgsConstructor;
@@ -35,6 +37,8 @@ public class UserBenefitsServiceImpl implements UserBenefitsService {
 
 	private final SmsService smsService;
 
+	private final YhShopDistributeOrdersDeductPointsRecordMapper yhShopDistributeOrdersDeductPointsRecordMapper;
+
 	@Override
 	public void deductDistributePoints(Long orderId, Long userId, BigDecimal deductPoints) {
 		if (deductPoints.compareTo(BigDecimal.ZERO) <= 0) {
@@ -144,4 +148,34 @@ public class UserBenefitsServiceImpl implements UserBenefitsService {
 			}
 		}
 	}
+
+	@Override
+	public void deductYhShopTakeMoney(Long orderId, Long shopUserId, BigDecimal deductMoney) {
+		if (deductMoney.compareTo(BigDecimal.ZERO) <= 0) {
+			return;
+		}
+		while (true) {
+			User user = userMapper.selectById(shopUserId);
+			if (user == null) break;
+			BigDecimal yhsMoney = user.getYhsMoney();
+			Integer success = userMapper.subYhShopUserMoney(shopUserId, yhsMoney, deductMoney);
+			if (success == 1){
+				//记录提成已发送后,退款后扣除用户店铺提成 记录
+				deductYhsMoneyRecord(orderId, shopUserId, deductMoney);
+				break;
+			}
+		}
+	}
+
+	private void deductYhsMoneyRecord(Long orderId, Long shopUserId, BigDecimal deductMoney) {
+		try {
+			YhShopDistributeOrdersDeductPointsRecord record = new YhShopDistributeOrdersDeductPointsRecord();
+			record.setOrderId(orderId);
+			record.setShopUserId(shopUserId);
+			record.setDeductMoney(deductMoney);
+			yhShopDistributeOrdersDeductPointsRecordMapper.insert(record);
+		} catch (DuplicateKeyException e) {
+
+		}
+	}
 }

+ 0 - 10
netflix-service/src/main/java/com/cyksj/service/yhShop/YhShopDistributeService.java

@@ -1,10 +0,0 @@
-package com.cyksj.service.yhShop;
-
-/*
- *项目名: yhlxj
- *文件名: YhShopDistributeService
- *创建者: JavaZou
- *创建时间:2023/9/19 17:05
- */
-public interface YhShopDistributeService {
-}

+ 0 - 13
netflix-service/src/main/java/com/cyksj/service/yhShop/YhShopDistributeServiceImpl.java

@@ -1,13 +0,0 @@
-package com.cyksj.service.yhShop;
-
-import org.springframework.stereotype.Service;
-
-/*
- *项目名: yhlxj
- *文件名: YhShopDistributeServiceImpl
- *创建者: JavaZou
- *创建时间:2023/9/19 17:05
- */
-@Service
-public class YhShopDistributeServiceImpl implements YhShopDistributeService{
-}