<?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.kmall.api.dao.mk.ApiMkStoreCampMinusMapper">

	<resultMap type="com.kmall.api.entity.mk.MkStoreCampMinusVo" id="mkStoreCampMinusMap">
		<result property="campMinusId" column="camp_minus_id"/>
		<result property="campName" column="camp_name"/>
		<result property="thirdMerchSn" column="third_merch_sn"/>
		<result property="storeId" column="store_id"/>
		<result property="storeTopicId" column="store_topic_id"/>
		<result property="campBegTime" column="camp_beg_time"/>
		<result property="campEndTime" column="camp_end_time"/>
		<result property="campMinusType" column="camp_minus_type"/>
		<result property="minusMode" column="minus_mode"/>
		<result property="applyType" column="apply_type"/>
		<result property="advImgUrl" column="adv_img_url"/>
		<result property="advDesc" column="adv_desc"/>
		<result property="isValid" column="is_valid"/>
		<result property="isPast" column="is_past"/>
		<result property="isStoreShow" column="is_store_show"/>
		<result property="note" column="note"/>
		<result property="createrSn" column="creater_sn"/>
		<result property="createTime" column="create_time"/>
		<result property="moderSn" column="moder_sn"/>
		<result property="modTime" column="mod_time"/>
		<result property="tstm" column="tstm"/>
		<result property="goodsBizType" column="goods_biz_type"/>
	</resultMap>

	<select id="queryObject" resultType="com.kmall.api.entity.mk.MkStoreCampMinusVo">
		select
		`camp_minus_id`,
		`camp_name`,
		`third_merch_sn`,
		`store_id`,
		`store_topic_id`,
		`camp_beg_time`,
		`camp_end_time`,
		`camp_minus_type`,
		`minus_mode`,
		`apply_type`,
		`adv_img_url`,
		`adv_desc`,
		`is_valid`,
		`is_past`,
		`is_store_show`,
		`note`,
		`creater_sn`,
		`create_time`,
		`moder_sn`,
		`mod_time`,
		`tstm`,
		`goods_biz_type`
		from mk_store_camp_minus
		where camp_minus_id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.api.entity.mk.MkStoreCampMinusVo">
		select
		`camp_minus_id`,
		`camp_name`,
		`third_merch_sn`,
		`store_id`,
		`store_topic_id`,
		`camp_beg_time`,
		`camp_end_time`,
		`camp_minus_type`,
		`minus_mode`,
		`apply_type`,
		`adv_img_url`,
		`adv_desc`,
		`is_valid`,
		`is_past`,
		`is_store_show`,
		`note`,
		`creater_sn`,
		`create_time`,
		`moder_sn`,
		`mod_time`,
		`tstm`,
		`goods_biz_type`
		from mk_store_camp_minus
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
		<choose>
			<when test="sidx != null and sidx.trim() != ''">
				order by ${sidx} ${order}
			</when>
			<otherwise>
				order by camp_minus_id desc
			</otherwise>
		</choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>

	<select id="queryTotal" resultType="int">
		select count(*) from mk_store_camp_minus
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
	</select>

	<select id="getCampMinusByStoreIdList" resultType="com.kmall.api.entity.mk.MkStoreCampMinusVo">
		select
		m.`camp_minus_id`,
		m.`camp_name`,
		m.`third_merch_sn`,
		m.`store_id`,
		m.`store_topic_id`,
		m.`camp_beg_time`,
		m.`camp_end_time`,
		m.`camp_minus_type`,
		m.`minus_mode`,
		m.`apply_type`,
		m.`adv_img_url`,
		m.`adv_desc`,
		m.`is_valid`,
		m.`is_past`,
		m.`is_store_show`,
		m.`note`,
		m.`creater_sn`,
		m.`create_time`,
		m.`moder_sn`,
		m.`mod_time`,
		m.`tstm`,
		m.`goods_biz_type`
		from mk_store_camp_minus m
		WHERE 1=1
		<if test="storeId != '' and storeId != null">
			AND m.store_id = #{storeId}
		</if>
		<if test="goodsBizType != '' and goodsBizType != null">
			AND m.goods_biz_type = #{goodsBizType}
		</if>
		<if test="isPast != '' and isPast != null">
			AND m.is_past = #{isPast}
		</if>
	</select>

	<select id="queryOrderCountByUserIdAndCampId" resultType="int">
		SELECT
			count(*)
		FROM
			mall_order o
			INNER JOIN mk_store_camp_minus m ON o.activity_id = m.store_topic_id
			INNER JOIN mall_user_camp_minus uc ON uc.store_topic_id = m.store_topic_id AND o.user_id = uc.user_id
		WHERE
			o.user_id = #{userId}
			AND m.camp_minus_id = #{campMinusId}
			AND uc.is_used = 1
	</select>

</mapper>