<?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.yonge.cooleshow.biz.dal.mapper.TenantAlbumPurchaseMapper">

	 
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ AS id
        , t.tenant_id_ AS tenantId
        , t.tenant_album_id_ AS tenantAlbumId
        , t.purchase_time_ AS purchaseTime
        , t.order_no_ AS orderNo
        , t.purchase_quantity_ AS purchaseQuantity
        , t.purchase_cycle_ AS purchaseCycle
        , t.active_quantity_ AS activeQuantity
        , t.purchase_price_ AS purchasePrice
        , t.purchase_status_ AS purchaseStatus
        , t.purchase_type_ AS purchaseType
        , t.active_status_ AS activeStatus
        , t.update_time_ AS updateTime
        , t.create_time_ AS createTime
        </sql>

    <select id="selectPage"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantAlbumPurchaseWrapper$TenantAlbumPurchase">
        SELECT
        <include refid="baseColumns"/>,ta.name_ as tenantAlbumName,ta.cover_img_ as tenantAlbumImg
        FROM tenant_album_purchase t
        LEFT JOIN tenant_album ta on t.tenant_album_id_ = ta.id_
        left join user_order t2 on t2.order_no_ = t.order_no_
        <where>
            <if test="param.keyword != null and param.keyword.trim() != ''">
                AND (ta.name_ like concat('%',#{param.keyword},'%')
                or t.purchase_quantity_ like concat('%',#{param.keyword},'%')
                )
            </if>
            <if test="param.tenantId != null">
                AND t.tenant_id_ = #{param.tenantId}
            </if>
            <if test="param.purchaseStatus != null and param.purchaseStatus.trim() != ''">
                <if test="param.purchaseStatus == 'WAIT_PAY'">
                    AND t2.status_ in ( 'WAIT_PAY','PAYING')
                </if>
                <if test="param.purchaseStatus == 'PAID'">
                    AND t2.status_ in ( 'PAID')
                </if>
                <if test="param.purchaseStatus == 'CLOSE'">
                    AND t2.status_ in ( 'CLOSE','FAIL')
                </if>
            </if>
            <if test="param.activeStatus != null">
                AND t.active_status_ = #{param.activeStatus}
            </if>
            <if test="param.purchaseStartTime != null">
                AND t.create_time_ >= #{param.purchaseStartTime}
            </if>
            <if test="param.purchaseEndTime != null">
                AND #{param.purchaseEndTime} >= t.create_time_
            </if>
        </where>
        order by t.create_time_ desc
    </select>
    
</mapper>