2026-05-25: 等级体系升级(20级)+论坛二级分类+会员空间

This commit is contained in:
ZhuiGuangAI Dev
2026-05-24 23:05:38 +08:00
parent 6c78c32157
commit 9bf3e7574a
118 changed files with 11842 additions and 3262 deletions
+67
View File
@@ -0,0 +1,67 @@
import { prisma } from "@/lib/prisma";
import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
import { NextResponse } from "next/server";
import { rewardPoints } from "@/lib/points-reward";
export async function POST(req: Request, { params }: { params: { id: string } }) {
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json({ error: "请先登录" }, { status: 401 });
}
const userId = parseInt(session.user.id);
const commentId = parseInt(params.id);
const [existing] = await prisma.commentLike.findMany({
where: { commentId, userId },
});
if (existing) {
await prisma.commentLike.delete({
where: { commentId_userId: { commentId, userId } },
});
await prisma.comment.update({
where: { id: commentId },
data: { likeCount: { decrement: 1 } },
});
return NextResponse.json({ liked: false });
}
const result = await prisma.$transaction(async (tx) => {
await tx.commentLike.create({
data: { commentId, userId },
});
await tx.comment.update({
where: { id: commentId },
data: { likeCount: { increment: 1 } },
});
const comment = await tx.comment.findUnique({
where: { id: commentId },
select: { userId: true },
});
if (comment && comment.userId !== userId) {
await tx.notification.create({
data: {
userId: comment.userId,
type: "COMMENT_LIKE",
title: `${session.user.name || "用户"} 点赞了你的评论`,
link: "/notifications",
},
});
}
return comment;
});
if (result) {
await rewardPoints(result.userId, "comment_like", "评论被点赞", "comment", commentId);
}
return NextResponse.json({ liked: true });
}