1159 lines
		
	
	
		
			52 KiB
		
	
	
	
		
			XML
		
	
	
	
			
		
		
	
	
			1159 lines
		
	
	
		
			52 KiB
		
	
	
	
		
			XML
		
	
	
	
| <?xml version="1.0" encoding="UTF-8"?>
 | ||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 | ||
| <mapper namespace="com.hzs.member.statis.mapper.CuBonusVertexStatisMapper">
 | ||
| 
 | ||
|     <!-- 奖金拨比列表-->
 | ||
|     <select id="queryCuBonusStatis" parameterType="com.hzs.member.statis.vo.CuBonusVertexStatisVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStatisVO">
 | ||
|         select cbs.*,
 | ||
|         <!-- 首购金额 = 注册 + 升级 + 特殊注册 + 特殊升级 + 虚拟订单(空单) -->
 | ||
|         (cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT)
 | ||
|         AS firstPurchaseAll,
 | ||
|         <!-- 复购金额 = 复购 + 直播 + 合作 + 特殊复购 + 福利订单 -->
 | ||
|         (cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER)
 | ||
|         AS repurchaseAllAmount,
 | ||
|         <!-- 首购拨出金额 = 直推收益 + 拓展收益 + 辅导收益 + 服务补贴  -->
 | ||
|         (cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS)
 | ||
|         AS mainBonus,
 | ||
|         <!-- 首购拨出比例 = 首购金额为0,首购拨出比例 = 0;否则,首购拨出比例 = 100 * 首购拨出金额 / 首购金额 -->
 | ||
|         case
 | ||
