<?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.fzm.mall.server.admin.marketing.mapper.CouponMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.fzm.mall.server.admin.marketing.model.Coupon">
        <id column="id" property="id" />
        <result column="coupon_id" property="couponId" />
        <result column="type" property="type" />
        <result column="name" property="name" />
        <result column="remark" property="remark" />
        <result column="scope" property="scope" />
        <result column="condition_val" property="conditionVal" />
        <result column="coupon_val" property="couponVal" />
        <result column="circulation" property="circulation" />
        <result column="amt" property="amt" />
        <result column="start_time" property="startTime" />
        <result column="end_time" property="endTime" />
        <result column="status" property="status" />
        <result column="range_type" property="rangeType" />
        <result column="exchange_price" property="exchangePrice" />
        <result column="merchant_id" property="merchantId" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <select id="listByOid" resultMap="BaseResultMap">
        select c.*
        from marketing_coupon c
        left join order_goods_coupon gc on gc.coupon_id = c.coupon_id
        where gc.oid = #{oid} and gc.uid = #{uid} and gc.goods_id in
        <foreach item="item" collection="list" separator="," open="(" close=")" index="">
            #{item}
        </foreach>
        order by create_time desc
    </select>

    <select id="page" resultType="com.fzm.mall.server.admin.marketing.entity.dto.CouponDTO">
        select *
        from marketing_coupon
        <where>
            merchant_id = #{merchantId}
            <if test="couponId != null and couponId != ''">
                and coupon_id like CONCAT('%', #{couponId},'%')
            </if>
            <if test="name != null and name != ''">
                and `name` like CONCAT('%', #{name},'%')
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
            <if test="status == null">
                and status != '0'
            </if>
        </where>
        order by create_time desc
    </select>
</mapper>
