<?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.stylefeng.guns.modular.system.dao.MerchantActivityMapper">
|
|
<!-- 通用查询映射结果 -->
|
<resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.MerchantActivity">
|
<id column="id" property="id"/>
|
<result column="merchantId" property="merchantId"/>
|
<result column="activityType" property="activityType"/>
|
<result column="name" property="name"/>
|
<result column="orderType" property="orderType"/>
|
<result column="type" property="type"/>
|
<result column="orderAmountFull" property="orderAmountFull"/>
|
<result column="orderNumber" property="orderNumber"/>
|
<result column="effectiveDays" property="effectiveDays"/>
|
<result column="status" property="status"/>
|
<result column="state" property="state"/>
|
<result column="createTime" property="createTime"/>
|
</resultMap>
|
|
|
<select id="getMerchantCoupon" resultType="com.stylefeng.guns.modular.system.warpper.MerchantCouponListWarpper">
|
select
|
a.id as activityId,
|
c.id,
|
c.`name`,
|
c.type,
|
c.content,
|
c.fullAmount,
|
c.discount,
|
d.totalNum as totalNum,
|
ifnull(e.receive, 0) as receive,
|
ifnull(f.writeOff, 0) as writeOff
|
from t_merchant_activity a
|
left join t_merchant_activity_slave b on (a.id = b.merchantActivityId)
|
left join t_merchant_coupon c on (b.merchantCouponId = c.id)
|
left join (select ifnull(sum(totalNumber), 0) as totalNum, merchantCouponId, merchantActivityId from t_merchant_activity_slave group by merchantCouponId, merchantActivityId) d on (b.merchantActivityId = d.merchantActivityId and b.merchantCouponId = d.merchantCouponId)
|
left join (select count(1) as receive, merchantCouponId, merchantActivityId from t_user_merchant_coupon where state != 3 group by merchantCouponId, merchantActivityId) e on (b.merchantActivityId = e.merchantActivityId and b.merchantCouponId = e.merchantCouponId)
|
left join (select count(1) as writeOff, merchantCouponId, merchantActivityId from t_user_merchant_coupon where state != 3 and `status` = 2 group by merchantCouponId, merchantActivityId) f on (b.merchantActivityId = f.merchantActivityId and b.merchantCouponId = f.merchantCouponId)
|
where 1 = 1
|
<if test="type != null">
|
and a.`status` = #{type} and a.state = 1 and a.merchantId = #{merchantId}
|
</if>
|
group by a.id, c.id order by c.createTime desc
|
<if test="null != pageNum and null != size">
|
limit #{pageNum}, #{size}
|
</if>
|
</select>
|
</mapper>
|