Browse Source

Merge branch 'ep_ac_reduce'

# Conflicts:
#	netflix-dao/src/main/java/com/cyksj/mapper/EquipmentActivityReduceMapper.java
#	netflix-dao/src/main/resources/mapper/EquipmentActivityReduceMapper.xml
#	netflix-service/src/main/java/com/cyksj/service/coupon/impl/EquipmentActivityReduceServiceImpl.java
#	netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java
#	netflix-web/src/main/java/com/cyksj/web/controller/goods/GoodsDonController.java
zoujiajian 2 years ago
parent
commit
8d539ed7ee

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/mapper/EquipmentActivityReduceMapper.java

@@ -13,5 +13,5 @@ import java.util.Date;
  * 创建时间:2024/1/30 11:00
  */
 public interface EquipmentActivityReduceMapper extends BaseMapper<EquipmentActivityReduce> {
-	Integer checkDupmentTimeDuration(@Param("id") Long id, @Param("st") Date st, @Param("et") Date et);
+	Integer checkRepeatTimeDuration(@Param("id") Long id, @Param("st") Date st, @Param("et") Date et);
 }

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/manage/statistics/StatisticsExportMapper.java

@@ -74,4 +74,6 @@ public interface StatisticsExportMapper{
 	List<NatureOrderDataDto> getGroupsOrderData(@Param("startDate") String startDate, @Param("endDate") String endDate);
 
 	List<MonthlyUserOrderDetailDto> getMonthlyUserOrderDetail(@Param("thisMonth") DateTime thisMonth, @Param("nextMonth") DateTime nextMonth);
+
+	Map<String, Long> getEpOrderNumsGroupSource(@Param("startDate") String startDate, @Param("endDate") String endDate);
 }

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/excel/ExcelMonthlyDistributeOrderData.java

