|
@@ -33,15 +33,13 @@ export const POST = withAuth(async (request) => {
|
|
|
for (const history of previousPointHistories) {
|
|
|
const user = await User.findById(history.user);
|
|
|
if (user) {
|
|
|
- user.points -= history.points;
|
|
|
- await user.save();
|
|
|
+ await User.findByIdAndUpdate(user._id, { $inc: { points: -history.points } });
|
|
|
}
|
|
|
await PointHistory.deleteOne({ _id: history._id });
|
|
|
}
|
|
|
|
|
|
// 2. 查找所有相关预测
|
|
|
const predictions = await Prediction.find({ match: matchId });
|
|
|
-
|
|
|
// 3. 根据比赛类型处理预测结果和积分
|
|
|
for (const prediction of predictions) {
|
|
|
let pointsEarned = 0;
|
|
@@ -49,9 +47,7 @@ export const POST = withAuth(async (request) => {
|
|
|
|
|
|
if (match.type === "football") {
|
|
|
// 足球比赛预测处理
|
|
|
- if (
|
|
|
- prediction.football?.whoWillWin?.prediction ===
|
|
|
- match.football.result.whoWillWin
|
|
|
+ if (prediction.football?.whoWillWin?.prediction == match.football.result.whoWillWin
|
|
|
) {
|
|
|
prediction.football.whoWillWin.result = "correct";
|
|
|
pointsEarned += match.football.pointRewards.whoWillWin;
|
|
@@ -60,20 +56,16 @@ export const POST = withAuth(async (request) => {
|
|
|
prediction.football.whoWillWin.result = "incorrect";
|
|
|
}
|
|
|
|
|
|
- if (
|
|
|
- prediction.football?.firstTeamToScore?.prediction ===
|
|
|
- match.football.result.firstTeamToScore
|
|
|
- ) {
|
|
|
+ if (prediction.football?.firstTeamToScore?.prediction == match.football.result.firstTeamToScore) {
|
|
|
prediction.football.firstTeamToScore.result = "correct";
|
|
|
pointsEarned += match.football.pointRewards.firstTeamToScore;
|
|
|
reasons.push("正确预测首先得分球队");
|
|
|
} else {
|
|
|
prediction.football.firstTeamToScore.result = "incorrect";
|
|
|
}
|
|
|
-
|
|
|
- const actualTotalGoals =
|
|
|
- match.football.homeTeamScore + match.football.awayTeamScore;
|
|
|
- if (prediction.football?.totalGoals?.prediction === actualTotalGoals) {
|
|
|
+ //总进球
|
|
|
+ const actualTotalGoals = match.homeTeamScore + match.awayTeamScore;
|
|
|
+ if (prediction.football?.totalGoals?.prediction == actualTotalGoals) {
|
|
|
prediction.football.totalGoals.result = "correct";
|
|
|
pointsEarned += match.football.pointRewards.totalGoals;
|
|
|
reasons.push("正确预测总进球数");
|
|
@@ -87,13 +79,11 @@ export const POST = withAuth(async (request) => {
|
|
|
const awayScore = match.awayTeamScore;
|
|
|
const winTeam = homeScore > awayScore ? "home" : "away";
|
|
|
|
|
|
- if (prediction.basketball?.whoWillWin?.prediction === winTeam) {
|
|
|
+ if (prediction.basketball?.whoWillWin?.prediction == winTeam) {
|
|
|
prediction.basketball.whoWillWin.result = "correct";
|
|
|
pointsEarned += match.basketball.pointRewards.whoWillWin;
|
|
|
reasons.push("正确预测比赛胜负");
|
|
|
} else {
|
|
|
- console.log(333);
|
|
|
-
|
|
|
prediction.basketball.whoWillWin.result = "incorrect";
|
|
|
}
|
|
|
|
|
@@ -108,7 +98,7 @@ export const POST = withAuth(async (request) => {
|
|
|
|
|
|
const spreadResult = homeScoreWithSpread > awayScore ? "home" : "away";
|
|
|
|
|
|
- if (prediction.basketball?.spread?.prediction === spreadResult) {
|
|
|
+ if (prediction.basketball?.spread?.prediction == spreadResult) {
|
|
|
prediction.basketball.spread.result = "correct";
|
|
|
pointsEarned += match.basketball.pointRewards.spread;
|
|
|
reasons.push("正确预测让分");
|
|
@@ -122,9 +112,7 @@ export const POST = withAuth(async (request) => {
|
|
|
const totalPointsResult =
|
|
|
totalPoints > totalPointsLine ? "over" : "under";
|
|
|
|
|
|
- if (
|
|
|
- prediction.basketball?.totalPoints?.prediction === totalPointsResult
|
|
|
- ) {
|
|
|
+ if (prediction.basketball?.totalPoints?.prediction == totalPointsResult) {
|
|
|
prediction.basketball.totalPoints.result = "correct";
|
|
|
pointsEarned += match.basketball.pointRewards.totalPoints;
|
|
|
reasons.push("正确预测总分");
|
|
@@ -141,13 +129,13 @@ export const POST = withAuth(async (request) => {
|
|
|
if (pointsEarned > 0) {
|
|
|
const user = await User.findById(prediction.user);
|
|
|
if (user) {
|
|
|
- user.points += pointsEarned;
|
|
|
- await user.save();
|
|
|
+ // user.points += pointsEarned;
|
|
|
+ // await user.save();
|
|
|
+ await User.findByIdAndUpdate(prediction.user, { $inc: { points: pointsEarned } });
|
|
|
|
|
|
// 创建积分历史记录
|
|
|
- const reason = `${match.homeTeam.name} vs ${match.awayTeam.name} ${
|
|
|
- match.type === "football" ? "足球" : "篮球"
|
|
|
- }比赛预测: ${reasons.join(", ")}`;
|
|
|
+ const reason = `${match.homeTeam.name} vs ${match.awayTeam.name} ${match.type === "football" ? "足球" : "篮球"
|
|
|
+ }比赛预测: ${reasons.join(", ")}`;
|
|
|
const pointHistory = new PointHistory({
|
|
|
user: user._id,
|
|
|
points: pointsEarned,
|