This commit is contained in:
张成
2026-04-01 10:13:22 +08:00
parent 14f5d75d9d
commit 494555a6e1
11 changed files with 52 additions and 90 deletions

View File

@@ -1,20 +1,12 @@
const stats = require("../service/biz_api_stats_service"); const stats = require("../service/biz_api_stats_service");
const crud = require("../service/biz_admin_crud"); const crud = require("../service/biz_admin_crud");
function getRequestBody(ctx) {
if (ctx.request && ctx.request.body && Object.keys(ctx.request.body).length > 0) {
return ctx.request.body;
}
if (typeof ctx.getBody === "function") {
return ctx.getBody() || {};
}
return {};
}
module.exports = { module.exports = {
/** 按用户查询调用统计 */ /** 按用户查询调用统计 */
"POST /biz_api_stats/by_user": async (ctx) => { "POST /biz_api_stats/by_user": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const { user_id, start_date, end_date } = body; const { user_id, start_date, end_date } = body;
if (!user_id) { if (!user_id) {
ctx.fail("缺少 user_id"); ctx.fail("缺少 user_id");
@@ -26,7 +18,7 @@ module.exports = {
/** 按接口路径查询调用统计 */ /** 按接口路径查询调用统计 */
"POST /biz_api_stats/by_api": async (ctx) => { "POST /biz_api_stats/by_api": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const { api_path, start_date, end_date } = body; const { api_path, start_date, end_date } = body;
if (!api_path) { if (!api_path) {
ctx.fail("缺少 api_path"); ctx.fail("缺少 api_path");
@@ -38,7 +30,7 @@ module.exports = {
/** 综合统计面板 */ /** 综合统计面板 */
"POST /biz_api_stats/summary": async (ctx) => { "POST /biz_api_stats/summary": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const { start_date, end_date, top_limit } = body; const { start_date, end_date, top_limit } = body;
const data = await stats.getSummary(start_date, end_date, top_limit || 10); const data = await stats.getSummary(start_date, end_date, top_limit || 10);
ctx.success(data); ctx.success(data);
@@ -46,7 +38,7 @@ module.exports = {
/** 调用日志分页列表(复用通用 CRUD */ /** 调用日志分页列表(复用通用 CRUD */
"POST /biz_api_call_log/page": async (ctx) => { "POST /biz_api_call_log/page": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const data = await crud.page("biz_api_call_log", body); const data = await crud.page("biz_api_call_log", body);
ctx.success({ rows: data.rows, count: data.count }); ctx.success({ rows: data.rows, count: data.count });
}, },

View File

@@ -1,14 +1,16 @@
const crud = require("../service/biz_admin_crud"); const crud = require("../service/biz_admin_crud");
const { getRequestBody } = crud;
module.exports = { module.exports = {
"POST /biz_audit_log/page": async (ctx) => { "POST /biz_audit_log/page": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const data = await crud.page("biz_audit_log", body); const data = await crud.page("biz_audit_log", body);
ctx.success({ rows: data.rows, count: data.count }); ctx.success({ rows: data.rows, count: data.count });
}, },
"POST /biz_audit_log/export": async (ctx) => { "POST /biz_audit_log/export": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const res = await crud.exportCsv("biz_audit_log", body); const res = await crud.exportCsv("biz_audit_log", body);
ctx.success(res); ctx.success(res);
}, },

View File

@@ -1,19 +1,11 @@
const logic = require("../service/biz_subscription_logic"); const logic = require("../service/biz_subscription_logic");
const audit = require("../service/biz_audit_service"); const audit = require("../service/biz_audit_service");
function getRequestBody(ctx) {
if (ctx.request && ctx.request.body && Object.keys(ctx.request.body).length > 0) {
return ctx.request.body;
}
if (typeof ctx.getBody === "function") {
return ctx.getBody() || {};
}
return {};
}
module.exports = { module.exports = {
"POST /biz_payment/confirm-offline": async (ctx) => { "POST /biz_payment/confirm-offline": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const row = await logic.confirmOfflinePayment(body); const row = await logic.confirmOfflinePayment(body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -25,7 +17,7 @@ module.exports = {
ctx.success(row); ctx.success(row);
}, },
"POST /biz_payment/confirm-link": async (ctx) => { "POST /biz_payment/confirm-link": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const row = await logic.confirmLinkPayment(body); const row = await logic.confirmLinkPayment(body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),

View File

@@ -1,16 +1,16 @@
const crud = require("../service/biz_admin_crud"); const crud = require("../service/biz_admin_crud");
const { getRequestBody } = crud;
const baseModel = require("../../middleware/baseModel"); const baseModel = require("../../middleware/baseModel");
const audit = require("../service/biz_audit_service"); const audit = require("../service/biz_audit_service");
module.exports = { module.exports = {
"POST /biz_plan/page": async (ctx) => { "POST /biz_plan/page": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const data = await crud.page("biz_plan", body); const data = await crud.page("biz_plan", body);
ctx.success({ rows: data.rows, count: data.count }); ctx.success({ rows: data.rows, count: data.count });
}, },
"POST /biz_plan/add": async (ctx) => { "POST /biz_plan/add": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const row = await crud.add("biz_plan", body); const row = await crud.add("biz_plan", body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -22,7 +22,7 @@ module.exports = {
ctx.success(row); ctx.success(row);
}, },
"POST /biz_plan/edit": async (ctx) => { "POST /biz_plan/edit": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
await crud.edit("biz_plan", body); await crud.edit("biz_plan", body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -33,7 +33,7 @@ module.exports = {
ctx.success({}); ctx.success({});
}, },
"POST /biz_plan/del": async (ctx) => { "POST /biz_plan/del": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
await crud.del("biz_plan", body); await crud.del("biz_plan", body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -53,7 +53,7 @@ module.exports = {
ctx.success(rows); ctx.success(rows);
}, },
"POST /biz_plan/toggle": async (ctx) => { "POST /biz_plan/toggle": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const id = body.id; const id = body.id;
if (id == null) return ctx.fail("缺少 id"); if (id == null) return ctx.fail("缺少 id");
const row = await baseModel.biz_plan.findByPk(id); const row = await baseModel.biz_plan.findByPk(id);
@@ -70,7 +70,7 @@ module.exports = {
ctx.success({ status: next }); ctx.success({ status: next });
}, },
"POST /biz_plan/export": async (ctx) => { "POST /biz_plan/export": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const res = await crud.exportCsv("biz_plan", body); const res = await crud.exportCsv("biz_plan", body);
ctx.success(res); ctx.success(res);
}, },

View File

@@ -1,12 +1,12 @@
const crud = require("../service/biz_admin_crud"); const crud = require("../service/biz_admin_crud");
const { getRequestBody } = crud;
const baseModel = require("../../middleware/baseModel"); const baseModel = require("../../middleware/baseModel");
const logic = require("../service/biz_subscription_logic"); const logic = require("../service/biz_subscription_logic");
const audit = require("../service/biz_audit_service"); const audit = require("../service/biz_audit_service");
module.exports = { module.exports = {
"POST /biz_subscription/page": async (ctx) => { "POST /biz_subscription/page": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const data = await crud.page("biz_subscription", body); const data = await crud.page("biz_subscription", body);
ctx.success({ rows: data.rows, count: data.count }); ctx.success({ rows: data.rows, count: data.count });
}, },
@@ -26,7 +26,7 @@ module.exports = {
ctx.success(rows); ctx.success(rows);
}, },
"POST /biz_subscription/open": async (ctx) => { "POST /biz_subscription/open": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const row = await logic.openSubscription(body); const row = await logic.openSubscription(body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -39,7 +39,7 @@ module.exports = {
ctx.success(row); ctx.success(row);
}, },
"POST /biz_subscription/upgrade": async (ctx) => { "POST /biz_subscription/upgrade": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const row = await logic.upgradeSubscription(body); const row = await logic.upgradeSubscription(body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -51,7 +51,7 @@ module.exports = {
ctx.success(row); ctx.success(row);
}, },
"POST /biz_subscription/renew": async (ctx) => { "POST /biz_subscription/renew": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const row = await logic.renewSubscription(body); const row = await logic.renewSubscription(body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -62,7 +62,7 @@ module.exports = {
ctx.success(row); ctx.success(row);
}, },
"POST /biz_subscription/cancel": async (ctx) => { "POST /biz_subscription/cancel": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const row = await logic.cancelSubscription(body); const row = await logic.cancelSubscription(body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -73,7 +73,7 @@ module.exports = {
ctx.success(row); ctx.success(row);
}, },
"POST /biz_subscription/export": async (ctx) => { "POST /biz_subscription/export": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const res = await crud.exportCsv("biz_subscription", body); const res = await crud.exportCsv("biz_subscription", body);
ctx.success(res); ctx.success(res);
}, },

View File

@@ -1,16 +1,16 @@
const crud = require("../service/biz_admin_crud"); const crud = require("../service/biz_admin_crud");
const { getRequestBody } = crud;
const tokenLogic = require("../service/biz_token_logic"); const tokenLogic = require("../service/biz_token_logic");
const audit = require("../service/biz_audit_service"); const audit = require("../service/biz_audit_service");
module.exports = { module.exports = {
"POST /biz_token/page": async (ctx) => { "POST /biz_token/page": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const data = await crud.page("biz_api_token", body); const data = await crud.page("biz_api_token", body);
ctx.success({ rows: data.rows, count: data.count }); ctx.success({ rows: data.rows, count: data.count });
}, },
"POST /biz_token/create": async (ctx) => { "POST /biz_token/create": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const result = await tokenLogic.createToken(body); const result = await tokenLogic.createToken(body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -31,7 +31,7 @@ module.exports = {
}); });
}, },
"POST /biz_token/revoke": async (ctx) => { "POST /biz_token/revoke": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const row = await tokenLogic.revokeToken(body); const row = await tokenLogic.revokeToken(body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -43,7 +43,7 @@ module.exports = {
ctx.success({ id: row.id, status: row.status }); ctx.success({ id: row.id, status: row.status });
}, },
"POST /biz_token/export": async (ctx) => { "POST /biz_token/export": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const res = await crud.exportCsv("biz_api_token", body); const res = await crud.exportCsv("biz_api_token", body);
ctx.success(res); ctx.success(res);
}, },

View File

@@ -1,24 +1,24 @@
const crud = require("../service/biz_admin_crud"); const crud = require("../service/biz_admin_crud");
const { getRequestBody } = crud;
module.exports = { module.exports = {
"POST /biz_usage/page": async (ctx) => { "POST /biz_usage/page": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const data = await crud.page("biz_usage_monthly", body); const data = await crud.page("biz_usage_monthly", body);
ctx.success({ rows: data.rows, count: data.count }); ctx.success({ rows: data.rows, count: data.count });
}, },
"POST /biz_usage/add": async (ctx) => { "POST /biz_usage/add": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const row = await crud.add("biz_usage_monthly", body); const row = await crud.add("biz_usage_monthly", body);
ctx.success(row); ctx.success(row);
}, },
"POST /biz_usage/edit": async (ctx) => { "POST /biz_usage/edit": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
await crud.edit("biz_usage_monthly", body); await crud.edit("biz_usage_monthly", body);
ctx.success({}); ctx.success({});
}, },
"POST /biz_usage/del": async (ctx) => { "POST /biz_usage/del": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
await crud.del("biz_usage_monthly", body); await crud.del("biz_usage_monthly", body);
ctx.success({}); ctx.success({});
}, },
@@ -28,7 +28,7 @@ module.exports = {
ctx.success(row); ctx.success(row);
}, },
"POST /biz_usage/export": async (ctx) => { "POST /biz_usage/export": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const res = await crud.exportCsv("biz_usage_monthly", body); const res = await crud.exportCsv("biz_usage_monthly", body);
ctx.success(res); ctx.success(res);
}, },

View File

@@ -1,17 +1,17 @@
const crud = require("../service/biz_admin_crud"); const crud = require("../service/biz_admin_crud");
const { getRequestBody } = crud;
const baseModel = require("../../middleware/baseModel"); const baseModel = require("../../middleware/baseModel");
const tokenLogic = require("../service/biz_token_logic"); const tokenLogic = require("../service/biz_token_logic");
const audit = require("../service/biz_audit_service"); const audit = require("../service/biz_audit_service");
module.exports = { module.exports = {
"POST /biz_user/page": async (ctx) => { "POST /biz_user/page": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const data = await crud.page("biz_user", body); const data = await crud.page("biz_user", body);
ctx.success({ rows: data.rows, count: data.count }); ctx.success({ rows: data.rows, count: data.count });
}, },
"POST /biz_user/add": async (ctx) => { "POST /biz_user/add": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const row = await crud.add("biz_user", body); const row = await crud.add("biz_user", body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -24,7 +24,7 @@ module.exports = {
ctx.success(row); ctx.success(row);
}, },
"POST /biz_user/edit": async (ctx) => { "POST /biz_user/edit": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
await crud.edit("biz_user", body); await crud.edit("biz_user", body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -36,7 +36,7 @@ module.exports = {
ctx.success({}); ctx.success({});
}, },
"POST /biz_user/del": async (ctx) => { "POST /biz_user/del": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
await crud.del("biz_user", body); await crud.del("biz_user", body);
await audit.logAudit({ await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx), admin_user_id: audit.pickAdminId(ctx),
@@ -73,7 +73,7 @@ module.exports = {
ctx.success(rows); ctx.success(rows);
}, },
"POST /biz_user/disable": async (ctx) => { "POST /biz_user/disable": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const id = body.id; const id = body.id;
if (id == null) return ctx.fail("缺少 id"); if (id == null) return ctx.fail("缺少 id");
await baseModel.biz_user.update({ status: "disabled" }, { where: { id } }); await baseModel.biz_user.update({ status: "disabled" }, { where: { id } });
@@ -87,7 +87,7 @@ module.exports = {
ctx.success({}); ctx.success({});
}, },
"POST /biz_user/enable": async (ctx) => { "POST /biz_user/enable": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const id = body.id; const id = body.id;
if (id == null) return ctx.fail("缺少 id"); if (id == null) return ctx.fail("缺少 id");
await baseModel.biz_user.update({ status: "active" }, { where: { id } }); await baseModel.biz_user.update({ status: "active" }, { where: { id } });
@@ -101,12 +101,12 @@ module.exports = {
ctx.success({}); ctx.success({});
}, },
"POST /biz_user/export": async (ctx) => { "POST /biz_user/export": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const res = await crud.exportCsv("biz_user", body); const res = await crud.exportCsv("biz_user", body);
ctx.success(res); ctx.success(res);
}, },
"POST /biz_user/revoke_all_tokens": async (ctx) => { "POST /biz_user/revoke_all_tokens": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const userId = body.user_id != null ? body.user_id : body.id; const userId = body.user_id != null ? body.user_id : body.id;
if (userId == null) return ctx.fail("缺少 user_id"); if (userId == null) return ctx.fail("缺少 user_id");
const n = await tokenLogic.revokeAllForUser(userId); const n = await tokenLogic.revokeAllForUser(userId);

View File

@@ -2,15 +2,7 @@ const swagger = require("../../_docs/swagger.json");
const auth = require("../service/biz_auth_verify"); const auth = require("../service/biz_auth_verify");
const proxy = require("../service/biz_proxy_service"); const proxy = require("../service/biz_proxy_service");
function getRequestBody(ctx) {
if (ctx.request && ctx.request.body && Object.keys(ctx.request.body).length > 0) {
return ctx.request.body;
}
if (typeof ctx.getBody === "function") {
return ctx.getBody() || {};
}
return {};
}
/** /**
* 从请求中提取 Token * 从请求中提取 Token
@@ -69,7 +61,7 @@ function buildProxyRoutes() {
api_path: path, api_path: path,
method: method.toUpperCase(), method: method.toUpperCase(),
query, query,
body: getRequestBody(ctx), body: ctx.getBody(),
headers: ctx.headers || {}, headers: ctx.headers || {},
auth_ctx: authResult.context, auth_ctx: authResult.context,
}); });

View File

@@ -1,18 +1,10 @@
const auth = require("../service/biz_auth_verify"); const auth = require("../service/biz_auth_verify");
function getRequestBody(ctx) {
if (ctx.request && ctx.request.body && Object.keys(ctx.request.body).length > 0) {
return ctx.request.body;
}
if (typeof ctx.getBody === "function") {
return ctx.getBody() || {};
}
return {};
}
module.exports = { module.exports = {
"POST /auth/verify": async (ctx) => { "POST /auth/verify": async (ctx) => {
const body = getRequestBody(ctx); const body = ctx.getBody();
const result = await auth.verifyRequest(body); const result = await auth.verifyRequest(body);
ctx.success(result); ctx.success(result);
}, },

View File

@@ -4,15 +4,7 @@
const baseModel = require("../../middleware/baseModel"); const baseModel = require("../../middleware/baseModel");
const { op } = baseModel; const { op } = baseModel;
function getRequestBody(ctx) {
if (ctx.request && ctx.request.body && Object.keys(ctx.request.body).length > 0) {
return ctx.request.body;
}
if (typeof ctx.getBody === "function") {
return ctx.getBody() || {};
}
return {};
}
function getModel(modelName) { function getModel(modelName) {
const m = baseModel[modelName]; const m = baseModel[modelName];