|         WHEN (cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND((#{perCent} * (cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS))
 | ||
|         / (cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT), 4)
 | ||
|         end AS mainBonusRate,
 | ||
|         <!-- 首购PV拨出比例 = 首购PV为0,首购PV拨出比例 = 0;否则,首购PV拨出比例 = 100 * 首购拨出金额 / 汇率 / 首购PV -->
 | ||
|         case
 | ||
|         WHEN (cbs.MAIN_REG_PV + cbs.MAIN_UP_PV + cbs.SPECIAL_REGISTER_PV + cbs.SPECIAL_UPGRADE_PV + cbs.FICTITIOUS_PV) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND((#{perCent} * (cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS))
 | ||
|         / #{rate} / (cbs.MAIN_REG_PV + cbs.MAIN_UP_PV + cbs.SPECIAL_REGISTER_PV + cbs.SPECIAL_UPGRADE_PV + cbs.FICTITIOUS_PV), 4)
 | ||
|         end AS mainBonusPvRate,
 | ||
|         <!-- 复购拨出金额 = 复购级差收益 + 复购拓展收益 + 复购推荐收益 + 复购辅导收益 -->
 | ||
|         (cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         AS repurBonus,
 | ||
|         <!-- 复购拨出比例 = 复购金额为0,复购拨出比例 = 0;否则,复购拨出比例 = 100 * 复购拨出金额 / 复购金额 -->
 | ||
|         case
 | ||
|         WHEN (cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * (cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         / (cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER), 4)
 | ||
|         end AS repurBonusRate,
 | ||
|         <!-- 复购PV拨出比例 = 复购PV为0,复购PV拨出比例 = 0;否则,复购PV拨出比例 = 100 * 首购拨出金额 / 汇率 / 首购PV -->
 | ||
|         case
 | ||
|         WHEN (cbs.MAIN_REPUR_PV + cbs.MALL_PV + cbs.COOPERATE_PV + cbs.SPECIAL_REPURCHASE_PV + cbs.WELFARE_ORDER_PV) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * (cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         / #{rate} / (cbs.MAIN_REPUR_PV + cbs.MALL_PV +cbs.COOPERATE_PV + cbs.SPECIAL_REPURCHASE_PV + cbs.WELFARE_ORDER_PV), 4)
 | ||
|         end AS repurBonusPvRate,
 | ||
|         <!-- 总拨出金额 = 直推收益 + 拓展收益 + 辅导收益 + 服务补贴 + 复购级差收益 + 复购拓展收益 + 复购推荐收益 + 复购辅导收益 -->
 | ||
|         (cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS
 | ||
|         + cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         AS totalBonus,
 | ||
|         <!-- 总拨出比例 = 首购 + 复购金额为0,总拨出比例 = 0;否则,总拨出比例 = 100 * 首购 + 复购拨出金额 / 首购 + 复购金额 -->
 | ||
|         CASE
 | ||
|         WHEN (cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT
 | ||
|         + cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT +cbs.WELFARE_ORDER) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND (#{perCent} * (cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS
 | ||
|         + cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         / (cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT
 | ||
|         + cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER), 4)
 | ||
|         end AS totalBonusRate
 | ||
|         from (
 | ||
|         SELECT
 | ||
|         cbs.PK_BD_VERTEX ,
 | ||
|         cbs.PK_TEAM_CODE ,
 | ||
|         cm.MEMBER_CODE ,
 | ||
|         cm.MEMBER_NAME ,
 | ||
|         cbs.PK_ID ,
 | ||
|         cbs.PERIOD ,
 | ||
|         cbs.CREATION_TIME ,
 | ||
|         cbs.PK_COUNTRY ,
 | ||
|         <!-- PV字段 -->
 | ||
|         cbs.MAIN_REG_PV ,
 | ||
|         cbs.MAIN_UP_PV ,
 | ||
|         cbs.MAIN_REPUR_PV ,
 | ||
|         cbs.SPECIAL_REGISTER_PV ,
 | ||
|         cbs.SPECIAL_UPGRADE_PV ,
 | ||
|         cbs.SPECIAL_REPURCHASE_PV ,
 | ||
|         cbs.FICTITIOUS_PV ,
 | ||
|         cbs.MALL_PV ,
 | ||
|         cbs.COOPERATE_PV ,
 | ||
|         cbs.WELFARE_ORDER_PV ,
 | ||
|         <!-- 金额字段 -->
 | ||
|         cbs.main_reg_amount,
 | ||
|         cbs.main_up_amount,
 | ||
|         cbs.main_repur_amount,
 | ||
|         cbs.special_register_amount,
 | ||
|         cbs.special_upgrade_amount,
 | ||
|         cbs.special_repurchase_amount,
 | ||
|         cbs.fictitious_amount,
 | ||
|         cbs.mall_amount,
 | ||
|         cbs.cooperate_amount,
 | ||
|         cbs.welfare_order,
 | ||
|         <!-- 奖金字段 -->
 | ||
|         cbs.introduce_bonus ,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.org_bonus
 | ||
|         else
 | ||
|         cbs.cal_fir_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         org_bonus
 | ||
|         end org_bonus,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.leader_bonus
 | ||
|         else
 | ||
|         cbs.cal_fir_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         leader_bonus
 | ||
|         end leader_bonus,
 | ||
|         cbs.service_bonus ,
 | ||
|         cbs.repur_range_bonus ,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.repur_org_bonus
 | ||
|         else
 | ||
|         cbs.cal_rep_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         org_bonus
 | ||
|         end repur_org_bonus,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.repur_leader_bonus
 | ||
|         else
 | ||
|         cbs.cal_rep_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         leader_bonus
 | ||
|         end repur_leader_bonus,
 | ||
|         cbs.repur_push_income
 | ||
|         FROM CU_BONUS_VERTEX_STATIS cbs
 | ||
|         LEFT JOIN CU_MEMBER cm ON cm.PK_ID = cbs.PK_BD_VERTEX AND cm.DEL_FLAG = 0
 | ||
|         WHERE 1 = 1
 | ||
|         <if test="pkCountry != null">
 | ||
|             and cbs.PK_COUNTRY = #{pkCountry}
 | ||
|         </if>
 | ||
|         <if test="pkVertex != null ">
 | ||
|             and cbs.PK_BD_VERTEX =#{pkVertex}
 | ||
|         </if>
 | ||
|         <if test="startDate != null and startDate != '' ">
 | ||
|             and cbs.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate != null and endDate != '' ">
 | ||
|             and cbs.CREATION_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         ORDER BY cbs.CREATION_TIME asc
 | ||
|         ) cbs
 | ||
|     </select>
 | ||
| 
 | ||
| 
 | ||
|     <!--     查询顶点拓展封顶人数-->
 | ||
|     <select id="queryOrgTopNumber" parameterType="com.hzs.member.statis.vo.CuBonusVertexStaticTotalVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStaticTotalVO">
 | ||
|         SELECT COUNT(cb.pk_id) orgTopNumber,
 | ||
|         #{pkVertex} pkVertex
 | ||
|         FROM cu_member_bonus cb
 | ||
|         INNER JOIN (
 | ||
|         SELECT pk_id, pk_settle_grade
 | ||
|         FROM cu_member cm
 | ||
|         START WITH cm.pk_id=#{pkVertex}
 | ||
|         CONNECT BY PRIOR pk_id = pk_place_parent
 | ||
|         ) a ON a.pk_id = cb.pk_member
 | ||
|         INNER JOIN bd_grade bg ON bg.pk_id = a.pk_settle_grade AND bg.del_flag = 0
 | ||
|         INNER JOIN cu_member_settle_period cp ON cb.period = cp.pk_id
 | ||
|         WHERE cb.del_flag = 0
 | ||
|         AND cp.del_flag = 0
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and cp.settle_date >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and cp.settle_date <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         AND (cb.expand_income + cb.repur_expand_income) >= bg.expand_capping
 | ||
|     </select>
 | ||
| 
 | ||
|     <!--    查询顶点拓展平均碰次和拓展最高碰次-->
 | ||
|     <select id="queryTouch" parameterType="com.hzs.member.statis.vo.CuBonusVertexStaticTotalVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStaticTotalVO">
 | ||
|         SELECT
 | ||
|         cm.pk_id pkVertex,
 | ||
|         round(sum(expand_touch) / count(pk_order), 2) orgAvTouch,
 | ||
|         max(expand_touch) orgMaxTouch
 | ||
|         FROM (
 | ||
|         SELECT #{pkVertex} pkVertex, b.*
 | ||
|         FROM (
 | ||
|         SELECT
 | ||
|         cd.pk_order,
 | ||
|         max(expand_touch) expand_touch
 | ||
|         FROM cu_member_bonus cb
 | ||
|         INNER JOIN cu_member_bonus_expand cd ON cb.pk_id = cd.pk_bonus
 | ||
|         INNER JOIN (
 | ||
|         SELECT * FROM cu_member cm
 | ||
|         START WITH cm.pk_id = #{pkVertex}
 | ||
|         CONNECT BY pk_place_parent = PRIOR pk_id
 | ||
|         ) a ON a.pk_id = cb.pk_member
 | ||
|         INNER JOIN cu_member_settle_period cp ON cb.period = cp.pk_id
 | ||
|         WHERE
 | ||
|         cb.del_flag = 0
 | ||
|         AND cp.del_flag = 0
 | ||
|         AND cd.del_flag = 0
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and cp.settle_date >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and cp.settle_date <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY cd.pk_order
 | ||
|         ) b
 | ||
|         ) a
 | ||
|         INNER JOIN cu_member cm ON a.pkVertex = cm.pk_id
 | ||
|         LEFT JOIN bd_vertex bv ON cm.pk_vertex = bv.pk_id
 | ||
|         GROUP BY
 | ||
|         cm.pk_id, cm.member_name, bv.vertex_name
 | ||
|     </select>
 | ||
| 
 | ||
|     <!-- 奖金拨比列表统计小计(最后一行)-->
 | ||
|     <select id="queryCuBonusSumStatis" parameterType="com.hzs.member.statis.vo.CuBonusVertexStatisVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStatisVO">
 | ||
|         SELECT
 | ||
|         <!-- 金额字段 -->
 | ||
|         sum (cbs.main_reg_amount) mainRegAmountSum,
 | ||
|         sum (cbs.main_up_amount) mainUpAmountSum,
 | ||
|         sum (cbs.main_repur_amount) mainRepurAmountSum,
 | ||
|         sum (cbs.special_register_amount) specialRegisterAmountSum,
 | ||
|         sum (cbs.special_upgrade_amount) specialUpgradeAmountSum,
 | ||
|         sum (cbs.special_repurchase_amount) specialRepurchaseAmountSum,
 | ||
|         <!-- 奖金字段 -->
 | ||
|         sum (cbs.INTRODUCE_BONUS) introduceBonusSum,
 | ||
|         sum (cbs.ORG_BONUS) orgBonusSum,
 | ||
|         sum (cbs.LEADER_BONUS) leaderBonusSum,
 | ||
|         sum (cbs.SERVICE_BONUS) serviceBonusSum,
 | ||
|         sum (cbs.REPUR_RANGE_BONUS) repurRangeBonusSum,
 | ||
|         sum (cbs.REPUR_ORG_BONUS) repurOrgBonusSum,
 | ||
|         sum (cbs.REPUR_LEADER_BONUS) repurLeaderBonusSum,
 | ||
|         sum (cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT)
 | ||
|         AS firstPurchaseAllSum,
 | ||
|         sum (cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER)
 | ||
|         AS repurchaseAllAmountSum,
 | ||
|         sum (cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS)
 | ||
|         AS mainBonusSum,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS)
 | ||
|         / sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT), 4)
 | ||
|         end AS mainBonusRateSum,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REG_PV + cbs.MAIN_UP_PV + cbs.SPECIAL_REGISTER_PV + cbs.SPECIAL_UPGRADE_PV + cbs.FICTITIOUS_PV) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS)
 | ||
|         / #{rate} / sum(cbs.MAIN_REG_PV + cbs.MAIN_UP_PV + cbs.SPECIAL_REGISTER_PV + cbs.SPECIAL_UPGRADE_PV + cbs.FICTITIOUS_PV), 4)
 | ||
|         end AS mainBonusPvRateSum,
 | ||
|         sum(cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS) AS repurBonusSum,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         / sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER), 4)
 | ||
|         end AS repurBonusRateSum,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REPUR_PV + cbs.MALL_PV + cbs.COOPERATE_PV + cbs.SPECIAL_REPURCHASE_PV + cbs.WELFARE_ORDER_PV) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         / #{rate} / sum(cbs.MAIN_REPUR_PV + cbs.MALL_PV +cbs.COOPERATE_PV + cbs.SPECIAL_REPURCHASE_PV + cbs.WELFARE_ORDER_PV), 4)
 | ||
|         end AS repurBonusPvRateSum,
 | ||
|         sum(cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS
 | ||
|         + cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         AS totalBonusSum,
 | ||
|         CASE
 | ||
|         WHEN sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT
 | ||
|         + cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT +cbs.WELFARE_ORDER) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND (#{perCent} * sum(cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS
 | ||
|         + cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         / sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT
 | ||
|         + cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER), 4)
 | ||
