<?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.czg.service.market.mapper.MkDiscountActivityMapper">

    <select id="selectOneByShopId" resultType="com.czg.market.entity.MkDiscountActivity">
        SELECT *
        FROM mk_discount_activity
        WHERE shop_id = #{shopId}
          AND is_del = 0
          AND status = 2
          AND CURDATE() BETWEEN valid_start_time AND valid_end_time
          AND (use_time_type = 'all' OR
               (use_time_type = 'custom' AND TIME(NOW()) BETWEEN use_start_time AND use_end_time))
          AND use_days LIKE CONCAT('%', #{useDay}, '%')
        ORDER BY sort DESC,
                 update_time DESC,
                 create_time DESC
        LIMIT 1;
    </select>
</mapper>
