You've already forked FrameTour-BE
优惠券
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.ycwl.basic.service.mobile;
|
||||
|
||||
import com.ycwl.basic.model.pc.couponRecord.entity.CouponRecordEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CouponRecordService {
|
||||
|
||||
List<CouponRecordEntity> queryByMemberIdAndFaceId(Long memberId, Long faceId);
|
||||
|
||||
CouponRecordEntity claimCoupon(Long memberId, Long faceId, Integer type);
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
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;
|
||||
import com.ycwl.basic.model.pc.couponRecord.entity.CouponRecordEntity;
|
||||
import com.ycwl.basic.model.pc.face.entity.FaceEntity;
|
||||
import com.ycwl.basic.repository.FaceRepository;
|
||||
import com.ycwl.basic.service.mobile.CouponRecordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CouponRecordServiceImpl implements CouponRecordService {
|
||||
|
||||
@Autowired
|
||||
private CouponRecordMapper couponRecordMapper;
|
||||
|
||||
@Autowired
|
||||
private CouponMapper couponMapper;
|
||||
@Autowired
|
||||
private FaceRepository faceRepository;
|
||||
|
||||
@Override
|
||||
public List<CouponRecordEntity> queryByMemberIdAndFaceId(Long memberId, Long faceId) {
|
||||
return couponRecordMapper.queryByMemberIdAndFaceId(memberId, faceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CouponRecordEntity claimCoupon(Long memberId, Long faceId, Integer type) {
|
||||
// 检查是否已经领取过该类型的优惠券
|
||||
CouponRecordEntity existingRecord = couponRecordMapper.queryByMemberIdAndFaceIdAndType(memberId, faceId, type);
|
||||
if (existingRecord != null) {
|
||||
throw new RuntimeException("该用户已经领取过此类型的优惠券");
|
||||
}
|
||||
FaceEntity face = faceRepository.getFace(faceId);
|
||||
if (face == null) {
|
||||
throw new RuntimeException("人脸数据不存在");
|
||||
}
|
||||
// 查找可用的优惠券
|
||||
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);
|
||||
|
||||
if (coupon == null) {
|
||||
throw new RuntimeException("未找到可领取的优惠券");
|
||||
}
|
||||
|
||||
// 创建优惠券记录
|
||||
CouponRecordEntity record = new CouponRecordEntity();
|
||||
record.setCouponId(coupon.getId());
|
||||
record.setMemberId(memberId);
|
||||
record.setFaceId(faceId);
|
||||
record.setStatus(0); // 有效状态
|
||||
record.setCreateTime(new Date());
|
||||
|
||||
couponRecordMapper.insert(record);
|
||||
return record;
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
package com.ycwl.basic.service.pc;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.model.pc.couponRecord.req.CouponRecordPageQueryReq;
|
||||
import com.ycwl.basic.model.pc.couponRecord.resp.CouponRecordPageResp;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
|
||||
public interface CouponRecordService {
|
||||
ApiResponse<PageInfo<CouponRecordPageResp>> pageQuery(CouponRecordPageQueryReq query);
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package com.ycwl.basic.service.pc.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.mapper.CouponRecordMapper;
|
||||
import com.ycwl.basic.model.pc.couponRecord.entity.CouponRecordEntity;
|
||||
import com.ycwl.basic.model.pc.couponRecord.req.CouponRecordPageQueryReq;
|
||||
import com.ycwl.basic.model.pc.couponRecord.resp.CouponRecordPageResp;
|
||||
import com.ycwl.basic.service.pc.CouponRecordService;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CouponRecordServiceImpl extends ServiceImpl<CouponRecordMapper, CouponRecordEntity> implements CouponRecordService {
|
||||
|
||||
@Autowired
|
||||
private CouponRecordMapper couponRecordMapper;
|
||||
|
||||
@Override
|
||||
public ApiResponse<PageInfo<CouponRecordPageResp>> pageQuery(CouponRecordPageQueryReq query) {
|
||||
PageHelper.startPage(query.getPageNum(), query.getPageSize());
|
||||
List<CouponRecordPageResp> list = couponRecordMapper.selectByPageQuery(query);
|
||||
PageInfo<CouponRecordPageResp> pageInfo = new PageInfo<>(list);
|
||||
return ApiResponse.success(pageInfo);
|
||||
}
|
||||
}
|
@@ -524,6 +524,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
order.setCouponId(null);
|
||||
if (couponRecord != null) {
|
||||
if (couponRecord.isUsable()) {
|
||||
log.info("优惠券可用,优惠券记录ID:{},优惠券ID:{}", couponRecord.getId(), couponRecord.getCouponId());
|
||||
order.setCouponId(couponRecord.getCouponId());
|
||||
order.setCouponRecordId(couponRecord.getId());
|
||||
order.setCouponPrice(couponRecord.getCoupon().calculateDiscountPrice(order.getPrice()));
|
||||
|
Reference in New Issue
Block a user