|         end AS totalBonusRateSum
 | ||
|         from (
 | ||
|         SELECT
 | ||
|         cbs.PK_BD_VERTEX ,
 | ||
|         cbs.PK_TEAM_CODE ,
 | ||
|         cm.MEMBER_CODE ,
 | ||
|         cm.MEMBER_NAME ,
 | ||
|         cbs.PK_ID ,
 | ||
|         cbs.PERIOD ,
 | ||
|         cbs.CREATION_TIME ,
 | ||
|         cbs.PK_COUNTRY ,
 | ||
|         <!-- PV字段 -->
 | ||
|         cbs.MAIN_REG_PV ,
 | ||
|         cbs.MAIN_UP_PV ,
 | ||
|         cbs.MAIN_REPUR_PV ,
 | ||
|         cbs.SPECIAL_REGISTER_PV ,
 | ||
|         cbs.SPECIAL_UPGRADE_PV ,
 | ||
|         cbs.SPECIAL_REPURCHASE_PV ,
 | ||
|         cbs.FICTITIOUS_PV ,
 | ||
|         cbs.MALL_PV ,
 | ||
|         cbs.COOPERATE_PV ,
 | ||
|         cbs.WELFARE_ORDER_PV ,
 | ||
|         <!-- 金额字段 -->
 | ||
|         cbs.main_reg_amount,
 | ||
|         cbs.main_up_amount,
 | ||
|         cbs.main_repur_amount,
 | ||
|         cbs.special_register_amount,
 | ||
|         cbs.special_upgrade_amount,
 | ||
|         cbs.special_repurchase_amount,
 | ||
|         cbs.fictitious_amount,
 | ||
|         cbs.mall_amount,
 | ||
|         cbs.cooperate_amount,
 | ||
|         cbs.welfare_order,
 | ||
|         <!-- 奖金字段 -->
 | ||
|         cbs.introduce_bonus ,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.org_bonus
 | ||
|         else
 | ||
|         cbs.cal_fir_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         org_bonus
 | ||
|         end org_bonus,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.leader_bonus
 | ||
|         else
 | ||
|         cbs.cal_fir_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         leader_bonus
 | ||
|         end leader_bonus,
 | ||
|         cbs.service_bonus ,
 | ||
|         cbs.repur_range_bonus ,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.repur_org_bonus
 | ||
|         else
 | ||
|         cbs.cal_rep_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         org_bonus
 | ||
|         end repur_org_bonus,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.repur_leader_bonus
 | ||
|         else
 | ||
|         cbs.cal_rep_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         leader_bonus
 | ||
|         end repur_leader_bonus,
 | ||
|         cbs.repur_push_income
 | ||
|         FROM CU_BONUS_VERTEX_STATIS cbs
 | ||
|         LEFT JOIN CU_MEMBER cm ON cm.PK_ID = cbs.PK_BD_VERTEX AND cm.DEL_FLAG = 0
 | ||
|         WHERE 1 = 1
 | ||
|         <if test="pkCountry != null">
 | ||
|             and cbs.PK_COUNTRY = #{pkCountry}
 | ||
|         </if>
 | ||
|         <if test="pkVertex != null ">
 | ||
|             and cbs.PK_BD_VERTEX = #{pkVertex}
 | ||
|         </if>
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and cbs.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and cbs.CREATION_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         ) cbs
 | ||
|     </select>
 | ||
| 
 | ||
|     <!-- 查询顶点奖金拨比汇总-->
 | ||
|     <select id="queryCuBonusStatisTotal" parameterType="com.hzs.member.statis.vo.CuBonusVertexStaticTotalVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStaticTotalVO">
 | ||
|         select * from(
 | ||
|         SELECT
 | ||
|         cbs.PK_BD_VERTEX pkVertex,
 | ||
|         cm.MEMBER_CODE as memberCode,
 | ||
|         cm.MEMBER_NAME as memberName,
 | ||
|         sum (cbs.INTRODUCE_BONUS) introduceBonus,
 | ||
|         sum (cbs.ORG_BONUS) orgBonus,
 | ||
|         sum (cbs.LEADER_BONUS) leaderBonus,
 | ||
|         sum (cbs.SERVICE_BONUS) serviceBonus,
 | ||
|         sum (cbs.REPUR_RANGE_BONUS) repurRangeBonus,
 | ||
|         sum (cbs.REPUR_ORG_BONUS) repurOrgBonus,
 | ||
|         sum (cbs.REPUR_LEADER_BONUS) repurLeaderBonus,
 | ||
|         sum (cbs.MAIN_REG_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT) regAmount,
 | ||
|         <!-- 首购相关 -->
 | ||
|         sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT)
 | ||
|         AS firstPurchaseAll,
 | ||
|         sum(cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS)
 | ||
|         AS mainBonus,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS)
 | ||
|         / sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT), 4)
 | ||
|         end AS mainBonusRate,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REG_PV + cbs.MAIN_UP_PV + cbs.SPECIAL_REGISTER_PV + cbs.SPECIAL_UPGRADE_PV + cbs.FICTITIOUS_PV) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS)
 | ||
|         / #{rate} / sum(cbs.MAIN_REG_PV + cbs.MAIN_UP_PV + cbs.SPECIAL_REGISTER_PV + cbs.SPECIAL_UPGRADE_PV + cbs.FICTITIOUS_PV), 4)
 | ||
|         end AS mainBonusPvRate,
 | ||
|         <!-- 复购相关 -->
 | ||
|         sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER)
 | ||
|         AS repurchaseAllAmount,
 | ||
|         sum(cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         AS repurBonus,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         / sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER), 4)
 | ||
|         end AS repurBonusRate,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REPUR_PV + cbs.MALL_PV + cbs.COOPERATE_PV + cbs.SPECIAL_REPURCHASE_PV + cbs.WELFARE_ORDER_PV) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         / #{rate} / sum(cbs.MAIN_REPUR_PV + cbs.MALL_PV + cbs.COOPERATE_PV + cbs.SPECIAL_REPURCHASE_PV + cbs.WELFARE_ORDER_PV), 4)
 | ||
|         end AS repurBonusPvRate
 | ||
|         FROM
 | ||
