init
This commit is contained in:
15
api/controller_admin/biz_audit_log.js
Normal file
15
api/controller_admin/biz_audit_log.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const crud = require("../service/biz_admin_crud");
|
||||
const { getRequestBody } = crud;
|
||||
|
||||
module.exports = {
|
||||
"POST /biz_audit_log/page": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
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 res = await crud.exportCsv("biz_audit_log", body);
|
||||
ctx.success(res);
|
||||
},
|
||||
};
|
||||
8
api/controller_admin/biz_dashboard.js
Normal file
8
api/controller_admin/biz_dashboard.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const dashboard = require("../service/biz_dashboard_service");
|
||||
|
||||
module.exports = {
|
||||
"GET /biz_dashboard/summary": async (ctx) => {
|
||||
const data = await dashboard.summary();
|
||||
ctx.success(data);
|
||||
},
|
||||
};
|
||||
24
api/controller_admin/biz_payment.js
Normal file
24
api/controller_admin/biz_payment.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const logic = require("../service/biz_subscription_logic");
|
||||
|
||||
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 row = await logic.confirmOfflinePayment(body);
|
||||
ctx.success(row);
|
||||
},
|
||||
"POST /biz_payment/confirm-link": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const row = await logic.confirmLinkPayment(body);
|
||||
ctx.success(row);
|
||||
},
|
||||
};
|
||||
77
api/controller_admin/biz_plan.js
Normal file
77
api/controller_admin/biz_plan.js
Normal file
@@ -0,0 +1,77 @@
|
||||
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 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 row = await crud.add("biz_plan", body);
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
action: "biz_plan.add",
|
||||
resource_type: "biz_plan",
|
||||
resource_id: row.id,
|
||||
detail: { plan_code: row.plan_code },
|
||||
});
|
||||
ctx.success(row);
|
||||
},
|
||||
"POST /biz_plan/edit": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
await crud.edit("biz_plan", body);
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
action: "biz_plan.edit",
|
||||
resource_type: "biz_plan",
|
||||
resource_id: body.id,
|
||||
});
|
||||
ctx.success({});
|
||||
},
|
||||
"POST /biz_plan/del": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
await crud.del("biz_plan", body);
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
action: "biz_plan.del",
|
||||
resource_type: "biz_plan",
|
||||
resource_id: body.id,
|
||||
});
|
||||
ctx.success({});
|
||||
},
|
||||
"GET /biz_plan/detail": async (ctx) => {
|
||||
const q = ctx.query || {};
|
||||
const row = await crud.detail("biz_plan", { id: q.id || q.ID });
|
||||
ctx.success(row);
|
||||
},
|
||||
"GET /biz_plan/all": async (ctx) => {
|
||||
const rows = await crud.all("biz_plan");
|
||||
ctx.success(rows);
|
||||
},
|
||||
"POST /biz_plan/toggle": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const id = body.id;
|
||||
if (id == null) return ctx.fail("缺少 id");
|
||||
const row = await baseModel.biz_plan.findByPk(id);
|
||||
if (!row) return ctx.fail("套餐不存在");
|
||||
const next = row.status === "active" ? "inactive" : "active";
|
||||
await row.update({ status: next });
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
action: "biz_plan.toggle",
|
||||
resource_type: "biz_plan",
|
||||
resource_id: id,
|
||||
detail: { status: next },
|
||||
});
|
||||
ctx.success({ status: next });
|
||||
},
|
||||
"POST /biz_plan/export": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const res = await crud.exportCsv("biz_plan", body);
|
||||
ctx.success(res);
|
||||
},
|
||||
};
|
||||
56
api/controller_admin/biz_subscription.js
Normal file
56
api/controller_admin/biz_subscription.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const crud = require("../service/biz_admin_crud");
|
||||
const baseModel = require("../../middleware/baseModel");
|
||||
const logic = require("../service/biz_subscription_logic");
|
||||
|
||||
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_subscription/page": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const data = await crud.page("biz_subscription", body);
|
||||
ctx.success({ rows: data.rows, count: data.count });
|
||||
},
|
||||
"GET /biz_subscription/detail": async (ctx) => {
|
||||
const q = ctx.query || {};
|
||||
const row = await crud.detail("biz_subscription", { id: q.id || q.ID });
|
||||
ctx.success(row);
|
||||
},
|
||||
"GET /biz_subscription/by_user": async (ctx) => {
|
||||
const q = ctx.query || {};
|
||||
const user_id = q.user_id || q.userId;
|
||||
if (!user_id) return ctx.fail("缺少 user_id");
|
||||
const rows = await baseModel.biz_subscription.findAll({
|
||||
where: { user_id },
|
||||
order: [["id", "DESC"]],
|
||||
});
|
||||
ctx.success(rows);
|
||||
},
|
||||
"POST /biz_subscription/open": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const row = await logic.openSubscription(body);
|
||||
ctx.success(row);
|
||||
},
|
||||
"POST /biz_subscription/upgrade": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const row = await logic.upgradeSubscription(body);
|
||||
ctx.success(row);
|
||||
},
|
||||
"POST /biz_subscription/renew": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const row = await logic.renewSubscription(body);
|
||||
ctx.success(row);
|
||||
},
|
||||
"POST /biz_subscription/cancel": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const row = await logic.cancelSubscription(body);
|
||||
ctx.success(row);
|
||||
},
|
||||
};
|
||||
34
api/controller_admin/biz_token.js
Normal file
34
api/controller_admin/biz_token.js
Normal file
@@ -0,0 +1,34 @@
|
||||
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 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 result = await tokenLogic.createToken(body);
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: result.row.user_id,
|
||||
action: "biz_token.create",
|
||||
resource_type: "biz_api_token",
|
||||
resource_id: result.row.id,
|
||||
detail: { token_name: result.row.token_name },
|
||||
});
|
||||
ctx.success({
|
||||
id: result.row.id,
|
||||
user_id: result.row.user_id,
|
||||
plan_id: result.row.plan_id,
|
||||
token_name: result.row.token_name,
|
||||
expire_at: result.row.expire_at,
|
||||
plain_token: result.plain_token,
|
||||
warn: result.warn,
|
||||
});
|
||||
},
|
||||
"POST /biz_token/revoke": async (ctx) => {
|
||||
const body = getRequestBody(ct
|
||||
35
api/controller_admin/biz_usage.js
Normal file
35
api/controller_admin/biz_usage.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const crud = require("../service/biz_admin_crud");
|
||||
const { getRequestBody } = crud;
|
||||
|
||||
module.exports = {
|
||||
"POST /biz_usage/page": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
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 row = await crud.add("biz_usage_monthly", body);
|
||||
ctx.success(row);
|
||||
},
|
||||
"POST /biz_usage/edit": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
await crud.edit("biz_usage_monthly", body);
|
||||
ctx.success({});
|
||||
},
|
||||
"POST /biz_usage/del": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
await crud.del("biz_usage_monthly", body);
|
||||
ctx.success({});
|
||||
},
|
||||
"GET /biz_usage/detail": async (ctx) => {
|
||||
const q = ctx.query || {};
|
||||
const row = await crud.detail("biz_usage_monthly", { id: q.id || q.ID });
|
||||
ctx.success(row);
|
||||
},
|
||||
"POST /biz_usage/export": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const res = await crud.exportCsv("biz_usage_monthly", body);
|
||||
ctx.success(res);
|
||||
},
|
||||
};
|
||||
109
api/controller_admin/biz_user.js
Normal file
109
api/controller_admin/biz_user.js
Normal file
@@ -0,0 +1,109 @@
|
||||
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 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 row = await crud.add("biz_user", body);
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: row.id,
|
||||
action: "biz_user.add",
|
||||
resource_type: "biz_user",
|
||||
resource_id: row.id,
|
||||
detail: { name: row.name },
|
||||
});
|
||||
ctx.success(row);
|
||||
},
|
||||
"POST /biz_user/edit": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
await crud.edit("biz_user", body);
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: body.id,
|
||||
action: "biz_user.edit",
|
||||
resource_type: "biz_user",
|
||||
resource_id: body.id,
|
||||
});
|
||||
ctx.success({});
|
||||
},
|
||||
"POST /biz_user/del": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
await crud.del("biz_user", body);
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: body.id,
|
||||
action: "biz_user.del",
|
||||
resource_type: "biz_user",
|
||||
resource_id: body.id,
|
||||
});
|
||||
ctx.success({});
|
||||
},
|
||||
"GET /biz_user/detail": async (ctx) => {
|
||||
const q = ctx.query || {};
|
||||
const id = q.id || q.ID;
|
||||
const user = await crud.detail("biz_user", { id });
|
||||
if (!user) {
|
||||
return ctx.fail("用户不存在");
|
||||
}
|
||||
const subscriptions = await baseModel.biz_subscription.findAll({
|
||||
where: { user_id: id },
|
||||
order: [["id", "DESC"]],
|
||||
limit: 10,
|
||||
});
|
||||
const tokenCount = await baseModel.biz_api_token.count({
|
||||
where: { user_id: id },
|
||||
});
|
||||
ctx.success({
|
||||
user,
|
||||
subscriptions,
|
||||
tokenCount,
|
||||
});
|
||||
},
|
||||
"GET /biz_user/all": async (ctx) => {
|
||||
const rows = await crud.all("biz_user");
|
||||
ctx.success(rows);
|
||||
},
|
||||
"POST /biz_user/disable": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const id = body.id;
|
||||
if (id == null) return ctx.fail("缺少 id");
|
||||
await baseModel.biz_user.update({ status: "disabled" }, { where: { id } });
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: id,
|
||||
action: "biz_user.disable",
|
||||
resource_type: "biz_user",
|
||||
resource_id: id,
|
||||
});
|
||||
ctx.success({});
|
||||
},
|
||||
"POST /biz_user/export": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
const res = await crud.exportCsv("biz_user", body);
|
||||
ctx.success(res);
|
||||
},
|
||||
"POST /biz_user/revoke_all_tokens": async (ctx) => {
|
||||
const body = getRequestBody(ctx);
|
||||
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);
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: userId,
|
||||
action: "biz_token.revoke_all",
|
||||
resource_type: "biz_user",
|
||||
resource_id: userId,
|
||||
detail: { affected: n },
|
||||
});
|
||||
ctx.success({ revoked: n });
|
||||
},
|
||||
};
|
||||
49
api/controller_admin/sys_file.js
Normal file
49
api/controller_admin/sys_file.js
Normal file
@@ -0,0 +1,49 @@
|
||||
var UUID = require("uuid");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
const ossTool = require("../service/ossTool");
|
||||
const funTool = require("../../tool/funTool");
|
||||
|
||||
module.exports = {
|
||||
"POST /sys_file/upload_img": async (ctx, next) => {
|
||||
const files = ctx.request.files; // 获取上传文件
|
||||
let fileArray = [];
|
||||
let rootPath = path.join(__dirname, "../../upload/imgs");
|
||||
for (var key in files) {
|
||||
fileArray.push(files[key]);
|
||||
}
|
||||
|
||||
//创建文件夹
|
||||
await funTool.mkdirsSync(rootPath);
|
||||
|
||||
let resArray = [];
|
||||
fileArray.forEach((file) => {
|
||||
// 创建可读流
|
||||
const reader = fs.createReadStream(file.path);
|
||||
|
||||
let filePath = `/${UUID.v1() + "_" + file.name}`;
|
||||
// 创建可写流
|
||||
const upStream = fs.createWriteStream(path.join(rootPath, filePath));
|
||||
// 可读流通过管道写入可写流
|
||||
|
||||
reader.pipe(upStream);
|
||||
|
||||
resArray.push({ name: file.name, path: path.join("/imgs", filePath) });
|
||||
});
|
||||
|
||||
ctx.success(resArray);
|
||||
},
|
||||
"POST /sys_file/upload_oos_img": async (ctx, next) => {
|
||||
let fileArray = [];
|
||||
const files = ctx.request.files; // 获取上传文件
|
||||
for (var key in files) {
|
||||
fileArray.push(files[key]);
|
||||
}
|
||||
let data = await ossTool.putImg(fileArray[0]);
|
||||
if (data.path) {
|
||||
return ctx.success(data);
|
||||
} else {
|
||||
return ctx.fail();
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user