新增订单推荐人和邀请码功能,优化支付流程中的订单插入逻辑,确保订单记录准确。更新小程序支付请求,支持传递邀请码以便于分销归属和对账。同时,调整数据库结构以支持新字段,提升系统的稳定性和用户体验。

This commit is contained in:
乘风
2026-02-06 18:34:02 +08:00
parent f8fac00c85
commit 2e65d68e1e
34 changed files with 3288 additions and 1255 deletions

View File

@@ -7,6 +7,7 @@ import { NextResponse } from 'next/server'
import fs from 'fs'
import path from 'path'
import { requireAdminResponse } from '@/lib/admin-auth'
import { query } from '@/lib/db'
// 获取书籍目录
const BOOK_DIR = path.join(process.cwd(), 'book')
@@ -286,27 +287,38 @@ export async function POST(request: Request) {
console.log('[AdminChapters] 更新章节:', { action, chapterId })
switch (action) {
case 'updatePrice':
// 更新章节价格
// TODO: 保存到数据库
case 'updatePrice': {
if (data?.price != null && chapterId) {
await query('UPDATE chapters SET price = ?, updated_at = NOW() WHERE id = ?', [Number(data.price), chapterId])
}
return NextResponse.json({
success: true,
data: { message: '价格更新成功', chapterId, price: data.price }
data: { message: '价格更新成功', chapterId, price: data?.price }
})
}
case 'toggleFree':
// 切换免费状态
case 'toggleFree': {
if (data?.isFree != null && chapterId) {
await query('UPDATE chapters SET is_free = ?, updated_at = NOW() WHERE id = ?', [!!data.isFree, chapterId])
}
return NextResponse.json({
success: true,
data: { message: '免费状态更新成功', chapterId, isFree: data.isFree }
data: { message: '免费状态更新成功', chapterId, isFree: data?.isFree }
})
}
case 'updateStatus':
// 更新发布状态
case 'updateStatus': {
if (data?.status && chapterId) {
const s = String(data.status)
if (['draft', 'published', 'archived'].includes(s)) {
await query('UPDATE chapters SET status = ?, updated_at = NOW() WHERE id = ?', [s, chapterId])
}
}
return NextResponse.json({
success: true,
data: { message: '发布状态更新成功', chapterId, status: data.status }
data: { message: '发布状态更新成功', chapterId, status: data?.status }
})
}
default:
return NextResponse.json({