|         (
 | ||
|         SELECT
 | ||
|         cbs.PK_BD_VERTEX ,
 | ||
|         cbs.PK_TEAM_CODE ,
 | ||
|         cbs.PK_ID ,
 | ||
|         cbs.PERIOD ,
 | ||
|         cbs.CREATION_TIME ,
 | ||
|         cbs.PK_COUNTRY ,
 | ||
|         <!-- PV字段 -->
 | ||
|         cbs.MAIN_REG_PV ,
 | ||
|         cbs.MAIN_UP_PV ,
 | ||
|         cbs.MAIN_REPUR_PV ,
 | ||
|         cbs.SPECIAL_REGISTER_PV ,
 | ||
|         cbs.SPECIAL_UPGRADE_PV ,
 | ||
|         cbs.SPECIAL_REPURCHASE_PV ,
 | ||
|         cbs.FICTITIOUS_PV ,
 | ||
|         cbs.MALL_PV ,
 | ||
|         cbs.COOPERATE_PV ,
 | ||
|         cbs.WELFARE_ORDER_PV ,
 | ||
|         <!-- 金额字段 -->
 | ||
|         cbs.main_reg_amount,
 | ||
|         cbs.main_up_amount,
 | ||
|         cbs.main_repur_amount,
 | ||
|         cbs.special_register_amount,
 | ||
|         cbs.special_upgrade_amount,
 | ||
|         cbs.special_repurchase_amount,
 | ||
|         cbs.fictitious_amount,
 | ||
|         cbs.mall_amount,
 | ||
|         cbs.cooperate_amount,
 | ||
|         cbs.welfare_order,
 | ||
|         <!-- 奖金字段 -->
 | ||
|         cbs.introduce_bonus ,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.org_bonus
 | ||
|         else
 | ||
|         cbs.cal_fir_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         org_bonus
 | ||
|         end org_bonus,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.leader_bonus
 | ||
|         else
 | ||
|         cbs.cal_fir_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         leader_bonus
 | ||
|         end leader_bonus,
 | ||
|         cbs.service_bonus ,
 | ||
|         cbs.repur_range_bonus ,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.repur_org_bonus
 | ||
|         else
 | ||
|         cbs.cal_rep_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         org_bonus
 | ||
|         end repur_org_bonus,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.repur_leader_bonus
 | ||
|         else
 | ||
|         cbs.cal_rep_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         leader_bonus
 | ||
|         end repur_leader_bonus,
 | ||
|         cbs.repur_push_income
 | ||
|         FROM CU_BONUS_VERTEX_STATIS cbs
 | ||
|         WHERE 1 = 1
 | ||
|         <if test="pkCountry != null">
 | ||
|             and cbs.PK_COUNTRY = #{pkCountry}
 | ||
|         </if>
 | ||
|         <if test="pkVertex != null ">
 | ||
|             and cbs.PK_BD_VERTEX = #{pkVertex}
 | ||
|         </if>
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and cbs.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and cbs.CREATION_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         )
 | ||
|         cbs
 | ||
|         LEFT JOIN CU_MEMBER cm ON cm.PK_ID = cbs.PK_BD_VERTEX and cm.del_flag = 0
 | ||
|         GROUP BY cbs.PK_BD_VERTEX, cm.MEMBER_CODE, cm.MEMBER_NAME
 | ||
|         )
 | ||
|         ORDER BY firstPurchaseAll desc, repurchaseAllAmount desc
 | ||
|     </select>
 | ||
| 
 | ||
|     <!--    顶点奖金拨比汇总查询总和-->
 | ||
|     <select id="queryCuBonusStatisSum" parameterType="com.hzs.member.statis.vo.CuBonusVertexStaticTotalVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStaticTotalVO">
 | ||
|         SELECT
 | ||
|         sum (cbs.INTRODUCE_BONUS) introduceBonus,
 | ||
|         sum (cbs.ORG_BONUS) orgBonus,
 | ||
|         sum (cbs.LEADER_BONUS) leaderBonus,
 | ||
|         sum (cbs.SERVICE_BONUS) serviceBonus,
 | ||
|         sum (cbs.REPUR_RANGE_BONUS) repurRangeBonus,
 | ||
|         sum (cbs.REPUR_ORG_BONUS) repurOrgBonus,
 | ||
|         sum (cbs.REPUR_LEADER_BONUS) repurLeaderBonus,
 | ||
|         <!-- 首购相关 -->
 | ||
|         sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT)
 | ||
|         AS firstPurchaseAll,
 | ||
|         sum(cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS)
 | ||
|         AS mainBonus,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS)
 | ||
|         / sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT), 4)
 | ||
|         end AS mainBonusRate,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REG_PV + cbs.MAIN_UP_PV + cbs.SPECIAL_REGISTER_PV + cbs.SPECIAL_UPGRADE_PV + cbs.FICTITIOUS_PV) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.INTRODUCE_BONUS + cbs.ORG_BONUS + cbs.LEADER_BONUS + cbs.SERVICE_BONUS)
 | ||
|         / #{rate} / sum(cbs.MAIN_REG_PV + cbs.MAIN_UP_PV + cbs.SPECIAL_REGISTER_PV + cbs.SPECIAL_UPGRADE_PV + cbs.FICTITIOUS_PV), 4)
 | ||
|         end AS mainBonusPvRate,
 | ||
|         <!-- 复购相关 -->
 | ||
|         sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER)
 | ||
|         AS repurchaseAllAmount,
 | ||
|         sum(cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         AS repurBonus,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         / sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER), 4)
 | ||
|         end AS repurBonusRate,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REPUR_PV + cbs.MALL_PV + cbs.COOPERATE_PV + cbs.SPECIAL_REPURCHASE_PV + cbs.WELFARE_ORDER_PV) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.REPUR_RANGE_BONUS + cbs.REPUR_ORG_BONUS + cbs.REPUR_PUSH_INCOME + cbs.REPUR_LEADER_BONUS)
 | ||
|         / #{rate} / sum(cbs.MAIN_REPUR_PV + cbs.MALL_PV + cbs.COOPERATE_PV + cbs.SPECIAL_REPURCHASE_PV + cbs.WELFARE_ORDER_PV), 4)
 | ||
|         end AS repurBonusPvRate,
 | ||
|         <!-- 首购奖金占比 -->
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.INTRODUCE_BONUS)
 | ||
|         / sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT), 4)
 | ||
|         end AS introduceBonusRate,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.ORG_BONUS)
 | ||
|         / sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT), 4)
 | ||
|         end AS orgBonusRate,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.LEADER_BONUS)
 | ||
|         / sum(cbs.MAIN_REG_AMOUNT + cbs.MAIN_UP_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT + cbs.SPECIAL_UPGRADE_AMOUNT + cbs.FICTITIOUS_AMOUNT), 4)
 | ||
|         end AS leaderBonusRate,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REG_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.SERVICE_BONUS)
 | ||
|         / sum(cbs.MAIN_REG_AMOUNT + cbs.SPECIAL_REGISTER_AMOUNT), 4)
 | ||
|         end AS serviceBonusRate,
 | ||
|         <!-- 复购奖金占比 -->
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.REPUR_RANGE_BONUS)
 | ||
|         / sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER), 4)
 | ||
|         end AS repurRangeBonusRate,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.REPUR_ORG_BONUS)
 | ||
|         / sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER), 4)
 | ||
|         end AS repurOrgBonusRate,
 | ||
|         case
 | ||
|         WHEN sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER) = 0
 | ||
|         THEN 0
 | ||
|         ELSE ROUND(#{perCent} * sum(cbs.REPUR_LEADER_BONUS)
 | ||
|         / sum(cbs.MAIN_REPUR_AMOUNT + cbs.MALL_AMOUNT + cbs.COOPERATE_AMOUNT + cbs.SPECIAL_REPURCHASE_AMOUNT + cbs.WELFARE_ORDER), 4)
 | ||
|         end AS repurLeaderBonusRate
 | ||
