feat: 管理后台增加免费章节和小程序配置

1. 系统设置页新增免费章节管理(可动态添加/删除)
2. 新增小程序配置项(API域名、购买优惠、绑定天数等)
3. 前端从后端读取免费章节配置
4. 配置API支持新格式
This commit is contained in:
卡若
2026-01-25 21:09:20 +08:00
parent afa8c59376
commit ac24853aa6
3 changed files with 228 additions and 2 deletions

View File

@@ -142,10 +142,28 @@ export async function GET(request: NextRequest) {
}
}
// 获取小程序配置
let mpConfig = null
try {
mpConfig = await getConfig('mp_config')
} catch (e) {}
// 提取前端需要的格式
const bookConfig = allConfigs.book_config || DEFAULT_CONFIGS.book_config
return NextResponse.json({
success: true,
configs: allConfigs,
sources
sources,
// 前端直接使用的格式
freeChapters: bookConfig.freeSections || DEFAULT_CONFIGS.book_config.freeSections,
mpConfig: mpConfig || {
appId: 'wxb8bbb2b10dec74aa',
apiDomain: 'https://soul.quwanzhi.com',
buyerDiscount: 5,
referralBindDays: 30,
minWithdraw: 10
}
})
} catch (error) {
@@ -159,10 +177,42 @@ export async function GET(request: NextRequest) {
/**
* POST - 保存配置到数据库
* 支持两种格式:
* 1. { key, config } - 单个配置
* 2. { freeChapters, mpConfig } - 批量配置
*/
export async function POST(request: NextRequest) {
try {
const body = await request.json()
// 支持批量配置格式
if (body.freeChapters || body.mpConfig) {
let successCount = 0
// 保存免费章节配置
if (body.freeChapters) {
const bookConfig = {
...DEFAULT_CONFIGS.book_config,
freeSections: body.freeChapters
}
const success = await setConfig('book_config', bookConfig, '书籍配置-免费章节')
if (success) successCount++
}
// 保存小程序配置
if (body.mpConfig) {
const success = await setConfig('mp_config', body.mpConfig, '小程序配置')
if (success) successCount++
}
return NextResponse.json({
success: true,
message: `配置保存成功 (${successCount}项)`,
successCount
})
}
// 原有的单配置格式
const { key, config, description } = body
if (!key || !config) {