大修改
This commit is contained in:
1 parent
a1cbc9404a
commit
e81481623c
47 files changed
+1453
-285
No files matched your search
@@ -36,15 +36,25 @@ export class OrdersService {
|
||||
throw AppError.badRequest('购买数量不合法');
|
||||
}
|
||||
|
||||
const course = await this.prisma.course.findUnique({ where: { code: courseCode } });
|
||||
// 购买的硬性前置条件:用户必须主动使用过登录功能。
|
||||
// 静默登录只建立身份,不算「登录」,所以这里查的是数据库里的标记而不是 token。
|
||||
const buyer = await this.prisma.active.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { is_login: true },
|
||||
});
|
||||
if (!buyer || buyer.is_login !== 1) {
|
||||
throw AppError.forbidden('请先使用微信登录后再购买');
|
||||
}
|
||||
|
||||
const course = await this.prisma.active.course.findUnique({ where: { code: courseCode } });
|
||||
if (!course || course.status !== 1) throw AppError.notFound('课程不存在或已下架');
|
||||
|
||||
const owned = await this.prisma.entitlement.findUnique({
|
||||
const owned = await this.prisma.active.entitlement.findUnique({
|
||||
where: { user_id_course_id: { user_id: userId, course_id: course.id } },
|
||||
});
|
||||
if (owned) throw AppError.conflict('你已拥有该课程');
|
||||
|
||||
const product = await this.prisma.product.findFirst({
|
||||
const product = await this.prisma.active.product.findFirst({
|
||||
where: { course_id: course.id, status: 1 },
|
||||
});
|
||||
if (!product) throw AppError.notFound('该课程尚未配置支付商品');
|
||||
@@ -52,7 +62,7 @@ export class OrdersService {
|
||||
const outTradeNo = this.newOutTradeNo();
|
||||
const amountFen = product.price_fen * quantity;
|
||||
|
||||
await this.prisma.order.create({
|
||||
await this.prisma.active.order.create({
|
||||
data: {
|
||||
out_trade_no: outTradeNo,
|
||||
user_id: userId,
|
||||
@@ -91,7 +101,7 @@ export class OrdersService {
|
||||
|
||||
/** 查询自己的订单状态。前端支付返回后用它确认是否已发货。 */
|
||||
async status(userId: number, outTradeNo: string) {
|
||||
const order = await this.prisma.order.findUnique({
|
||||
const order = await this.prisma.active.order.findUnique({
|
||||
where: { out_trade_no: outTradeNo },
|
||||
include: { course: { select: { code: true, title: true } } },
|
||||
});
|
||||
@@ -113,7 +123,7 @@ export class OrdersService {
|
||||
|
||||
/** 我的订单列表。 */
|
||||
async list(userId: number) {
|
||||
const rows = await this.prisma.order.findMany({
|
||||
const rows = await this.prisma.active.order.findMany({
|
||||
where: { user_id: userId },
|
||||
orderBy: { created_at: 'desc' },
|
||||
take: 100,
|
||||
|
||||
Reference in new issue
Block a user