|         FROM (
 | ||
|         SELECT
 | ||
|         cbs.PK_BD_VERTEX ,
 | ||
|         cbs.PK_TEAM_CODE ,
 | ||
|         cm.MEMBER_CODE ,
 | ||
|         cm.MEMBER_NAME ,
 | ||
|         cbs.PK_ID ,
 | ||
|         cbs.PERIOD ,
 | ||
|         cbs.CREATION_TIME ,
 | ||
|         cbs.PK_COUNTRY ,
 | ||
|         <!-- PV字段 -->
 | ||
|         cbs.MAIN_REG_PV ,
 | ||
|         cbs.MAIN_UP_PV ,
 | ||
|         cbs.MAIN_REPUR_PV ,
 | ||
|         cbs.SPECIAL_REGISTER_PV ,
 | ||
|         cbs.SPECIAL_UPGRADE_PV ,
 | ||
|         cbs.SPECIAL_REPURCHASE_PV ,
 | ||
|         cbs.FICTITIOUS_PV ,
 | ||
|         cbs.MALL_PV ,
 | ||
|         cbs.COOPERATE_PV ,
 | ||
|         cbs.WELFARE_ORDER_PV ,
 | ||
|         <!-- 金额字段 -->
 | ||
|         cbs.main_reg_amount,
 | ||
|         cbs.main_up_amount,
 | ||
|         cbs.main_repur_amount,
 | ||
|         cbs.special_register_amount,
 | ||
|         cbs.special_upgrade_amount,
 | ||
|         cbs.special_repurchase_amount,
 | ||
|         cbs.fictitious_amount,
 | ||
|         cbs.mall_amount,
 | ||
|         cbs.cooperate_amount,
 | ||
|         cbs.welfare_order,
 | ||
|         <!-- 奖金字段 -->
 | ||
|         cbs.introduce_bonus ,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.org_bonus
 | ||
|         else
 | ||
|         cbs.cal_fir_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         org_bonus
 | ||
|         end org_bonus,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.leader_bonus
 | ||
|         else
 | ||
|         cbs.cal_fir_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         leader_bonus
 | ||
|         end leader_bonus,
 | ||
|         cbs.service_bonus ,
 | ||
|         cbs.repur_range_bonus ,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.repur_org_bonus
 | ||
|         else
 | ||
|         cbs.cal_rep_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         org_bonus
 | ||
|         end repur_org_bonus,
 | ||
|         case
 | ||
|         when cbs.cal_fir_achieve = 0 and cbs.cal_rep_achieve = 0 then
 | ||
|         cbs.repur_leader_bonus
 | ||
|         else
 | ||
|         cbs.cal_rep_achieve / (cbs.cal_fir_achieve + cbs.cal_rep_achieve) *
 | ||
|         leader_bonus
 | ||
|         end repur_leader_bonus,
 | ||
|         cbs.repur_push_income
 | ||
|         FROM CU_BONUS_VERTEX_STATIS cbs
 | ||
|         LEFT JOIN CU_MEMBER cm ON cm.PK_ID = cbs.PK_BD_VERTEX AND cm.DEL_FLAG = 0
 | ||
|         WHERE 1 = 1
 | ||
|         <if test="pkCountry != null">
 | ||
|             and cbs.PK_COUNTRY = #{pkCountry}
 | ||
|         </if>
 | ||
|         <if test="pkVertex != null ">
 | ||
|             and cbs.PK_BD_VERTEX = #{pkVertex}
 | ||
|         </if>
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and cbs.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and cbs.CREATION_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         ) cbs
 | ||
|         LEFT JOIN CU_MEMBER cm ON cm.PK_ID = cbs.PK_BD_VERTEX and cm.del_flag = 0
 | ||
|     </select>
 | ||
| 
 | ||
|     <!--    查询时间内奖金拨比顶点会员-->
 | ||
|     <select id="queryCuBonusVertex" parameterType="com.hzs.member.statis.vo.CuBonusVertexStaticTotalVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStaticTotalVO">
 | ||
|         select cbs.PK_BD_VERTEX pkVertex
 | ||
|         from CU_BONUS_VERTEX_STATIS cbs where 1=1
 | ||
|         <if test="pkCountry != null">
 | ||
|             and cbs.PK_COUNTRY=#{pkCountry}
 | ||
|         </if>
 | ||
|         <if test="pkVertex != null">
 | ||
|             and cbs.PK_BD_VERTEX=#{pkVertex}
 | ||
|         </if>
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and cbs.CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and cbs.CREATION_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY cbs.PK_BD_VERTEX
 | ||
|     </select>
 | ||
| 
 | ||
|     <!--    查询小于当天全部已支付或撤单订单信息-->
 | ||
|     <select id="querySaOrderByLessDay" parameterType="com.hzs.member.statis.vo.CuBonusVertexStatisVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStatisVO">
 | ||
