<?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.qs.mp.user.mapper.UserTicketOrderItemMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qs.mp.user.domain.UserTicketOrderItem">
        <id column="item_id" property="itemId" />
        <result column="order_id" property="orderId" />
        <result column="user_id" property="userId" />
        <result column="box_id" property="boxId" />
        <result column="ticket_id" property="ticketId" />
        <result column="created_time" property="createdTime" />
        <result column="updated_time" property="updatedTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        item_id, order_id, user_id, box_id, ticket_id, created_time, updated_time
    </sql>

    <select id="listTicketOrderItemVO" resultMap="BaseResultMap">
        select t1.*
        from mp_user_ticket_order_item t1
        left join mp_user_ticket_order t2 on t1.order_id = t2.order_id
            ${ew.customSqlSegment}
    </select>

    <select id="listMyTicketVO" resultType="com.qs.mp.admin.domain.vo.TicketListVO">
        select t1.item_id,
                t1.title,
                t1.pic_url,
                t3.ticket_id,
                t3.box_id,
                t3.serial_no,
                t3.face_price,
                t3.plain_lucky_num,
                t3.`status`,
                t6.title prizeInfo,
                t6.`value`,
                t6.prize_type
        from mp_user_ticket_order_item t1
         left join mp_user_ticket_order t2 on t1.order_id = t2.order_id
         left join mp_ticket t3 on t1.ticket_id = t3.ticket_id
         left join mp_ticket_box t4 on t3.box_id = t4.box_id
         left join mp_user_hit_prize t5 on t5.ticket_id = t1.ticket_id
         left join mp_ticket_awards_prize t6 on t6.prize_id = t5.prize_id
            ${ew.customSqlSegment}
    </select>

    <select id="countMyTicket" resultType="Integer">
        select count(*)
        from mp_user_ticket_order_item t1
         left join mp_user_ticket_order t2 on t1.order_id = t2.order_id
         left join mp_ticket t3 on t1.ticket_id = t3.ticket_id
            ${ew.customSqlSegment}
    </select>

    <select id="listTicketDetailByOrderId" resultType="com.qs.mp.admin.domain.vo.UserTicketOrderTicketDetailVO">
        select t2.serial_no,
                t2.status,
                t4.name prizeGrade,
                t5.title prizeTitle
        from mp_user_ticket_order_item t1
            left join mp_ticket t2 on t1.ticket_id = t2.ticket_id
            left join mp_user_hit_prize t3 on t1.item_id = t3.order_item_id
            left join mp_ticket_awards t4 on t3.awards_id = t4.awards_id
            left join mp_ticket_awards_prize t5 on t3.prize_id = t5.prize_id
        ${ew.customSqlSegment}
    </select>

    <select id="listUserTicketOrderItem" resultType="com.qs.mp.admin.domain.vo.UserTicketOrderItemVO">
        select t3.serial_no,
               t1.title ticketTitle,
               t2.resource ticketType,
               t2.sale_price ,
               t2.sale_comm_rate,
               t3.status ticketStatus,
               t5.name awardsName,
               t6.title prizeName,
               t6.value,
               t6.prize_type,
               t1.order_id,
               t2.status orderStatus,
               t2.created_time,
               t8.user_name,
               t8.phonenumber userPhone,
               t7.name channelName
        from mp_user_ticket_order_item t1
                 left join mp_user_ticket_order t2 on t1.order_id = t2.order_id
                 left join mp_ticket t3 on t1.ticket_id = t3.ticket_id
                 left join mp_user_hit_prize t4 on t1.item_id = t4.order_item_id
                 left join mp_ticket_awards t5 on t4.awards_id = t5.awards_id
                 left join mp_ticket_awards_prize t6 on t4.prize_id = t6.prize_id
                 left join mp_channel t7 on t2.channel_id = t7.channel_id
                 left join sys_user t8 on t1.user_id = t8.user_id
        ${ew.customSqlSegment}
    </select>

    <select id="countUserTicketOrderItem" resultType="int">
        select count(*)
        from mp_user_ticket_order_item t1
            left join mp_user_ticket_order t2 on t1.order_id = t2.order_id
            left join mp_ticket t3 on t1.ticket_id = t3.ticket_id
            left join mp_user_hit_prize t4 on t1.item_id = t4.order_item_id
            left join mp_ticket_awards t5 on t4.awards_id = t5.awards_id
            left join mp_ticket_awards_prize t6 on t4.prize_id = t6.prize_id
            left join mp_channel t7 on t2.channel_id = t7.channel_id
            left join sys_user t8 on t1.user_id = t8.user_id
        ${ew.customSqlSegment}
    </select>
</mapper>
