后台:权限
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { GMUserModel } from '@db/GMUser';
|
||||
import { GMGroupModel } from '@db/GMGroup';
|
||||
import { GMUserGroupModel } from '@db/GMUserGroup';
|
||||
import { ApiModel } from '@db/Api';
|
||||
import { Service } from 'egg';
|
||||
import { STATUS } from '@consts';
|
||||
import { gameData } from '@pubUtils/data';
|
||||
|
||||
/**
|
||||
* Test Service
|
||||
@@ -24,9 +24,9 @@ export default class GMUsers extends Service {
|
||||
if(!user) {
|
||||
return ctx.service.utils.resResult(STATUS.GM_ERR_PASSWORD);
|
||||
}
|
||||
let userGroups = await GMUserGroupModel.getUserGroupByUid(user.uid, 1);
|
||||
let userGroup = await GMUserGroupModel.getUserGroupByUid(user.uid);
|
||||
let group = new Array();
|
||||
for(let userGroup of userGroups) {
|
||||
if(userGroup) {
|
||||
let g = await GMGroupModel.getGroupById(userGroup.groupId);
|
||||
if(g) group.push(g.group);
|
||||
}
|
||||
@@ -42,8 +42,15 @@ export default class GMUsers extends Service {
|
||||
|
||||
public async currentUser() {
|
||||
const {ctx} = this;
|
||||
console.log('*****', ctx.user)
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {user: ctx.user});
|
||||
let user = ctx.user;
|
||||
let userGroup = await GMUserGroupModel.getUserGroupByUid(user.uid);
|
||||
let group = new Array();
|
||||
if(userGroup) {
|
||||
let g = await GMGroupModel.getGroupById(userGroup.groupId);
|
||||
if(g) group.push(g.group);
|
||||
}
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { user: ctx.user, group });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,23 +73,23 @@ export default class GMUsers extends Service {
|
||||
* 后台账号列表
|
||||
*/
|
||||
public async getGmList() {
|
||||
// const {ctx} = this;
|
||||
let list = await GMUserModel.getGmAccountList();
|
||||
if(list) {
|
||||
let result = new Array();
|
||||
for(let user of list) {
|
||||
let uid = user.uid;
|
||||
let userGroupList = await GMUserGroupModel.getUserGroupByUid(uid, 1);
|
||||
let groupArr = new Array(), groupStrArr = new Array();
|
||||
for(let userGroup of userGroupList) {
|
||||
let userGroup = await GMUserGroupModel.getUserGroupByUid(uid);
|
||||
let groupId = 0, groupStr = '暂无', envs = [];
|
||||
if(userGroup) {
|
||||
let group = await GMGroupModel.getGroupById(userGroup.groupId);
|
||||
console.log(userGroup.groupId, group);
|
||||
if(group) {
|
||||
groupArr.push(userGroup.groupId);
|
||||
groupStrArr.push(group.name);
|
||||
groupId = userGroup.groupId;
|
||||
envs = userGroup.envs
|
||||
groupStr = group.name;
|
||||
}
|
||||
}
|
||||
result.push({...user, group:groupArr, groupStr: groupStrArr.length?groupStrArr.join():'暂无'});
|
||||
result.push({...user, group: groupId, groupStr, env: envs});
|
||||
}
|
||||
|
||||
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
@@ -115,7 +122,10 @@ export default class GMUsers extends Service {
|
||||
*/
|
||||
public async getApiList() {
|
||||
const {ctx} = this;
|
||||
let list = await ApiModel.getAllApi();
|
||||
let list = [];
|
||||
for(let [_, obj] of gameData.apiByUrl) {
|
||||
list.push(obj);
|
||||
}
|
||||
|
||||
if(list) {
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
@@ -126,25 +136,6 @@ export default class GMUsers extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Api
|
||||
*/
|
||||
public async saveApi(api:string, name:string) {
|
||||
const {ctx} = this;
|
||||
let result = await ApiModel.getApi(api);
|
||||
if(result) {
|
||||
return ctx.service.utils.resResult(STATUS.GM_DUPLICATE_API);
|
||||
} else {
|
||||
let result = await ApiModel.createApi(api, name);
|
||||
if(result) {
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
} else {
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 后台用户组列表
|
||||
*/
|
||||
@@ -207,32 +198,9 @@ export default class GMUsers extends Service {
|
||||
/**
|
||||
* 用户组添加接口
|
||||
*/
|
||||
public async saveGmGroupToUser(uid: number, groups: Array<number>) {
|
||||
let allUserGroup = await GMUserGroupModel.getUserGroupByUid(uid, 1);
|
||||
public async saveGmGroupToUser(uid: number, groupId: number, envs: string[]) {
|
||||
|
||||
let removeArr = allUserGroup.filter(userGroup => {
|
||||
let gid = userGroup.groupId;
|
||||
return groups.indexOf(gid) == -1;
|
||||
}).map(cur => cur.groupId);
|
||||
|
||||
let flag = 0;
|
||||
let result = await GMUserGroupModel.removeUserGroup(uid, 1, removeArr);
|
||||
if(!result) {
|
||||
flag = 1;
|
||||
}
|
||||
|
||||
if(!flag) {
|
||||
for(let group of groups) {
|
||||
let result = await GMUserGroupModel.addUserGroup(uid, 1, group);
|
||||
if(!result) {
|
||||
flag = 1; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(flag) {
|
||||
return this.ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
}
|
||||
await GMUserGroupModel.addUserGroup(uid, groupId, envs);
|
||||
return this.ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user