<?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.gxwebsoft.shop.mapper.UserCouponMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM shop_user_coupon a
        <where>
            <if test="param.userCouponId != null">
                AND a.user_coupon_id = #{param.userCouponId}
            </if>
            <if test="param.couponId != null">
                AND a.coupon_id = #{param.couponId}
            </if>
            <if test="param.name != null">
                AND a.name LIKE CONCAT('%', #{param.name}, '%')
            </if>
            <if test="param.couponType != null">
                AND a.coupon_type = #{param.couponType}
            </if>
            <if test="param.reducePrice != null">
                AND a.reduce_price = #{param.reducePrice}
            </if>
            <if test="param.discount != null">
                AND a.discount = #{param.discount}
            </if>
            <if test="param.minPrice != null">
                AND a.min_price = #{param.minPrice}
            </if>
            <if test="param.expireType != null">
                AND a.expire_type = #{param.expireType}
            </if>
            <if test="param.expireDay != null">
                AND a.expire_day = #{param.expireDay}
            </if>
            <if test="param.startTime != null">
                AND a.start_time = #{param.startTime}
            </if>
            <if test="param.endTime != null">
                AND a.end_time = #{param.endTime}
            </if>
            <if test="param.applyRange != null">
                AND a.apply_range = #{param.applyRange}
            </if>
            <if test="param.applyRangeConfig != null">
                AND a.apply_range_config LIKE CONCAT('%', #{param.applyRangeConfig}, '%')
            </if>
            <if test="param.isExpire != null">
                AND a.is_expire = #{param.isExpire}
            </if>
            <if test="param.isUse != null">
                AND a.is_use = #{param.isUse}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.shop.entity.UserCoupon">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.shop.entity.UserCoupon">
        <include refid="selectSql"></include>
    </select>

</mapper>
