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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qs.mp.user.domain.UserExchangeOrder">
        <id column="order_id" property="orderId" />
        <result column="user_id" property="userId" />
        <result column="goods_id" property="goodsId" />
        <result column="sku_id" property="skuId" />
        <result column="order_coin" property="orderCoin" />
        <result column="created_time" property="createdTime" />
        <result column="updated_time" property="updatedTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        order_id, user_id, goods_id, sku_id, order_coin, created_time, updated_time
    </sql>

    <select id="listByWrapper" resultType="com.qs.mp.user.domain.vo.TicketHitPrizeBarrageVO">
        select  t2.avatar,
                t2.nick_name,
                t1.created_time,
               t3.title prizeInfo
        from mp_user_exchange_order t1
         left join sys_user t2 on t1.user_id = t2.user_id
         left join mp_goods t3 on t1.goods_id = t3.goods_id
         ${ew.customSqlSegment}
    </select>

    <select id="listUserExchangeOrderByWrapper" resultType="com.qs.mp.admin.domain.vo.UserExchangeOrderVO">
        select t1.created_time,
               t1.order_coin payPrice,
               t2.pic_url,
               t2.title goodsName,
               t2.exchange_price,
               t3.name sku,
               t4.nick_name,
               t4.phonenumber phone,
                t1.num
        from mp_user_exchange_order t1
                 left join mp_goods t2 on t1.goods_id = t2.goods_id
                 left join mp_goods_sku t3 on t1.sku_id = t3.sku_id
                 left join sys_user t4 on t1.user_id = t4.user_id
        ${ew.customSqlSegment}
    </select>

    <select id="countUserExchangeOrderByWrapper" resultType="int">
        select count(*)
        from mp_user_exchange_order t1
        left join mp_goods t2 on t1.goods_id = t2.goods_id
        left join mp_goods_sku t3 on t1.sku_id = t3.sku_id
        left join sys_user t4 on t1.user_id = t4.user_id
        ${ew.customSqlSegment}
    </select>
</mapper>