You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
13 KiB

<?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.qniao.dam.infrastructure.persistent.dao.view.RevenueRewardViewDao">
<select id="getRevenueRewardAbstract"
resultType="com.qniao.dam.api.query.revenuereward.user.response.UseGetRevenueRewardAbstractVo">
select
drr.id,
SUM(drrr.revenue) as totalRevenue,
SUM(IF(drrr.trade_scene=1,drrr.revenue,0)) as onlineRevenue,
SUM(IF(drrr.trade_scene=2,drrr.revenue,0)) as offlineRevenue,
SUM(drrr.earnings) as totalEarnings,
SUM(IF(drrr.trade_scene=1,drrr.earnings,0)) as onlineEarnings,
SUM(IF(drrr.trade_scene=2,drrr.earnings,0)) as offlineEarnings
from da_revenue_reward_record as drrr
LEFT JOIN da_revenue_reward as drr on drr.id=drrr.revenue_reward_id
WHERE drr.is_delete=0
<if test="queryParams.queryUserId != null">
and drr.user_id = #{queryParams.queryUserId}
</if>
<if test="queryParams.queryOrgId != null">
and drr.org_id = #{queryParams.queryOrgId}
</if>
<if test="queryParams.tradeType != null">
and drrr.trade_type = #{queryParams.tradeType}
</if>
<if test="queryParams.revenueTimeFrom != null and queryParams.revenueTimeTo != null">
and drrr.create_time BETWEEN #{queryParams.revenueTimeFrom} and #{queryParams.revenueTimeTo}
</if>
GROUP BY drr.id
limit 1
</select>
<select id="pageRevenueRewardRecord"
resultType="com.qniao.dam.api.query.revenuereward.user.response.UseGetRevenueRewardRecordVo">
select
drrr.trade_type,
drrr.revenue,
drrr.earnings,
drrr.total_associate_order_amount as associateOrderAmount,
drrr.content,
drrr.create_time as revenueTime
from da_revenue_reward_record as drrr
LEFT JOIN da_revenue_reward as drr on drr.id=drrr.revenue_reward_id
WHERE drr.is_delete=0
<if test="queryParams.queryUserId != null">
and drr.user_id = #{queryParams.queryUserId}
</if>
<if test="queryParams.queryOrgId != null">
and drr.org_id = #{queryParams.queryOrgId}
</if>
<if test="queryParams.tradeType != null">
and drrr.trade_type = #{queryParams.tradeType}
</if>
<if test="queryParams.revenueTimeFrom != null and queryParams.revenueTimeTo != null">
and drrr.create_time BETWEEN #{queryParams.revenueTimeFrom} and #{queryParams.revenueTimeTo}
</if>
ORDER BY drrr.create_time desc
</select>
<select id="pageRevenueRewardRecordByOperator"
resultType="com.qniao.dam.api.query.revenuereward.user.response.UserPageRevenueRewardRecordByOperatorVo">
select
darrr.id as revenueRewardRecordId,
darrr.create_time,
dam.user_id as matchmakerUserId,
dam.type as matchmakerType,
if(darr.identity_type=1,dam.`name`,dao3.full_name) as revenueOwnerName,
dam.phone as revenueOwnerPhone,
dao3.id as orgId,
darr.identity_type,
darrr.trade_type,
darrr.trade_scene,
darrr.total_associate_order_amount,
darrr.revenue_pct,
darrr.revenue,
darrr.service_pct,
darrr.earnings,
dao1.full_name as storeName,
dao2.full_name as operationCenterName
from da_revenue_reward_record as darrr
INNER JOIN da_revenue_reward as darr on darrr.revenue_reward_id=darr.id
LEFT JOIN da_matchmaker as dam on dam.is_delete=0 and dam.user_id=darr.user_id
LEFT JOIN da_store as das on dam.store_id=das.id
LEFT JOIN da_organization dao1 on dao1.id= das.org_id
LEFT JOIN da_organization dao2 on dao2.id= das.operation_center_org_id
LEFT JOIN da_organization dao3 on dao3.id=darr.org_id
where darr.is_delete=0
<if test="queryParams.tradeScene != null">
and darrr.trade_scene = #{queryParams.tradeScene}
</if>
<if test="queryParams.identityType != null">
and darr.identity_type = #{queryParams.identityType}
</if>
<if test="queryParams.revenueOwnerName != null and queryParams.revenueOwnerName != '' ">
AND (dam.`name` LIKE CONCAT('%', TRIM(#{queryParams.revenueOwnerName}), '%') or
dao3.`full_name` LIKE CONCAT('%', TRIM(#{queryParams.revenueOwnerName}), '%'))
</if>
<if test="queryParams.revenueOwnerPhone != null and queryParams.revenueOwnerPhone != '' ">
AND dam.phone LIKE CONCAT('%', TRIM(#{queryParams.revenueOwnerPhone}), '%')
</if>
<if test="queryParams.storeName != null and queryParams.storeName != '' ">
AND dao1.full_name LIKE CONCAT('%', TRIM(#{queryParams.storeName}), '%')
</if>
<if test="queryParams.operationCenterName != null and queryParams.operationCenterName != '' ">
AND dao2.full_name LIKE CONCAT('%', TRIM(#{queryParams.operationCenterName}), '%')
</if>
<if test="queryParams.createTimeFrom != null and queryParams.createTimeTo != null">
and darrr.create_time BETWEEN #{queryParams.createTimeFrom} and #{queryParams.createTimeTo}
</if>
order by darrr.create_time desc
</select>
<select id="listAssociateOrderRecord"
resultType="com.qniao.dam.api.query.revenuereward.user.response.RevenueRewardAssociateOrderRecordVo">
select
darraor.revenue_reward_record_id,
darraor.associate_order_id,
dao.order_code,
darraor.associate_order_amount,
dao.paid_time as orderTime,
dapco.ext_order_no as wechatOrderNo,
dao.order_belong_name as serviceUserName,
daa.tid as serviceUserPhone
from da_revenue_reward_associate_order_record as darraor
LEFT JOIN da_order as dao on darraor.associate_order_id=dao.id
LEFT JOIN da_marriage_information as dami on dami.id=dao.id
LEFT JOIN da_payment_order as dapo on dapo.is_delete=0 and dapo.`status`=3 and dapo.order_id=dao.id
LEFT JOIN da_payment_channel_order as dapco on dapco.is_delete=0 and dapco.txn_order_id=dapo.id and
dapco.`status`=2
LEFT JOIN da_account as daa on daa.is_delete=0 and daa.user_id=dao.user_id and daa.type=2
where darraor.revenue_reward_record_id in
<foreach collection="revenueRewardRecordIdList" item="revenueRewardRecordId" open="(" close=")" separator=",">
#{revenueRewardRecordId}
</foreach>
</select>
<select id="getRevenueRewardAbstractByOperator"
resultType="com.qniao.dam.api.query.revenuereward.user.response.UserGetRevenueRewardAbstractByOperatorVo">
select
SUM(IFNULL(darrr.revenue,0)) as totalRevenue,
SUM(IFNULL(darrr.earnings,0)) as totalEarnings
from da_revenue_reward as darr
LEFT JOIN da_revenue_reward_record as darrr on darrr.revenue_reward_id=darr.id
LEFT JOIN da_matchmaker as dam on dam.is_delete=0 and dam.user_id=darr.user_id
LEFT JOIN da_store as das on dam.store_id=das.id
LEFT JOIN da_organization dao1 on dao1.id= das.org_id
LEFT JOIN da_organization dao2 on dao2.id= das.operation_center_org_id
LEFT JOIN da_organization dao3 on dao3.id=darr.org_id
where darr.is_delete=0
<if test="queryParams.tradeScene != null">
and darrr.trade_scene = #{queryParams.tradeScene}
</if>
<if test="queryParams.identityType != null">
and darr.identity_type = #{queryParams.identityType}
</if>
<if test="queryParams.revenueOwnerName != null and queryParams.revenueOwnerName != '' ">
AND (dam.`name` LIKE CONCAT('%', TRIM(#{queryParams.revenueOwnerName}), '%') or
dao3.`full_name` LIKE CONCAT('%', TRIM(#{queryParams.revenueOwnerName}), '%'))
</if>
<if test="queryParams.revenueOwnerPhone != null and queryParams.revenueOwnerPhone != '' ">
AND dam.phone LIKE CONCAT('%', TRIM(#{queryParams.revenueOwnerPhone}), '%')
</if>
<if test="queryParams.storeName != null and queryParams.storeName != '' ">
AND dao1.full_name LIKE CONCAT('%', TRIM(#{queryParams.storeName}), '%')
</if>
<if test="queryParams.operationCenterName != null and queryParams.operationCenterName != '' ">
AND dao2.full_name LIKE CONCAT('%', TRIM(#{queryParams.operationCenterName}), '%')
</if>
<if test="queryParams.createTimeFrom != null and queryParams.createTimeTo != null">
and darrr.create_time BETWEEN #{queryParams.createTimeFrom} and #{queryParams.createTimeTo}
</if>
</select>
<select id="listMatchmakerRevenueRewardStatistics"
resultType="com.qniao.dam.api.query.revenuereward.user.response.UserListMatchmakerRevenueRewardStatisticsVo">
SELECT
dam.id as matchmakerId,
dam.`name` as matchmakerName,
SUM(darrr.revenue) as revenue,
SUM(JSON_EXTRACT(ext_info,'$.matchmakerOrderType')='1') as inviteMatchmakerNum
from da_revenue_reward_record as darrr
INNER JOIN da_revenue_reward as darr on darr.is_delete=0 and darr.id=darrr.revenue_reward_id
INNER JOIN da_revenue_reward_associate_order_record as darrasor on darrasor.revenue_reward_record_id=darrr.id
INNER JOIN da_order as dao on dao.is_delete=0 and dao.id=darrasor.associate_order_id
INNER JOIN da_matchmaker as dam on dam.is_delete=0 and dam.user_id=darr.user_id
where darrr.trade_scene=1
<if test="queryParams.revenueTimeFrom != null and queryParams.revenueTimeTo != null">
and darrr.create_time BETWEEN #{queryParams.revenueTimeFrom} and #{queryParams.revenueTimeTo}
</if>
<if test="storeIdList.size > 0">
and dam.store_id in
<foreach collection="storeIdList" item="storeId" open="(" close=")" separator=",">
#{storeId}
</foreach>
</if>
GROUP BY dam.id
order by inviteMatchmakerNum desc
</select>
<select id="pageMatchmakerRevenueRewardRecord"
resultType="com.qniao.dam.api.query.revenuereward.user.response.UserPageMatchmakerRevenueRewardRecordVo">
SELECT
dam.`name` as revenueOwnerName,
dam.user_id as matchmakerUserId,
daorg.full_name as storeName,
dam.type as matchmakerType,
darrr.trade_type,
darrr.revenue,
darrr.revenue_pct,
darrr.service_pct,
darrr.earnings,
darrr.total_associate_order_amount,
darrr.content,
darrr.create_time,
dami.nick_name as serviceUserName
from da_revenue_reward_record as darrr
INNER JOIN da_revenue_reward as darr on darr.is_delete=0 and darr.id=darrr.revenue_reward_id
LEFT JOIN da_revenue_reward_associate_order_record as darrasor on darrasor.revenue_reward_record_id=darrr.id
LEFT JOIN da_order as dao on dao.is_delete=0 and dao.id=darrasor.associate_order_id
LEFT JOIN da_marriage_information as dami on dami.id=dao.mi_id
LEFT JOIN da_user_marriage_information as daumi on daumi.is_delete=0 and daumi.mi_id=dao.mi_id
LEFT JOIN da_account daa on daa.is_delete=0 and daa.user_id=daumi.user_id and daa.type=2
LEFT JOIN da_matchmaker as dam on dam.is_delete=0 and dam.user_id=darr.user_id
LEFT JOIN da_store as das on das.id=dam.store_id
LEFT JOIN da_organization as daorg on daorg.id=das.org_id
where darrr.trade_scene=1
<if test="queryParams.revenueTimeFrom != null and queryParams.revenueTimeTo != null">
and darrr.create_time BETWEEN #{queryParams.revenueTimeFrom} and #{queryParams.revenueTimeTo}
</if>
<if test="queryParams.storeId != null">
and dam.store_id = #{queryParams.storeId}
</if>
<if test="queryParams.tradeType != null">
and darrr.trade_type = #{queryParams.tradeType}
</if>
<if test="queryParams.matchmakerName != null and queryParams.matchmakerName != '' ">
AND dam.name LIKE CONCAT('%', TRIM(#{queryParams.matchmakerName}), '%')
</if>
<if test="queryParams.serviceUserInfo != null and queryParams.serviceUserInfo != '' ">
AND (dami.nick_name LIKE CONCAT('%', TRIM(#{queryParams.serviceUserInfo}), '%') or
daa.tid LIKE CONCAT('%', TRIM(#{queryParams.serviceUserInfo}), '%'))
</if>
<if test="storeIdList.size > 0">
and dam.store_id in
<foreach collection="storeIdList" item="storeId" open="(" close=")" separator=",">
#{storeId}
</foreach>
</if>
GROUP BY darrr.id
order by darrr.create_time desc
</select>
</mapper>