if(o.payment_term IS NOT NULL ,CONCAT(o.payment_term,(case o.payment_term_unit when 'Y' then '年' when 'M' then '月' else '日' END ) ),(SELECT e.element_text from ag_po_order_life_product_elements e where o.id = e.order_id and e.factor_code like 'f_pay_term' LIMIT 1)) paymentTermUnit,
if(o.cover_term IS NOT NULL ,o.cover_term_type ,(SELECT e.element_text from ag_po_order_life_product_elements e where o.id = e.order_id and e.factor_code like 'f_coverage_term' LIMIT 1)) coverTermType,
o.order_price orderPrice,
pra.name practitionerName,
dept.name insurerBranchDeptName,
sub.name subordinateSystemName,
f.practitioner_level practitionerLevel,
f.commission_amount commissionAmount,
f.commission_type commissionType,
f.referral_rate referralRate,
f.referral_amount referralAmount,
op.drop_option_name commissionPayoutStatus,
pb.payout_yearmonth monthPeriod
from ag_acl_customer_fortune f
LEFT JOIN ag_po_order o
LEFT JOIN ag_acl_insurer i ON i.id = o.insurer_id
LEFT JOIN ag_product p ON p.id = o.product_id
LEFT JOIN ag_product_plan pp ON pp.id = o.plan_id
ON o.id = f.order_id
LEFT JOIN ag_acl_practitioner pra
LEFT JOIN ag_acl_insurer_branch_dept dept ON pra.dept_id = dept.id
LEFT JOIN ag_acl_practitioner_subordinate_system sub ON sub.id = pra.subordinate_system_id
Left Join ag_acl_practitioner_setting setting on setting.practitioner_id = pra.id
ON pra.customer_id = f.customer_id
LEFT JOIN ag_acl_customer_fortune_payout_batch pb ON pb.id = f.payout_batch_id
LEFT JOIN ag_md_drop_options op
LEFT JOIN ag_md_drop_master mas ON mas.id = op.drop_master_id
ON op.drop_option_code = f.commission_payout_status
left join ag_po_order_commission_check c on o.commission_check_id = c.id
IF(o.cover_term IS NOT NULL ,o.cover_term_type ,(SELECT e.element_text FROM ag_po_order_life_product_elements e WHERE o.id = e.order_id AND e.factor_code LIKE 'f_coverage_term' LIMIT 1)) coverTermType,
IF(o.cover_term IS NOT NULL ,o.cover_term_type ,(SELECT e.element_text FROM ag_po_order_life_product_elements e WHERE o.id = e.order_id AND e.factor_code LIKE 'f_coverage_term' LIMIT 1)) coverTermType,
o.order_price orderPrice,
o.order_price orderPrice,
pra.name practitionerName,
pra.name practitionerName,
cha.name channelName,
dept.name insurerBranchDeptName,
dept.name insurerBranchDeptName,
sub.name subordinateSystemName,
sub.name subordinateSystemName,
op1.drop_option_name practitionerLevel,
op1.drop_option_name practitionerLevel,
...
@@ -83,7 +45,8 @@
...
@@ -83,7 +45,8 @@
t.predict_month_period predictMonthPeriod,
t.predict_month_period predictMonthPeriod,
op.drop_option_name commissionPayoutStatus,
op.drop_option_name commissionPayoutStatus,
t.remark,
t.remark,
pb.payout_yearmonth monthPeriod
pb.payout_yearmonth monthPeriod,
t.channel_type channelType
FROM ag_acl_customer_fortune t
FROM ag_acl_customer_fortune t
LEFT JOIN ag_po_order o ON o.id = t.order_id
LEFT JOIN ag_po_order o ON o.id = t.order_id
LEFT JOIN ag_product p ON p.id = o.product_id
LEFT JOIN ag_product p ON p.id = o.product_id
...
@@ -98,16 +61,15 @@
...
@@ -98,16 +61,15 @@
LEFT JOIN ag_md_drop_master mas ON mas.id = op.drop_master_id
LEFT JOIN ag_md_drop_master mas ON mas.id = op.drop_master_id
LEFT JOIN ag_md_drop_options op1 ON op1.id = setting.practitioner_level
LEFT JOIN ag_md_drop_options op1 ON op1.id = setting.practitioner_level
LEFT JOIN ag_md_drop_master mas1 ON mas1.id = op1.drop_master_id
LEFT JOIN ag_md_drop_master mas1 ON mas1.id = op1.drop_master_id
LEFT JOIN (SELECT distinct poc.order_id,poc.commission_period,c.* FROM ag_po_order_commission poc,ag_po_order_commission_check c
LEFT JOIN ag_acl_channel_new cha ON cha.id = t.channel_id
LEFT JOIN (select distinct poc.order_id,poc.commission_period,c.* FROM ag_po_order_commission poc,ag_po_order_commission_check c
WHERE poc.commission_check_id=c.id AND poc.commission_status='2' AND poc.commission_type='1'
WHERE poc.commission_check_id=c.id AND poc.commission_status='2' AND poc.commission_type='1'
<iftest="item.commissionPayoutYearmonth == null">
<iftest="item.commissionPayoutYearmonth == null">
GROUP BY poc.order_id,poc.commission_period
GROUP BY poc.order_id,poc.commission_period
</if>
</if>
) c ON c.order_id=t.order_id AND c.commission_period=t.commission_period
) c ON c.order_id=t.order_id AND c.commission_period=t.commission_period
WHERE t.settlement_type = '1'
WHERE ((t.settlement_type='1' and setting.practitioner_type_id=28 and mas1.scenario_code='practitioner_level' ) or (t.settlement_type='3' and t.order_id is not null))
AND mas.drop_code = 'Fortune_Payout_Status'
and mas.drop_code = 'Fortune_Payout_Status'
AND mas1.scenario_code = 'practitioner_level'
and setting.practitioner_type_id = 28
and EXISTS(select 1 from ag_po_order_commission poc
and EXISTS(select 1 from ag_po_order_commission poc
where poc.commission_status='2' and poc.commission_type='1'
where poc.commission_status='2' and poc.commission_type='1'
and poc.order_id=t.order_id and poc.commission_period=t.commission_period)
and poc.order_id=t.order_id and poc.commission_period=t.commission_period)
...
@@ -120,12 +82,15 @@
...
@@ -120,12 +82,15 @@
<iftest="item.insurerBranchId != null">
<iftest="item.insurerBranchId != null">
and pra.insurer_branch_id = #{item.insurerBranchId,jdbcType=BIGINT}
and pra.insurer_branch_id = #{item.insurerBranchId,jdbcType=BIGINT}
</if>
</if>
<iftest="item.channelId != null">
and cha.id = #{item.channelId,jdbcType=BIGINT}
</if>
<iftest="item.channelType != null">
and t.channel_type = #{item.channelType,jdbcType=VARCHAR}
</if>
<iftest="item.insurerBranchDeptId != null">
<iftest="item.insurerBranchDeptId != null">
and dept.id = #{item.insurerBranchDeptId,jdbcType=BIGINT}
and dept.id = #{item.insurerBranchDeptId,jdbcType=BIGINT}
</if>
</if>
<!-- <if test="item.subordinateSystemId != null">
and sub.id = #{item.subordinateSystemId,jdbcType=BIGINT}
</if>-->
<iftest="item.subsystemIdList != null and item.subsystemIdList.size() > 0">
<iftest="item.subsystemIdList != null and item.subsystemIdList.size() > 0">
and (c.check_yearmonth = #{item.commissionPayoutYearmonth,jdbcType=VARCHAR}
and (c.check_yearmonth = #{item.commissionPayoutYearmonth,jdbcType=VARCHAR}
...
@@ -166,6 +128,7 @@
...
@@ -166,6 +128,7 @@
'' coverTermType,
'' coverTermType,
'0.00' orderPrice,
'0.00' orderPrice,
pra.name practitionerName,
pra.name practitionerName,
cha.name channelName,
dept.name insurerBranchDeptName,
dept.name insurerBranchDeptName,
sub.name subordinateSystemName,
sub.name subordinateSystemName,
op1.drop_option_name practitionerLevel,
op1.drop_option_name practitionerLevel,
...
@@ -176,7 +139,8 @@
...
@@ -176,7 +139,8 @@
t.predict_month_period predictMonthPeriod,
t.predict_month_period predictMonthPeriod,
op.drop_option_name commissionPayoutStatus,
op.drop_option_name commissionPayoutStatus,
t.remark,
t.remark,
pb.payout_yearmonth monthPeriod
pb.payout_yearmonth monthPeriod,
t.channel_type channelType
FROM ag_acl_customer_fortune t
FROM ag_acl_customer_fortune t
LEFT JOIN ag_acl_practitioner pra ON pra.id = t.practitioner_id
LEFT JOIN ag_acl_practitioner pra ON pra.id = t.practitioner_id
LEFT JOIN ag_acl_insurer_branch_dept dept ON pra.dept_id = dept.id
LEFT JOIN ag_acl_insurer_branch_dept dept ON pra.dept_id = dept.id
...
@@ -187,19 +151,21 @@
...
@@ -187,19 +151,21 @@
LEFT JOIN ag_md_drop_master mas ON mas.id = op.drop_master_id
LEFT JOIN ag_md_drop_master mas ON mas.id = op.drop_master_id
LEFT JOIN ag_md_drop_options op1 ON op1.id = setting.practitioner_level
LEFT JOIN ag_md_drop_options op1 ON op1.id = setting.practitioner_level
LEFT JOIN ag_md_drop_master mas1 ON mas1.id = op1.drop_master_id
LEFT JOIN ag_md_drop_master mas1 ON mas1.id = op1.drop_master_id
WHERE t.settlement_type = '2'
LEFT JOIN ag_acl_channel_new cha ON cha.id = t.channel_id
WHERE ((t.settlement_type='2' and mas1.scenario_code='practitioner_level' and setting.practitioner_type_id=28) or (t.settlement_type='3' and t.order_id is null))
AND mas.drop_code = 'Fortune_Payout_Status'
AND mas.drop_code = 'Fortune_Payout_Status'
AND mas1.scenario_code = 'practitioner_level'
and setting.practitioner_type_id = 28
<iftest="item.insurerBranchId != null">
<iftest="item.insurerBranchId != null">
and pra.insurer_branch_id = #{item.insurerBranchId,jdbcType=BIGINT}
and pra.insurer_branch_id = #{item.insurerBranchId,jdbcType=BIGINT}
</if>
</if>
<iftest="item.insurerBranchDeptId != null">
<iftest="item.insurerBranchDeptId != null">
and dept.id = #{item.insurerBranchDeptId,jdbcType=BIGINT}
and dept.id = #{item.insurerBranchDeptId,jdbcType=BIGINT}
</if>
</if>
<!-- <if test="item.subordinateSystemId != null">
<iftest="item.channelId != null">
and sub.id = #{item.subordinateSystemId,jdbcType=BIGINT}
and cha.id = #{item.channelId,jdbcType=BIGINT}
</if>-->
</if>
<iftest="item.channelType != null">
and t.channel_type = #{item.channelType,jdbcType=VARCHAR}
</if>
<iftest="item.subsystemIdList != null and item.subsystemIdList.size() > 0">
<iftest="item.subsystemIdList != null and item.subsystemIdList.size() > 0">
(select name from ag_acl_channel where id = f.channel_id) '18' /*渠道*/,
(select name from ag_acl_channel_new where id = f.channel_id) '18' /*渠道*/,
ifnull(coalesce(l.s1_id,l.s2_id,l.s3_id),(SELECT a.subordinate_system_id from ag_acl_practitioner a where a.id = f.sale_practitioner_id)) as '19' /*FYC体系*/,
ifnull(coalesce(l.s1_id,l.s2_id,l.s3_id),(SELECT a.subordinate_system_id from ag_acl_practitioner a where a.id = f.sale_practitioner_id)) as '19' /*FYC体系*/,
ifnull(l.practitioner_name,(select t.name from ag_acl_practitioner t where t.id = f.sale_practitioner_id)) '20' /*销售经纪人*/,
ifnull(l.practitioner_name,(select t.name from ag_acl_practitioner t where t.id = f.sale_practitioner_id)) '20' /*销售经纪人*/,
ifnull(l.practitioner_level,
ifnull(l.practitioner_level,
...
@@ -714,7 +684,11 @@
...
@@ -714,7 +684,11 @@
sum(case when drop_option_code ='C14' then f.calculation_rate else null end) '64' /*C14直接销售加码佣金率*/,
sum(case when drop_option_code ='C14' then f.calculation_rate else null end) '64' /*C14直接销售加码佣金率*/,
sum(case when drop_option_code ='C14' then f.referral_amount else null end) '65' /*C14直接销售加码佣金*/,
sum(case when drop_option_code ='C14' then f.referral_amount else null end) '65' /*C14直接销售加码佣金*/,
IF(f.rule_id is null, if(o.settlement_rule_type=1,'简单基本法','标准基本法'),
(select (case settlement_rule_type when 1 then '简单基本法' when 2 then '标准基本法' when 3 then '特殊结算' when 4 then if(o.settlement_rule_type=1,'简单基本法','标准基本法') end)
from ag_settlement_rule_base where id = f.rule_id
)
) '66' /*基本法属性*/,
sum(case when drop_option_code ='S01' then f.referral_amount else null end) '67' /*S01-首年度销售佣金*/,
sum(case when drop_option_code ='S01' then f.referral_amount else null end) '67' /*S01-首年度销售佣金*/,
(SELECT GROUP_CONCAT(referral_amount)
(SELECT GROUP_CONCAT(referral_amount)
FROM ag_acl_customer_fortune t
FROM ag_acl_customer_fortune t
...
@@ -840,6 +814,13 @@
...
@@ -840,6 +814,13 @@
sum(case when drop_option_code ='C97' then f.referral_amount else null end) as '90' /*其它税前加扣款3*/,
sum(case when drop_option_code ='C97' then f.referral_amount else null end) as '90' /*其它税前加扣款3*/,
sum(case when drop_option_code ='C98' then f.referral_amount else null end) as '91' /*其它税前加扣款4*/,
sum(case when drop_option_code ='C98' then f.referral_amount else null end) as '91' /*其它税前加扣款4*/,
sum(case when drop_option_code ='C99' then f.referral_amount else null end) as '92' /*其它*/,
sum(case when drop_option_code ='C99' then f.referral_amount else null end) as '92' /*其它*/,
sum(case when drop_option_code ='C11' then f.referral_amount else null end) as '93' /*C11-独立经纪人展业津贴*/,
sum(case when drop_option_code ='D01' then f.referral_amount else null end) as '94' /*D01-首年渠道服务费*/,
sum(case when drop_option_code ='D02' then f.referral_amount else null end) as '95' /*D02-续年渠道服务费*/,
sum(case when drop_option_code ='D91' then f.referral_amount else null end) as '96' /*D91-渠道加扣款1*/,
sum(case when drop_option_code ='D92' then f.referral_amount else null end) as '97' /*D92-渠道加扣款2*/,
IF(f.rule_id is null, if(o.settlement_rule_type=1,'简单基本法','标准基本法'),
(select (case settlement_rule_type when 1 then '简单基本法' when 2 then '标准基本法' when 3 then '特殊结算' when 4 then if(o.settlement_rule_type=1,'简单基本法','标准基本法') end)
and (b.approve_status >= t.approve_step_id OR b.approve_status = 0)
</when>
</when>
<whentest='status == "2" '>
<whentest='status == "2" '>
and t.approving_status = 0
and ((b.approve_status != 0 and b.approve_status < t.approve_step_id-1) or b.approve_status is null)
and t.id <= (select max(a.id) from ag_acl_practitioner_hiring_approve_records a where a.hiring_basic_info_id = t.hiring_basic_info_id and a.approving_status=0)
<!-- and (t.approving_status = 0 or b.approve_status < t.approve_step_id or b.approve_status is null) -->
(CASE (t.task_type) WHEN 1 THEN '商机' WHEN 2 THEN '增员' ELSE '其他' END) taskType,
op.drop_option_name dropOptionName,
t.track_time trackTime,
t.task_time_from taskTimeFrom,
task_time_end taskTimeEnd,
t.notice ,
t.created_at createdAt
FROM ag_mkt_schedule_task_tracking t, ag_acl_practitioner p, ag_md_drop_options op
WHERE t.practitioner_id = p.id AND op.id = t.md_drop_option_id
<iftest="trackTime != null">
AND date_format(t.track_time, '%Y-%m-%d') >= #{trackTime,jdbcType=VARCHAR} AND date_format(t.track_time, '%Y-%m-%d') <= #{trackTime,jdbcType=VARCHAR}
</if>
<iftest="practitionerId != null">
AND t.practitioner_id = #{practitionerId,jdbcType=BIGINT}
</if>
<iftest="taskType != null">
AND t.task_type = #{taskType,jdbcType=BIGINT}
</if>
<iftest="dropOptionName != null">
AND op.drop_option_name like concat(concat('%',#{dropOptionName,jdbcType=VARCHAR}),'%')
FROM ag_mkt_schedule_task_tracking t, ag_acl_practitioner p, ag_md_drop_options op
WHERE t.practitioner_id = p.id AND op.id = t.md_drop_option_id
<iftest="trackTime != null">
AND date_format(t.track_time, '%Y-%m-%d') >= #{trackTime,jdbcType=VARCHAR} AND date_format(t.track_time, '%Y-%m-%d') <= #{trackTime,jdbcType=VARCHAR}
</if>
<iftest="practitionerId != null">
AND t.practitioner_id = #{practitionerId,jdbcType=BIGINT}
</if>
<iftest="taskType != null">
AND t.task_type = #{taskType,jdbcType=BIGINT}
</if>
<iftest="dropOptionName != null">
AND op.drop_option_name like concat(concat('%',#{dropOptionName,jdbcType=VARCHAR}),'%')
where t.approving_practitioner_id = #{practitionerId,jdbcType=BIGINT}
where t.approving_practitioner_id = #{practitionerId,jdbcType=BIGINT}
and t.approving_status = #{approvingStatus,jdbcType=BIGINT}
<iftest="approvingStatus != null">
<choose>
<whentest='approvingStatus == "1" '>
and (b.approve_status >= t.approve_step_id OR b.approve_status = 0)
</when>
<whentest='approvingStatus == "2" '>
and ((b.approve_status != 0 and b.approve_status < t.approve_step_id-1) or b.approve_status is null)
and t.id <= (select max(a.id) from ag_acl_practitioner_hiring_approve_records a where a.hiring_basic_info_id = t.hiring_basic_info_id and a.approving_status=0)
<!-- and (t.approving_status = 0 or b.approve_status < t.approve_step_id or b.approve_status is null) -->