IFNULL(t0.员工手机号,t0.员工id) as 员工id ,t0.员工姓名,t1.员工手机号,t0.4s店商户号,t0.门店,主服务商id,(case when 主服务商名称=''深圳嘀加'' then ''直营'' else 主服务商名称 end) as 服务商,t0.业务类型,t0.scene_type,
订单数 ,
ifnull(总触客,0) 到店量人,
ifnull(是否派发平板,''否'')是否派发平板,
ifnull(t7.派发日期, ''--'') as 派发日期,
ifnull(接待天数,0)平板出勤,
DATEDIFF(
(case when date_format(''endtimexxxxxx'',''%Y-%m'')=date_format(date_sub(''endtimexxxxxx'',interval 1 week ),''%Y-%m'') then date_sub(''endtimexxxxxx'',interval 1 day ) else date_sub(date_format(''endtimexxxxxx'',''%Y-%m-01''),interval 1 day )end)
,(case when date_format(''endtimexxxxxx'',''%Y-%m'')=date_format(date_sub(''endtimexxxxxx'',interval 1 week ),''%Y-%m'') then date_format(''endtimexxxxxx'',''%Y-%m-01'') else date_sub(date_format(''endtimexxxxxx'',''%Y-%m-01''),interval 1 month )end)
)+2 从1号到上周日的实际天数,
DATEDIFF(
(case when date_format(''endtimexxxxxx'',''%Y-%m'')=date_format(date_sub(''endtimexxxxxx'',interval 1 week ),''%Y-%m'') then date_sub(''endtimexxxxxx'',interval 1 day ) else date_sub(date_format(''endtimexxxxxx'',''%Y-%m-01''),interval 1 day )end)
,(case when date_format(''endtimexxxxxx'',''%Y-%m'')=date_format(date_sub(''endtimexxxxxx'',interval 1 week ),''%Y-%m'') then date_format(''endtimexxxxxx'',''%Y-%m-01'') else date_sub(date_format(''endtimexxxxxx'',''%Y-%m-01''),interval 1 month )end)
)+2 -4 - ifnull(接待天数,0) as 平板缺勤,
ifnull(t5.接待次数,0) 预计接待批次数,
ifnull(t6.接待次数,0) 真实接待数量,
ifnull(总触客,0)- ifnull(t5.接待次数,0) as 录音缺失,
ifnull(t8.report_count, 0) as report_count,
ifnull(t8.approved_count, 0) as approved_count,
now() created_date
from (
SELECT
iam.custodian_phone AS 员工id,
'''' AS 4s店商户号,
'''' AS 业务类型,
'''' AS scene_type,
iam.custodian AS 员工姓名,
'''' AS 门店,
iam.custodian_phone AS 员工手机号
FROM inspection_asset_management iam
WHERE iam.deleted_flag = ''N''
AND NOT EXISTS (
SELECT 1
FROM dj_car_life_staff_info dclsi
WHERE dclsi.deleted_flag = ''N''
AND dclsi.phone_number = iam.custodian_phone
AND EXISTS (
SELECT 1
FROM dj_car_life_goods_order a
LEFT JOIN dj_car_life_pay_order b ON a.order_code = b.order_code
AND b.deleted_flag = ''N''
AND b.order_code IS NOT NULL
WHERE a.seller_user_id = dclsi.staff_uuid
AND a.deleted_flag = ''N''
AND a.status IN (2, 4, 6)
AND a.upgrade_flag IN (''Y'', ''N'')
AND a.seller_user_id IS NOT NULL
AND a.scene_type IN (0, 1)
AND DATE_FORMAT(IFNULL(b.success_date, a.order_time), ''%Y-%m-%d'')
BETWEEN DATE_SUB(DATE_FORMAT(''starttimexxxxxx'', ''%Y-%m-%d''), INTERVAL 1 MONTH) AND ''endtimexxxxxx''
)
)
union
select 员工id,4s店商户号,业务类型, scene_type,员工姓名,4s店商户名称 as 门店,员工手机号
select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on rcf.staff_uuid=dclsi.员工uuid
LEFT JOIN inspection_badge_recordings t2 ON rcf.id = t2.reception_id where t2.recording_start_time is not null
)t
where date_format (reception_start_time,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
group by staff_uuid
)t4 on t0.员工id=t4.staff_uuid
left join (
select staff_uuid ,bussiness_type, merchant_id,
count(1)接待次数
from (
select ifnull(员工手机号,rcf.staff_uuid)staff_uuid,(case when bussiness_type=2 then 1 when bussiness_type=1 then 0 end )bussiness_type, merchant_id,reception_start_time
from reception_customer_info rcf
left join (
select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on rcf.staff_uuid=dclsi.员工uuid
LEFT JOIN inspection_badge_recordings t2 ON rcf.id = t2.reception_id where t2.recording_start_time is not null
)t
where date_format (reception_start_time,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
group by staff_uuid ,bussiness_type,merchant_id
)t5 on t0.4s店商户号=t5.merchant_id and t0.员工id=t5.staff_uuid and t0.scene_type=t5.bussiness_type
left join (
SELECT
t1.staff_uuid,(case when t1.bussiness_type=2 then 1 when t1.bussiness_type=1 then 0 end )bussiness_type,t1.merchant_id,
count(1) as ''接待次数'', AVG(t3.score) as 质检平均分
FROM (select ifnull(员工手机号,t1.staff_uuid)staff_uuid,bussiness_type,id,merchant_id,reception_start_time from reception_customer_info t1
left join ( select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on t1.staff_uuid=dclsi.员工uuid
) t1
LEFT JOIN inspection_badge_recordings t2 ON t1.id = t2.reception_id
LEFT JOIN inspection_conversation_batch t3 ON t2.id = t3.record_id
where t2.che_result_flag =2 and t3.score>20
and date_format (reception_start_time,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
GROUP BY t1.staff_uuid, t1.bussiness_type, t1.merchant_id
)t6 on t0.4s店商户号=t6.merchant_id and t0.员工id=t6.staff_uuid and t0.scene_type=t6.bussiness_type
-- 派发日期关联查询
left join (
select custodian_phone, DATE_FORMAT(MAX(dis_date), ''%Y-%m-%d'') as 派发日期
from inspection_asset_management
where deleted_flag = ''N''
group by custodian_phone
) t7 on t1.员工手机号 = t7.custodian_phone
-- 【新增】系统报备数量关联查询
left join (
select staff_phone,
COUNT(*) as report_count,
SUM(CASE WHEN audit_status = 1 THEN 1 ELSE 0 END) as approved_count
from reception_missing_report
where deleted_flag = ''N''
and report_date between date_format(''starttimexxxxxx'', ''%Y-%m-%d'') and ''endtimexxxxxx''
group by staff_phone
) t8 on t1.员工手机号 = t8.staff_phone
having 门店 not in (''杰西集团的门店2'',''杰西集团的门店'',''内部测试4S店'')
(case when 总触客 is null then 1 else (case when 总触客>ifnull(t6.接待次数,0) or ifnull(订单数,0)>总触客 then 1 else 0 end)end)日报有误天
from (
SELECT ifnull(员工手机号,员工id)员工id,统计时间,4s店商户号,场景,业务类型,员工手机号 FROM (
SELECT distinct t1.staff_uuid 员工id, DATE_FORMAT(t1.reception_start_time, ''%Y-%m-%d'') AS 统计时间,t1.merchant_id 4s店商户号,
(case when t1.bussiness_type=2 then 1 when t1.bussiness_type=1 then 0 end )场景, (case when t1.bussiness_type=2 then ''精品升级'' when t1.bussiness_type=1 then ''会员权益/升级'' else null end) 业务类型
FROM reception_customer_info t1
LEFT JOIN inspection_badge_recordings t2 ON t1.id = t2.reception_id
LEFT JOIN inspection_conversation_batch t3 ON t2.id = t3.record_id
where t2.che_result_flag =2 and t3.score>20
and date_format (reception_start_time,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
GROUP BY t1.staff_uuid, t1.bussiness_type, t1.merchant_id,date_format (reception_start_time,''%Y-%m-%d'')
union
select distinct 员工id,统计时间,4s店商户号,scene_type 场景,业务类型 from (
left join (select * from dj_car_life_pay_order where deleted_flag = ''N'' and order_code is not null) b on a.order_code=b.order_code
) dclgo
where dclgo.deleted_flag=''N''and dclgo.status in (2, 4, 6)and dclgo.upgrade_flag in (''Y'',''N'')and seller_user_id is not null and scene_type in (0,1)
and DATE_FORMAT(dclgo.order_time,''%Y-%m-%d'') between date_format(''starttimexxxxxx'',''%Y-%m-%d'')and ''endtimexxxxxx''
)t group by 员工id,统计时间,4s店商户号,业务类型
union
select distinct staff_uuid 员工id,DATE_FORMAT(report_date,''%Y-%m-%d'')统计时间,merchant_id 4s店商户号,scene_type 场景, (case when scene_type=1 then ''精品升级'' when scene_type=0 then ''会员权益/升级'' else null end) 业务类型
from dj_car_life_staff_daily_report_huawei
where deleted_flag = ''N''
and DATE_FORMAT(report_date,''%Y-%m-%d'')between date_format(''starttimexxxxxx'',''%Y-%m-%d'') and ''endtimexxxxxx''
)tt
left join (
select staff_uuid 员工uuid,staff_name 员工姓名 ,phone_number 员工手机号 from dj_car_life_staff_info where deleted_flag = ''N''
)dclsi on tt.员工id=dclsi.员工uuid
)t left join (
select 员工id,4s店商户号,业务类型, scene_type,order_time,
员工姓名,4s店商户名称 as 门店,
sum(total_price) 产值,
count(distinct (case when upgrade_flag=''Y'' then order_code else null end))订单数