This commit is contained in:
张成
2025-12-16 06:00:04 +08:00
parent a262fb7ff7
commit 119568f961
5 changed files with 647 additions and 11 deletions

View File

@@ -0,0 +1,114 @@
/**
* 推广邀请管理控制器(客户端接口)
* 提供客户端调用的推广邀请相关接口
*/
const Framework = require("../../framework/node-core-framework.js");
module.exports = {
/**
* @swagger
* /api/invite/info:
* get:
* summary: 获取邀请信息
* description: 根据用户ID获取邀请码和邀请链接
* tags: [前端-推广邀请]
* responses:
* 200:
* description: 获取成功
*/
'GET /invite/info': async (ctx) => {
try {
// 从query或body中获取user_id实际应该从token中解析
const body = ctx.getBody();
const user_id = body.user_id || ctx.query?.user_id;
if (!user_id) {
return ctx.fail('请先登录');
}
// 生成邀请码基于用户ID
const invite_code = `INV${user_id}${Date.now().toString(36).toUpperCase()}`;
const invite_link = `https://work.light120.com/invite?code=${invite_code}`;
return ctx.success({
invite_code,
invite_link,
user_id
});
} catch (error) {
console.error('获取邀请信息失败:', error);
return ctx.fail('获取邀请信息失败: ' + error.message);
}
},
/**
* @swagger
* /api/invite/statistics:
* get:
* summary: 获取邀请统计
* description: 根据用户ID获取邀请统计数据
* tags: [前端-推广邀请]
* responses:
* 200:
* description: 获取成功
*/
'GET /invite/statistics': async (ctx) => {
try {
// 从query或body中获取user_id实际应该从token中解析
const body = ctx.getBody() || {};
const user_id = body.user_id || ctx.query?.user_id;
if (!user_id) {
return ctx.fail('请先登录');
}
// 这里可以从数据库查询邀请统计,暂时返回模拟数据
return ctx.success({
totalInvites: 0,
activeInvites: 0,
rewardPoints: 0,
rewardAmount: 0
});
} catch (error) {
console.error('获取邀请统计失败:', error);
return ctx.fail('获取邀请统计失败: ' + error.message);
}
},
/**
* @swagger
* /api/invite/generate:
* post:
* summary: 生成邀请码
* description: 为用户生成新的邀请码
* tags: [前端-推广邀请]
* responses:
* 200:
* description: 生成成功
*/
'POST /invite/generate': async (ctx) => {
try {
// 从query或body中获取user_id实际应该从token中解析
const body = ctx.getBody() || {};
const user_id = body.user_id || ctx.query?.user_id;
if (!user_id) {
return ctx.fail('请先登录');
}
// 生成新的邀请码
const invite_code = `INV${user_id}${Date.now().toString(36).toUpperCase()}`;
const invite_link = `https://work.light120.com/invite?code=${invite_code}`;
return ctx.success({
invite_code,
invite_link
});
} catch (error) {
console.error('生成邀请码失败:', error);
return ctx.fail('生成邀请码失败: ' + error.message);
}
}
};