GameRound status 调整
This commit is contained in:
@@ -6,6 +6,7 @@ import com.tailbet.model.entity.RedPacket;
|
||||
import com.tailbet.model.entity.RedPacketRecv;
|
||||
import com.tailbet.model.vo.R;
|
||||
import com.tailbet.model.vo.UserContext;
|
||||
import com.tailbet.service.IGameService;
|
||||
import com.tailbet.service.IRedPacketService;
|
||||
import com.tailbet.util.RedisLockUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -20,20 +21,21 @@ import org.springframework.web.bind.annotation.*;
|
||||
public class RedPacketController {
|
||||
|
||||
private final IRedPacketService redPacketService;
|
||||
private final IGameService gameService;
|
||||
|
||||
/**
|
||||
* 发红包
|
||||
*/
|
||||
@PostMapping("/send")
|
||||
public R<RedPacket> sendRp(@RequestBody SendRpDTO dto) {
|
||||
try {
|
||||
Long userId = UserContext.getUserId();
|
||||
var rp = redPacketService.sendRp(userId, dto.getGroupId(),
|
||||
dto.getTotalAmount(), dto.getTotalCount(), dto.getRoundId());
|
||||
return R.ok(rp);
|
||||
} catch (RuntimeException e) {
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
Long userId = UserContext.getUserId();
|
||||
// roundId从当前group的进行中局获取
|
||||
var ongoingRound = gameService.getOngoingRound(dto.getGroupId());
|
||||
Long roundId = ongoingRound == null ? null : ongoingRound.getId();
|
||||
var rp = redPacketService.sendRp(userId, dto.getGroupId(),
|
||||
dto.getTotalAmount(), dto.getTotalCount(), roundId);
|
||||
return R.ok(rp);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,18 +43,15 @@ public class RedPacketController {
|
||||
*/
|
||||
@PostMapping("/receive")
|
||||
public R<RedPacketRecv> receiveRp(@RequestBody ReceiveRpDTO dto) {
|
||||
try {
|
||||
Long userId = UserContext.getUserId();
|
||||
// 使用分布式锁防止多领
|
||||
var recv = RedisLockUtil.lock("rp:receive:" + dto.getRpId(),
|
||||
() -> redPacketService.receiveRp(dto.getRpId(), userId));
|
||||
if (recv == null) {
|
||||
return R.fail("领取失败,请重试");
|
||||
}
|
||||
return R.ok(recv);
|
||||
} catch (RuntimeException e) {
|
||||
return R.fail(e.getMessage());
|
||||
Long userId = UserContext.getUserId();
|
||||
// 使用分布式锁防止多领
|
||||
var recv = RedisLockUtil.lock("rp:receive:" + dto.getRpId(),
|
||||
() -> redPacketService.receiveRp(dto.getRpId(), userId));
|
||||
if (recv == null) {
|
||||
return R.fail("领取失败,请重试");
|
||||
}
|
||||
return R.ok(recv);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user