优惠券软删除

This commit is contained in:
2025-08-01 16:56:54 +08:00
parent 9e92be78ff
commit 72d3530942
7 changed files with 85 additions and 18 deletions

View File

@@ -18,20 +18,75 @@
FROM coupon c
LEFT JOIN scenic s ON c.scenic_id = s.id
<where>
AND c.deleted = 0
<if test="scenicId != null">AND scenic_id = #{scenicId}</if>
<if test="name != null and name != ''">AND c.name = concat('%',#{name},'%')</if>
<if test="type != null">AND type = #{type}</if>
<if test="discountType != null">AND discount_type = #{discountType}</if>
<if test="status != null">AND c.status = #{status}</if>
<if test="createAtStart != null">AND create_time >= #{createAtStart}</if>
<if test="createAtEnd != null">AND create_time &lt;= #{createAtEnd}
<if test="createAtStart != null">AND create_at >= #{createAtStart}</if>
<if test="createAtEnd != null">AND create_at &lt;= #{createAtEnd}
</if>
</where>
ORDER BY create_time DESC
ORDER BY create_at DESC
</select>
<select id="getById" resultType="com.ycwl.basic.model.pc.coupon.entity.CouponEntity">
SELECT id, scenic_id, name, broadcast, config_ids, discount_price, type, discount_type, status, create_at
SELECT id, scenic_id, name, description, countdown, broadcast, config_ids, discount_price, type, discount_type, status, create_at, deleted, deleted_at
FROM coupon
WHERE id = #{id} AND deleted = 0
</select>
<insert id="insert" parameterType="com.ycwl.basic.model.pc.coupon.entity.CouponEntity" useGeneratedKeys="true" keyProperty="id">
INSERT INTO coupon (
scenic_id, name, description, countdown, broadcast,
config_ids, discount_price, type, discount_type,
status, create_at, deleted, deleted_at
) VALUES (
#{scenicId}, #{name}, #{description}, #{countdown}, #{broadcast},
#{configIds}, #{discountPrice}, #{type}, #{discountType},
#{status}, #{createAt}, #{deleted}, #{deletedAt}
)
</insert>
<update id="updateById" parameterType="com.ycwl.basic.model.pc.coupon.entity.CouponEntity">
UPDATE coupon SET
scenic_id = #{scenicId},
name = #{name},
description = #{description},
countdown = #{countdown},
broadcast = #{broadcast},
config_ids = #{configIds},
discount_price = #{discountPrice},
type = #{type},
discount_type = #{discountType},
status = #{status},
create_at = #{createAt},
deleted = #{deleted},
deleted_at = #{deletedAt}
WHERE id = #{id}
</update>
<delete id="deleteById">
UPDATE coupon SET deleted = 1, deleted_at = NOW() WHERE id = #{id}
</delete>
<select id="selectById" resultType="com.ycwl.basic.model.pc.coupon.entity.CouponEntity">
SELECT id, scenic_id, name, description, countdown, broadcast, config_ids, discount_price, type, discount_type, status, create_at, deleted, deleted_at
FROM coupon
WHERE id = #{id}
</select>
<select id="selectList" resultType="com.ycwl.basic.model.pc.coupon.entity.CouponEntity">
SELECT id, scenic_id, name, description, countdown, broadcast, config_ids, discount_price, type, discount_type, status, create_at, deleted, deleted_at
FROM coupon
WHERE deleted = 0
ORDER BY create_at DESC
</select>
<select id="selectByScenicIdAndTypeAndStatus" resultType="com.ycwl.basic.model.pc.coupon.entity.CouponEntity">
SELECT id, scenic_id, name, description, countdown, broadcast, config_ids, discount_price, type, discount_type, status, create_at, deleted, deleted_at
FROM coupon
WHERE scenic_id = #{scenicId} AND type = #{type} AND status = #{status} AND deleted = 0
LIMIT 1
</select>
</mapper>

View File

@@ -3,12 +3,12 @@
<mapper namespace="com.ycwl.basic.mapper.CouponRecordMapper">
<select id="queryByUserWithGoodsId"
resultType="com.ycwl.basic.model.pc.couponRecord.entity.CouponRecordEntity">
select * from coupon_record where member_id = #{memberId} and coupon_id in (select id from coupon where scenic_id = #{scenicId} and FIND_IN_SET(#{goodsId},config_ids))
select * from coupon_record where deleted = 0 and member_id = #{memberId} and coupon_id in (select id from coupon where deleted = 0 and scenic_id = #{scenicId} and FIND_IN_SET(#{goodsId},config_ids))
</select>
<select id="queryByMemberIdAndFaceId"
resultType="com.ycwl.basic.model.pc.couponRecord.entity.CouponRecordEntity">
select * from coupon_record where member_id = #{memberId} and face_id = #{faceId}
select * from coupon_record where deleted = 0 and member_id = #{memberId} and face_id = #{faceId}
</select>
<select id="queryByMemberIdAndFaceIdAndType"
@@ -16,7 +16,7 @@
select cr.*
from coupon_record cr
inner join coupon c on cr.coupon_id = c.id
where cr.member_id = #{memberId} and cr.face_id = #{faceId} and c.type = #{type}
where cr.deleted = 0 and c.deleted = 0 and cr.member_id = #{memberId} and cr.face_id = #{faceId} and c.type = #{type}
limit 1
</select>
@@ -51,6 +51,7 @@
inner join coupon c on cr.coupon_id = c.id
inner join scenic s on c.scenic_id = s.id
<where>
and cr.deleted = 0 and c.deleted = 0
<if test="scenicId != null">
and c.scenic_id = #{scenicId}
</if>