<?xml version="1.0" encoding="UTF-8"?>
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
<mapper namespace="com.nova.sankuai.infra.mapper.ChannelLogMapper">
|
|
<select id="importTotal" resultType="com.nova.sankuai.domain.vo.channel.ChannelReportTotalVo">
|
select channelName,channelCode,sum(successCountSum) as successCountSum,sum(failCountSum) as failCountSum,
|
#{reportDto.startDate} as startDate, #{reportDto.endDate} as endDate from (
|
select ci.name as channelName,ci.code as channelCode,IF((cu.id is not null),1,0) as successCountSum,
|
0 as failCountSum
|
from channel_info ci
|
left join customer cu on cu.source_channel = ci.code
|
<if test="reportDto.startDate != null">
|
and cu.apply_date >= #{reportDto.startDate}
|
</if>
|
<if test="reportDto.endDate != null">
|
and cu.apply_date <= #{reportDto.endDate}
|
</if>
|
<where>
|
ci.type = 0
|
<if test="reportDto.channelCode != null">
|
and ci.code = #{reportDto.channelCode}
|
</if>
|
</where>
|
group by cu.id
|
) t group by channelCode
|
</select>
|
|
|
<select id="importDetail" resultType="com.nova.sankuai.domain.vo.channel.ChannelImportReportVo">
|
select cu.id as recordId,
|
cu.phone as phone,
|
cu.name as name,
|
su.company_name as mechanismName,
|
ci.name as channelName,
|
ci.code as channelCode,
|
cu.apply_date as applyDate,
|
cu.sync_channel_name as syncChannelName
|
from customer cu
|
left join channel_info ci on cu.source_channel = ci.code
|
left join sys_user su on cu.mechanism_id = su.id
|
<where>
|
cu.source_channel = #{reportDto.channelCode}
|
<if test="reportDto.startDate != null">
|
and cu.apply_date >= #{reportDto.startDate}
|
</if>
|
<if test="reportDto.endDate != null">
|
and cu.apply_date <= #{reportDto.endDate}
|
</if>
|
<if test="reportDto.name != null and reportDto.name !=''">
|
and cu.name like concat('%',#{reportDto.name},'%')
|
</if>
|
<if test="reportDto.phone != null and reportDto.phone !=''">
|
and cu.phone like concat('%',#{reportDto.phone},'%')
|
</if>
|
<if test="reportDto.mechanismName != null and reportDto.mechanismName !=''">
|
and su.company_name like concat('%',#{reportDto.mechanismName},'%')
|
</if>
|
</where>
|
</select>
|
|
|
<select id="exportTotal" resultType="com.nova.sankuai.domain.vo.channel.ChannelReportTotalVo">
|
select ci.name as channelName,ci.code as channelCode,
|
sum(IF((cl.status='1'),1,0)) as successCountSum,
|
#{reportDto.startDate} as startDate,
|
#{reportDto.endDate} as endDate
|
from (select * from channel_log group by customer_record_id,source,export_source,record_id,status,type) as cl
|
inner join channel_info ci on cl.export_source = ci.code
|
<if test="reportDto.startDate != null">
|
and cl.creation_date >= #{reportDto.startDate}
|
</if>
|
<if test="reportDto.endDate != null">
|
and cl.creation_date <= #{reportDto.endDate}
|
</if>
|
<where>
|
ci.type = 1 and ci.status = 1 and ci.code!=12
|
<if test="reportDto.channelCode != null">
|
and ci.code = #{reportDto.channelCode}
|
</if>
|
</where>
|
group by channelCode
|
</select>
|
|
<select id="exportSupermarketTotal" resultType="com.nova.sankuai.domain.vo.channel.ChannelReportTotalVo">
|
select concat(ls.`name`,"(",ci.`name`,")") as channelName,
|
cl.source as importChannel,
|
cl.export_source as channelCode,
|
count(cl.id) as successCountSum,
|
#{reportDto.startDate} as startDate,
|
#{reportDto.endDate} as endDate,
|
ls.id as supermarketId
|
from (
|
select cl.id,cl.source,cl.export_source,cl.record_id, cl.creation_date,
|
date_format(cl.creation_date,'%Y/%m/%d') as date
|
from channel_log cl
|
left join customer cu on cl.customer_record_id = cu.id
|
where cl.export_source = 12 and cl.status = 1 and cl.type = 1
|
group by cl.source,cl.record_id,cu.phone,date
|
) as cl
|
left join loan_supermarket ls on record_id = ls.id
|
left join channel_info ci on cl.source = ci.`code`
|
<where>
|
ls.delete_flag = 0
|
<if test="reportDto.startDate != null">
|
and cl.creation_date >= #{reportDto.startDate}
|
</if>
|
<if test="reportDto.endDate != null">
|
and cl.creation_date <= #{reportDto.endDate}
|
</if>
|
</where>
|
group by cl.record_id,cl.source
|
</select>
|
|
|
<select id="exportDetail" resultType="com.nova.sankuai.domain.vo.channel.ChannelExportReportVo">
|
select cl.customer_record_id as recordId,
|
cu.phone as phone,
|
cu.name as name,
|
su.company_name as mechanismName,
|
ci.name as exportChannel,
|
ici.name as importChannel,
|
cl.export_source as channelCode,
|
cu.apply_date as applyDate
|
from (select * from channel_log group by customer_record_id,source,export_source,record_id,status,type) as cl
|
left join channel_info ci on cl.export_source = ci.code
|
left join channel_info ici on cl.source = ici.code
|
left join customer cu on cl.customer_record_id = cu.id and cu.delete_flag = 0
|
left join sys_user su on cu.mechanism_id = su.id
|
<where>
|
cl.export_source = #{reportDto.channelCode} and cl.status = 1 and cl.type = 1
|
<if test="reportDto.startDate != null">
|
and cl.creation_date >= #{reportDto.startDate}
|
</if>
|
<if test="reportDto.endDate != null">
|
and cl.creation_date <= #{reportDto.endDate}
|
</if>
|
<if test="reportDto.importChannel != null">
|
and cl.source = #{reportDto.importChannel}
|
</if>
|
<if test="reportDto.name != null and reportDto.name !=''">
|
and cu.name like concat('%',#{reportDto.name},'%')
|
</if>
|
<if test="reportDto.phone != null and reportDto.phone !=''">
|
and cu.phone like concat('%',#{reportDto.phone},'%')
|
</if>
|
<if test="reportDto.mechanismName != null and reportDto.mechanismName !=''">
|
and su.company_name like concat('%',#{reportDto.mechanismName},'%')
|
</if>
|
</where>
|
</select>
|
|
|
<select id="exportLoanMarketDetail" resultType="com.nova.sankuai.domain.vo.channel.ChannelExportReportVo">
|
select cl.customer_record_id as recordId,
|
cl.phone as phone,
|
cl.name as name,
|
su.company_name as mechanismName,
|
ci.name as exportChannel,
|
ici.name as importChannel,
|
cl.export_source as channelCode,
|
cl.apply_date as applyDate,
|
ls.name as supermarketName
|
from (
|
select cl.id,cl.source,cl.export_source,cl.record_id,cl.customer_record_id,
|
cu.phone,cu.name,cu.apply_date,cu.mechanism_id, cl.creation_date,
|
date_format(cl.creation_date,'%Y/%m/%d') as date
|
from channel_log cl
|
left join customer cu on cl.customer_record_id = cu.id and cu.delete_flag = 0
|
where cl.export_source = 12 and cl.status = 1 and cl.type = 1
|
group by cl.source,cl.record_id,cu.phone,date
|
) as cl
|
left join channel_info ci on cl.export_source = ci.code
|
left join channel_info ici on cl.source = ici.code
|
left join sys_user su on cl.mechanism_id = su.id
|
left join loan_supermarket ls on cl.record_id = ls.id
|
<where>
|
cl.export_source = #{reportDto.channelCode}
|
<if test="reportDto.startDate != null">
|
and cl.creation_date >= #{reportDto.startDate}
|
</if>
|
<if test="reportDto.endDate != null">
|
and cl.creation_date <= #{reportDto.endDate}
|
</if>
|
<if test="reportDto.supermarketId != null">
|
and cl.record_id = #{reportDto.supermarketId}
|
</if>
|
<if test="reportDto.importChannel != null">
|
and cl.source = #{reportDto.importChannel}
|
</if>
|
<if test="reportDto.name != null and reportDto.name !=''">
|
and cl.name like concat('%',#{reportDto.name},'%')
|
</if>
|
<if test="reportDto.phone != null and reportDto.phone !=''">
|
and cl.phone like concat('%',#{reportDto.phone},'%')
|
</if>
|
<if test="reportDto.mechanismName != null and reportDto.mechanismName !=''">
|
and su.company_name like concat('%',#{reportDto.mechanismName},'%')
|
</if>
|
</where>
|
</select>
|
|
<select id="selectDuplicateLogs" resultType="com.nova.sankuai.domain.entity.ChannelLog">
|
select * from channel_log where source = #{channelLog.source}
|
and export_source = #{channelLog.exportSource}
|
and type = #{channelLog.type}
|
and status = #{channelLog.status}
|
and record_id = #{channelLog.recordId}
|
and customer_record_id = #{channelLog.customerRecordId}
|
and creation_date <= #{endOfDay}
|
and creation_date >= #{beginOfDay}
|
</select>
|
|
<select id="getChannelProportion" resultType="com.nova.sankuai.domain.vo.ChannelProportionVo">
|
SELECT
|
D.tHour AS tHour,
|
D.hHour AS hHour,
|
D.hDay AS hDay,
|
A.chName AS chName,
|
A.uvSum AS uvSum,
|
B.pkSum AS pkSum,
|
concat(ROUND(B.pkSum / A.uvSum*100, 2),"%") AS pkPropertion,
|
C.vipSum AS vipSum,
|
concat(ROUND(C.vipSum / A.uvSum*100, 2),"%") AS vipPropertion
|
FROM(
|
select
|
DATE_FORMAT(tHour,'%m-%d') AS hDay,
|
DATE_FORMAT(tHour,'%H') AS hHour,
|
tHour AS tHour
|
from(
|
<foreach collection="hourStr" item="item" index="index">
|
<if test="item=='00'">
|
select concat(#{startDayStr},' ',#{item}) as tHour
|
</if>
|
<if test="item!='00'">
|
union select concat(#{startDayStr},' ',#{item}) as tHour
|
</if>
|
</foreach>
|
<foreach collection="hourStr" item="item" index="index">
|
union select concat(#{endDayStr},' ',#{item}) as tHour
|
</foreach>
|
) as tmp
|
) as D
|
left join
|
(SELECT
|
IF ((cv.visit_type = '0'),'UV','PV') AS vType,
|
ci.name AS chName,
|
count(cv.id) AS uvSum,
|
DATE_FORMAT(cv.creation_date,'%m-%d') AS hDay,
|
DATE_FORMAT(cv.creation_date,'%H') AS hHour,
|
DATE_FORMAT(cv.creation_date,'%Y-%m-%d %H') AS tHour
|
FROM channel_view_log cv
|
LEFT JOIN channel_info ci ON cv.channel_id = ci.id
|
WHERE ci.code =#{chCode}
|
AND cv.visit_type = '0'
|
and cv.creation_date >= #{startDate} and cv.creation_date <= #{endDate}
|
GROUP BY tHour ORDER BY tHour
|
) AS A on D.tHour = A.tHour
|
LEFT JOIN (SELECT
|
count(od.id) AS pkSum,
|
date_format(od.creation_date,'%Y-%m-%d %H') AS tHour
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE ci.code =#{chCode}
|
AND od.status = 'END' AND od.vip_type = 1
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate}
|
GROUP BY tHour ORDER BY tHour DESC
|
) AS B ON D.tHour = B.tHour
|
LEFT JOIN (
|
SELECT count(od.id) AS vipSum,
|
date_format(od.creation_date,'%Y-%m-%d %H') AS tHour
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE ci.code =#{chCode}
|
AND od.status = 'END' AND od.vip_type = 0
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate}
|
GROUP BY tHour ORDER BY tHour DESC
|
) AS C ON D.tHour = C.tHour;
|
</select>
|
|
<select id="getLoanSupermarketStatistics" resultType="com.nova.sankuai.domain.vo.LoanSupermarketStatisticsVo">
|
select
|
ci.name as chName,
|
ls.`name` as suName,
|
count(cl.id) as uvSum,
|
cl.tDay as tDay,
|
cl.tHour as hHour
|
from (
|
select cl.id,cl.source,cl.export_source,cl.record_id, cl.creation_date,
|
date_format(cl.creation_date,'%m/%d') as tDay,
|
date_format(cl.creation_date,'%H') as tHour
|
from channel_log cl
|
left join customer cu on cl.customer_record_id = cu.id
|
where cl.export_source = 12 and cl.status = 1 and cl.type = 1
|
and cl.creation_date >= #{startDate} and cl.creation_date <=#{endDate}
|
group by cl.source,cl.record_id,cu.phone,tHour
|
) as cl
|
left join loan_supermarket ls on record_id = ls.id
|
left join channel_info ci on cl.source = ci.`code`
|
<where>
|
ls.delete_flag = 0
|
<if test="suId != null">
|
and ls.id = #{suId}
|
</if>
|
<if test="chCode != null">
|
AND cl.`source` = #{chCode}
|
</if>
|
</where>
|
group by cl.tHour,cl.record_id,cl.source
|
</select>
|
|
<select id="getAutoStatistics" resultType="com.nova.sankuai.domain.vo.AutoStatisticsVo">
|
select
|
A.hDay,
|
A.suName,
|
A.chName,
|
A.suCode,
|
A.id,
|
B.uv as uv,
|
C.inletFlowSum as inletFlowSum,
|
D.pkAmount as pkAmount,
|
E.vipAmount as vipAmount,
|
concat(ROUND(E.vipSum / C.inletFlowSum*100, 2),"%") AS vipPropertion
|
from(
|
SELECT IF ((has_third_channel = 1),name,'') AS suName,
|
IF ((has_third_channel = 0),name, '') AS chName,
|
IF ((has_third_channel = 1),code,auto_parent_code) AS suCode,
|
`id` as id,
|
`code` as chCode,DATE_FORMAT(#{startDate},'%m-%d') AS hDay from channel_info WHERE has_third_channel =1 or third_channel_code is not null
|
) as A
|
LEFT JOIN
|
(SELECT
|
ci.code AS chCode,
|
sum(IF ((cv.visit_type = '0' and ci.has_third_channel = 1),1,0)) AS uv,
|
DATE_FORMAT(cv.creation_date,'%m-%d') AS hDay
|
FROM channel_view_log cv
|
LEFT JOIN channel_info ci ON cv.channel_id = ci.id
|
WHERE
|
cv.creation_date >= #{startDate} and cv.creation_date <= #{endDate}
|
GROUP BY ci.id
|
) as B ON A.hDay = B.hDay and A.chCode = B.chCode
|
left join
|
(SELECT
|
ci.`code` AS chCode,
|
count(cu.id) AS inletFlowSum,
|
DATE_FORMAT(cu.apply_date,'%m-%d') AS hDay
|
FROM customer cu
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
where 1 = 1
|
and cu.apply_date >= #{startDate} and cu.apply_date <= #{endDate}
|
GROUP BY ci.code
|
) AS C ON A.hDay = C.hDay and A.chCode = C.chCode
|
LEFT JOIN (SELECT
|
sum(od.price) AS pkAmount,
|
date_format(od.creation_date,'%m-%d') AS hDay,
|
ci.code as chCode
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE
|
od.status = 'END' AND od.vip_type = 1
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate}
|
GROUP BY ci.code
|
) AS D ON A.hDay = D.hDay and A.chCode = D.chCode
|
LEFT JOIN (
|
SELECT
|
sum(od.price) AS vipAmount,
|
count(od.id) AS vipSum,
|
date_format(od.creation_date,'%m-%d') AS hDay,
|
ci.code as chCode
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE
|
od.status = 'END' AND od.vip_type = 0
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate}
|
GROUP BY ci.code
|
) AS E ON A.hDay = E.hDay and A.chCode = E.chCode
|
</select>
|
|
<select id="getWholeProcessStatistics" resultType="com.nova.sankuai.domain.vo.WholeProcessStatisticsVo">
|
select
|
E.date as date,
|
IFNull(A.downloadCount,0) as downloadCount,
|
IFNull(B.appLoginCount,0) as appLoginCount,
|
IFNull(G.h5LoginCount,0) as h5LoginCount,
|
IFNull(sum(C.aCount+C.bCount+C.cCount+C.C.dCount),0) as baseInfoCount,
|
IFNull(sum(C.bCount+C.cCount+C.C.dCount),0) as ocrCount,
|
IFNull(sum(C.cCount+C.C.dCount),0) as bankInfoCount,
|
IFNull(sum(C.cCount),0) as capitalInfoCount,
|
IFNull(D.nCount,0) as queueNormalCount,
|
IFNull(D.vCount,0) as queueVipCount,
|
IFNull(D.sCount,0) as payQueueCount,
|
IFNull(cnt,0) as payVipCount
|
from (select DATE_FORMAT(#{startDate},'%m-%d') AS date) as E
|
left join(
|
select
|
DATE_FORMAT(cd.creation_date,'%m-%d') AS date,
|
count(cd.id) as downloadCount
|
from channel_download_log cd
|
<if test="chCode != null">
|
LEFT JOIN channel_info ci ON cd.channel_id = ci.id
|
</if>
|
where cd.creation_date >= #{startDate} and cd.creation_date <=#{endDate}
|
<if test="chCode != null">
|
and ci.`code` = #{chCode}
|
</if>
|
) as A on E.date = A.date
|
left join (
|
select
|
DATE_FORMAT(cu.app_last_updated_date,'%m-%d') AS date,
|
count(cu.id) as appLoginCount
|
from customer_user cu
|
where cu.app_last_updated_date >= #{startDate} and cu.app_last_updated_date <=#{endDate}
|
<if test="chCode != null">
|
and cu.source_channel = #{chCode}
|
</if>
|
) as B on E.date = B.date
|
left join (
|
select
|
DATE_FORMAT(cu.h5_last_updated_date,'%m-%d') AS date,
|
count(cu.id) as h5LoginCount
|
from customer_user cu
|
where cu.h5_last_updated_date >= #{startDate} and cu.h5_last_updated_date <=#{endDate}
|
<if test="chCode != null">
|
and cu.source_channel = #{chCode}
|
</if>
|
) as G on G.date = E.date
|
left join (
|
select
|
DATE_FORMAT(cu.apply_date,'%m-%d') AS date,
|
sum(IF(cu.status = 0,1,0)) as aCount,
|
sum(IF(cu.status = 1,1,0)) as bCount,
|
sum(IF(cu.status = 2,1,0)) as cCount,
|
sum(IF(cu.status = 3,1,0)) as dCount
|
from customer cu
|
where cu.apply_date >= #{startDate} and cu.apply_date <=#{endDate}
|
<if test="chCode != null">
|
and cu.source_channel = #{chCode}
|
</if>
|
) as C on E.date = C.date
|
left join(
|
select
|
DATE_FORMAT(od.creation_date,'%m-%d') AS date,
|
sum(IF(vc.queue_vip_code = 'NORMAL',1,0)) as nCount,
|
sum(IF(vc.queue_vip_code = 'NORMAL',0,1)) as vCount,
|
sum(IF(od.status = 'END',1,0)) as sCount
|
from vip_card_order od
|
left join vip_card vc on od.card_id = vc.card_id
|
<if test="chCode != null">
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
</if>
|
where od.creation_date >= #{startDate} and od.creation_date <=#{endDate}
|
and od.vip_type = 1
|
<if test="chCode != null">
|
and ci.code = #{chCode}
|
</if>
|
) as D on E.date = D.date
|
left join(
|
select
|
DATE_FORMAT(od.creation_date,'%m-%d') AS date,
|
count(vc.id) as cnt
|
from vip_card_order od
|
left join vip_card vc on od.card_id = vc.card_id
|
<if test="chCode != null">
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
</if>
|
where od.creation_date >= #{startDate} and od.creation_date <=#{endDate}
|
and od.vip_type = 0 and od.status = 'END'
|
<if test="chCode != null">
|
and ci.code = #{chCode}
|
</if>
|
) as F on E.date = F.date
|
|
</select>
|
|
<select id="dataRepair">
|
UPDATE `channel_info` ci1,`channel_info` ci2 SET ci1.auto_parent_code = ci2.`code`
|
WHERE ci1.third_channel_code LIKE CONCAT(ci2.app_id,'%')
|
AND ci1.id = #{id}
|
</select>
|
|
<select id="channelStatistics" resultType="com.nova.sankuai.domain.vo.ChannelStatisticsListVo">
|
SELECT
|
M.hDay AS hDay,
|
M.chName as chName,
|
A.uvSum AS uvSum,
|
B.pkSum AS pkSum,
|
ROUND(B.pkSum / A.uvSum, 4) AS pkPropertion,
|
C.vipSum AS vipSum,
|
ROUND(C.vipSum / A.uvSum, 4) AS vipPropertion
|
FROM
|
(
|
select
|
DATE_FORMAT(str.tDay,'%m-%d') AS hDay,
|
ci.code as chCode,
|
ci.name as chName
|
from (
|
select #{startDate} as tDay
|
union select #{endDate} as tDay) as str
|
,channel_info ci
|
<if test="chCodes != null">
|
where ci.code in
|
<foreach collection="chCodes" item="item" index="index" open="(" separator="," close=")">
|
#{item}
|
</foreach>
|
</if>
|
) as M
|
left join (SELECT
|
ci.name AS chName,
|
count(cu.id) AS uvSum,
|
DATE_FORMAT(cu.apply_date,'%m-%d') AS hDay,
|
ci.code as chCode
|
FROM customer cu
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE 1 = 1
|
<if test="chCodes != null">
|
and ci.code in
|
<foreach collection="chCodes" item="item" index="index" open="(" separator="," close=")">
|
#{item}
|
</foreach>
|
</if>
|
and cu.apply_date >= #{startDate} and cu.apply_date <= #{endDate}
|
GROUP BY hDay ,chCode
|
) AS A on A.hDay = M.hDay and A.chCode = M.chCode
|
LEFT JOIN (SELECT
|
count(od.id) AS pkSum,
|
date_format(od.creation_date,'%m-%d') AS hDay,
|
ci.code as chCode
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE od.status = 'END' AND od.vip_type = 1
|
<if test="chCodes != null">
|
and ci.code in
|
<foreach collection="chCodes" item="item" index="index" open="(" separator="," close=")">
|
#{item}
|
</foreach>
|
</if>
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate}
|
GROUP BY hDay ,chCode
|
) AS B ON B.hDay = M.hDay and B.chCode = M.chCode
|
LEFT JOIN (
|
SELECT count(od.id) AS vipSum,
|
date_format(od.creation_date,'%m-%d') AS hDay,
|
ci.code as chCode
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE od.status = 'END' AND od.vip_type = 0
|
<if test="chCodes != null">
|
and ci.code in
|
<foreach collection="chCodes" item="item" index="index" open="(" separator="," close=")">
|
#{item}
|
</foreach>
|
</if>
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate}
|
GROUP BY hDay ,chCode
|
) AS C ON C.hDay = M.hDay and C.chCode = M.chCode
|
</select>
|
|
<select id="getBaseProfitAnalysisReportVo" resultType="com.nova.sankuai.domain.vo.BaseProfitAnalysisReportVo">
|
SELECT
|
M.chName as chName,
|
M.chCode as chCode,
|
IFNull(N.uv,0) AS uvSum,
|
IFNull(N.uvCost,0) AS uvCost,
|
IFNull(B.pkIncome,0) AS pkIncome,
|
IFNull(C.vipIncome,0) AS vipIncome,
|
IFNull(D.loanIncome,0) AS loanIncome
|
FROM
|
(
|
SELECT name as chName,
|
code AS chCode
|
FROM channel_info
|
WHERE status = 1 and code = #{chCode}
|
) as M
|
-- 计算UV总数及UV成本
|
LEFT JOIN (
|
SELECT
|
ci.code AS chCode,
|
ci.name as chName,
|
sum(IF ((cv.visit_type = '0'),1,0)) AS uv,
|
sum(IF ((cv.visit_type = '0'),1,0))*cc.uv_price as uvCost
|
FROM channel_view_log cv
|
LEFT JOIN channel_info ci ON cv.channel_id = ci.id
|
left JOIN cost_config cc
|
ON ci.code = cc.channel_code and cc.is_delete = 0 and cc.default_flag = 1
|
WHERE
|
cv.creation_date >= #{startDate} and cv.creation_date <= #{endDate}
|
and ci.type = 0 and ci.code = #{chCode}
|
) N ON N.chCode = M.chCode
|
-- 计算审批加速包收入
|
LEFT JOIN (SELECT
|
ci.name AS chName,
|
sum(od.price) AS pkIncome,
|
ci.code as chCode
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE od.status = 'END' AND od.vip_type = 1
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate} and ci.code = #{chCode}
|
) AS B ON B.chCode = M.chCode
|
-- 计算会员购买收入
|
LEFT JOIN (
|
SELECT count(od.id) AS vipSum,
|
sum(od.price) AS vipIncome,
|
ci.code as chCode
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE od.status = 'END' AND od.vip_type = 0
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate} and ci.code = #{chCode}
|
) AS C ON C.chCode = M.chCode
|
-- 计算贷超会员购买收入
|
LEFT JOIN (
|
SELECT count(od.id) AS loanSum,
|
sum(od.price) AS loanIncome,
|
ci.code as chCode
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE od.status = 'END' AND od.vip_type = 2
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate} and ci.code = #{chCode}
|
) AS D ON D.chCode = M.chCode
|
</select>
|
|
<select id="getCityProfitAnalysisReportVo" resultType="com.nova.sankuai.domain.vo.CityProfitAnalysisReportVo">
|
SELECT
|
M.chName as chName,
|
M.chCode as chCode,
|
ifnull(A.registerSum,0) as registerSum,
|
ifnull(A.registerPrice,0) as registerCost,
|
ifnull(B.collisionSum,0) as collisionSum,
|
ifnull(B.collisionPrice,0) as collisionIncome,
|
ifnull(C.capitalSum,0) as capitalSum,
|
ifnull(C.capitalPrice,0) as capitalIncome,
|
ifnull(D.auditSum,0) as auditSum,
|
ifnull(D.auditPrice,0) as auditIncome
|
FROM
|
-- 以渠道为主表进行查询
|
(SELECT name as chName,
|
code AS chCode
|
FROM channel_info
|
WHERE status = 1 and code = #{chCode}
|
) as M
|
-- 计算注册总数及注册成本
|
left join (
|
select
|
cu.chCode,
|
sum(cu.registerSum) as registerSum,
|
sum(cu.registerSum * ifnull(cc.register_price,de.register_price)) as registerPrice
|
from (
|
select cus.source_channel as chCode,
|
count(cus.id) as registerSum,
|
ifNull(cu.city,'默认') as cityId
|
from customer_user cus
|
left join (select id,phone,city from customer
|
where source_channel = #{chCode}
|
and apply_date >= #{startDate} and apply_date <=#{endDate} group by phone
|
) as cu on cus.phone = cu.phone
|
where cus.source_channel = #{chCode}
|
and cus.creation_date >= #{startDate} and cus.creation_date <=#{endDate}
|
group by cu.city) as cu
|
left join cost_config cc
|
on cu.chCode = cc.channel_code and cu.cityId = cc.relation_city_id and cc.is_delete = 0 and cc.default_flag = 0
|
left join cost_config de
|
on cu.chCode = de.channel_code and de.default_flag = 1 and de.is_delete = 0
|
) as A on M.chCode = A.chCode
|
-- 计算联登人数及联登收入
|
left join (
|
select ccr.chCode,
|
sum(ccr.collisionSum) as collisionSum,
|
sum(ccr.collisionSum * ifnull(ic.collision_price,de.collision_price)) as collisionPrice
|
from (select
|
cu.source_channel as chCode,
|
ccr.capital_info_code as capitalCode,
|
count(ccr.id) as collisionSum,
|
ifNull(cu.city,'默认') as cityId
|
from customer_capital_result ccr
|
inner join capital_info ci on ci.id = ccr.capital_info_id
|
left join customer cu
|
on ccr.customer_record_id = cu.id
|
where ci.fee_mode = 1
|
and ccr.approval_result = 1 and ccr.last_updated_date >= #{startDate} and ccr.last_updated_date <=#{endDate}
|
and cu.source_channel = #{chCode}
|
group by capitalCode,cityId) as ccr
|
left join income_config ic on ccr.capitalCode = ic.config_record_code and ic.type = 0 and ic.default_flag = 0
|
and ccr.cityId = ic.relation_city_id and ic.is_delete = 0
|
left join income_config de on ccr.capitalCode = de.config_record_code and de.type = 0
|
and de.default_flag = 1 and de.is_delete = 0
|
) as B on M.chCode = B.chCode
|
-- 计算资方列表人数及资方列表收入
|
left join (
|
select ccr.chCode,
|
sum(ccr.capitalSum) as capitalSum,
|
sum(ccr.capitalSum * ifnull(ic.capital_price,de.capital_price)) as capitalPrice
|
from (select
|
cu.source_channel as chCode,
|
ccr.capital_info_code as capitalCode,
|
count(ccr.id) as capitalSum,
|
ifNull(cu.city,'默认') as cityId
|
from customer_capital_result ccr
|
inner join capital_info ci on ci.id = ccr.capital_info_id
|
left join customer cu
|
on ccr.customer_record_id = cu.id
|
where ci.fee_mode = 0
|
and ccr.approval_result = 1 and ccr.last_updated_date >= #{startDate} and ccr.last_updated_date <=#{endDate}
|
and cu.source_channel = #{chCode}
|
group by capitalCode,cityId) as ccr
|
left join income_config ic on ccr.capitalCode = ic.config_record_code and ic.type = 0 and ic.default_flag = 0
|
and ccr.cityId = ic.relation_city_id and ic.is_delete = 0
|
left join income_config de on ccr.capitalCode = de.config_record_code and de.type = 0
|
and de.default_flag = 1 and de.is_delete = 0
|
) as C on M.chCode = C.chCode
|
-- 计算审批分流人数及审批分流收入
|
left join (
|
select acr.chCode,
|
sum(acr.auditSum) as auditSum,
|
sum(acr.auditSum * ifnull(ic.audit_price,de.audit_price)) as auditPrice
|
from (select
|
cu.source_channel as chCode,
|
ac.company_code as auditCode,
|
count(acr.id) as auditSum,
|
ifNull(cu.city,'默认') as cityId
|
from api_company_record acr
|
inner join api_company ac on ac.id = acr.company_id
|
left join customer cu
|
on acr.customer_record_id = cu.id
|
where acr.status = 1
|
and acr.creation_date >= #{startDate} and acr.creation_date <=#{endDate}
|
and cu.source_channel = #{chCode}
|
group by auditCode,cityId) as acr
|
left join income_config ic on acr.auditCode = ic.config_record_code and ic.type =1 and ic.default_flag = 0
|
and acr.cityId = ic.relation_city_id and ic.is_delete = 0
|
left join income_config de on acr.auditCode = de.config_record_code and de.type = 1
|
and de.default_flag = 1 and de.is_delete = 0
|
) as D on M.chCode = D.chCode;
|
</select>
|
</mapper>
|