<?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.UserMerchantCouponMapper">
|
|
<!-- 通用查询映射结果 -->
|
<resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.UserMerchantCoupon">
|
<id column="id" property="id"/>
|
<result column="code" property="code"/>
|
<result column="userType" property="userType"/>
|
<result column="userId" property="userId"/>
|
<result column="merchantActivityId" property="merchantActivityId"/>
|
<result column="merchantCouponId" property="merchantCouponId"/>
|
<result column="endTime" property="endTime"/>
|
<result column="status" property="status"/>
|
<result column="writeOffTime" property="writeOffTime"/>
|
<result column="writeOffUserType" property="writeOffUserType"/>
|
<result column="writeOffUserId" property="writeOffUserId"/>
|
<result column="state" property="state"/>
|
<result column="createTime" property="createTime"/>
|
</resultMap>
|
|
|
<select id="getUserMerchantCoupon" resultType="com.stylefeng.guns.modular.system.warpper.UserMerchantCouponWapper">
|
select
|
u.id,
|
u.`code`,
|
a.`name`,
|
a.type,
|
a.content,
|
a.fullAmount,
|
a.discount,
|
b.totalNum,
|
c.receive,
|
d.writeOff,
|
DATE_FORMAT(u.endTime, '%Y-%m-%d %H:%i:%s') as endTime,
|
u.`status`,
|
if(u.userType = 1, ifnull(e.name, e.nickName), f.name) as userName,
|
if(u.userType = 1, e.phone, f.phone) as phone,
|
g.name as merchantName
|
from t_user_merchant_coupon u
|
left join t_merchant_coupon a on (u.merchantCouponId = a.id)
|
left join (select sum(totalNumber) as totalNum, merchantCouponId from t_merchant_activity_slave group by merchantCouponId) b on (a.id = b.merchantCouponId)
|
left join (select count(1) as receive, merchantCouponId from t_user_merchant_coupon where state != 3 group by merchantCouponId) c on (a.id = c.merchantCouponId)
|
left join (select count(1) as writeOff, merchantCouponId from t_user_merchant_coupon where state != 3 and `status` = 2 group by merchantCouponId) d on (a.id = d.merchantCouponId)
|
left join t_user e on (u.userType = 1 and u.userId = e.id)
|
left join t_driver f on (u.userType = 2 and u.userId = f.id)
|
left join t_merchant g on (a.merchantId = g.id)
|
where u.state = 1 and u.`code` = #{code}
|
</select>
|
|
|
|
<select id="getWriteOffHistory" resultType="map">
|
select
|
a.id,
|
if(a.userType = 1, ifnull(b.name, b.nickName), c.`name`) as `name`,
|
if(a.userType = 1, b.phone, c.phone) as phone,
|
DATE_FORMAT(a.writeOffTime, '%Y/%m/%d/%H:%i') as writeOffTime
|
from t_user_merchant_coupon a
|
left join t_user b on (a.userType = 1 and a.userId = b.id)
|
left join t_driver c on (a.userType = 2 and a.userId = c.id)
|
where a.`status` = 2 and a.merchantActivityId = #{activityId} and a.merchantCouponId = #{id} order by a.writeOffTime desc limit #{pageNum}, #{size}
|
</select>
|
|
|
<select id="getMyMerchantCoupon" resultType="com.stylefeng.guns.modular.system.warpper.MerchantCouponWarpper">
|
select
|
a.id,
|
b.`name`,
|
b.type,
|
b.content,
|
b.fullAmount,
|
b.discount,
|
DATE_FORMAT(a.endTime, '%Y-%m-%d %H:%i:%s') as endTime,
|
b.merchantId,
|
c.`name` as merchantName,
|
c.headImg,
|
c.address,
|
c.contactName,
|
c.contactPhone,
|
a.`code`
|
from t_user_merchant_coupon a
|
left join t_merchant_coupon b on (a.merchantCouponId = b.id)
|
left join t_merchant c on (b.merchantId = c.id)
|
where a.state = 1 and a.userType = 1 and a.userId = #{uid}
|
<if test="null != type and 1 == type">
|
and a.`status` = 1
|
</if>
|
<if test="null != type and 2 == type">
|
and a.`status` != 1
|
</if>
|
order by a.createTime desc
|
</select>
|
|
|
<update id="updateExpired">
|
update t_user_merchant_coupon set `status` = 3 where `status` = 1 and state = 1 and userType = 1 and now() > endTime
|
</update>
|
</mapper>
|