<?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.UserPrizeStorageMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qs.mp.user.domain.UserPrizeStorage">
        <id column="storage_id" property="storageId" />
        <result column="user_id" property="userId" />
        <result column="goods_id" property="goodsId" />
        <result column="sku_id" property="skuId" />
        <result column="properties" property="properties" />
        <result column="title" property="title" />
        <result column="pic_url" property="picUrl" />
        <result column="goods_num" property="goodsNum" />
        <result column="in_type" property="inType" />
        <result column="ref_id" property="refId" />
        <result column="status" property="status" />
        <result column="created_time" property="createdTime" />
        <result column="updated_time" property="updatedTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        storage_id, user_id, goods_id, sku_id, properties, title, pic_url, goods_num, in_type, ref_id, status, created_time, updated_time
    </sql>

    <select id="listByQueryWrapper" resultType="com.qs.mp.user.domain.vo.UserPrizeStorageVO">
        SELECT
        t1.*,
        t2.multi_sku isMoreSku ,
        t2.type goodsType,
        t2.discount_rate,
        t5.type
        FROM
        mp_user_prize_storage t1
        LEFT JOIN mp_goods t2 ON t1.goods_id = t2.goods_id
        LEFT JOIN mp_user_hit_prize t3 on t1.ref_id = t3.id
        LEFT JOIN mp_ticket t4 on t3.ticket_id = t4.ticket_id
        LEFT JOIN mp_ticket_box t5 on t4.box_id = t5.box_id
        ${ew.customSqlSegment}
    </select>
    <select id="listGoodsPrizeCost" resultType="com.qs.mp.user.domain.vo.UserPrizeStorageVO">
        SELECT
            t2.cost,
            t1.*
        FROM
            mp_user_prize_storage t1
            LEFT JOIN mp_goods t2 ON t1.goods_id = t2.goods_id
            ${ew.customSqlSegment}
    </select>
    <select id="listAllPrizeStorageGoodsCost" resultType="com.qs.mp.user.domain.vo.UserPrizeStorageVO">
        SELECT
            t2.cost,
            t1.*
        FROM
            mp_user_prize_storage t1
                LEFT JOIN mp_goods t2 ON t1.goods_id = t2.goods_id
            ${ew.customSqlSegment}
    </select>
    <select id="listTicketGoodsCost" resultType="com.qs.mp.user.domain.vo.UserPrizeStorageVO">
        SELECT
            t3.cost,
            t1.*
        FROM
            mp_user_prize_storage t1
                left join mp_user_ticket_order_item t2 on t2.item_id = t1.ref_id
                LEFT JOIN mp_goods t3 ON t1.goods_id = t3.goods_id
            ${ew.customSqlSegment}
    </select>
</mapper>
