|
@@ -733,4 +733,131 @@
|
|
|
</where>
|
|
|
order by mpa.user_id
|
|
|
</select>
|
|
|
- </mapper>
|
|
|
+
|
|
|
+ <!--资产评估人员提成计算-->
|
|
|
+ <select id="assetsEvaluatorCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
|
|
|
+ SELECT bpd.member_id as id,
|
|
|
+ u.name as userName,
|
|
|
+ SUM(IF(cd.defined_low_limit_amount < fc.claim_amount,
|
|
|
+ fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
|
|
|
+ cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
|
|
|
+ )) AS commissionTotalAmount
|
|
|
+ FROM
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ claim_amount,
|
|
|
+ order_fund_id,
|
|
|
+ production_fund_id,
|
|
|
+ claim_datetime
|
|
|
+ FROM
|
|
|
+ finance_claim
|
|
|
+ WHERE
|
|
|
+ deleted = 0
|
|
|
+ AND production_fund_id IS NOT NULL
|
|
|
+ AND claim_datetime >= #{vo.startDate}
|
|
|
+ AND claim_datetime <= #{vo.endDate}
|
|
|
+ UNION ALL
|
|
|
+ SELECT
|
|
|
+ allot_amount AS claim_amount,
|
|
|
+ order_fund_id,
|
|
|
+ production_fund_id,
|
|
|
+ created AS claim_datetime
|
|
|
+ FROM
|
|
|
+ order_fund_allot
|
|
|
+ WHERE
|
|
|
+ deleted = 0
|
|
|
+ AND created >= #{vo.startDate}
|
|
|
+ AND created <= #{vo.endDate}
|
|
|
+ ) fc
|
|
|
+ INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
|
|
|
+ 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
|
|
|
+ )
|
|
|
+ INNER JOIN ( SELECT id, business_id, project_name, production_no, production_type, save_file_date, created FROM
|
|
|
+ assets_production
|
|
|
+ WHERE deleted = 0 AND save_file_date IS NOT NULL ) ap ON ap.production_no = pf.production_no
|
|
|
+ LEFT JOIN assets a ON a.id = ap.business_id
|
|
|
+ INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id, ratio, defined_low_limit_amount FROM
|
|
|
+ commission_declare WHERE
|
|
|
+ business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
|
|
|
+ cd.business_id = a.id
|
|
|
+ AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
|
|
|
+ LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
|
|
|
+ LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
|
|
|
+ LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution FROM
|
|
|
+ business_performance_distribution WHERE deleted = 0
|
|
|
+ AND user_type = '评估人员'
|
|
|
+
|
|
|
+ ) bpd ON ( bpd.business_id = a.id AND bpd.report_no = ap.production_no)
|
|
|
+ LEFT JOIN user u ON u.id = bpd.member_id
|
|
|
+
|
|
|
+ GROUP BY
|
|
|
+ bpd.member_id
|
|
|
+# ,
|
|
|
+# u.name,
|
|
|
+# commissionTotalAmount
|
|
|
+# having 1=1
|
|
|
+ <if test="vo!=null and vo.userName!=null and vo.userName!=''">
|
|
|
+ and u.name like concat ('%',#{vo.userName},'%')
|
|
|
+ </if>
|
|
|
+ order by commissionTotalAmount DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!--资产评估人员提成计算详情-->
|
|
|
+ <select id="assetsEvaluatorCommissionDetail" resultType="com.dayou.vo.UserCommissionProdVO">
|
|
|
+ SELECT
|
|
|
+ ap.id,
|
|
|
+ fc.claim_amount as realAmount,
|
|
|
+ ap.production_no AS reportNo,
|
|
|
+ IF
|
|
|
+ ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
|
|
|
+ ap.project_name AS name,
|
|
|
+ ap.created,
|
|
|
+ dd.NAME AS businessCate,
|
|
|
+ bcr.min_ratio AS ratio,
|
|
|
+ bpd.member_id,
|
|
|
+ bpd.performance_distribution AS allotRatio,
|
|
|
+ ( fc.claim_amount * ( bcr.min_ratio / 100 )* bpd.performance_distribution ) AS commissionAmount,
|
|
|
+ ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
|
|
|
+ u.name as userName
|
|
|
+ FROM
|
|
|
+ (
|
|
|
+ SELECT
|
|
|
+ claim_amount,
|
|
|
+ order_fund_id,
|
|
|
+ production_fund_id,
|
|
|
+ claim_datetime
|
|
|
+ FROM
|
|
|
+ finance_claim
|
|
|
+ WHERE
|
|
|
+ deleted = 0
|
|
|
+ AND production_fund_id IS NOT NULL
|
|
|
+ AND claim_datetime >= #{vo.startDate}
|
|
|
+ AND claim_datetime <= #{vo.endDate}
|
|
|
+ UNION ALL
|
|
|
+ SELECT
|
|
|
+ allot_amount AS claim_amount,
|
|
|
+ order_fund_id,
|
|
|
+ production_fund_id,
|
|
|
+ created AS claim_datetime
|
|
|
+ FROM
|
|
|
+ order_fund_allot
|
|
|
+ WHERE
|
|
|
+ deleted = 0
|
|
|
+ AND created >= #{vo.startDate}
|
|
|
+ AND created <= #{vo.endDate}
|
|
|
+ ) fc
|
|
|
+ INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
|
|
|
+ INNER JOIN ( SELECT id, business_id, project_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) ap ON ap.production_no = pf.production_no
|
|
|
+ LEFT JOIN assets a ON a.id = ap.business_id
|
|
|
+ INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
|
|
|
+ cd.business_id = a.id
|
|
|
+ AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
|
|
|
+ LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
|
|
|
+ LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
|
|
|
+ LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '评估人员' ) bpd ON ( bpd.business_id = a.id AND bpd.report_no = ap.production_no)
|
|
|
+ LEFT JOIN user u on u.id = bpd.member_id
|
|
|
+ WHERE
|
|
|
+ bpd.member_id = #{vo.userId}
|
|
|
+ order by settleDate DESC
|
|
|
+ </select>
|
|
|
+</mapper>
|