2026-03-04 16:06:55 +08:00
|
|
|
|
<?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.jsowell.pile.mapper.CouponTemplateMapper">
|
|
|
|
|
|
|
|
|
|
|
|
<resultMap id="BaseResultMap" type="com.jsowell.pile.domain.CouponTemplate">
|
|
|
|
|
|
<id column="id" property="id"/>
|
|
|
|
|
|
<result column="name" property="name"/>
|
|
|
|
|
|
<result column="type" property="type"/>
|
|
|
|
|
|
<result column="creator_type" property="creatorType"/>
|
|
|
|
|
|
<result column="creator_merchant_id" property="creatorMerchantId"/>
|
|
|
|
|
|
<result column="scope_type" property="scopeType"/>
|
|
|
|
|
|
<result column="points_cost" property="pointsCost"/>
|
|
|
|
|
|
<result column="discount_rate" property="discountRate"/>
|
|
|
|
|
|
<result column="min_charge_amount" property="minChargeAmount"/>
|
|
|
|
|
|
<result column="max_discount_amount" property="maxDiscountAmount"/>
|
|
|
|
|
|
<result column="exchange_start_time" property="exchangeStartTime"/>
|
|
|
|
|
|
<result column="exchange_end_time" property="exchangeEndTime"/>
|
|
|
|
|
|
<result column="stock_total" property="stockTotal"/>
|
|
|
|
|
|
<result column="stock_remain" property="stockRemain"/>
|
|
|
|
|
|
<result column="validity_type" property="validityType"/>
|
|
|
|
|
|
<result column="valid_start_time" property="validStartTime"/>
|
|
|
|
|
|
<result column="valid_end_time" property="validEndTime"/>
|
|
|
|
|
|
<result column="valid_days" property="validDays"/>
|
|
|
|
|
|
<result column="daily_limit" property="dailyLimit"/>
|
|
|
|
|
|
<result column="monthly_limit" property="monthlyLimit"/>
|
|
|
|
|
|
<result column="total_limit" property="totalLimit"/>
|
|
|
|
|
|
<result column="status" property="status"/>
|
|
|
|
|
|
<result column="description" property="description"/>
|
2026-03-11 10:59:30 +08:00
|
|
|
|
<result column="image" property="image"/>
|
2026-03-04 16:06:55 +08:00
|
|
|
|
<result column="update_by" property="updateBy"/>
|
|
|
|
|
|
<result column="create_by" property="createBy"/>
|
|
|
|
|
|
<result column="create_time" property="createTime"/>
|
|
|
|
|
|
<result column="update_time" property="updateTime"/>
|
|
|
|
|
|
<result column="del_flag" property="delFlag"/>
|
|
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
|
|
|
|
<sql id="Base_Column_List">
|
|
|
|
|
|
id, name, type, creator_type, creator_merchant_id, scope_type,
|
|
|
|
|
|
points_cost, discount_rate, min_charge_amount, max_discount_amount,
|
|
|
|
|
|
exchange_start_time, exchange_end_time,
|
|
|
|
|
|
stock_total, stock_remain, validity_type,
|
|
|
|
|
|
valid_start_time, valid_end_time, valid_days,
|
|
|
|
|
|
daily_limit, monthly_limit, total_limit,
|
2026-03-11 10:59:30 +08:00
|
|
|
|
status, description, image, update_by, create_by, create_time, update_time, del_flag
|
2026-03-04 16:06:55 +08:00
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selectById" resultMap="BaseResultMap">
|
|
|
|
|
|
SELECT <include refid="Base_Column_List"/>
|
|
|
|
|
|
FROM coupon_template
|
|
|
|
|
|
WHERE id = #{id} AND del_flag = '0'
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<select id="selectList" resultMap="BaseResultMap">
|
|
|
|
|
|
SELECT <include refid="Base_Column_List"/>
|
|
|
|
|
|
FROM coupon_template
|
|
|
|
|
|
WHERE del_flag = '0'
|
|
|
|
|
|
<if test="creatorMerchantId != null">
|
|
|
|
|
|
AND creator_merchant_id = #{creatorMerchantId}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="status != null">
|
|
|
|
|
|
AND status = #{status}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="type != null">
|
|
|
|
|
|
AND type = #{type}
|
|
|
|
|
|
</if>
|
|
|
|
|
|
<if test="name != null and name != ''">
|
|
|
|
|
|
AND name LIKE CONCAT('%', #{name}, '%')
|
|
|
|
|
|
</if>
|
|
|
|
|
|
ORDER BY create_time DESC
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
|
|
|
|
|
INSERT INTO coupon_template (
|
|
|
|
|
|
name, type, creator_type, creator_merchant_id, scope_type,
|
|
|
|
|
|
points_cost, discount_rate, min_charge_amount, max_discount_amount,
|
|
|
|
|
|
exchange_start_time, exchange_end_time,
|
|
|
|
|
|
stock_total, stock_remain, validity_type,
|
|
|
|
|
|
valid_start_time, valid_end_time, valid_days,
|
|
|
|
|
|
daily_limit, monthly_limit, total_limit,
|
2026-03-11 10:59:30 +08:00
|
|
|
|
status, description, image, update_by, create_by, create_time, update_time, del_flag
|
2026-03-04 16:06:55 +08:00
|
|
|
|
) VALUES (
|
|
|
|
|
|
#{name}, #{type}, #{creatorType}, #{creatorMerchantId}, #{scopeType},
|
|
|
|
|
|
#{pointsCost}, #{discountRate}, #{minChargeAmount}, #{maxDiscountAmount},
|
|
|
|
|
|
#{exchangeStartTime}, #{exchangeEndTime},
|
|
|
|
|
|
#{stockTotal}, #{stockRemain}, #{validityType},
|
|
|
|
|
|
#{validStartTime}, #{validEndTime}, #{validDays},
|
|
|
|
|
|
#{dailyLimit}, #{monthlyLimit}, #{totalLimit},
|
2026-03-11 10:59:30 +08:00
|
|
|
|
#{status}, #{description}, #{image}, #{updateBy}, #{createBy}, NOW(), NOW(), '0'
|
2026-03-04 16:06:55 +08:00
|
|
|
|
)
|
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
|
|
<update id="updateById">
|
|
|
|
|
|
UPDATE coupon_template
|
|
|
|
|
|
<set>
|
|
|
|
|
|
<if test="name != null">name = #{name},</if>
|
|
|
|
|
|
<if test="status != null">status = #{status},</if>
|
|
|
|
|
|
<if test="stockTotal != null">stock_total = #{stockTotal},</if>
|
|
|
|
|
|
<if test="dailyLimit != null">daily_limit = #{dailyLimit},</if>
|
|
|
|
|
|
<if test="monthlyLimit != null">monthly_limit = #{monthlyLimit},</if>
|
|
|
|
|
|
<if test="totalLimit != null">total_limit = #{totalLimit},</if>
|
|
|
|
|
|
<if test="description != null">description = #{description},</if>
|
2026-03-11 10:59:30 +08:00
|
|
|
|
<if test="image != null">image = #{image},</if>
|
2026-03-04 16:06:55 +08:00
|
|
|
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
|
|
|
|
|
update_time = NOW()
|
|
|
|
|
|
</set>
|
|
|
|
|
|
WHERE id = #{id} AND del_flag = '0'
|
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 原子扣减库存:stock_remain=-1(不限) 时跳过扣减直接返回1 -->
|
|
|
|
|
|
<update id="deductStock">
|
|
|
|
|
|
UPDATE coupon_template
|
|
|
|
|
|
SET stock_remain = stock_remain - 1,
|
|
|
|
|
|
update_time = NOW()
|
|
|
|
|
|
WHERE id = #{id}
|
|
|
|
|
|
AND del_flag = '0'
|
|
|
|
|
|
AND (stock_remain = -1 OR stock_remain >= 1)
|
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 检查是否已有兑换记录(用于冻结字段校验) -->
|
|
|
|
|
|
<select id="countExchangeRecord" resultType="int">
|
|
|
|
|
|
SELECT COUNT(1) FROM member_coupon
|
|
|
|
|
|
WHERE template_id = #{templateId} AND del_flag = '0'
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
</mapper>
|