|
@@ -1180,275 +1180,430 @@
|
|
|
</select>
|
|
|
<!--资产评估人员提成计算-->
|
|
|
<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 allCommissionTotalAmount,
|
|
|
- SUM(IF(ap.save_file_date IS NOT NULL, (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)
|
|
|
- )), 0)) 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, assets_name, production_no, production_type, save_file_date, created FROM
|
|
|
- assets_production
|
|
|
- WHERE deleted = 0) 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
|
|
|
- having 1=1
|
|
|
- <if test="vo!=null and vo.userName!=null and vo.userName!=''">
|
|
|
- and u.name like concat ('%',#{vo.userName},'%')
|
|
|
+ <if test="vo.commissionType != null and vo.commissionType == '预计提成'">
|
|
|
+ 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, assets_name, production_no, production_type, save_file_date, created FROM
|
|
|
+ assets_production
|
|
|
+ WHERE deleted = 0) 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
|
|
|
+ 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
|
|
|
+ </if>
|
|
|
+ <if test="vo.commissionType != null and vo.commissionType == '已归档提成'">
|
|
|
+ SELECT user.id AS id,
|
|
|
+ user.name AS userName,
|
|
|
+ SUM((IF(decl.defined_low_limit_amount < claim.claim_amount,
|
|
|
+ claim.claim_amount * (decl.ratio / 100) *
|
|
|
+ (distribution.performance_distribution / 100),
|
|
|
+ decl.defined_low_limit_amount * (decl.ratio / 100) *
|
|
|
+ (distribution.performance_distribution / 100)
|
|
|
+ ))) AS commissionTotalAmount
|
|
|
+ FROM finance_claim AS claim
|
|
|
+ INNER JOIN finance_real_fund AS rFund ON rFund.deleted = 0 AND rFund.id = claim.real_fund_id
|
|
|
+ INNER JOIN production_fund AS pFund ON pFund.deleted = 0 AND business_type = 'ASSET_BUSINESS' AND
|
|
|
+ pFund.id = claim.production_fund_id AND
|
|
|
+ pFund.order_fund_id = claim.order_fund_id
|
|
|
+ INNER JOIN assets_production AS pro
|
|
|
+ ON pro.deleted = 0 AND save_file_date IS NOT NULL AND pro.production_no = pFund.production_no
|
|
|
+ INNER JOIN assets ON assets.id = pro.business_id
|
|
|
+ INNER JOIN user ON user.id = assets.principal_id
|
|
|
+ INNER JOIN commission_declare AS decl
|
|
|
+ ON decl.deleted = 0 AND decl.business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND
|
|
|
+ decl.business_id = assets.id AND decl.production_id = pro.id
|
|
|
+ INNER JOIN business_performance_distribution AS distribution
|
|
|
+ ON distribution.deleted = 0 AND distribution.business_type = 'ASSET_BUSINESS' AND
|
|
|
+ distribution.declare_id = decl.id AND member_id = decl.declare_user_id
|
|
|
+ WHERE claim.deleted = 0
|
|
|
+ AND claim.production_fund_id IS NOT NULL
|
|
|
+ AND IF(claim.claim_datetime > pro.save_file_date, claim.claim_datetime, pro.save_file_date) BETWEEN #{vo.startDate} AND #{vo.endDate}
|
|
|
+ <if test="vo!=null and vo.userName!=null and vo.userName!=''">
|
|
|
+ AND user.name like concat ('%',#{vo.userName},'%')
|
|
|
+ </if>
|
|
|
+ GROUP BY user.id
|
|
|
</if>
|
|
|
- order by commissionTotalAmount DESC
|
|
|
</select>
|
|
|
|
|
|
<!--资产评估人员提成计算详情-->
|
|
|
<select id="assetsEvaluatorCommissionDetail" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
|
|
|
- SELECT
|
|
|
+ <if test="vo.commissionType != null and vo.commissionType == '预计提成'">
|
|
|
+ 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,
|
|
|
+ IF( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
|
|
|
IFNULL(ap.assets_name, a.name) AS name,
|
|
|
- ap.created,
|
|
|
+ ap.create_production_date AS created,
|
|
|
dd.name AS businessCate,
|
|
|
IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
|
|
|
cd.defined_low_limit_amount AS lowLimitAmount,
|
|
|
bpd.member_id,
|
|
|
bpd.performance_distribution AS allotRatio,
|
|
|
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)
|
|
|
+ fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
|
|
|
+ cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
|
|
|
) AS commissionAmount,
|
|
|
IF(cd.defined_low_limit_amount < fc.claim_amount,
|
|
|
- fc.claim_amount * (cd.ratio / 100),
|
|
|
- cd.defined_low_limit_amount * (cd.ratio / 100)
|
|
|
+ fc.claim_amount * (cd.ratio / 100),
|
|
|
+ cd.defined_low_limit_amount * (cd.ratio / 100)
|
|
|
) AS totalAmount,
|
|
|
u.name AS userName,
|
|
|
- pf.modified AS realFundDateTime
|
|
|
- FROM
|
|
|
+ pf.modified AS realFundDateTime,
|
|
|
+ bpd.member_type
|
|
|
+ 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}
|
|
|
+ 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,modified 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, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0) 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
|
|
|
- WHERE
|
|
|
+ INNER JOIN ( SELECT id, order_fund_id, business_id, production_no,modified 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, assets_name, production_no, production_type, save_file_date, create_production_date, created FROM assets_production WHERE deleted = 0) 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, member_type 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
|
|
|
+ order by settleDate DESC
|
|
|
+ </if>
|
|
|
+ <if test="vo.commissionType != null and vo.commissionType == '已归档提成'">
|
|
|
+ SELECT user.id,
|
|
|
+ user.name AS userName,
|
|
|
+ pro.production_no AS reportNo,
|
|
|
+ IFNULL(pro.assets_name, assets.name) AS name,
|
|
|
+ dd.name AS businessCate,
|
|
|
+ IFNULL(decl.ratio, bcr.min_ratio) AS ratio,
|
|
|
+ decl.defined_low_limit_amount AS lowLimitAmount,
|
|
|
+ distribution.performance_distribution AS allotRatio,
|
|
|
+ distribution.member_type,
|
|
|
+ IF(decl.defined_low_limit_amount < claim.claim_amount,
|
|
|
+ claim.claim_amount * (decl.ratio / 100) * (distribution.performance_distribution / 100),
|
|
|
+ decl.defined_low_limit_amount * (decl.ratio / 100) * (distribution.performance_distribution / 100)
|
|
|
+ ) AS commissionAmount,
|
|
|
+ IF(decl.defined_low_limit_amount < claim.claim_amount,
|
|
|
+ claim.claim_amount * (decl.ratio / 100),
|
|
|
+ decl.defined_low_limit_amount * (decl.ratio / 100)
|
|
|
+ ) AS totalAmount,
|
|
|
+ pFund.modified AS realFundDateTime,
|
|
|
+ IF(claim.claim_datetime > pro.save_file_date, claim.claim_datetime, pro.save_file_date) AS settleDate,
|
|
|
+ pro.create_production_date AS created,
|
|
|
+ claim.claim_amount as realAmount
|
|
|
+ FROM finance_claim AS claim
|
|
|
+ INNER JOIN finance_real_fund AS rFund ON rFund.deleted = 0 AND rFund.id = claim.real_fund_id
|
|
|
+ INNER JOIN production_fund AS pFund ON pFund.deleted = 0 AND business_type = 'ASSET_BUSINESS' AND
|
|
|
+ pFund.id = claim.production_fund_id AND
|
|
|
+ pFund.order_fund_id = claim.order_fund_id
|
|
|
+ INNER JOIN assets_production AS pro
|
|
|
+ ON pro.deleted = 0 AND save_file_date IS NOT NULL AND pro.production_no = pFund.production_no
|
|
|
+ INNER JOIN assets ON assets.id = pro.business_id
|
|
|
+ INNER JOIN user ON user.id = assets.principal_id
|
|
|
+ INNER JOIN commission_declare AS decl
|
|
|
+ ON decl.deleted = 0 AND decl.business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND
|
|
|
+ decl.business_id = assets.id AND decl.production_id = pro.id
|
|
|
+ INNER JOIN business_performance_distribution AS distribution
|
|
|
+ ON distribution.deleted = 0 AND distribution.business_type = 'ASSET_BUSINESS' AND
|
|
|
+ distribution.declare_id = decl.id AND member_id = decl.declare_user_id
|
|
|
+ LEFT JOIN business_commission_rate bcr ON bcr.id = decl.commission_rate_id
|
|
|
+ LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
|
|
|
+ WHERE claim.deleted = 0
|
|
|
+ AND claim.production_fund_id IS NOT NULL
|
|
|
+ AND user.id = #{vo.userId}
|
|
|
+ AND IF(claim.claim_datetime > pro.save_file_date, claim.claim_datetime, pro.save_file_date) BETWEEN #{vo.startDate} AND #{vo.endDate}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
<!--资产评估人员合计导出-->
|
|
|
<select id="assetsEvaluatorTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
|
|
|
- SELECT bpd.member_id as id,
|
|
|
- u.name as userName,
|
|
|
- ROUND(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)
|
|
|
- )), 2) AS allCommissionTotalAmount,
|
|
|
- ROUND(SUM(IF(ap.save_file_date IS NOT NULL, (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)
|
|
|
- )), 0)), 2) AS commissionTotalAmount,
|
|
|
- '评估人员' as userType,
|
|
|
- '资产业务' as businessType,
|
|
|
- #{vo.startDate} as startDate,
|
|
|
- #{vo.endDate} as endDate
|
|
|
- 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,
|
|
|
- assets_name,
|
|
|
- production_no,
|
|
|
- production_type,
|
|
|
- save_file_date,
|
|
|
- created
|
|
|
- FROM assets_production
|
|
|
- WHERE deleted = 0) 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, defined_low_limit_amount, ratio
|
|
|
- FROM commission_declare
|
|
|
- WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE'
|
|
|
- AND deleted = 0
|
|
|
- AND declare_result = '审核通过') cd ON (
|
|
|
+ <if test="vo.commissionType != null and vo.commissionType == '预计提成'">
|
|
|
+ SELECT bpd.member_id as id,
|
|
|
+ u.name as userName,
|
|
|
+ ROUND(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)
|
|
|
+ )), 2) AS commissionTotalAmount,
|
|
|
+ '评估人员' as userType,
|
|
|
+ '资产业务' as businessType,
|
|
|
+ #{vo.startDate} as startDate,
|
|
|
+ #{vo.endDate} as endDate
|
|
|
+ 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,
|
|
|
+ assets_name,
|
|
|
+ production_no,
|
|
|
+ production_type,
|
|
|
+ save_file_date,
|
|
|
+ created
|
|
|
+ FROM assets_production
|
|
|
+ WHERE deleted = 0) 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, defined_low_limit_amount, ratio
|
|
|
+ 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
|
|
|
+ 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
|
|
|
+ </if>
|
|
|
+ <if test="vo.commissionType != null and vo.commissionType == '已归档提成'">
|
|
|
+ SELECT user.id AS id,
|
|
|
+ user.name AS userName,
|
|
|
+ SUM((IF(decl.defined_low_limit_amount < claim.claim_amount,
|
|
|
+ claim.claim_amount * (decl.ratio / 100) *
|
|
|
+ (distribution.performance_distribution / 100),
|
|
|
+ decl.defined_low_limit_amount * (decl.ratio / 100) *
|
|
|
+ (distribution.performance_distribution / 100)
|
|
|
+ ))) AS commissionTotalAmount,
|
|
|
+ '评估人员' as userType,
|
|
|
+ '资产业务' as businessType,
|
|
|
+ #{vo.startDate} as startDate,
|
|
|
+ #{vo.endDate} as endDate
|
|
|
+ FROM finance_claim AS claim
|
|
|
+ INNER JOIN finance_real_fund AS rFund ON rFund.deleted = 0 AND rFund.id = claim.real_fund_id
|
|
|
+ INNER JOIN production_fund AS pFund ON pFund.deleted = 0 AND business_type = 'ASSET_BUSINESS' AND
|
|
|
+ pFund.id = claim.production_fund_id AND
|
|
|
+ pFund.order_fund_id = claim.order_fund_id
|
|
|
+ INNER JOIN assets_production AS pro
|
|
|
+ ON pro.deleted = 0 AND save_file_date IS NOT NULL AND pro.production_no = pFund.production_no
|
|
|
+ INNER JOIN assets ON assets.id = pro.business_id
|
|
|
+ INNER JOIN user ON user.id = assets.principal_id
|
|
|
+ INNER JOIN commission_declare AS decl
|
|
|
+ ON decl.deleted = 0 AND decl.business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND
|
|
|
+ decl.business_id = assets.id AND decl.production_id = pro.id
|
|
|
+ INNER JOIN business_performance_distribution AS distribution
|
|
|
+ ON distribution.deleted = 0 AND distribution.business_type = 'ASSET_BUSINESS' AND
|
|
|
+ distribution.declare_id = decl.id AND member_id = decl.declare_user_id
|
|
|
+ WHERE claim.deleted = 0
|
|
|
+ AND claim.production_fund_id IS NOT NULL
|
|
|
+ AND IF(claim.claim_datetime > pro.save_file_date, claim.claim_datetime, pro.save_file_date) BETWEEN #{vo.startDate} AND #{vo.endDate}
|
|
|
+ GROUP BY user.id
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
<!--资产评估人员提成信息导出-->
|
|
|
<select id="assetsEvaluatorUserDetailExport" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
|
|
|
- SELECT
|
|
|
- ap.id,
|
|
|
- ROUND(fc.claim_amount,2) 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.assets_name AS name,
|
|
|
- ap.created,
|
|
|
- dd.NAME AS businessCate,
|
|
|
- IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
|
|
|
- cd.defined_low_limit_amount AS lowLimitAmount,
|
|
|
- ROUND(bcr.min_ratio,2) AS ratio,
|
|
|
- bpd.member_id AS userId,
|
|
|
- ROUND(bpd.performance_distribution,2) AS allotRatio,
|
|
|
- ROUND(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)
|
|
|
- ),2) AS commissionAmount,
|
|
|
- ROUND(IF(cd.defined_low_limit_amount < fc.claim_amount,
|
|
|
- fc.claim_amount * (cd.ratio / 100),
|
|
|
- cd.defined_low_limit_amount * (cd.ratio / 100)
|
|
|
- ),2) AS totalAmount,
|
|
|
- u.name as userName,
|
|
|
- pf.modified AS realFundDateTime
|
|
|
- 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,modified 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, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 ) 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
|
|
|
- <where>
|
|
|
+ <if test="vo.commissionType != null and vo.commissionType == '预计提成'">
|
|
|
+ SELECT
|
|
|
+ ap.id,
|
|
|
+ ROUND(fc.claim_amount,2) 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.assets_name AS name,
|
|
|
+ ap.created,
|
|
|
+ dd.NAME AS businessCate,
|
|
|
+ IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
|
|
|
+ cd.defined_low_limit_amount AS lowLimitAmount,
|
|
|
+ ROUND(bcr.min_ratio,2) AS ratio,
|
|
|
+ bpd.member_id AS userId,
|
|
|
+ ROUND(bpd.performance_distribution,2) AS allotRatio,
|
|
|
+ ROUND(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)
|
|
|
+ ),2) AS commissionAmount,
|
|
|
+ ROUND(IF(cd.defined_low_limit_amount < fc.claim_amount,
|
|
|
+ fc.claim_amount * (cd.ratio / 100),
|
|
|
+ cd.defined_low_limit_amount * (cd.ratio / 100)
|
|
|
+ ),2) AS totalAmount,
|
|
|
+ u.name as userName,
|
|
|
+ pf.modified AS realFundDateTime
|
|
|
+ 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,modified 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, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 ) 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
|
|
|
+ <where>
|
|
|
+ <if test="vo!=null and vo.userId!=null">
|
|
|
+ and bpd.member_id = #{vo.userId}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ order by bpd.member_id
|
|
|
+ </if>
|
|
|
+ <if test="vo.commissionType != null and vo.commissionType == '已归档提成'">
|
|
|
+ SELECT user.id,
|
|
|
+ user.name AS userName,
|
|
|
+ pro.production_no AS reportNo,
|
|
|
+ IFNULL(pro.assets_name, assets.name) AS name,
|
|
|
+ dd.name AS businessCate,
|
|
|
+ IFNULL(decl.ratio, bcr.min_ratio) AS ratio,
|
|
|
+ decl.defined_low_limit_amount AS lowLimitAmount,
|
|
|
+ distribution.performance_distribution AS allotRatio,
|
|
|
+ distribution.member_type,
|
|
|
+ IF(decl.defined_low_limit_amount < claim.claim_amount,
|
|
|
+ claim.claim_amount * (decl.ratio / 100) * (distribution.performance_distribution / 100),
|
|
|
+ decl.defined_low_limit_amount * (decl.ratio / 100) * (distribution.performance_distribution / 100)
|
|
|
+ ) AS commissionAmount,
|
|
|
+ IF(decl.defined_low_limit_amount < claim.claim_amount,
|
|
|
+ claim.claim_amount * (decl.ratio / 100),
|
|
|
+ decl.defined_low_limit_amount * (decl.ratio / 100)
|
|
|
+ ) AS totalAmount,
|
|
|
+ pFund.modified AS realFundDateTime,
|
|
|
+ IF(claim.claim_datetime > pro.save_file_date, claim.claim_datetime, pro.save_file_date) AS settleDate,
|
|
|
+ pro.create_production_date AS created,
|
|
|
+ claim.claim_amount as realAmount
|
|
|
+ FROM finance_claim AS claim
|
|
|
+ INNER JOIN finance_real_fund AS rFund ON rFund.deleted = 0 AND rFund.id = claim.real_fund_id
|
|
|
+ INNER JOIN production_fund AS pFund ON pFund.deleted = 0 AND business_type = 'ASSET_BUSINESS' AND
|
|
|
+ pFund.id = claim.production_fund_id AND
|
|
|
+ pFund.order_fund_id = claim.order_fund_id
|
|
|
+ INNER JOIN assets_production AS pro
|
|
|
+ ON pro.deleted = 0 AND save_file_date IS NOT NULL AND pro.production_no = pFund.production_no
|
|
|
+ INNER JOIN assets ON assets.id = pro.business_id
|
|
|
+ INNER JOIN user ON user.id = assets.principal_id
|
|
|
+ INNER JOIN commission_declare AS decl
|
|
|
+ ON decl.deleted = 0 AND decl.business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND
|
|
|
+ decl.business_id = assets.id AND decl.production_id = pro.id
|
|
|
+ INNER JOIN business_performance_distribution AS distribution
|
|
|
+ ON distribution.deleted = 0 AND distribution.business_type = 'ASSET_BUSINESS' AND
|
|
|
+ distribution.declare_id = decl.id AND member_id = decl.declare_user_id
|
|
|
+ LEFT JOIN business_commission_rate bcr ON bcr.id = decl.commission_rate_id
|
|
|
+ LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
|
|
|
+ WHERE claim.deleted = 0
|
|
|
+ AND claim.production_fund_id IS NOT NULL
|
|
|
<if test="vo!=null and vo.userId!=null">
|
|
|
- and bpd.member_id = #{vo.userId}
|
|
|
+ AND user.id = #{vo.userId}
|
|
|
</if>
|
|
|
- </where>
|
|
|
- order by bpd.member_id
|
|
|
+ AND IF(claim.claim_datetime > pro.save_file_date, claim.claim_datetime, pro.save_file_date) BETWEEN #{vo.startDate} AND #{vo.endDate}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
<!--资产市场人员提成计算-->
|
|
@@ -1503,9 +1658,8 @@
|
|
|
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.assets_name AS name,
|
|
|
+ IF( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) AS settleDate,
|
|
|
+ IFNULL(ap.assets_name, a.name) AS name,
|
|
|
ap.created,
|
|
|
dd.NAME AS businessCate,
|
|
|
bcr.min_ratio AS ratio,
|
|
@@ -1542,7 +1696,7 @@
|
|
|
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, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 AND delivery = TRUE ) ap ON ap.production_no = pf.production_no
|
|
|
+ INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, delivery_date, created FROM assets_production WHERE deleted = 0 AND delivery = TRUE ) 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_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
|
|
|
cd.business_id = a.id
|