@@ -63,6 +63,9 @@ public class ExcelMonthlyDistributeOrderData {
 	@ExcelProperty({"下单率","自然流量渠道","自然渠道下单人数"})
 	private Integer natureUserSourceOrderNum;
 
+	@ExcelProperty({"下单率","自然流量渠道","自然渠道设备下单数"})
+	private Integer natureUserSourceEpOrderNum;
+
 	@ExcelProperty({"下单率","自然流量渠道","下单率"})
 	private String natureUserSourceOrderRate;
 
@@ -72,6 +75,9 @@ public class ExcelMonthlyDistributeOrderData {
 	@ExcelProperty({"下单率","分销渠道","分销渠道下单人数"})
 	private Integer channelUserSourceOrderNum;
 
+	@ExcelProperty({"下单率","分销渠道","分销渠道设备下单数"})
+	private Integer channelUserSourceEpOrderNum;
+
 	@ExcelProperty({"下单率","分销渠道","下单率"})
 	private String channelUserSourceOrderRate;
 }

+ 2 - 2
netflix-dao/src/main/java/com/cyksj/model/views/DistributeOrdersDetailView.java

@@ -18,8 +18,8 @@ import java.util.Date;
  */
 @Getter
 @Setter
-@SearchBean(tables = "distribute_waiting_send_points dp left join order_don od on od.id = dp.order_id" +
-		" left join user u on u.id = dp.user_id" +
+@SearchBean(tables = "distribute_waiting_send_points dp inner join order_don od on od.id = dp.order_id" +
+		" inner join user u on u.id = dp.user_id" +
 		" left join goods_don gd on gd.id = od.goods_id")
 public class DistributeOrdersDetailView {
 	@DbField("u.nickname")

+ 7 - 2
netflix-dao/src/main/java/com/cyksj/model/views/RegisterDistributeOrdersDetailView.java

@@ -18,8 +18,7 @@ import java.util.Date;
  */
 @Getter
 @Setter
-@SearchBean(tables = "order_don od left join goods_don gd on gd.id = od.goods_id",
-		where = "od.is_fixed_distribute is true")
+@SearchBean(tables = "order_don od left join goods_don gd on gd.id = od.goods_id")
 public class RegisterDistributeOrdersDetailView {
 
 	@DbField("od.created_time")
@@ -48,4 +47,10 @@ public class RegisterDistributeOrdersDetailView {
 
 	@DbIgnore
 	private String specVal;
+
+	@DbField("od.is_distribute")
+	private Boolean isDistribute;
+
+	@DbField("od.is_fixed_distribute")
+	private Boolean isFixedDistribute;
 }

+ 65 - 0
netflix-dao/src/main/java/com/cyksj/model/views/UserCommonDistributeView.java

@@ -0,0 +1,65 @@
+package com.cyksj.model.views;
+
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.DbIgnore;
+import com.ejlchina.searcher.bean.SearchBean;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: UserCommonDistributeView
+ * 创建者: JavaZou
+ * 创建时间:2024/1/31 17:35
+ */
+@Getter
+@Setter
+@SearchBean(tables = "(select id,nickname from user where 1 = 1 :condition:) u left join user_distribute_shared us on u.id = us.shared_id" +
+		" left join user_distribute ud on ud.user_id = u.id and ud.deleted is true" +
+		" left join order_don od on od.user_id = us.user_id and od.is_distribute = 1 and od.status not in ('noPayment', 'close') :time:"
+		, where = "ud.id is null",
+		groupBy = "u.id,u.nickname")
+public class UserCommonDistributeView {
+
+	@DbField("u.id")
+	private Long userId;
+
+	@DbField("u.nickname")
+	private String nickname;
+
+	@DbField("count(od.id)")
+	private Integer orders;
+
+	/**
+	 * 分销人数
+	 * 其中拉新用户购买一单又退款,且无后续下单动作的不算分销用户,不统计在此字段内
+	 */
+	@DbField("count(DISTINCT CASE WHEN od.status != 'refund' THEN us.user_id ELSE null END)")
+	private Integer distributeUserNum;
+
+	/**
+	 * 邀请人数
+	 */
+	@DbField("count(DISTINCT us.user_id)")
+	private Integer inviteNum;
+
+	/**
+	 * 分销订单金额(无需产生积分)
+	 */
+	@DbField("(ifnull(sum(if(od.is_dp and od.ori_money != 0,od.ori_money,od.money)),0) - ifnull(sum(od.refund_money),0))")
+	private BigDecimal distributeOrdersMoney;
+
+	/**
+	 * 分销消费占比
+	 */
+	@DbField("ifnull(cast(count(DISTINCT CASE WHEN od.status != 'refund' THEN us.user_id ELSE null END)/count(DISTINCT us.user_id) as decimal(10,2)),0)")
+	private BigDecimal distributeConsumerRate;
+
+	/**
+	 * 销量最高的产品
+	 */
+	@DbIgnore
+	private String goodsTitle;
+}

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

@@ -3,7 +3,7 @@
 
 <mapper namespace="com.cyksj.mapper.EquipmentActivityReduceMapper">
 
-    <select id="checkDupmentTimeDuration" resultType="java.lang.Integer">
+    <select id="checkRepeatTimeDuration" resultType="java.lang.Integer">
         select count(*) from equipment_activity_reduce where
         <if test="id != null">
             id != #{id} and

+ 14 - 0
netflix-dao/src/main/resources/mapper/StatisticsExportMapper.xml

@@ -505,4 +505,18 @@
           and o.created_time BETWEEN #{thisMonth} and #{nextMonth}
           and u.created_time BETWEEN #{thisMonth} and #{nextMonth}
     </select>
+
+    <select id="getEpOrderNumsGroupSource" resultType="java.util.Map">
+        select count(if(is_distribute = 0,1,NULL)) naturalEpOrders,count(if(is_distribute = 1,1,NULL)) distributeOrders
+        from order_don
+        where status not in ('close', 'noPayment', 'refund')
+        and goods_id = 15
+        <if test="startDate != null">
+            and created_time >= #{startDate}
+        </if>
+        <if test="endDate != null">
+            and created_time &lt; #{endDate}
+        </if>
+        group by DATE_FORMAT(created_time, '%Y-%m')
+    </select>
 </mapper>

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/coupon/impl/EquipmentActivityReduceServiceImpl.java

@@ -44,7 +44,7 @@ public class EquipmentActivityReduceServiceImpl extends ServiceImpl<EquipmentAct
 			throw BusinessRuntimeException.getInstance("满减金额不可小于0");
 		}
 
-		Integer count = equipmentActivityReduceMapper.checkDupmentTimeDuration(equipmentActivityReduce.getId(), st, et);
+		Integer count = equipmentActivityReduceMapper.checkRepeatTimeDuration(equipmentActivityReduce.getId(), st, et);
 		if (count > 0) {
 			throw BusinessRuntimeException.getInstance("存在活动时间重叠的记录..");
 		}

+ 7 - 0
netflix-service/src/main/java/com/cyksj/service/mange/statistics/impl/StatisticsDataServiceImpl.java

@@ -735,6 +735,13 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		excelMonthlyDistributeOrderData.setChannelUserSourceNum(channelUserSourceNum);
 		excelMonthlyDistributeOrderData.setChannelUserSourceOrderNum(channelUserSourceOrderNum);
 		excelMonthlyDistributeOrderData.setChannelUserSourceOrderRate(channelUserSourceOrderRate);
+
+		Map<String, Long> epOrderSourceMap = statisticsExportMapper.getEpOrderNumsGroupSource(startDate, endDate);
+
+		Integer naturalEpOrders = Integer.parseInt(epOrderSourceMap.get("naturalEpOrders").toString());
+		Integer distributeOrders = Integer.parseInt(epOrderSourceMap.get("distributeOrders").toString());
+		excelMonthlyDistributeOrderData.setNatureUserSourceEpOrderNum(naturalEpOrders);
+		excelMonthlyDistributeOrderData.setChannelUserSourceEpOrderNum(distributeOrders);
 		excelSheetDataList.add(new ExcelSheetAndData("每月用户分销数据", List.of(excelMonthlyDistributeOrderData), ExcelMonthlyDistributeOrderData.class, 2));
 	}
 

+ 41 - 31
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -431,14 +431,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		if (payRequest.getPopularizeId() != null) {
 			orderDon.setPopularizeId(payRequest.getPopularizeId());
 		}
-		if (sku != null) {
-			//扣除使用优惠券、余额的订单金额
-			deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType(), payRequest.getGcCash(), payRequest.getGcpIds(), payRequest.getIsAcReduce());
-		}
-
-		if (isSpecificPrice && (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0 || orderDon.getMoney().compareTo(specificPrice) != 0)) {
-			throw BusinessRuntimeException.getInstance("专属价格不支持使用其他优惠");
-		}
 
 		orderDon.setSkuId(payRequest.getSkuId());
 		orderDon.setRelationId(relationId);
@@ -465,6 +457,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 				throw BusinessRuntimeException.getInstance("车位与车队规格不一致");
 			}
 		}
