This commit is contained in:
张成
2026-04-01 10:37:51 +08:00
parent 494555a6e1
commit 7199c6b5cf
10 changed files with 187 additions and 17 deletions

View File

@@ -1,5 +1,4 @@
const crud = require("../service/biz_admin_crud");
const baseModel = require("../../middleware/baseModel");
const audit = require("../service/biz_audit_service");

View File

@@ -1,3 +1,4 @@
const Sequelize = require("sequelize");
const crud = require("../service/biz_admin_crud");
const baseModel = require("../../middleware/baseModel");
@@ -7,8 +8,31 @@ const audit = require("../service/biz_audit_service");
module.exports = {
"POST /biz_user/page": async (ctx) => {
const body = ctx.getBody();
const data = await crud.page("biz_user", body);
ctx.success({ rows: data.rows, count: data.count });
const param = body.param || body;
const pageOption = param.pageOption || {};
const seachOption = param.seachOption || {};
const pageNum = parseInt(pageOption.page, 10) || 1;
const pageSize = parseInt(pageOption.pageSize, 10) || 20;
const offset = (pageNum - 1) * pageSize;
const model = baseModel.biz_user;
const where = crud.buildSearchWhere(model, seachOption);
const { count, rows } = await model.findAndCountAll({
where,
offset,
limit: pageSize,
order: [["id", "DESC"]],
attributes: {
include: [
[
Sequelize.literal(
`(SELECT COUNT(*) FROM biz_api_tokens WHERE biz_api_tokens.user_id = biz_user.id)`
),
"token_count",
],
],
},
});
ctx.success({ rows, count });
},
"POST /biz_user/add": async (ctx) => {
const body = ctx.getBody();
@@ -62,10 +86,17 @@ module.exports = {
const tokenCount = await baseModel.biz_api_token.count({
where: { user_id: id },
});
const tokens = await baseModel.biz_api_token.findAll({
where: { user_id: id },
order: [["id", "DESC"]],
limit: 200,
attributes: ["id", "user_id", "plan_id", "token_name", "status", "expire_at", "last_used_at"],
});
ctx.success({
user,
subscriptions,
tokenCount,
tokens,
});
},
"GET /biz_user/all": async (ctx) => {