2026-05-31 01:41:33 +08:00
|
|
|
import { ALL, Body, Controller, Inject, Post, Provide } from "@midwayjs/core";
|
|
|
|
|
import { BaseController, PlusService, SysInstallInfo, SysSettingsService } from "@certd/lib-server";
|
2026-07-12 02:29:54 +08:00
|
|
|
import { AuditType } from "../../../modules/sys/enterprise/service/audit-constants.js";
|
2024-09-23 01:52:42 +08:00
|
|
|
|
|
|
|
|
export type PreBindUserReq = {
|
|
|
|
|
userId: number;
|
|
|
|
|
};
|
2024-09-23 13:33:46 +08:00
|
|
|
export type BindUserReq = {
|
|
|
|
|
userId: number;
|
|
|
|
|
};
|
2024-09-23 01:52:42 +08:00
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
@Provide()
|
2026-05-31 01:41:33 +08:00
|
|
|
@Controller("/api/sys/account")
|
2024-09-23 01:52:42 +08:00
|
|
|
export class BasicController extends BaseController {
|
|
|
|
|
@Inject()
|
|
|
|
|
plusService: PlusService;
|
|
|
|
|
|
|
|
|
|
@Inject()
|
|
|
|
|
sysSettingsService: SysSettingsService;
|
|
|
|
|
|
2026-07-12 02:29:54 +08:00
|
|
|
getAuditType(): string {
|
|
|
|
|
return AuditType.account;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post("/preBindUser", { description: "sys:settings:edit", summary: "预绑定用户" })
|
2024-09-23 01:52:42 +08:00
|
|
|
public async preBindUser(@Body(ALL) body: PreBindUserReq) {
|
2026-03-04 23:15:48 +08:00
|
|
|
if (body.userId == null || body.userId <= 0) {
|
|
|
|
|
throw new Error("用户ID不能为空");
|
|
|
|
|
}
|
2024-11-07 02:22:14 +08:00
|
|
|
await this.plusService.userPreBind(body.userId);
|
2026-07-12 02:29:54 +08:00
|
|
|
await this.auditLog({ content: `预绑定了用户(ID:${body.userId})` });
|
2024-09-23 01:52:42 +08:00
|
|
|
return this.ok({});
|
|
|
|
|
}
|
2024-09-23 13:33:46 +08:00
|
|
|
|
2026-07-12 02:29:54 +08:00
|
|
|
@Post("/bindUser", { description: "sys:settings:edit", summary: "绑定用户" })
|
2024-09-23 13:33:46 +08:00
|
|
|
public async bindUser(@Body(ALL) body: BindUserReq) {
|
2026-03-04 23:15:48 +08:00
|
|
|
if (body.userId == null || body.userId <= 0) {
|
|
|
|
|
throw new Error("用户ID不能为空");
|
|
|
|
|
}
|
2024-09-23 13:33:46 +08:00
|
|
|
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
|
|
|
|
installInfo.bindUserId = body.userId;
|
|
|
|
|
await this.sysSettingsService.saveSetting(installInfo);
|
2026-07-12 02:29:54 +08:00
|
|
|
await this.auditLog({ content: `绑定了用户(ID:${body.userId})` });
|
2024-09-23 13:33:46 +08:00
|
|
|
return this.ok({});
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-12 02:29:54 +08:00
|
|
|
@Post("/unbindUser", { description: "sys:settings:edit", summary: "解绑用户" })
|
2024-09-23 13:33:46 +08:00
|
|
|
public async unbindUser() {
|
|
|
|
|
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
|
|
|
|
installInfo.bindUserId = null;
|
|
|
|
|
await this.sysSettingsService.saveSetting(installInfo);
|
2026-07-12 02:29:54 +08:00
|
|
|
await this.auditLog({ content: "解绑了用户" });
|
2024-09-23 13:33:46 +08:00
|
|
|
return this.ok({});
|
|
|
|
|
}
|
2024-09-23 14:04:33 +08:00
|
|
|
|
2026-07-12 02:29:54 +08:00
|
|
|
@Post("/updateLicense", { description: "sys:settings:edit", summary: "更新许可证" })
|
2024-09-23 14:04:33 +08:00
|
|
|
public async updateLicense(@Body(ALL) body: { license: string }) {
|
2024-09-24 11:11:08 +08:00
|
|
|
await this.plusService.updateLicense(body.license);
|
2026-07-12 02:29:54 +08:00
|
|
|
await this.auditLog({ content: "更新了许可证" });
|
2024-09-23 14:04:33 +08:00
|
|
|
return this.ok(true);
|
|
|
|
|
}
|
2024-09-23 01:52:42 +08:00
|
|
|
}
|