This commit is contained in:
dute7liang
2024-02-24 00:51:35 +08:00
parent 59d7005319
commit e9a40fa89d

View File

@@ -61,6 +61,14 @@ public class UserGiftServiceImpl extends ServiceImpl<UserGiftMapper, UserGift> i
if(gift == null){
throw new ServiceException("礼物不存在");
}
User toUser = userService.getById(query.getToUserId());
Anchor anchor = anchorService.getByUserId(query.getToUserId());
if(toUser == null){
throw new ServiceException("主播不存在");
}
if(anchor == null){
throw new ServiceException("只能给主播送礼物哦");
}
String guardLock = LockManager.getSendGuardLock(fromUserId);
RLock lock = redissonClient.getLock(guardLock);
if(lock.isLocked()){
@@ -71,8 +79,6 @@ public class UserGiftServiceImpl extends ServiceImpl<UserGiftMapper, UserGift> i
try {
lock.lock(3, TimeUnit.SECONDS);
User fromUser = userService.getById(fromUserId);
User toUser = userService.getById(query.getToUserId());
Anchor anchor = anchorService.getByUserId(query.getToUserId());
Long price = gift.getPrice();
Long traceId = IdManager.nextId();
Long giftAmount = query.getGiftCount() * price;