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 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 = {
/** 按用户查询调用统计 */
"POST /biz_api_stats/by_user": async (ctx) => {
const body = getRequestBody(ctx);
const body = ctx.getBody();
const { user_id, start_date, end_date } = body;
if (!user_id) {
ctx.fail("缺少 user_id");
@@ -26,7 +18,7 @@ module.exports = {
/** 按接口路径查询调用统计 */
"POST /biz_api_stats/by_api": async (ctx) => {
const body = getRequestBody(ctx);
const body = ctx.getBody();
const { api_path, start_date, end_date } = body;
if (!api_path) {
ctx.fail("缺少 api_path");
@@ -38,7 +30,7 @@ module.exports = {
/** 综合统计面板 */
"POST /biz_api_stats/summary": async (ctx) => {
const body = getRequestBody(ctx);
const body = ctx.getBody();
const { start_date, end_date, top_limit } = body;
const data = await stats.getSummary(start_date, end_date, top_limit || 10);
ctx.success(data);
@@ -46,7 +38,7 @@ module.exports = {
/** 调用日志分页列表(复用通用 CRUD */
"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);
ctx.success({ rows: data.rows, count: data.count });
},

View File

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

View File

@@ -1,19 +1,11 @@
const logic = require("../service/biz_subscription_logic");
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 = {
"POST /biz_payment/confirm-offline": async (ctx) => {
const body = getRequestBody(ctx);
const body = ctx.getBody();
const row = await logic.confirmOfflinePayment(body);
await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx),
@@ -25,7 +17,7 @@ module.exports = {
ctx.success(row);
},
"POST /biz_payment/confirm-link": async (ctx) => {
const body = getRequestBody(ctx);
const body = ctx.getBody();
const row = await logic.confirmLinkPayment(body);
await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx),

View File

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

View File

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

View File

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

View File

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

View File

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