+		if (sku != null) {
+			//扣除使用优惠券、余额的订单金额
+			deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType(), payRequest.getGcCash(), payRequest.getGcpIds(), payRequest.getIsAcReduce());
+		}
+
+		if (isSpecificPrice && (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0 || orderDon.getMoney().compareTo(specificPrice) != 0)) {
+			throw BusinessRuntimeException.getInstance("专属价格不支持使用其他优惠");
+		}
 		orderDon.setPayDesc(goodsDon.getPayDesc());
 		StringBuilder payTitle = new StringBuilder();
 		payTitle.append(goodsDon.getTitle());
@@ -2090,6 +2090,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		//针对设备 满减活动优惠 不支持使用优惠券等优惠
 		if (isAcReduce != null && isAcReduce && orderDon.getGoodsId() == 15) {
 			epOrderDonActivityReduce(orderDon);
+			//存在余额
+			deductBalancePayOrderMoney(orderDon, balance, user);
 			return;
 		}
 		//存在优惠券
@@ -2172,24 +2174,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		}
 
 		//存在余额
-		if (balance != null && balance.compareTo(BigDecimal.ZERO) > 0) {
-			BigDecimal money = orderDon.getMoney();
-			//去掉余额 多出的部分
-			BigDecimal subBalance = balance;
-			orderDon.setMoney(money.subtract(subBalance));
-			if (balance.compareTo(money) >= 0) {
-				orderDon.setMoney(BigDecimal.ZERO);
-				orderDon.setBalance(money);
-				subBalance = money;
-				orderDon.setType(OrderDon.Type.BALANCE);
-			}
-			BigDecimal userBalance = user.getBalance();
-			//扣除余额 是否成功
-			Integer success = userMapper.deductBalance(user.getId(), subBalance, userBalance);
-			if (success != 1) throw BusinessRuntimeException.getInstance("您的余额不足!");
-			orderDon.setBalance(subBalance);
-			userBenefitsService.recordBalanceBySource(user.getId(), BigDecimal.valueOf(-subBalance.longValue()), UserBalanceSourceRecord.Source.payment);
-		}
+		deductBalancePayOrderMoney(orderDon, balance, user);
 	}
 
 	/**
@@ -2748,26 +2733,51 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		}
 		DateTime now = DateTime.now();
 		EquipmentActivityReduce equipmentActivityReduce = equipmentActivityReduceMapper.selectOne(Wrappers.lambdaQuery(EquipmentActivityReduce.class)
-				.ge(EquipmentActivityReduce::getSt, now)
-				.lt(EquipmentActivityReduce::getEt, now)
+				.le(EquipmentActivityReduce::getSt, now)
+				.gt(EquipmentActivityReduce::getEt, now)
 				.eq(EquipmentActivityReduce::getDeleted, true)
 				.last("limit 1"));
+		if (equipmentActivityReduce == null) {
+			return;
+		}
 		BigDecimal money = orderDon.getMoney();
 		BigDecimal acReduceMoney = BigDecimal.ZERO;
 		if (money.compareTo(Constant.FIVE_HUNDRED) >= 0 && money.compareTo(Constant.THOUSAND) < 0) {
 			//500-1000
 			acReduceMoney = equipmentActivityReduce.getF();
-			log.info("活动设备订单:{}达到500元资格,满减金额:{}", orderDon.getId(), acReduceMoney.divide(BigDecimal.valueOf(100)));
+			log.info("活动设备订单:{}达到500元资格,满减金额:{}", orderDon.getOrderNo(), acReduceMoney.divide(BigDecimal.valueOf(100)));
 		} else if (money.compareTo(Constant.THOUSAND) >= 0 && money.compareTo(Constant.TWO_THOUSAND) < 0) {
 			//1000-2000
 			acReduceMoney = equipmentActivityReduce.getQ();
-			log.info("活动设备订单:{}达到1000元资格,满减金额:{}", orderDon.getId(), acReduceMoney.divide(BigDecimal.valueOf(100)));
+			log.info("活动设备订单:{}达到1000元资格,满减金额:{}", orderDon.getOrderNo(), acReduceMoney.divide(BigDecimal.valueOf(100)));
 		} else if (money.compareTo(Constant.TWO_THOUSAND) >= 0) {
 			//2000
 			acReduceMoney = equipmentActivityReduce.getTq();
-			log.info("活动设备订单:{}达到2000元资格,满减金额:{}", orderDon.getId(), acReduceMoney.divide(BigDecimal.valueOf(100)));
+			log.info("活动设备订单:{}达到2000元资格,满减金额:{}", orderDon.getOrderNo(), acReduceMoney.divide(BigDecimal.valueOf(100)));
 		}
 		orderDon.setMoney(orderDon.getMoney().subtract(acReduceMoney));
 		orderDon.setCouponMoney(acReduceMoney);
 	}
+
+	public void deductBalancePayOrderMoney(OrderDon orderDon, BigDecimal balance, User user) {
+		//存在余额
+		if (balance != null && balance.compareTo(BigDecimal.ZERO) > 0) {
+			BigDecimal money = orderDon.getMoney();
+			//去掉余额 多出的部分
+			BigDecimal subBalance = balance;
+			orderDon.setMoney(money.subtract(subBalance));
+			if (balance.compareTo(money) >= 0) {
+				orderDon.setMoney(BigDecimal.ZERO);
+				orderDon.setBalance(money);
+				subBalance = money;
+				orderDon.setType(OrderDon.Type.BALANCE);
+			}
+			BigDecimal userBalance = user.getBalance();
+			//扣除余额 是否成功
+			Integer success = userMapper.deductBalance(user.getId(), subBalance, userBalance);
+			if (success != 1) throw BusinessRuntimeException.getInstance("您的余额不足!");
+			orderDon.setBalance(subBalance);
+			userBenefitsService.recordBalanceBySource(user.getId(), BigDecimal.valueOf(-subBalance.longValue()), UserBalanceSourceRecord.Source.payment);
+		}
+	}
 }

+ 1 - 1
netflix-web/src/main/java/com/cyksj/web/controller/goods/GoodsDonController.java

@@ -1042,7 +1042,7 @@ public class GoodsDonController {
 				.field(EquipmentActivityReduce::getSt, now).op(Operator.LessEqual)
 				.field(EquipmentActivityReduce::getEt, now).op(Operator.GreaterThan)
 				.field(EquipmentActivityReduce::getDeleted, 1)
-				.onlySelect(EquipmentActivityReduce::getF, EquipmentActivityReduce::getQ, EquipmentActivityReduce::getTq)
+				.onlySelect(EquipmentActivityReduce::getF, EquipmentActivityReduce::getQ, EquipmentActivityReduce::getTq, EquipmentActivityReduce::getSt, EquipmentActivityReduce::getEt)
 				.build());
 		return GatewayResponse.SUCCESS.newBuilder().toResult(equipmentActivityReduce);
 	}

+ 27 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/distribute/DistributeController.java

@@ -338,7 +338,7 @@ public class DistributeController {
 	public Result<SearchResult<RegisterDistributeOrdersView>> getRegisterDistributeUserDetail() {
 		SearchResult<RegisterDistributeOrdersView> search = beanSearcher.search(RegisterDistributeOrdersView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
 		search.getDataList().forEach(data -> {
-			List<RegisterDistributeOrdersDetailView> ordersDetailViewList = beanSearcher.searchAll(RegisterDistributeOrdersDetailView.class, MapUtils.builder().field(RegisterDistributeOrdersDetailView::getUserId, data.getUserId()).op(Operator.Equal).build());
+			List<RegisterDistributeOrdersDetailView> ordersDetailViewList = beanSearcher.searchAll(RegisterDistributeOrdersDetailView.class, MapUtils.flatBuilder(request.getParameterMap()).field(RegisterDistributeOrdersDetailView::getUserId, data.getUserId()).op(Operator.Equal).build());
 			data.setOrderNums(ordersDetailViewList.size());
 			Optional<BigDecimal> money = ordersDetailViewList.stream().filter(order -> {
 				if (!Constant.noOrderAllStatus.contains(order.getStatus().name())) {
@@ -1241,4 +1241,30 @@ public class DistributeController {
 		SearchResult<UserDistributeSharedWhite> search = beanSearcher.search(UserDistributeSharedWhite.class, MapUtils.flatBuilder(request.getParameterMap()).build());
 		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
 	}
+
+	/**
+	 * 普通渠道列表
+	 */
+	@GetMapping("/get/common/distribute")
+	public Result<SearchResult<UserCommonDistributeView>> getCommonDistribute(Long userId, String nickname) {
+		String condition = StrUtil.EMPTY;
+		if (userId != null) {
+			condition += String.format(" and id = %s", userId);
+		}
+		if (StrUtil.isNotEmpty(nickname)) {
+			condition += String.format(" and nickname like '%%%s%%'", nickname);
+		}
+		MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
+		if (StrUtil.isNotEmpty(condition)) {
+			builder.put("condition", condition);
+		}
+		SearchResult<UserCommonDistributeView> search = beanSearcher.search(UserCommonDistributeView.class,
+				builder.build());
+		search.getDataList().forEach(view -> {
+			if (view.getDistributeOrdersMoney().compareTo(BigDecimal.ZERO) > 0) {
+				Optional.ofNullable(userDistributeMapper.selectSoldMaxGoods(view.getUserId())).ifPresent(title -> view.setGoodsTitle(title));
+			}
+		});
+		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
+	}
 }

+ 1 - 1
netflix-web/src/main/java/com/cyksj/web/controller/user/AuthorizationController.java

@@ -511,7 +511,7 @@ public class AuthorizationController {
     @PostMapping("/google/login")
     public Result<UserAuthLoginResp> googleLogin(LoginReq loginReq,String credential) throws Exception {
         log.info("google loginReq:{},credential:{}", loginReq, credential);
-        String result = HttpUtil.post("https://galaxydvd.com/8081/api/auth/google/login/inner?credential=" + credential, new HashMap<>());
+        String result = HttpUtil.post("https://galaxyva.com/8081/api/auth/google/login/inner?credential=" + credential, new HashMap<>());
         log.info("google result:{}",result);
         GoogleLoginRep googleLoginRep = Jsons.parseObject(Jsons.toMap(result).get("data"), GoogleLoginRep.class);
         loginReq.setType(3);