Răsfoiți Sursa

fix 设置商务提成通用比例

zoujiajian 2 ani în urmă
părinte
comite
609d48ba02

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/manage/distribute/UserDistributeBusinessGeneralRateMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper.manage.distribute;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.UserDistributeBusinessGeneralRate;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: UserDistributeBusinessGeneralRateMapper
+ * 创建者: JavaZou
+ * 创建时间:2023/11/8 14:46
+ */
+public interface UserDistributeBusinessGeneralRateMapper extends BaseMapper<UserDistributeBusinessGeneralRate> {
+}

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/manage/distribute/UserDistributeBusinessRateMapper.java

@@ -17,4 +17,6 @@ public interface UserDistributeBusinessRateMapper extends BaseMapper<UserDistrib
 	List<Long> selectNoThisGoodsDistribute(Long goodsId);
 
 	void batchInsertDistributePlatRate(@Param("list") List<UserPlatDistributeRate> part);
+
+	void insertOrUpdateBusinessGoodsSkuRate(@Param("list") List<Long> businessIds, @Param("goodsId") Long goodsId, @Param("skuId") Long skuId, @Param("firstOrderRate") Integer firstOrderRate, @Param("renewOrderRate") Integer renewOrderRate);
 }

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

@@ -0,0 +1,35 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/*
+ *项目名: netflix
+ *文件名: UserDistributeBusinessGeneralRate
+ *创建者: JavaZou
+ *创建时间:2023/11/8 14:45
+ */
+@Getter
+@Setter
+public class UserDistributeBusinessGeneralRate extends BaseEntity {
+
+	/**
+	 * 平台id
+	 */
+	private Long goodsId;
+
+	/**
+	 * 规格id
+	 */
+	private Long skuId;
+
+	/**
+	 * 首单提成比例
+	 */
+	private Integer firstOrderRate;
+
+	/**
+	 * 首单续费提成比例
+	 */
+	private Integer renewOrderRate;
+}

+ 63 - 0
netflix-dao/src/main/java/com/cyksj/model/views/UserDistributeBusinessGeneralRateView.java

@@ -0,0 +1,63 @@
+package com.cyksj.model.views;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: UserDistributeBusinessGeneralRateView
+ * 创建者: JavaZou
+ * 创建时间:2023/11/8 14:47
+ */
+
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.SearchBean;
+import lombok.Getter;
+import lombok.Setter;
+
+/*
+ *项目名: netflix
+ *文件名: UserDistributeBusinessRateRecordView
+ *创建者: JavaZou
+ *创建时间:2023/3/27 15:53
+ */
+@Getter
+@Setter
+@SearchBean(tables = "goods_don g left join goods_don_sku gdk on gdk.goods_id = g.id" +
+		" left join user_distribute_business_general_rate ur on ur.sku_id = gdk.id",
+		where = "g.deleted is true and g.status is true and g.is_distribute is true and gdk.status is true")
+public class UserDistributeBusinessGeneralRateView {
+	@DbField("ur.id")
+	private Long id;
+
+	/**
+	 * 平台id
+	 */
+	@DbField("g.id")
+	private Long goodsId;
+
+	@DbField("g.title")
+	private String goodsName;
+
+	/**
+	 * 规格id
+	 */
+	@DbField("gdk.id")
+	private Long skuId;
+
+	@DbField("gdk.spec_val")
+	private String specVal;
+
+	/**
+	 * 首单提成比例
+	 */
+	@DbField("ifnull(ur.first_order_rate,0)")
+	private Integer firstOrderRate;
+
+	/**
+	 * 首单续费提成比例
+	 */
+	@DbField("ifnull(ur.renew_order_rate,0)")
+	private Integer renewOrderRate;
+
+	@DbField("g.type")
+	private Integer type;
+}
+

+ 13 - 1
netflix-dao/src/main/resources/mapper/UserDistributeBusinessRateMapper.xml

