<?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.mzl.flower.mapper.coupon.CouponRecordMapperCustom">
|
|
<!-- 通用查询映射结果 -->
|
<resultMap id="BaseResultMap" type="com.mzl.flower.entity.coupon.CouponRecordDO">
|
<id column="id" property="id" />
|
<result column="deleted" property="deleted" />
|
<result column="create_by" property="createBy" />
|
<result column="update_by" property="updateBy" />
|
<result column="create_time" property="createTime" />
|
<result column="update_time" property="updateTime" />
|
<result column="coupon_id" property="couponId" />
|
<result column="user_id" property="userId" />
|
<result column="customer_id" property="customerId" />
|
<result column="status" property="status" />
|
<result column="effective_start" property="effectiveStart" />
|
<result column="effective_end" property="effectiveEnd" />
|
<result column="order_id" property="orderId" />
|
<result column="used_time" property="usedTime" />
|
<result column="coupon_discount_value" property="couponDiscountValue" />
|
<result column="min_order_amount" property="minOrderAmount" />
|
<result column="category" property="category" />
|
<result column="coupon_code" property="couponCode" />
|
<result column="coupon_name" property="couponName" />
|
<result column="get_type" property="getType" />
|
<result column="coupon_discount_type" property="couponDiscountType" />
|
<result column="get_user_type" property="getUserType" />
|
|
<result column="point" property="point" />
|
|
</resultMap>
|
<update id="checkCouponExpired">
|
update t_coupon_record set `status`='expired' where `status`='unused' and effective_end < NOW()
|
<if test="param.userId != null and param.userId != ''">
|
AND user_id = #{param.userId}
|
</if>
|
<if test="param.customerId != null and param.customerId != ''">
|
AND customer_id = #{param.customerId}
|
</if>
|
</update>
|
|
<select id="statisCouponTemplateCount" resultType="java.lang.Integer">
|
select IFNULL(count(1),0) as cnt from t_coupon_record where deleted=false and category=#{param.category}
|
</select>
|
<select id="statisCouponTemplateCurMonCount" resultType="java.lang.Integer">
|
select IFNULL(count(1),0) as cnt from t_coupon_record where deleted=false and category=#{param.category} AND DATE_FORMAT(create_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
|
</select>
|
<select id="statisCouponPointCurMonPointAmonut" resultType="java.lang.Integer">
|
select IFNULL(sum(point),0) as cnt from t_coupon_record where deleted=false and category='point' AND DATE_FORMAT(create_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
|
</select>
|
|
<select id="getPage" resultType="com.mzl.flower.dto.response.coupon.CouponRecordVO">
|
<include refid="QuerySql"/>
|
</select>
|
<select id="getList" resultType="com.mzl.flower.dto.response.coupon.CouponRecordVO">
|
<include refid="QuerySql"/>
|
</select>
|
<select id="getMineCouponRecordList" resultType="com.mzl.flower.dto.response.coupon.CouponRecordVO">
|
select *
|
from t_coupon_record t
|
where t.deleted=false
|
<if test="param.userId != null and param.userId != ''">
|
AND t.user_id = #{param.userId}
|
</if>
|
<if test="param.customerId != null and param.customerId != ''">
|
AND t.customer_id = #{param.customerId}
|
</if>
|
<if test="param.status != null and param.status != ''">
|
AND t.status = #{param.status}
|
</if>
|
</select>
|
|
<sql id="QuerySql">
|
select *
|
from (
|
select r.*,
|
i.name as customerName,
|
u.tel,
|
o.order_no
|
from t_coupon_record r
|
left join t_customer_info i
|
on r.customer_id=i.id
|
left join t_user u
|
on i.user_id=u.id
|
left join t_order o
|
on r.order_id=o.id
|
) t
|
where t.deleted=0
|
<if test="param.name != null and param.name != ''">
|
AND t.coupon_name like concat('%', #{param.name},'%')
|
</if>
|
<if test="param.couponDiscountType != null and param.couponDiscountType != ''">
|
AND t.coupon_discount_type = #{param.couponDiscountType}
|
</if>
|
<if test="param.getType != null and param.getType != ''">
|
AND t.get_type = #{param.getType}
|
</if>
|
<if test="param.getUserType != null and param.getUserType != ''">
|
AND t.get_user_type = #{param.getUserType}
|
</if>
|
<if test="param.id != null and param.id != ''">
|
AND t.id = #{param.id}
|
</if>
|
<if test="param.orderNo != null and param.orderNo != ''">
|
AND t.order_no like concat('%', #{param.orderNo},'%')
|
</if>
|
<if test="param.tel != null and param.tel != ''">
|
AND t.tel like concat('%', #{param.tel},'%')
|
</if>
|
<if test="param.status != null and param.status != ''">
|
AND t.status = #{param.status}
|
</if>
|
<if test="param.keyword != null and param.keyword != ''">
|
AND (t.customerName like concat('%', #{param.keyword},'%')
|
or t.user_id like concat('%', #{param.keyword},'%') )
|
</if>
|
<if test="param.couponId != null and param.couponId != ''">
|
and t.coupon_id = #{param.couponId}
|
</if>
|
<if test="param.category != null and param.category != ''">
|
and t.category = #{param.category}
|
</if>
|
|
|
|
order by t.create_time desc
|
</sql>
|
|
|
|
</mapper>
|