zhwl/zhwl-business/zhwl-statistics/target/classes/mapper/statistics/ZdyTicketSellerMapper.xml
2025-07-01 17:54:58 +08:00

242 lines
9.4 KiB
XML

<?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.zhwl.statistics.mapper.ZdyTicketSellServiceMapper">
<select id="ticketSellerStatistics" resultType="com.zhwl.statistics.domain.vo.ChildParkStatisticsVo">
SELECT
a.create_by sellerIdus,
su.user_name sellerUsername,
su.nick_name sellerName,
totalAmount,
totalCount,
refundTotalAmount,
refundTotalCount,
totalAmount-refundTotalAmount actualIncomeAmount
FROM
(SELECT
zto.create_by,
SUM(ztod.product_total_price) totalAmount,
SUM(ztod.buy_quantity) totalCount
FROM
zdy_ticket_order zto
LEFT JOIN zdy_ticket_order_detail ztod ON ztod.order_id = zto.id
<where>
zto.order_source = 1
<if test="startTime != null and endTime != null ">and zto.create_time between #{startTime} and #{endTime}</if>
</where>
GROUP BY zto.create_by) a
LEFT JOIN
(SELECT
zto.create_by,
SUM(ztod.product_total_price) refundTotalAmount,
SUM(ztod.buy_quantity) refundTotalCount
FROM
zdy_ticket_order zto
LEFT JOIN zdy_ticket_order_detail ztod ON ztod.order_id = zto.id
<where>
zto.order_source = 1 AND ztod.refund_status = 200
<if test="startTime != null and endTime != null ">and zto.create_time between #{startTime} and #{endTime}
</if>
</where>
GROUP BY zto.create_by) b ON a.create_by = b.create_by
left join sys_user su on su.user_id= a.create_by
<where>
<if test="sellerName != null and sellerName != ''">and (su.user_name like concat('%', #{sellerName}, '%' )
or
su.nick_name like concat('%', #{sellerName}, '%') )
</if>
</where>
</select>
<select id="ticketStatistics" resultType="com.zhwl.statistics.domain.vo.TicketStatisticsVo">
SELECT
a.ticket_id ticketId,
a.ticket_name ticketName,
totalCount,
refundTotalCount,
refundTotalAmount,
totalAmount,
c.cashAmount,
d.wechatAmount,
e.alipayAmount,
totalAmount-refundTotalAmount actualIncomeAmount,
ticketPrice
FROM
(SELECT
zto.ticket_id,
zto.ticket_name,
SUM(ztod.product_total_price) totalAmount,
SUM(ztod.buy_quantity) totalCount,
zto.ticket_price ticketPrice
FROM
zdy_ticket_order zto
LEFT JOIN zdy_ticket_order_detail ztod ON ztod.order_id = zto.id
<where>
zto.order_source = 1
<if test="startTime != null and endTime != null ">and zto.create_time between #{startTime} and #{endTime}</if>
<if test="userId != '' and userId != null ">and zto.create_by = #{userId} </if>
</where>
GROUP BY zto.ticket_id) a
LEFT JOIN
(SELECT
zto.ticket_id,
SUM(ztod.product_total_price) refundTotalAmount,
SUM(ztod.buy_quantity) refundTotalCount
FROM
zdy_ticket_order zto
LEFT JOIN zdy_ticket_order_detail ztod ON ztod.order_id = zto.id
<where>
zto.order_source = 1 AND ztod.refund_status = 200
<if test="startTime != null and endTime != null ">and zto.create_time between #{startTime} and #{endTime}
</if>
<if test="userId != '' and userId != null ">and zto.create_by = #{userId} </if>
</where>
GROUP BY zto.ticket_id) b ON a.ticket_id = b.ticket_id
LEFT JOIN
(SELECT
zto.ticket_id,
SUM(ztod.product_total_price) cashAmount
FROM
zdy_ticket_order zto
LEFT JOIN zdy_ticket_order_detail ztod ON ztod.order_id = zto.id and ztod.payment_method =1
<where>
zto.order_source = 1
<if test="startTime != null and endTime != null ">and zto.create_time between #{startTime} and #{endTime}
</if>
<if test="userId != '' and userId != null ">and zto.create_by = #{userId} </if>
</where>
GROUP BY zto.ticket_id) c ON a.ticket_id = c.ticket_id
LEFT JOIN
(SELECT
zto.ticket_id,
SUM(ztod.product_total_price) wechatAmount
FROM
zdy_ticket_order zto
LEFT JOIN zdy_ticket_order_detail ztod ON ztod.order_id = zto.id and ztod.payment_method =2
<where>
zto.order_source = 1
<if test="startTime != null and endTime != null ">and zto.create_time between #{startTime} and #{endTime}
</if>
<if test="userId != '' and userId != null ">and zto.create_by = #{userId} </if>
</where>
GROUP BY zto.ticket_id) d ON a.ticket_id = d.ticket_id
LEFT JOIN
(SELECT
zto.ticket_id,
SUM(ztod.product_total_price) alipayAmount
FROM
zdy_ticket_order zto
LEFT JOIN zdy_ticket_order_detail ztod ON ztod.order_id = zto.id and ztod.payment_method =3
<where>
zto.order_source = 1
<if test="startTime != null and endTime != null ">and zto.create_time between #{startTime} and #{endTime}
</if>
<if test="userId != '' and userId != null ">and zto.create_by = #{userId} </if>
</where>
GROUP BY zto.ticket_id) e ON a.ticket_id = e.ticket_id
</select>
<select id="ticketStatisticsSum" resultType="com.zhwl.statistics.domain.vo.TicketStatisticsSumVo"
parameterType="com.zhwl.statistics.domain.vo.TicketStatisticsVo">
SELECT
totalCountSum,
refundTotalCountSum,
refundTotalAmountSum,
totalAmountSum
FROM
(SELECT
zto.ticket_id,
zto.ticket_name,
SUM(ztod.product_total_price) totalAmountSum,
SUM(ztod.buy_quantity) totalCountSum,
zto.ticket_price ticketPrice
FROM
zdy_ticket_order zto
LEFT JOIN zdy_ticket_order_detail ztod ON ztod.order_id = zto.id
<where>
zto.order_source = 1
<if test="startTime != null and endTime != null ">and zto.create_time between #{startTime} and #{endTime}</if>
<if test="userId != '' and userId != null ">and zto.create_by = #{userId} </if>
</where>
) a
LEFT JOIN
(SELECT
zto.ticket_id,
SUM(ztod.product_total_price) refundTotalAmountSum,
SUM(ztod.buy_quantity) refundTotalCountSum
FROM
zdy_ticket_order zto
LEFT JOIN zdy_ticket_order_detail ztod ON ztod.order_id = zto.id
<where>
zto.order_source = 1 AND ztod.refund_status = 200
<if test="startTime != null and endTime != null ">and zto.create_time between #{startTime} and #{endTime}
</if>
<if test="userId != '' and userId != null ">and zto.create_by = #{userId} </if>
</where>
) b ON a.ticket_id = b.ticket_id
</select>
<select id="selectGatherTop5" resultType="java.util.Map">
SELECT
DATE_FORMAT( a.date, '%Y-%m-%d' ) AS date,
a.ticketName,
a.totalPrice
FROM (
(
SELECT ANY_VALUE ( create_time ) AS date, ANY_VALUE (ticket_name) AS ticketName, SUM( total_price ) AS totalPrice
FROM zdy_ticket_order_item
<where>
<if test="startTime != null">and create_time >= #{startTime}</if>
<if test="endTime != null">and create_time &lt;= #{endTime}</if>
</where>
GROUP BY ticket_id
ORDER BY totalPrice DESC LIMIT 5
) UNION ALL
(
SELECT ANY_VALUE ( create_time ) AS date, ANY_VALUE(product_name) AS ticketName, SUM( total_price ) AS totalPrice
FROM zdy_eatery_order_product
<where>
<if test="startTime != null">and create_time >= #{startTime}</if>
<if test="endTime != null">and create_time &lt;= #{endTime}</if>
</where>
GROUP BY product_id
ORDER BY totalPrice DESC LIMIT 5
) UNION ALL
(
SELECT
ANY_VALUE ( create_time ) AS date,
ANY_VALUE ( goods_title ) AS ticketName, SUM( total_price ) AS totalPrice
FROM zdy_wcsc_order_item
<where>
<if test="startTime != null">and create_time >= #{startTime}</if>
<if test="endTime != null">and create_time &lt;= #{endTime}</if>
</where>
GROUP BY goods_id
ORDER BY totalPrice DESC LIMIT 5
) UNION ALL
(
SELECT
ANY_VALUE ( hho.create_time ) AS date,
ANY_VALUE (
CONCAT( hh.NAME, hhrc.level2_name )) AS ticketName,
SUM( hhord.room_charge ) AS totalPrice
FROM
zdy_hotel_homestay_order_room_detail hhord
JOIN zdy_hotel_homestay_order hho ON hho.id = hhord.order_id
JOIN zdy_hotel_homestay_room hhor ON hhord.room_id = hhor.id
JOIN zdy_hotel_homestay_room_classify hhrc ON hhord.room_classify_id = hhrc.id
JOIN zdy_hotel_homestay hh ON hh.id = hhrc.hotel_homestay_id
<where>
<if test="startTime != null">and hho.create_time >= #{startTime}</if>
<if test="endTime != null">and hho.create_time &lt;= #{endTime}</if>
</where>
GROUP BY hhord.room_classify_id
ORDER BY totalPrice DESC LIMIT 5
)) a
ORDER BY a.totalPrice DESC LIMIT 5;
</select>
</mapper>