<?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.sinata.rest.modular.member.dao.MyCouponMapper">
|
<select id="getCouponList" resultType="com.sinata.rest.modular.member.model.MyCoupon">
|
select * from (
|
/*没有被删除的 还有库存的 没有过使用期的 普通优惠券 */
|
SELECT * FROM `my_coupon`
|
WHERE is_delete = 0 AND type = 1 AND stock > 0 AND NOW() <= end_time
|
AND ( `condition` = '0' OR FIND_IN_SET( #{role}, `condition` ))
|
AND id NOT IN ( SELECT coupon_id FROM my_user_coupon where user_id = #{userId})
|
UNION
|
/*没有被删除的 还有库存的 没有过使用期的 有价优惠券 */
|
SELECT mc.* FROM `my_coupon` mc
|
LEFT JOIN sys_area_city sc on sc.id = mc.city_code
|
WHERE mc.is_delete = 0 AND mc.type = 2 AND mc.stock > 0 AND NOW() <= end_time
|
AND ( mc.`condition` = '0' OR FIND_IN_SET(#{role}, `condition`))
|
AND ( mc.city_code = 0 or sc.province_code = #{cityCode}
|
or sc.city_code = #{cityCode} or sc.county_code = #{cityCode})
|
AND mc.quota > ( SELECT count( id ) FROM my_user_coupon WHERE coupon_id = id AND user_id = #{userId} )
|
)tab
|
</select>
|
|
<select id="getCouponGoodsList" resultType="com.sinata.rest.modular.mall.model.MallGoods">
|
SELECT
|
mg.*
|
FROM
|
my_coupon_product cp
|
LEFT JOIN mall_goods mg on mg.id = cp.product_id
|
where cp.coupon_id = #{couponId}
|
</select>
|
|
<update id="subCouponStock">
|
update my_coupon set stock = stock - 1 where id = #{couponId} and stock > 0
|
</update>
|
|
<update id="addCouponStock">
|
update my_coupon set stock = stock + 1 where id = #{couponId}
|
</update>
|
|
<select id="getCouponByUserCouponId" resultType="com.sinata.rest.modular.member.model.MyCoupon">
|
SELECT * FROM
|
my_coupon o
|
LEFT JOIN my_user_coupon uc ON uc.coupon_id = o.id
|
WHERE
|
uc.id = #{userCouponId}
|
</select>
|
|
<select id="orderCoupon" resultType="com.sinata.rest.modular.member.model.MyCoupon">
|
SELECT *
|
FROM my_coupon c
|
LEFT JOIN my_user_coupon uc ON c.id = uc.coupon_id
|
LEFT JOIN my_coupon_product up ON up.coupon_id = c.id
|
WHERE c.is_delete = 0
|
AND coupon_type <![CDATA[ <> ]]> 3
|
AND uc.user_id = #{userId}
|
AND uc.is_use = 0
|
<if test="goodsType != null">
|
AND (c.server_type = #{goodsType} OR c.server_type = 4)
|
</if>
|
<if test="goodsId != null">
|
and up.product_id = #{goodsId}
|
<!-- 这里传入的商品id 优惠券保存的也是商品id 不是门店商品id*/
|
in (
|
SELECT sk1.goods_id
|
FROM mall_goods_sku sk1
|
LEFT JOIN mall_goods_sku sk2 on sk2.sku_id = sk1.id
|
where sk2.goods_id = #{goodsId} )-->
|
</if>
|
<if test="price != null">
|
and (c.use_amount = 0 or c.use_amount <= #{price})
|
</if>
|
<if test="dateTime != null and dateTime != ''">
|
AND uc.begin_time <![CDATA[ <= ]]> #{dateTime}
|
AND uc.end_time <![CDATA[ >= ]]> #{dateTime}
|
</if>
|
group by uc.id
|
</select>
|
|
|
<update id="updateUseCoupon">
|
UPDATE my_user_coupon
|
SET is_use = #{isUse}
|
WHERE
|
coupon_id = #{couponId}
|
AND user_id = #{userId}
|
</update>
|
|
</mapper>
|