|         select * from (
 | ||
|         select
 | ||
|         cm.pk_id pkMember,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         so.PK_COUNTRY pkCountry,
 | ||
|         so.ORDER_TYPE orderType,
 | ||
|         (so.ORDER_AMOUNT-nvl(so.CONSUME_AMOUNT,0)) orderAmount,
 | ||
|         so.ORDER_ACHIEVE orderAchieve,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
 | ||
|         from (
 | ||
|         SELECT
 | ||
|         cm.pk_id
 | ||
|         FROM
 | ||
|         cu_member cm
 | ||
|         WHERE del_flag=0 and category=0
 | ||
|         START WITH pk_place_parent =#{pkVertex}
 | ||
|         CONNECT BY pk_place_parent = PRIOR pk_id
 | ||
|         ) cm
 | ||
|         INNER JOIN SA_ORDER so on so.pk_member=cm.pk_id
 | ||
|         where so.ORDER_TYPE in (1,2,3,4,5,6,7,10,12,13,14,18,19,20,22,24,25,26,27,28,31)
 | ||
|         <if test="pkCountry != null">
 | ||
|             and so.pk_country=#{pkCountry}
 | ||
|         </if>
 | ||
|         <if test="delFlag != null">
 | ||
|             AND so.DEL_FLAG=#{delFlag}
 | ||
|         </if>
 | ||
|         <if test="orderStatus != null">
 | ||
|             AND so.order_status=#{orderStatus}
 | ||
|         </if>
 | ||
| 
 | ||
|         <if test="startDate != null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate != null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         <if test="payTimeStr != null and payTimeStr!='' ">
 | ||
|             AND so.PAY_TIME = to_date(#{payTimeStr}, 'YYYY-MM-dd')
 | ||
|         </if>
 | ||
|         )
 | ||
|     </select>
 | ||
| 
 | ||
|     <!-- 7天重算查询订单-->
 | ||
|     <select id="queryAnewSaOrderByLessDay" parameterType="com.hzs.member.statis.vo.CuBonusVertexStatisVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStatisVO">
 | ||
|         select * from (
 | ||
|         select
 | ||
|         cm.pk_Member pkMember,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         so.PK_COUNTRY pkCountry,
 | ||
|         so.ORDER_TYPE orderType,
 | ||
|         so.ORDER_AMOUNT orderAmount,
 | ||
|         so.ORDER_ACHIEVE orderAchieve,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'), 'yyyy-mm-dd') AS creationTime
 | ||
|         from (
 | ||
|         SELECT pk_member
 | ||
|         FROM ${settleTableName}
 | ||
|         WHERE category = 0
 | ||
|         start with pk_member = #{pkVertex}
 | ||
|         connect by pk_place_parent = prior pk_member
 | ||
|         ) cm
 | ||
|         INNER JOIN SA_ORDER so on so.pk_member = cm.pk_member
 | ||
|         where so.ORDER_TYPE in (1, 2, 3, 13, 20, 24, 25, 26)
 | ||
|         <if test="pkCountry != null">
 | ||
|             and so.pk_country = #{pkCountry}
 | ||
|         </if>
 | ||
|         <if test="delFlag != null">
 | ||
|             AND so.DEL_FLAG = #{delFlag}
 | ||
|         </if>
 | ||
|         <if test="orderStatus != null">
 | ||
|             AND so.order_status = #{orderStatus}
 | ||
|         </if>
 | ||
|         <if test="startDate != null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate != null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         <if test="payTimeStr != null and payTimeStr!='' ">
 | ||
|             AND so.PAY_TIME = to_date(#{payTimeStr}, 'YYYY-MM-dd')
 | ||
|         </if>
 | ||
|         )
 | ||
|     </select>
 | ||
| 
 | ||
|     <!-- 删除奖金拨比统计表数据-->
 | ||
|     <delete id="delStatis">
 | ||
|         delete from CU_BONUS_VERTEX_STATIS
 | ||
|         where 1 = 1
 | ||
|         <if test="pkVertexList!=null and pkVertexList.size> 0 ">
 | ||
|             and PK_BD_VERTEX not in
 | ||
|             <foreach collection="pkVertexList" item="item" open="(" close=")" separator=",">
 | ||
|                 #{item}
 | ||
|             </foreach>
 | ||
|         </if>
 | ||
|         <if test="startDate != null and startDate!='' ">
 | ||
|             and CREATION_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate != null and endDate!='' ">
 | ||
|             and CREATION_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|     </delete>
 | ||
| 
 | ||
|     <!--   查询奖金扣项配置参数-->
 | ||
|     <select id="bonusDeductlist" parameterType="com.hzs.member.statis.vo.CuBonusVertexStatisVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStatisVO">
 | ||
|         select a.PK_ID,
 | ||
|         b.PK_ID as pkId,
 | ||
|         (a.BACK_RATIO+a.PLATFORM_RATIO)/100 backRatio
 | ||
|         from BD_BONUS_ITEMS b
 | ||
|         left JOIN BD_BONUS_DEDUCT a on a.PK_BONUS_ITEMS=b.PK_ID
 | ||
|         where
 | ||
|         b.DEL_FLAG =0
 | ||
|         and a.BACK_RATIO>0
 | ||
|         and a.PLATFORM_RATIO>0
 | ||
|         <if test="pkCountry != null ">
 | ||
|             AND b.PK_COUNTRY = #{pkCountry}
 | ||
|         </if>
 | ||
|         ORDER BY a.BACK_RATIO,a.PLATFORM_RATIO DESC
 | ||
|     </select>
 | ||
| 
 | ||
|     <!--      查询生效国外国家-->
 | ||
|     <select id="countrylist" parameterType="com.hzs.member.statis.vo.CuBonusVertexStatisVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStatisVO">
 | ||
|         select pk_id as pkCountry
 | ||
|         from BD_COUNTRY
 | ||
|         where pk_id!=1 and del_flag = 0 and EFFECTIVE_DATE <= sysdate
 | ||
| 
 | ||
|     </select>
 | ||
| 
 | ||
|     <!-- 查询有效顶点 -->
 | ||
|     <select id="vertexList" parameterType="com.hzs.member.statis.vo.CuBonusVertexStatisVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStatisVO">
 | ||
|         SELECT
 | ||
|         m.pk_id as pkVertex,
 | ||
|         m.MEMBER_CODE as memberCode,
 | ||
|         m.MEMBER_NAME as memberName
 | ||
|         FROM
 | ||
|         cu_member m
 | ||
|         WHERE
 | ||
|         m.pk_place_parent = 2
 | ||
|         AND m.del_flag = 0
 | ||
|         AND m.category = 0
 | ||
|         AND m.pk_country = 1
 | ||
|         AND m.pay_status = 1
 | ||
|         <if test="pkVertex != null">
 | ||
|             AND m.pk_id = #{pkVertex}
 | ||
|         </if>
 | ||
|         ORDER BY m.pk_id ASC
 | ||
|     </select>
 | ||
| 
 | ||
|     <!--     查询中国奖金-->
 | ||
|     <select id="queryChinaCountryBonus" parameterType="com.hzs.member.statis.vo.CuBonusVertexStatisVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStatisVO">
 | ||
|         select
 | ||
|         #{pkCountry} pkCountry,sum(mbp.REAL_INCOME) realIncome,
 | ||
|         mbp.PK_COUNTRY con,
 | ||
|         bbi.BONUS_VALUE bonusType,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
 | ||
|         from cu_member_bonus_push mbp
 | ||
|         INNER JOIN CU_MEMBER_BONUS cmb on mbp.PK_BONUS=cmb.pk_id
 | ||
|         INNER join ( SELECT cm.pk_id FROM cu_member cm WHERE del_flag = 0 AND category = 0 START WITH pk_place_parent
 | ||
|         =#{pkVertex} CONNECT BY pk_place_parent = PRIOR pk_id ) cm
 | ||
|         on cm.pk_id = cmb.pk_member
 | ||
|         inner join BD_BONUS_ITEMS bbi on bbi.pk_id=mbp.PK_BONUS_ITEMS
 | ||
|         INNER JOIN sa_order so on so.pk_id=mbp.pk_order and so.PK_COUNTRY=#{pkCountry} and so.del_flag=0
 | ||
|         where mbp.DEL_FLAG=0
 | ||
|         and mbp.INCOME_STATUS=0
 | ||
|         and bbi.BONUS_VALUE in (3,4,5,7,8,9,12,24,20,21,14,15,16,1)
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY mbp.PK_COUNTRY,
 | ||
|         bbi.BONUS_VALUE,
 | ||
|         to_char(so.PAY_TIME, 'yyyy-mm-dd')
 | ||
|         UNION ALL
 | ||
|         select
 | ||
|         #{pkCountry} pkCountry,sum(mbe.REAL_INCOME) realIncome,
 | ||
|         mbe.PK_COUNTRY con,
 | ||
|         bbi.BONUS_VALUE bonusType,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
 | ||
|         from CU_MEMBER_BONUS_EXPAND mbe
 | ||
|         INNER JOIN CU_MEMBER_BONUS cmb on mbe.PK_BONUS=cmb.pk_id
 | ||
|         INNER join ( SELECT cm.pk_id FROM cu_member cm WHERE del_flag = 0 AND category = 0 START WITH pk_place_parent
 | ||
|         =#{pkVertex} CONNECT BY pk_place_parent = PRIOR pk_id ) cm
 | ||
|         on cm.pk_id = cmb.pk_member
 | ||
|         inner join BD_BONUS_ITEMS bbi on bbi.pk_id=mbe.PK_BONUS_ITEMS
 | ||
|         INNER JOIN sa_order so on so.pk_id=mbe.pk_order and so.PK_COUNTRY=#{pkCountry} and so.del_flag=0
 | ||
|         where mbe.DEL_FLAG=0
 | ||
|         and mbe.INCOME_STATUS=0
 | ||
|         and bbi.BONUS_VALUE in (3,4,5,7,8,9,12,24,20,21,14,15,16,1)
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY mbe.PK_COUNTRY,
 | ||
|         bbi.BONUS_VALUE,
 | ||
|         to_char(so.PAY_TIME, 'yyyy-mm-dd')
 | ||
|         UNION ALL
 | ||
|         select
 | ||
|         #{pkCountry} pkCountry,sum(mbc.REAL_INCOME) realIncome,
 | ||
|         mbc.PK_COUNTRY con,
 | ||
|         bbi.BONUS_VALUE bonusType,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
 | ||
|         from CU_MEMBER_BONUS_COACH mbc
 | ||
|         INNER JOIN CU_MEMBER_BONUS cmb on mbc.PK_BONUS=cmb.pk_id
 | ||
|         INNER join ( SELECT cm.pk_id FROM cu_member cm WHERE del_flag = 0 AND category = 0 START WITH pk_place_parent
 | ||
|         =#{pkVertex} CONNECT BY pk_place_parent = PRIOR pk_id ) cm
 | ||
|         on cm.pk_id = cmb.pk_member
 | ||
|         inner join BD_BONUS_ITEMS bbi on bbi.pk_id=mbc.PK_BONUS_ITEMS
 | ||
|         INNER JOIN sa_order so on so.pk_id=mbc.pk_order and so.PK_COUNTRY=#{pkCountry} and so.del_flag=0
 | ||
|         where mbc.DEL_FLAG=0
 | ||
|         and mbc.INCOME_STATUS=0
 | ||
|         and bbi.BONUS_VALUE in (3,4,5,7,8,9,12,24,20,21,14,15,16,1)
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY mbc.PK_COUNTRY,
 | ||
|         bbi.BONUS_VALUE,
 | ||
|         to_char(so.PAY_TIME, 'yyyy-mm-dd')
 | ||
|         UNION ALL
 | ||
|         select
 | ||
|         #{pkCountry} pkCountry,sum(mbr.REAL_INCOME) realIncome,
 | ||
|         mbr.PK_COUNTRY con,
 | ||
|         bbi.BONUS_VALUE bonusType,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
 | ||
|         from cu_member_bonus_range mbr
 | ||
|         INNER JOIN CU_MEMBER_BONUS cmb on mbr.PK_BONUS=cmb.pk_id
 | ||
|         INNER join ( SELECT cm.pk_id FROM cu_member cm WHERE del_flag = 0 AND category = 0 START WITH pk_place_parent
 | ||
|         =#{pkVertex} CONNECT BY pk_place_parent = PRIOR pk_id ) cm
 | ||
|         on cm.pk_id = cmb.pk_member
 | ||
|         inner join BD_BONUS_ITEMS bbi on bbi.pk_id=mbr.PK_BONUS_ITEMS
 | ||
|         INNER JOIN sa_order so on so.pk_id=mbr.pk_order and so.PK_COUNTRY=#{pkCountry} and so.del_flag=0
 | ||
|         where mbr.DEL_FLAG=0
 | ||
|         and mbr.INCOME_STATUS=0
 | ||
|         and bbi.BONUS_VALUE in (3,4,5,7,8,9,12,24,20,21,14,15,16,1)
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY bbi.BONUS_VALUE,
 | ||
|         mbr.PK_COUNTRY,
 | ||
|         to_char(so.PAY_TIME, 'yyyy-mm-dd')
 | ||
|         UNION ALL
 | ||
|         select
 | ||
|         #{pkCountry} pkCountry,sum(mbd.REAL_INCOME) realIncome,
 | ||
|         mbd.PK_COUNTRY con,
 | ||
|         bbi.BONUS_VALUE bonusType,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime
 | ||
|         from cu_member_bonus_detail mbd
 | ||
|         INNER JOIN CU_MEMBER_BONUS cmb on mbd.PK_BONUS=cmb.pk_id
 | ||
|         INNER join ( SELECT cm.pk_id FROM cu_member cm WHERE del_flag = 0 AND category = 0 START WITH pk_place_parent
 | ||
|         =#{pkVertex} CONNECT BY pk_place_parent = PRIOR pk_id ) cm
 | ||
|         on cm.pk_id = cmb.pk_member
 | ||
|         inner join BD_BONUS_ITEMS bbi on bbi.pk_id=mbd.PK_BONUS_ITEMS
 | ||
|         INNER JOIN sa_order so on so.pk_id=mbd.pk_order and so.PK_COUNTRY=#{pkCountry} and so.del_flag=0
 | ||
|         where mbd.DEL_FLAG=0
 | ||
|         and mbd.INCOME_STATUS=0
 | ||
|         and bbi.BONUS_VALUE in (3,4,5,7,8,9,12,24,20,21,14,15,16,1)
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY bbi.BONUS_VALUE,
 | ||
|         mbd.PK_COUNTRY,
 | ||
|         to_char(so.PAY_TIME, 'yyyy-mm-dd')
 | ||
|     </select>
 | ||
| 
 | ||
|     <!-- 查询7天重算奖金查询-->
 | ||
|     <select id="queryVertexChinaCountryBonus" parameterType="com.hzs.member.statis.vo.CuBonusVertexStatisVO"
 | ||
|             resultType="com.hzs.member.statis.vo.CuBonusVertexStatisVO">
 | ||
|         <!-- 直推收益 -->
 | ||
|         select
 | ||
|         #{pkCountry} pkCountry, mbp.PK_COUNTRY con,
 | ||
|         sum(mbp.REAL_INCOME) realIncome,
 | ||
|         bbi.BONUS_VALUE bonusType,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'), 'yyyy-mm-dd') AS creationTime,
 | ||
|         0 cal_fir_achieve, 0 cal_rep_achieve
 | ||
|         from cu_member_bonus_push mbp
 | ||
|         INNER JOIN CU_MEMBER_BONUS cmb on mbp.PK_BONUS = cmb.pk_id
 | ||
|         INNER join (
 | ||
|         SELECT pk_member
 | ||
|         FROM ${settleTableName}
 | ||
|         WHERE category = 0
 | ||
|         start with pk_member = #{pkVertex}
 | ||
|         connect by pk_place_parent = prior pk_member) cm
 | ||
|         on cm.pk_member = cmb.pk_member
 | ||
|         inner join BD_BONUS_ITEMS bbi on bbi.pk_id = mbp.PK_BONUS_ITEMS
 | ||
|         INNER JOIN sa_order so on so.pk_id = mbp.pk_order
 | ||
|         and so.PK_COUNTRY = #{pkCountry} and so.del_flag = 0
 | ||
|         where mbp.DEL_FLAG = 0
 | ||
|         and mbp.INCOME_STATUS = 0
 | ||
|         and bbi.BONUS_VALUE in (1, 3, 4, 5, 7, 8, 9, 12, 14, 15, 16, 20, 21, 24, 25)
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY mbp.PK_COUNTRY,
 | ||
|         bbi.BONUS_VALUE,
 | ||
|         to_char(so.PAY_TIME, 'yyyy-mm-dd')
 | ||
|         UNION ALL
 | ||
|         <!-- 拓展收益、消费拓展收益,收益状态:正常,延缓发放 -->
 | ||
|         select
 | ||
|         #{pkCountry} pkCountry, mbe.PK_COUNTRY con,
 | ||
|         sum(mbe.REAL_INCOME) realIncome,
 | ||
|         bbi.BONUS_VALUE bonusType,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'),'yyyy-mm-dd') AS creationTime,
 | ||
|         sum(mbe.cal_fir_achieve) cal_fir_achieve, sum(mbe.cal_rep_achieve) cal_rep_achieve
 | ||
|         from CU_MEMBER_BONUS_EXPAND mbe
 | ||
|         INNER JOIN CU_MEMBER_BONUS cmb on mbe.PK_BONUS=cmb.pk_id
 | ||
|         INNER join ( SELECT pk_member
 | ||
|         FROM ${settleTableName}
 | ||
|         WHERE category = 0
 | ||
|         start with pk_member = #{pkVertex}
 | ||
|         connect by pk_place_parent = prior pk_member ) cm
 | ||
|         on cm.pk_member = cmb.pk_member
 | ||
|         inner join BD_BONUS_ITEMS bbi on bbi.pk_id = mbe.PK_BONUS_ITEMS
 | ||
|         INNER JOIN sa_order so on so.pk_id = mbe.pk_order
 | ||
|         and so.PK_COUNTRY = #{pkCountry} and so.del_flag = 0
 | ||
|         where mbe.DEL_FLAG = 0
 | ||
|         and mbe.INCOME_STATUS in (0, 4)
 | ||
|         and mbe.pk_order != 0
 | ||
|         and bbi.BONUS_VALUE in (1, 3, 4, 5, 7, 8, 9, 12, 14, 15, 16, 20, 21, 24, 25)
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY mbe.PK_COUNTRY,
 | ||
|         bbi.BONUS_VALUE,
 | ||
|         to_char(so.PAY_TIME, 'yyyy-mm-dd')
 | ||
|         UNION ALL
 | ||
|         <!-- 辅导收益,收益状态:正常,延缓发放 -->
 | ||
|         select
 | ||
|         #{pkCountry} pkCountry, mbc.PK_COUNTRY con,
 | ||
|         sum(mbc.REAL_INCOME) realIncome,
 | ||
|         bbi.BONUS_VALUE bonusType,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'), 'yyyy-mm-dd') AS creationTime,
 | ||
|         0, 0
 | ||
|         from CU_MEMBER_BONUS_COACH mbc
 | ||
|         INNER JOIN CU_MEMBER_BONUS cmb on mbc.PK_BONUS=cmb.pk_id
 | ||
|         INNER join ( SELECT pk_member
 | ||
|         FROM ${settleTableName}
 | ||
|         WHERE category=0
 | ||
|         start with pk_member = #{pkVertex}
 | ||
|         connect by pk_place_parent = prior pk_member ) cm
 | ||
|         on cm.pk_member = cmb.pk_member
 | ||
|         inner join BD_BONUS_ITEMS bbi on bbi.pk_id = mbc.PK_BONUS_ITEMS
 | ||
|         INNER JOIN sa_order so on so.pk_id = mbc.pk_order
 | ||
|         and so.PK_COUNTRY = #{pkCountry} and so.del_flag = 0
 | ||
|         where mbc.DEL_FLAG = 0
 | ||
|         and mbc.INCOME_STATUS in (0, 4)
 | ||
|         and mbc.pk_order != 0
 | ||
|         and bbi.BONUS_VALUE in (1, 3, 4, 5, 7, 8, 9, 12, 14, 15, 16, 20, 21, 24, 25)
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY mbc.PK_COUNTRY,
 | ||
|         bbi.BONUS_VALUE,
 | ||
|         to_char(so.PAY_TIME, 'yyyy-mm-dd')
 | ||
|         UNION ALL
 | ||
|         <!-- 复购级差 -->
 | ||
|         select
 | ||
|         #{pkCountry} pkCountry, mbr.PK_COUNTRY con,
 | ||
|         sum(mbr.REAL_INCOME) realIncome,
 | ||
|         bbi.BONUS_VALUE bonusType,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'), 'yyyy-mm-dd') AS creationTime,
 | ||
|         0, 0
 | ||
|         from cu_member_bonus_range mbr
 | ||
|         INNER JOIN CU_MEMBER_BONUS cmb on mbr.PK_BONUS=cmb.pk_id
 | ||
|         INNER join ( SELECT pk_member
 | ||
|         FROM ${settleTableName}
 | ||
|         WHERE category = 0
 | ||
|         start with pk_member = #{pkVertex}
 | ||
|         connect by pk_place_parent = prior pk_member ) cm
 | ||
|         on cm.pk_member = cmb.pk_member
 | ||
|         inner join BD_BONUS_ITEMS bbi on bbi.pk_id = mbr.PK_BONUS_ITEMS
 | ||
|         INNER JOIN sa_order so on so.pk_id = mbr.pk_order
 | ||
|         and so.PK_COUNTRY = #{pkCountry} and so.del_flag = 0
 | ||
|         where mbr.DEL_FLAG = 0
 | ||
|         and mbr.INCOME_STATUS = 0
 | ||
|         and bbi.BONUS_VALUE in (1, 3, 4, 5, 7, 8, 9, 12, 14, 15, 16, 20, 21, 24, 25)
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY bbi.BONUS_VALUE,
 | ||
|         mbr.PK_COUNTRY,
 | ||
|         to_char(so.PAY_TIME, 'yyyy-mm-dd')
 | ||
|         UNION ALL
 | ||
|         <!-- 报单服务费 -->
 | ||
|         select
 | ||
|         #{pkCountry} pkCountry, mbd.PK_COUNTRY con,
 | ||
|         sum(mbd.REAL_INCOME) realIncome,
 | ||
|         bbi.BONUS_VALUE bonusType,
 | ||
|         #{pkVertex} pkVertex,
 | ||
|         to_date(to_char(so.PAY_TIME, 'yyyy-mm-dd'), 'yyyy-mm-dd') AS creationTime,
 | ||
|         0, 0
 | ||
|         from cu_member_bonus_detail mbd
 | ||
|         INNER JOIN CU_MEMBER_BONUS cmb on mbd.PK_BONUS=cmb.pk_id
 | ||
|         INNER join ( SELECT pk_member
 | ||
|         FROM ${settleTableName}
 | ||
|         WHERE category = 0
 | ||
|         start with pk_member = #{pkVertex}
 | ||
|         connect by pk_place_parent = prior pk_member ) cm
 | ||
|         on cm.pk_member = cmb.pk_member
 | ||
|         inner join BD_BONUS_ITEMS bbi on bbi.pk_id = mbd.PK_BONUS_ITEMS
 | ||
|         INNER JOIN sa_order so on so.pk_id = mbd.pk_order
 | ||
|         and so.PK_COUNTRY = #{pkCountry} and so.del_flag = 0
 | ||
|         where mbd.DEL_FLAG = 0
 | ||
|         and mbd.INCOME_STATUS = 0
 | ||
|         and bbi.BONUS_VALUE in (1, 3, 4, 5, 7, 8, 9, 12, 14, 15, 16, 20, 21, 24, 25)
 | ||
|         <if test="startDate!=null and startDate!='' ">
 | ||
|             and so.PAY_TIME >= to_date(#{startDate}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|         <if test="endDate!=null and endDate!='' ">
 | ||
|             and so.PAY_TIME <= to_date(#{endDate} || ' 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
 | ||
|         </if>
 | ||
|         GROUP BY bbi.BONUS_VALUE,
 | ||
|         mbd.PK_COUNTRY,
 | ||
|         to_char(so.PAY_TIME, 'yyyy-mm-dd')
 | ||
|     </select>
 | ||
| 
 | ||
|     <!--   查询当天团队统计数据-->
 | ||
|     <select id="getCuBonusStatis" parameterType="com.hzs.common.domain.member.statis.CuBonusVertexStatis"
 | ||
|             resultType="com.hzs.common.domain.member.statis.CuBonusVertexStatis">
 | ||
|         SELECT *
 | ||
|         FROM CU_BONUS_VERTEX_STATIS a
 | ||
|         WHERE 1 = 1
 | ||
|         <if test="pkBdVertex != null ">
 | ||
|             AND a.PK_BD_VERTEX = #{pkBdVertex}
 | ||
|         </if>
 | ||
|         <if test="pkCountry != null ">
 | ||
|             AND a.PK_COUNTRY = #{pkCountry}
 | ||
|         </if>
 | ||
|         <if test="creationTime != null ">
 | ||
|             and to_char(a.CREATION_TIME, 'yyyy-mm-dd') = to_char(#{creationTime}, 'yyyy-mm-dd')
 | ||
|         </if>
 | ||
|     </select>
 | ||
| 
 | ||
| </mapper>
 |