You've already forked FrameTour-BE
feat(repository): 增加优惠券验证功能
- 在 SourceRepository 中添加了 IVoucherService 和 FaceRepository 的依赖 - 在 getUserIsBuy 方法中增加了对优惠券的验证逻辑 - 如果用户拥有全场免费的优惠券,则直接返回 true - 优化了代码结构,增加了日志记录
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
package com.ycwl.basic.repository;
|
package com.ycwl.basic.repository;
|
||||||
|
|
||||||
import com.ycwl.basic.mapper.SourceMapper;
|
import com.ycwl.basic.mapper.SourceMapper;
|
||||||
|
import com.ycwl.basic.model.pc.face.entity.FaceEntity;
|
||||||
import com.ycwl.basic.model.pc.source.entity.MemberSourceEntity;
|
import com.ycwl.basic.model.pc.source.entity.MemberSourceEntity;
|
||||||
import com.ycwl.basic.model.pc.source.entity.SourceEntity;
|
import com.ycwl.basic.model.pc.source.entity.SourceEntity;
|
||||||
|
import com.ycwl.basic.pricing.dto.VoucherInfo;
|
||||||
|
import com.ycwl.basic.pricing.enums.VoucherDiscountType;
|
||||||
|
import com.ycwl.basic.pricing.service.IVoucherService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -10,12 +15,17 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class SourceRepository {
|
public class SourceRepository {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SourceMapper sourceMapper;
|
private SourceMapper sourceMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<String, String> redisTemplate;
|
private RedisTemplate<String, String> redisTemplate;
|
||||||
|
@Autowired
|
||||||
|
private IVoucherService iVoucherService;
|
||||||
|
@Autowired
|
||||||
|
private FaceRepository faceRepository;
|
||||||
|
|
||||||
public void addSource(SourceEntity source) {
|
public void addSource(SourceEntity source) {
|
||||||
sourceMapper.add(source);
|
sourceMapper.add(source);
|
||||||
@@ -42,6 +52,19 @@ public class SourceRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean getUserIsBuy(Long userId, int type, Long faceId) {
|
public boolean getUserIsBuy(Long userId, int type, Long faceId) {
|
||||||
|
FaceEntity face = faceRepository.getFace(faceId);
|
||||||
|
if (face == null) {
|
||||||
|
log.info("faceId:{} is not exist", faceId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 确认人员faceId是否有券码
|
||||||
|
List<VoucherInfo> voucherDetails = iVoucherService.getVoucherDetails(faceId, face.getScenicId());
|
||||||
|
if (voucherDetails != null && !voucherDetails.isEmpty()) {
|
||||||
|
VoucherInfo voucherInfo = voucherDetails.getFirst();
|
||||||
|
if (voucherInfo.getDiscountType().equals(VoucherDiscountType.FREE_ALL)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 1:
|
case 1:
|
||||||
List<SourceEntity> videoSourceList = sourceMapper.listVideoByFaceRelation(userId, faceId);
|
List<SourceEntity> videoSourceList = sourceMapper.listVideoByFaceRelation(userId, faceId);
|
||||||
|
Reference in New Issue
Block a user