You've already forked FrameTour-BE
优惠券软删除
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.ycwl.basic.mapper;
|
||||
import com.ycwl.basic.model.pc.coupon.entity.CouponEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ycwl.basic.model.pc.coupon.req.CouponQueryReq;
|
||||
import com.ycwl.basic.model.pc.coupon.resp.CouponRespVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -8,10 +7,22 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CouponMapper extends BaseMapper<CouponEntity> {
|
||||
public interface CouponMapper {
|
||||
List<CouponRespVO> selectByQuery(CouponQueryReq query);
|
||||
|
||||
int updateStatus(Integer id);
|
||||
|
||||
CouponEntity getById(Integer couponId);
|
||||
|
||||
int insert(CouponEntity coupon);
|
||||
|
||||
int updateById(CouponEntity coupon);
|
||||
|
||||
int deleteById(Integer id);
|
||||
|
||||
List<CouponEntity> selectList();
|
||||
|
||||
CouponEntity selectById(Integer id);
|
||||
|
||||
CouponEntity selectByScenicIdAndTypeAndStatus(Long scenicId, Integer type, Integer status);
|
||||
}
|
@@ -46,6 +46,9 @@ public class CouponEntity {
|
||||
*/
|
||||
private Integer status;
|
||||
private Date createAt;
|
||||
|
||||
private Integer deleted;
|
||||
private Date deletedAt;
|
||||
|
||||
public BigDecimal calculateDiscountPrice(BigDecimal originalPrice) {
|
||||
if (originalPrice == null) {
|
||||
|
@@ -19,4 +19,7 @@ public class CouponRecordEntity {
|
||||
private Date createTime;
|
||||
private Date usedTime;
|
||||
private Long usedOrderId;
|
||||
|
||||
private Integer deleted;
|
||||
private Date deletedAt;
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.ycwl.basic.service.mobile.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.ycwl.basic.mapper.CouponMapper;
|
||||
import com.ycwl.basic.mapper.CouponRecordMapper;
|
||||
import com.ycwl.basic.model.pc.coupon.entity.CouponEntity;
|
||||
@@ -50,11 +49,7 @@ public class AppCouponRecordServiceImpl implements AppCouponRecordService {
|
||||
}
|
||||
// 查找可用的优惠券
|
||||
Long scenicId = face.getScenicId();
|
||||
QueryWrapper<CouponEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("scenic_id", scenicId)
|
||||
.eq("type", type)
|
||||
.eq("status", 1); // 开启状态
|
||||
CouponEntity coupon = couponMapper.selectOne(queryWrapper);
|
||||
CouponEntity coupon = couponMapper.selectByScenicIdAndTypeAndStatus(scenicId, type, 1);
|
||||
|
||||
if (coupon == null) {
|
||||
throw new RuntimeException("未找到可领取的优惠券");
|
||||
|
@@ -1,5 +1,4 @@
|
||||
package com.ycwl.basic.service.pc.impl;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ycwl.basic.mapper.CouponMapper;
|
||||
import com.ycwl.basic.model.pc.coupon.entity.CouponEntity;
|
||||
import com.ycwl.basic.model.pc.coupon.req.CouponQueryReq;
|
||||
@@ -11,7 +10,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponEntity> implements CouponService {
|
||||
public class CouponServiceImpl implements CouponService {
|
||||
|
||||
@Autowired
|
||||
private CouponMapper couponMapper;
|
||||
@@ -28,7 +27,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponEntity> i
|
||||
|
||||
@Override
|
||||
public Boolean delete(Integer id) {
|
||||
return removeById(id);
|
||||
return couponMapper.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -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 <= #{createAtEnd}
|
||||
<if test="createAtStart != null">AND create_at >= #{createAtStart}</if>
|
||||
<if test="createAtEnd != null">AND create_at <= #{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>
|
@@ -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>
|
||||
|
Reference in New Issue
Block a user