|
@@ -439,4 +439,35 @@ router.post('/subUser/delete', async (ctx) => {
|
|
|
util.fail(ctx, '删除失败,请重试');
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+/**
|
|
|
+ * 平台管理员创建用户账号
|
|
|
+ */
|
|
|
+router.post('/create/account', async (ctx) => {
|
|
|
+ const { userName, userPwd } = ctx.request.body;
|
|
|
+ if (!userName || !userPwd) {
|
|
|
+ util.fail(ctx, '用户名或密码不能为空');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const user = await userService.search(userName);
|
|
|
+ if (user) {
|
|
|
+ util.fail(ctx, '当前用户已存在');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const nickName = userName.split('@')[0];
|
|
|
+ const pwd = new md5().update(userPwd).digest('hex');
|
|
|
+ const res = await userService.create(nickName, userName, pwd);
|
|
|
+ if (res.affectedRows == 1) {
|
|
|
+ const token = util.createToken({ userName, userId: res.insertId });
|
|
|
+
|
|
|
+ util.success(ctx, {
|
|
|
+ userId: res.id,
|
|
|
+ userName,
|
|
|
+ token,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ util.fail(ctx, '创建失败,请稍后重试');
|
|
|
+ }
|
|
|
+});
|
|
|
module.exports = router;
|