|
|
@@ -86,95 +86,104 @@
|
|
|
</select>
|
|
|
|
|
|
<select id="commissionDetails" resultType="com.jzg.commons.entity.vo.DistributionCommissionDetailVo">
|
|
|
+ SELECT
|
|
|
+ t.orderNo,
|
|
|
+ t.premium,
|
|
|
+ t.salesman,
|
|
|
+ su_sales.mobile AS salesmanMobile,
|
|
|
+ t.signingTime,
|
|
|
+ t.distributor,
|
|
|
+ t.distributorMobile,
|
|
|
+ t.commission,
|
|
|
+ t.distributionRatio,
|
|
|
+ t.distributionLevel
|
|
|
+ FROM (
|
|
|
+ -- 一级分销
|
|
|
SELECT
|
|
|
ifo.order_no AS orderNo,
|
|
|
ifo.total_premium AS premium,
|
|
|
io.real_quote_user_id AS salesman,
|
|
|
- io.real_quote_user_id AS salesmanMobile,
|
|
|
io.signing_time AS signingTime,
|
|
|
- suji.name as distributor,
|
|
|
- su.mobile as distributorMobile,
|
|
|
- ifo.first_distribution_fee as commission,
|
|
|
+ suji.name AS distributor,
|
|
|
+ su.mobile AS distributorMobile,
|
|
|
+ ifo.first_distribution_fee AS commission,
|
|
|
ifo.first_distribution_ratio AS distributionRatio,
|
|
|
- '1' AS distributionLevel -- 标识为一级分销
|
|
|
- FROM
|
|
|
- ins_fee_orders ifo
|
|
|
- LEFT JOIN ins_orders io ON ifo.order_no = io.id
|
|
|
+ '1' AS distributionLevel,
|
|
|
+ ifo.first_distributor_id AS distributor_id
|
|
|
+ FROM ins_fee_orders ifo
|
|
|
+ INNER JOIN ins_orders io ON ifo.order_no = io.id
|
|
|
LEFT JOIN sys_user_jzg_info suji ON ifo.first_distributor_id = suji.id AND suji.is_delete = 0
|
|
|
- left join sys_user su on su.id = suji.user_id AND su.is_delete = 0
|
|
|
- WHERE
|
|
|
- ifo.is_delete = 0
|
|
|
- and ifo.first_distributor_id IS NOT NULL
|
|
|
+ LEFT JOIN sys_user su ON su.id = suji.user_id AND su.is_delete = 0
|
|
|
+ WHERE ifo.is_delete = 0
|
|
|
+ AND ifo.first_distributor_id IS NOT NULL
|
|
|
<if test="distributionCommissionDetailVo.distributor != null and distributionCommissionDetailVo.distributor != ''">
|
|
|
- and suji.name = #{distributionCommissionDetailVo.distributor}
|
|
|
+ AND suji.name = #{distributionCommissionDetailVo.distributor}
|
|
|
</if>
|
|
|
<if test="distributionCommissionDetailVo.distributorMobile != null and distributionCommissionDetailVo.distributorMobile != ''">
|
|
|
- and su.mobile = #{distributionCommissionDetailVo.distributorMobile}
|
|
|
- </if>
|
|
|
- <if test="distributionCommissionDetailVo.signingTimeStart != null">
|
|
|
- and io.signing_time between #{distributionCommissionDetailVo.signingTimeStart} and #{distributionCommissionDetailVo.signingTimeEnd}
|
|
|
+ AND su.mobile = #{distributionCommissionDetailVo.distributorMobile}
|
|
|
</if>
|
|
|
+
|
|
|
UNION ALL
|
|
|
+
|
|
|
+ -- 二级分销
|
|
|
SELECT
|
|
|
ifo.order_no AS orderNo,
|
|
|
ifo.total_premium AS premium,
|
|
|
io.real_quote_user_id AS salesman,
|
|
|
- io.real_quote_user_id AS salesmanMobile,
|
|
|
io.signing_time AS signingTime,
|
|
|
- suji.name as distributor,
|
|
|
- su.mobile as distributorMobile,
|
|
|
- ifo.second_distribution_fee as commission,
|
|
|
+ suji.name AS distributor,
|
|
|
+ su.mobile AS distributorMobile,
|
|
|
+ ifo.second_distribution_fee AS commission,
|
|
|
ifo.second_distribution_ratio AS distributionRatio,
|
|
|
- '2' AS distributionLevel -- 标识为二级分销
|
|
|
- FROM
|
|
|
- ins_fee_orders ifo
|
|
|
- LEFT JOIN ins_orders io ON ifo.order_no = io.id
|
|
|
+ '2' AS distributionLevel,
|
|
|
+ ifo.second_distributor_id AS distributor_id
|
|
|
+ FROM ins_fee_orders ifo
|
|
|
+ INNER JOIN ins_orders io ON ifo.order_no = io.id
|
|
|
LEFT JOIN sys_user_jzg_info suji ON ifo.second_distributor_id = suji.id AND suji.is_delete = 0
|
|
|
- left join sys_user su on su.id = suji.user_id AND su.is_delete = 0
|
|
|
- WHERE
|
|
|
- ifo.is_delete = 0
|
|
|
- and ifo.second_distributor_id IS NOT NULL
|
|
|
- <if test="distributionCommissionDetailVo.signingTimeStart != null">
|
|
|
- and io.signing_time between #{distributionCommissionDetailVo.signingTimeStart} and #{distributionCommissionDetailVo.signingTimeEnd}
|
|
|
- </if>
|
|
|
+ LEFT JOIN sys_user su ON su.id = suji.user_id AND su.is_delete = 0
|
|
|
+ WHERE ifo.is_delete = 0
|
|
|
+ AND ifo.second_distributor_id IS NOT NULL
|
|
|
<if test="distributionCommissionDetailVo.distributor != null and distributionCommissionDetailVo.distributor != ''">
|
|
|
- and suji.name = #{distributionCommissionDetailVo.distributor}
|
|
|
+ AND suji.name = #{distributionCommissionDetailVo.distributor}
|
|
|
</if>
|
|
|
<if test="distributionCommissionDetailVo.distributorMobile != null and distributionCommissionDetailVo.distributorMobile != ''">
|
|
|
- and su.mobile = #{distributionCommissionDetailVo.distributorMobile}
|
|
|
+ AND su.mobile = #{distributionCommissionDetailVo.distributorMobile}
|
|
|
</if>
|
|
|
+
|
|
|
UNION ALL
|
|
|
+
|
|
|
+ -- 三级分销
|
|
|
SELECT
|
|
|
ifo.order_no AS orderNo,
|
|
|
ifo.total_premium AS premium,
|
|
|
io.real_quote_user_id AS salesman,
|
|
|
- io.real_quote_user_id AS salesmanMobile,
|
|
|
io.signing_time AS signingTime,
|
|
|
- suji.name AS distributor,
|
|
|
- su.mobile as distributorMobile,
|
|
|
- ifo.third_distribution_fee as commission,
|
|
|
+ suji.name AS distributor,
|
|
|
+ su.mobile AS distributorMobile,
|
|
|
+ ifo.third_distribution_fee AS commission,
|
|
|
ifo.third_distribution_ratio AS distributionRatio,
|
|
|
- '3' AS distributionLevel
|
|
|
- FROM
|
|
|
- ins_fee_orders ifo
|
|
|
- LEFT JOIN ins_orders io ON ifo.order_no = io.id
|
|
|
+ '3' AS distributionLevel,
|
|
|
+ ifo.third_distributor_id AS distributor_id
|
|
|
+ FROM ins_fee_orders ifo
|
|
|
+ INNER JOIN ins_orders io ON ifo.order_no = io.id
|
|
|
LEFT JOIN sys_user_jzg_info suji ON ifo.third_distributor_id = suji.id AND suji.is_delete = 0
|
|
|
- left join sys_user su on su.id = suji.user_id AND su.is_delete = 0
|
|
|
- WHERE
|
|
|
- ifo.is_delete = 0
|
|
|
- and ifo.third_distributor_id IS NOT NULL
|
|
|
- <if test="distributionCommissionDetailVo.signingTimeStart != null">
|
|
|
- and io.signing_time between #{distributionCommissionDetailVo.signingTimeStart} and #{distributionCommissionDetailVo.signingTimeEnd}
|
|
|
- </if>
|
|
|
+ LEFT JOIN sys_user su ON su.id = suji.user_id AND su.is_delete = 0
|
|
|
+ WHERE ifo.is_delete = 0
|
|
|
+ AND ifo.third_distributor_id IS NOT NULL
|
|
|
<if test="distributionCommissionDetailVo.distributor != null and distributionCommissionDetailVo.distributor != ''">
|
|
|
- and suji.name = #{distributionCommissionDetailVo.distributor}
|
|
|
+ AND suji.name = #{distributionCommissionDetailVo.distributor}
|
|
|
</if>
|
|
|
<if test="distributionCommissionDetailVo.distributorMobile != null and distributionCommissionDetailVo.distributorMobile != ''">
|
|
|
- and su.mobile = #{distributionCommissionDetailVo.distributorMobile}
|
|
|
+ AND su.mobile = #{distributionCommissionDetailVo.distributorMobile}
|
|
|
+ </if>
|
|
|
+ ) t
|
|
|
+ LEFT JOIN sys_user su_sales ON su_sales.id = t.salesman AND su_sales.is_delete = 0
|
|
|
+ WHERE 1 = 1
|
|
|
+ <if test="distributionCommissionDetailVo.signingTimeStart != null and distributionCommissionDetailVo.signingTimeEnd != null">
|
|
|
+ AND t.signingTime BETWEEN #{distributionCommissionDetailVo.signingTimeStart}
|
|
|
+ AND #{distributionCommissionDetailVo.signingTimeEnd}
|
|
|
</if>
|
|
|
- ORDER BY
|
|
|
- orderNo,
|
|
|
- distributionLevel
|
|
|
+ ORDER BY t.orderNo, t.distributionLevel
|
|
|
</select>
|
|
|
|
|
|
<select id="distributionTeam" resultType="com.jzg.commons.entity.vo.DistributionTeamVo">
|