<?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.sqx.modules.coupon.dao.TbCouponDao">

    <select id="selectCouponByShopId" resultType="com.sqx.modules.coupon.entity.TbCoupon">
        select * from tb_coupon where 1 = 1 and shop_id in
        <foreach collection="userShops" item="item" open="(" close=")" separator=",">
            #{item.shopId}
        </foreach>
    </select>

    <select id="selectCouponPage" resultType="com.sqx.modules.coupon.entity.TbCoupon">
        select t.*,g.shop_name as shopName from tb_coupon t
        left join goods_shop g on g.shop_id=t.shop_id
        where 1=1
        <if test="shopId!=null and shopId!=-1">
            and t.shop_id=#{shopId}
        </if>
        <if test="shopId!=null and shopId==-1">
            and t.shop_id!=0
        </if>
        <if test="shopName!=null and shopName!=''">
            and g.shop_name=#{shopName}
        </if>
        order by coupon_id desc
    </select>

    <select id="selectCouponList" resultType="com.sqx.modules.coupon.entity.TbCoupon">
        select t.*,g.shop_name as shopName from tb_coupon t
        left join goods_shop g on g.shop_id=t.shop_id
        where 1=1
        <if test="shopId!=null and shopId!=-1">
            and t.shop_id=#{shopId}
        </if>
        <if test="shopId!=null and shopId==-1">
            and t.shop_id!=0
        </if>
        <if test="shopName!=null and shopName!=''">
            and g.shop_name=#{shopName}
        </if>
        order by coupon_id desc
    </select>


    <select id="selectCouponListByShopIdList" resultType="com.sqx.modules.coupon.entity.TbCoupon">
        select t.*,g.shop_name as shopName from tb_coupon t
        left join goods_shop g on g.shop_id=t.shop_id
        where 1=1
        <if test="shopIdList.size()>0">
            and t.shop_id in
            <foreach collection="shopIdList" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="shopName!=null and shopName!=''">
            and g.shop_name=#{shopName}
        </if>
        order by coupon_id desc
    </select>



</mapper>