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

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

@@ -5,34 +5,33 @@ import { query } from '@/lib/db'
export async function GET() {
try {
// 方案1: 优先从数据库读取章节数据
// 方案1: 优先从数据库读取(使用实际存在的 chapters 表,不是 sections
try {
const dbChapters = await query(`
SELECT
id, section_id, title, section_title, content,
is_free, price, words, section_order, chapter_order,
created_at, updated_at
FROM sections
ORDER BY section_order ASC, chapter_order ASC
`) as any[]
id, part_id, part_title, chapter_id, chapter_title, section_title, content,
word_count, is_free, price, sort_order, created_at, updated_at
FROM chapters
WHERE status = 'published'
ORDER BY sort_order ASC
`, []) as any[]
if (dbChapters && dbChapters.length > 0) {
console.log('[All Chapters API] 从数据库读取成功,共', dbChapters.length, '章')
console.log('[All Chapters API] 从数据库 chapters 表读取成功,共', dbChapters.length, '章')
// 格式化数据
const allChapters = dbChapters.map((chapter: any) => ({
id: chapter.id,
sectionId: chapter.section_id,
title: chapter.title,
sectionTitle: chapter.section_title,
content: chapter.content,
isFree: !!chapter.is_free,
price: chapter.price || 0,
words: chapter.words || Math.floor(Math.random() * 3000) + 2000,
sectionOrder: chapter.section_order,
chapterOrder: chapter.chapter_order,
createdAt: chapter.created_at,
updatedAt: chapter.updated_at
const allChapters = dbChapters.map((row: any, idx: number) => ({
id: row.id,
sectionId: row.chapter_id || row.part_id,
title: row.chapter_title || row.section_title,
sectionTitle: row.part_title || row.section_title,
content: row.content,
isFree: !!row.is_free,
price: Number(row.price) || 0,
words: row.word_count || Math.floor(Math.random() * 3000) + 2000,
sectionOrder: row.sort_order ?? idx + 1,
chapterOrder: idx + 1,
createdAt: row.created_at,
updatedAt: row.updated_at
}))
return NextResponse.json({