|
@@ -28,6 +28,7 @@ import com.qs.mp.user.domain.UserCouponChannel;
|
|
|
import com.qs.mp.user.domain.UserHitPrize;
|
|
|
import com.qs.mp.user.domain.UserPrizeStorage;
|
|
|
import com.qs.mp.user.domain.UserTicketOrderItem;
|
|
|
+import com.qs.mp.user.domain.vo.TicketHitPrizeBarrageVO;
|
|
|
import com.qs.mp.user.mapper.UserHitPrizeMapper;
|
|
|
import com.qs.mp.user.service.IUserCoinService;
|
|
|
import com.qs.mp.user.service.IUserCouponChannelService;
|
|
@@ -36,9 +37,13 @@ import com.qs.mp.user.service.IUserHitPrizeService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qs.mp.user.service.IUserPrizeStorageService;
|
|
|
import com.qs.mp.user.service.IUserTicketOrderItemService;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+
|
|
|
import org.codehaus.janino.IClass.IField;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -59,102 +64,112 @@ import org.springframework.util.CollectionUtils;
|
|
|
@Service
|
|
|
public class UserHitPrizeServiceImpl extends ServiceImpl<UserHitPrizeMapper, UserHitPrize> implements IUserHitPrizeService {
|
|
|
|
|
|
- protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
+ protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
- @Autowired
|
|
|
- private IUserTicketOrderItemService userTicketOrderItemService;
|
|
|
+ @Autowired
|
|
|
+ private IUserTicketOrderItemService userTicketOrderItemService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ITicketAwardsPrizeService ticketAwardsPrizeService;
|
|
|
+ @Autowired
|
|
|
+ private ITicketAwardsPrizeService ticketAwardsPrizeService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IUserPrizeStorageService userPrizeStorageService;
|
|
|
+ @Autowired
|
|
|
+ private IUserPrizeStorageService userPrizeStorageService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IUserCoinService userCoinService;
|
|
|
+ @Autowired
|
|
|
+ private IUserCoinService userCoinService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ICouponService couponService;
|
|
|
+ @Autowired
|
|
|
+ private ICouponService couponService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ITicketAwardsService ticketAwardsService;
|
|
|
+ @Autowired
|
|
|
+ private ITicketAwardsService ticketAwardsService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ITicketService ticketService;
|
|
|
+ @Autowired
|
|
|
+ private ITicketService ticketService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private BizIdGenerator bizIdGenerator;
|
|
|
+ @Autowired
|
|
|
+ private BizIdGenerator bizIdGenerator;
|
|
|
|
|
|
- @Override
|
|
|
- public List<TicketAwardsPrize> listPrize(Ticket ticket, Long userId) {
|
|
|
- UserHitPrize userHitPrize = getOne(new LambdaQueryWrapper<UserHitPrize>().eq(UserHitPrize::getTicketId, ticket.getTicketId()));
|
|
|
- UserTicketOrderItem orderItem = userTicketOrderItemService.queryFinishedOrderItem(userId, ticket.getTicketId());
|
|
|
- if (null == orderItem) {
|
|
|
- LogUtil.error(logger, "查询盲票的奖品信息,盲票订单不存在。ticketId:{0}, userId:{1}",
|
|
|
- new Object[]{ticket.getTicketId(), userId});
|
|
|
- throw new ServiceException("盲票订单不存在");
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public List<TicketAwardsPrize> listPrize(Ticket ticket, Long userId) {
|
|
|
+ UserHitPrize userHitPrize = getOne(new LambdaQueryWrapper<UserHitPrize>().eq(UserHitPrize::getTicketId, ticket.getTicketId()));
|
|
|
+ UserTicketOrderItem orderItem = userTicketOrderItemService.queryFinishedOrderItem(userId, ticket.getTicketId());
|
|
|
+ if (null == orderItem) {
|
|
|
+ LogUtil.error(logger, "查询盲票的奖品信息,盲票订单不存在。ticketId:{0}, userId:{1}",
|
|
|
+ new Object[]{ticket.getTicketId(), userId});
|
|
|
+ throw new ServiceException("盲票订单不存在");
|
|
|
+ }
|
|
|
|
|
|
- if (null == userHitPrize) {
|
|
|
- List<TicketDrawNumDTO> drawNumDTOList = JSONObject.parseArray(ticket.getDrawNum(), TicketDrawNumDTO.class);
|
|
|
- for (TicketDrawNumDTO ticketDrawNumDTO : drawNumDTOList) {
|
|
|
- if (ticketDrawNumDTO.getNum() == ticket.getPlainLuckyNum()) {
|
|
|
- userHitPrize = new UserHitPrize();
|
|
|
- userHitPrize.setId(bizIdGenerator.newIdWithUidSharding(String.valueOf(userId)));
|
|
|
- userHitPrize.setUserId(userId);
|
|
|
- userHitPrize.setOrderId(orderItem.getOrderId());
|
|
|
- userHitPrize.setOrderItemId(orderItem.getItemId());
|
|
|
- userHitPrize.setTicketId(ticket.getTicketId());
|
|
|
- TicketAwards ticketAwards = ticketAwardsService.getOne(new LambdaQueryWrapper<TicketAwards>()
|
|
|
- .eq(TicketAwards::getBoxId, ticket.getBoxId()).eq(TicketAwards::getName, ticketDrawNumDTO.getName()));
|
|
|
- userHitPrize.setAwardsId(ticketAwards.getAwardsId());
|
|
|
- // 奖品ID等用户选择后填入
|
|
|
+ if (null == userHitPrize) {
|
|
|
+ List<TicketDrawNumDTO> drawNumDTOList = JSONObject.parseArray(ticket.getDrawNum(), TicketDrawNumDTO.class);
|
|
|
+ for (TicketDrawNumDTO ticketDrawNumDTO : drawNumDTOList) {
|
|
|
+ if (ticketDrawNumDTO.getNum() == ticket.getPlainLuckyNum()) {
|
|
|
+ userHitPrize = new UserHitPrize();
|
|
|
+ userHitPrize.setId(bizIdGenerator.newIdWithUidSharding(String.valueOf(userId)));
|
|
|
+ userHitPrize.setUserId(userId);
|
|
|
+ userHitPrize.setOrderId(orderItem.getOrderId());
|
|
|
+ userHitPrize.setOrderItemId(orderItem.getItemId());
|
|
|
+ userHitPrize.setTicketId(ticket.getTicketId());
|
|
|
+ TicketAwards ticketAwards = ticketAwardsService.getOne(new LambdaQueryWrapper<TicketAwards>()
|
|
|
+ .eq(TicketAwards::getBoxId, ticket.getBoxId()).eq(TicketAwards::getName, ticketDrawNumDTO.getName()));
|
|
|
+ userHitPrize.setAwardsId(ticketAwards.getAwardsId());
|
|
|
+ // 奖品ID等用户选择后填入
|
|
|
// userHitPrize.setPrizeId();
|
|
|
- save(userHitPrize);
|
|
|
+ save(userHitPrize);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- List<TicketAwardsPrize> awardsPrizes = ticketAwardsPrizeService.list(new LambdaQueryWrapper<TicketAwardsPrize>()
|
|
|
- .eq(TicketAwardsPrize::getAwardsId, userHitPrize.getAwardsId()).orderByDesc(TicketAwardsPrize::getRemainQty));
|
|
|
- return awardsPrizes;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public void cashPrize(Ticket ticket, Long userId, String awardsId, String prizeId) {
|
|
|
- // 更新奖品已兑奖数量
|
|
|
- TicketAwardsPrize ticketAwardsPrize = ticketAwardsPrizeService.getById(prizeId);
|
|
|
- if (ticketAwardsPrize.getRemainQty() <= 0) {
|
|
|
- throw new ServiceException("奖品已兑完,请重新选择");
|
|
|
- }
|
|
|
- // 乐观锁
|
|
|
- ticketAwardsPrizeService.update(new LambdaUpdateWrapper<TicketAwardsPrize>().set(TicketAwardsPrize::getCashedQty, ticketAwardsPrize.getCashedQty() + 1)
|
|
|
- .set(TicketAwardsPrize::getRemainQty, ticketAwardsPrize.getRemainQty() - 1)
|
|
|
- .eq(TicketAwardsPrize::getPrizeId, prizeId).eq(TicketAwardsPrize::getCashedQty, ticketAwardsPrize.getCashedQty()));
|
|
|
-
|
|
|
- // 保存奖品到中奖记录中
|
|
|
- UserHitPrize userHitPrize = getOne(new LambdaQueryWrapper<UserHitPrize>().eq(UserHitPrize::getTicketId, ticket.getTicketId()));
|
|
|
- if (StringUtils.isNotBlank(userHitPrize.getPrizeId())) {
|
|
|
- throw new ServiceException("盲票已兑奖");
|
|
|
- }
|
|
|
- userHitPrize.setPrizeId(prizeId);
|
|
|
- updateById(userHitPrize);
|
|
|
-
|
|
|
- // 放入仓库
|
|
|
- if (ticketAwardsPrize.getPrizeType() == TicketPrizeTypeEnum.COIN) {
|
|
|
- userCoinService.produce(userId, ticketAwardsPrize.getValue(), userHitPrize.getId());
|
|
|
- } else if (ticketAwardsPrize.getPrizeType() == TicketPrizeTypeEnum.COUPON) {
|
|
|
- couponService.distribute(ticket, userId, ticketAwardsPrize.getRefId());
|
|
|
- } else {
|
|
|
- userPrizeStorageService.takeInStorage(userId, ticketAwardsPrize, PrizeStorageInTypeEnum.TICKET_CASHED, userHitPrize.getId());
|
|
|
+ List<TicketAwardsPrize> awardsPrizes = ticketAwardsPrizeService.list(new LambdaQueryWrapper<TicketAwardsPrize>()
|
|
|
+ .eq(TicketAwardsPrize::getAwardsId, userHitPrize.getAwardsId()).orderByDesc(TicketAwardsPrize::getRemainQty));
|
|
|
+ return awardsPrizes;
|
|
|
}
|
|
|
|
|
|
- boolean rtn = ticketService.update(new LambdaUpdateWrapper<Ticket>().set(Ticket::getStatus, TicketStatusEnum.CASHED)
|
|
|
- .eq(Ticket::getTicketId, ticket.getTicketId()).eq(Ticket::getStatus, TicketStatusEnum.ACTIVATED));
|
|
|
- Assert.isTrue(rtn, "兑奖后更新盲票状态失败。ticketId:" + ticket.getTicketId());
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void cashPrize(Ticket ticket, Long userId, String awardsId, String prizeId) {
|
|
|
+ // 更新奖品已兑奖数量
|
|
|
+ TicketAwardsPrize ticketAwardsPrize = ticketAwardsPrizeService.getById(prizeId);
|
|
|
+ if (ticketAwardsPrize.getRemainQty() <= 0) {
|
|
|
+ throw new ServiceException("奖品已兑完,请重新选择");
|
|
|
+ }
|
|
|
+ // 乐观锁
|
|
|
+ ticketAwardsPrizeService.update(new LambdaUpdateWrapper<TicketAwardsPrize>().set(TicketAwardsPrize::getCashedQty, ticketAwardsPrize.getCashedQty() + 1)
|
|
|
+ .set(TicketAwardsPrize::getRemainQty, ticketAwardsPrize.getRemainQty() - 1)
|
|
|
+ .eq(TicketAwardsPrize::getPrizeId, prizeId).eq(TicketAwardsPrize::getCashedQty, ticketAwardsPrize.getCashedQty()));
|
|
|
+
|
|
|
+ // 保存奖品到中奖记录中
|
|
|
+ UserHitPrize userHitPrize = getOne(new LambdaQueryWrapper<UserHitPrize>().eq(UserHitPrize::getTicketId, ticket.getTicketId()));
|
|
|
+ if (StringUtils.isNotBlank(userHitPrize.getPrizeId())) {
|
|
|
+ throw new ServiceException("盲票已兑奖");
|
|
|
+ }
|
|
|
+ userHitPrize.setPrizeId(prizeId);
|
|
|
+ updateById(userHitPrize);
|
|
|
+
|
|
|
+ // 放入仓库
|
|
|
+ if (ticketAwardsPrize.getPrizeType() == TicketPrizeTypeEnum.COIN) {
|
|
|
+ userCoinService.produce(userId, ticketAwardsPrize.getValue(), userHitPrize.getId());
|
|
|
+ } else if (ticketAwardsPrize.getPrizeType() == TicketPrizeTypeEnum.COUPON) {
|
|
|
+ couponService.distribute(ticket, userId, ticketAwardsPrize.getRefId());
|
|
|
+ } else {
|
|
|
+ userPrizeStorageService.takeInStorage(userId, ticketAwardsPrize, PrizeStorageInTypeEnum.TICKET_CASHED, userHitPrize.getId());
|
|
|
+ }
|
|
|
|
|
|
+ boolean rtn = ticketService.update(new LambdaUpdateWrapper<Ticket>().set(Ticket::getStatus, TicketStatusEnum.CASHED)
|
|
|
+ .eq(Ticket::getTicketId, ticket.getTicketId()).eq(Ticket::getStatus, TicketStatusEnum.ACTIVATED));
|
|
|
+ Assert.isTrue(rtn, "兑奖后更新盲票状态失败。ticketId:" + ticket.getTicketId());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<TicketHitPrizeBarrageVO> hitPrizeBarrage(Long userId) {
|
|
|
+ return this.getBaseMapper().selectTicketHitPrizeBarrageNotByUserId(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TicketHitPrizeBarrageVO> hitPrizeBarrageByUserId(Long userId) {
|
|
|
+ LocalDateTime startTime = LocalDateTime.of(LocalDateTime.now().toLocalDate(), LocalTime.MIN);
|
|
|
+ LocalDateTime endTime = LocalDateTime.now().withNano(0);
|
|
|
+ return this.getBaseMapper().selectTicketHitPrizeBarrageByUserId(userId, startTime, endTime);
|
|
|
+ }
|
|
|
|
|
|
}
|