<?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.UserCouponRecordMapper">
|
|
<!-- 通用查询映射结果 -->
|
<resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.UserCouponRecord">
|
<id column="id" property="id"/>
|
<result column="money" property="money"/>
|
<result column="fullMoney" property="fullMoney"/>
|
<result column="expirationTime" property="expirationTime"/>
|
<result column="insertTime" property="insertTime"/>
|
<result column="companyId" property="companyId"/>
|
<result column="state" property="state"/>
|
<result column="endTime" property="endTime"/>
|
<result column="couponUseType" property="couponUseType"/>
|
<result column="couponType" property="couponType"/>
|
<result column="userId" property="userId"/>
|
<result column="couponId" property="couponId"/>
|
<result column="couponActivityId" property="couponActivityId"/>
|
<result column="activityType" property="activityType"/>
|
<result column="paymentRecordId" property="paymentRecordId"/>
|
</resultMap>
|
|
|
|
<select id="queryAvailable" resultType="int">
|
select
|
count(a.id)
|
from t_user_coupon_record a
|
left join t_company b on (a.companyId = b.id)
|
where a.expirationTime >= now()
|
<if test="null != uid">
|
and a.userId = #{uid}
|
</if>
|
<if test="null != companyId">
|
and a.companyId = #{companyId}
|
</if>
|
<if test="null != state">
|
and a.state = #{state}
|
</if>
|
<if test="null != couponUseType">
|
and a.couponUseType = #{couponUseType}
|
</if>
|
<if test="null != money">
|
and if(a.couponType = 1, a.money <= #{money}, a.fullMoney <= #{money})
|
</if>
|
</select>
|
|
<select id="queryCoupon" resultType="map">
|
select
|
a.id as id,
|
a.money as money,
|
a.couponUseType as userType,
|
DATE_FORMAT(a.expirationTime, '%Y-%m-%d') as time,
|
a.couponType as `type`,
|
a.fullMoney as fullMoney,
|
a.state as state,
|
b.`name` as `name`,
|
a.activityType as activityType,
|
a.couponId as couponId
|
from t_user_coupon_record a
|
left join t_company b on (a.companyId = b.id)
|
where a.expirationTime >= now()
|
<if test="null != uid">
|
and a.userId = #{uid}
|
</if>
|
<if test="null != companyId">
|
and a.companyId = #{companyId}
|
</if>
|
<if test="null != state">
|
and a.state = #{state}
|
</if>
|
<if test="null != couponUseType">
|
and a.couponUseType = #{couponUseType}
|
</if>
|
<if test="null != money">
|
and if(a.couponType = 1, a.money <= #{money}, a.fullMoney <= #{money})
|
</if>
|
order by a.insertTime desc
|
<if test="null != pageNum and null != size">
|
limit #{pageNum}, #{size}
|
</if>
|
</select>
|
|
|
|
|
|
|
<select id="queryMyCoupons" resultType="map">
|
select
|
a.id as id,
|
a.money as money,
|
a.couponUseType as userType,
|
DATE_FORMAT(a.expirationTime, '%Y-%m-%d') as time,
|
a.couponType as `type`,
|
a.fullMoney as fullMoney,
|
a.state as state,
|
b.`name` as `name`
|
from t_user_coupon_record a
|
left join t_company b on (a.companyId = b.id)
|
where 1 = 1
|
<if test="null != uid">
|
and a.userId = #{uid}
|
</if>
|
<if test="null != state">
|
<if test="state == 1">
|
and a.state = 1
|
</if>
|
<if test="state == 2">
|
and a.state in (2,3)
|
</if>
|
</if>
|
order by a.insertTime desc
|
<if test="null != pageNum and null != size">
|
limit #{pageNum}, #{size}
|
</if>
|
</select>
|
|
|
|
<update id="updateTimeOut">
|
update t_user_coupon_record set state = 3,endTime = now() where now() > expirationTime and state = 1
|
</update>
|
</mapper>
|