Skip to content

Commit 5fab292

Browse files
committed
fix(chatroom): 修复红包功能中的余额检查逻辑
- 移除了重复的余额检查代码块 - 将余额检查逻辑移到正确的位置 - 确保石头剪刀布红包类型也有余额检查 - 确保其他红包类型也有余额检查 - 保持了原有的错误提示信息
1 parent 775276a commit 5fab292

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/main/java/org/b3log/symphony/processor/ChatroomProcessor.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -962,14 +962,6 @@ public synchronized void openRedPacket(final RequestContext context) {
962962
}*/
963963
}
964964

965-
if ("heartbeat".equals(redPacket.getString("type")) || "rockPaperScissors".equals(redPacket.getString("type"))) {
966-
// 如果要抢石头剪刀布红包,先看账户余额是否大于平均数
967-
if (currentUser.optInt(UserExt.USER_POINT) < redPacket.optInt("money")) {
968-
context.renderJSON(StatusCodes.ERR).renderMsg("抢红包失败!你的账户余额低于该红包金额。");
969-
return;
970-
}
971-
}
972-
973965
// 开始领取红包
974966
int meGot = 0;
975967
if ("average".equals(redPacket.getString("type"))) {
@@ -1077,6 +1069,11 @@ public synchronized void openRedPacket(final RequestContext context) {
10771069
meGot = RED_PACKET_BUCKET.get(oId).packs.poll();
10781070
}
10791071
} else if ("rockPaperScissors".equals(redPacket.getString("type"))) {
1072+
if (currentUser.optInt(UserExt.USER_POINT) < redPacket.optInt("money")) {
1073+
context.renderJSON(StatusCodes.ERR).renderMsg("抢红包失败!你的账户余额低于该红包金额。");
1074+
return;
1075+
}
1076+
10801077
if (redPacketIsOpened(who, userId)) {
10811078
context.renderJSON(new JSONObject().put("who", who).put("info", info));
10821079
return;
@@ -1103,6 +1100,10 @@ public synchronized void openRedPacket(final RequestContext context) {
11031100
meGot = -money;
11041101
}
11051102
} else {
1103+
if (currentUser.optInt(UserExt.USER_POINT) < redPacket.optInt("money")) {
1104+
context.renderJSON(StatusCodes.ERR).renderMsg("抢红包失败!你的账户余额低于该红包金额。");
1105+
return;
1106+
}
11061107
if (redPacketIsOpened(who, userId)) {
11071108
context.renderJSON(new JSONObject().put("who", who).put("info", info));
11081109
return;

0 commit comments

Comments
 (0)