@@ -10,7 +10,19 @@
             (#{item.distributeId},#{item.goodsId},#{item.rate},#{item.secondRate},now(),now())
         </foreach>
         ON DUPLICATE KEY UPDATE rate = VALUES(rate)
-</insert>
+    </insert>
+
+    <insert id="insertOrUpdateBusinessGoodsSkuRate">
+        insert into
+        user_distribute_business_rate(`distribute_id`,`goods_id`,`sku_id`,`first_order_rate`,`renew_order_rate`,`created_time`,`update_time`)
+        values
+        <foreach collection="list" item="item" separator=",">
+            (#{item},#{goodsId},#{skuId},#{firstOrderRate},#{renewOrderRate},now(),now())
+        </foreach>
+        ON DUPLICATE KEY UPDATE
+        first_order_rate = VALUES(first_order_rate),
+        renew_order_rate = VALUES(renew_order_rate)
+    </insert>
 
     <select id="selectNoThisGoodsDistribute" resultType="java.lang.Long">
         select distinct ud.id from user_distribute ud left join user_plat_distribute_rate ur

+ 70 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/distribute/DistributeController.java

@@ -51,6 +51,7 @@ import javax.validation.constraints.NotNull;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
 /*
@@ -107,6 +108,8 @@ public class DistributeController {
 
 	private final UserDistributeRuleOrderRecordMapper userDistributeRuleOrderRecordMapper;
 
+	private final UserDistributeBusinessGeneralRateMapper businessGeneralRateMapper;
+
 	/**
 	 * 添加固定推广者
 	 */
@@ -919,6 +922,73 @@ public class DistributeController {
 		return GatewayResponse.SUCCESS.newBuilder().toResult(collect);
 	}
 
+	/**
+	 * 针对商务
+	 * 获取商务 分销平台通用比例
+	 */
+	@GetMapping("/get/business/general/rate")
+	public Result<List<UserDistributeBusinessGeneralRateView>> getBusinessGeneralRate() {
+		List<UserDistributeBusinessGeneralRateView> userDistributeBusinessGeneralRateViews = beanSearcher.searchAll(UserDistributeBusinessGeneralRateView.class, MapUtils.flatBuilder(request.getParameterMap())
+				.field(UserDistributeBusinessGeneralRateView::getType, 2).build());
+		return GatewayResponse.SUCCESS.newBuilder().toResult(userDistributeBusinessGeneralRateViews);
+	}
+
+	/**
+	 * 编辑商务 分销平台通用比例
+	 * 商务的平台规格提成 根据这个改变
+	 */
+	@PutMapping("/put/business/general/rate")
+	@Transactional(rollbackFor = Throwable.class)
+	public Result<String> updateBusinessGeneralRate(@RequestBody List<UserDistributeBusinessGeneralRate> generalRates) {
+		List<CmsUserVO> userVOS = beanSearcher.searchAll(CmsUserVO.class, MapUtils.builder().field(CmsUserVO::getRoleNames, "商务").op(Operator.Contain).build());
+		List<Long> collect = userVOS.stream().map(CmsUserVO::getId).collect(Collectors.toList());
+		final List<Long> businessIds = collect;
+		generalRates.forEach(data -> {
+			if (data.getId() == null) {
+				try {
+					//新增
+					UserDistributeBusinessGeneralRate businessGeneralRate = new UserDistributeBusinessGeneralRate();
+					if (data.getGoodsId() == null || data.getSkuId() == null) {
+						throw BusinessRuntimeException.getInstance("缺少必要参数");
+					}
+					businessGeneralRate.setGoodsId(data.getGoodsId());
+					businessGeneralRate.setSkuId(data.getSkuId());
+					Integer firstOrderRate = Optional.ofNullable(data.getFirstOrderRate()).orElse(0);
+					businessGeneralRate.setFirstOrderRate(firstOrderRate);
+					Integer renewOrderRate = Optional.ofNullable(data.getRenewOrderRate()).orElse(0);
+					businessGeneralRate.setRenewOrderRate(renewOrderRate);
+					businessGeneralRateMapper.insert(businessGeneralRate);
+					if (CollUtil.isNotEmpty(businessIds)) {
+						userDistributeBusinessRateMapper.insertOrUpdateBusinessGoodsSkuRate(businessIds, data.getGoodsId(), data.getSkuId(), firstOrderRate, renewOrderRate);
+					}
+				} catch (DuplicateKeyException e) {
+				}
+				return;
+			}
+			UserDistributeBusinessGeneralRate dbGeneralRate = businessGeneralRateMapper.selectById(data.getId());
+			if (dbGeneralRate != null) {
+				Integer firstOrderRate_new = dbGeneralRate.getFirstOrderRate();
+				Integer renewOrderRate_new = dbGeneralRate.getRenewOrderRate();
+				AtomicBoolean is_change = new AtomicBoolean(false);
+				//需要更新首单比例
+				if (data.getFirstOrderRate() != null && dbGeneralRate.getFirstOrderRate() != data.getFirstOrderRate()) {
+					firstOrderRate_new = data.getFirstOrderRate();
+					is_change.set(true);
+				}
+				//需要更新续费比例
+				if (data.getRenewOrderRate() != null && dbGeneralRate.getRenewOrderRate() != data.getRenewOrderRate()) {
+					renewOrderRate_new = data.getRenewOrderRate();
+					is_change.set(true);
+				}
+				if (CollUtil.isNotEmpty(businessIds) && is_change.get()) {
+					//获取所有商务
+					userDistributeBusinessRateMapper.insertOrUpdateBusinessGoodsSkuRate(businessIds, data.getGoodsId(), data.getSkuId(), firstOrderRate_new, renewOrderRate_new);
+				}
+			}
+		});
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
 	/**
 	 * 是否有未配置比例的规格
 	 */