<?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="shop.alien.mapper.StoreMembershipCardOrderMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="shop.alien.entity.store.StoreMembershipCardOrder">
        <id column="id" property="id"/>
        <result column="card_id" property="cardId"/>
        <result column="order_code" property="orderCode"/>
        <result column="order_status" property="orderStatus"/>
        <result column="order_type" property="orderType"/>
        <result column="purchase_pattern" property="purchasePattern"/>
        <result column="opening_time" property="openingTime"/>
        <result column="expiration_time" property="expirationTime"/>
        <result column="payment_amount" property="paymentAmount"/>
        <result column="delete_flag" property="deleteFlag"/>
        <result column="created_time" property="createdTime"/>
        <result column="updated_time" property="updatedTime"/>
        <result column="created_user_id" property="createdUserId"/>
        <result column="updated_user_id" property="updatedUserId"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id
        , card_id, order_code, order_status, order_type, purchase_pattern, opening_time, expiration_time, payment_amount, delete_flag, created_time, updated_time, created_user_id, updated_user_id
    </sql>
    <select id="selectCardLIstPage" resultType="shop.alien.entity.store.vo.StoreMembershipCardOrderVo">
        SELECT
        `order`.order_code,
        card.store_id,
        card.store_name,
        order.order_status,
        CASE
        `order`.order_status
        WHEN "0" THEN
        "未过期"
        WHEN "1" THEN
        "已过期"
        END AS `order_status_str`,
        card.membership_type,
        CASE
        card.membership_type
        WHEN "0" THEN
        "黄金vip"
        WHEN "1" THEN
        "白金vip"
        END AS `membership_type_str`,
        `order`.purchase_pattern,
        CASE
        `order`.purchase_pattern
        WHEN "0" THEN
        "包月"
        WHEN "1" THEN
        "包季"
        WHEN "2" THEN
        "半年卡"
        WHEN "3" THEN
        "年卡"
        END AS `purchase_pattern_str`,
        `order`.opening_time,
        `order`.expiration_time ,
        `order`.payment_amount
        FROM
        store_membership_card_order `order`
        LEFT JOIN store_membership_card card ON card.id = `order`.card_id
        WHERE
        card.store_id IS NOT NULL
        <if test="storeId != null and storeId != ''">
            AND card.store_id = #{storeId}
        </if>
        <if test="storeName != null and storeName != ''">
            AND card.store_name LIKE CONCAT('%', #{storeName}, '%')
        </if>
        <if test="orderCode != null and orderCode != ''">
            AND `order`.order_code LIKE CONCAT('%', #{orderCode}, '%')
        </if>
        <if test="orderStatus != null and orderStatus != ''">
            AND `order`.order_status = #{orderStatus}
        </if>
        <if test="buyType != null and buyType != ''">
            AND `order`.purchase_pattern = #{buyType}
        </if>
        <if test="endTime != null and endTime != ''">
            AND `order`.expiration_time LIKE CONCAT('%', #{endTime}, '%')
        </if>
        <if test="vipType != null and vipType != ''">
            AND `order`.order_type = #{vipType}
        </if>

    </select>

</mapper>
