diff --git a/gm-server/app/controller/users.ts b/gm-server/app/controller/users.ts index ceefc96c5..0010b32af 100644 --- a/gm-server/app/controller/users.ts +++ b/gm-server/app/controller/users.ts @@ -16,6 +16,12 @@ export default class UserController extends Controller { ctx.body = await ctx.service.users.createRole(uid, serverId, roleName); } + public async deleteRole() { + const { ctx } = this; + const { roleId } = ctx.request.body; + ctx.body = await ctx.service.users.deleteRole(roleId); + } + public async getrolelist() { const { ctx } = this; const { field, value } = ctx.request.body; diff --git a/gm-server/app/router.ts b/gm-server/app/router.ts index 2860f9c9e..f7d551a33 100644 --- a/gm-server/app/router.ts +++ b/gm-server/app/router.ts @@ -25,6 +25,7 @@ export default (app: Application) => { router.post('/api/users/getuserlist',tokenParser, controller.users.getuserlist); router.post('/api/users/createrole',tokenParser, controller.users.createRole); + router.post('/api/users/deleterole',tokenParser, controller.users.deleteRole); router.post('/api/users/getrolelist',tokenParser, controller.users.getrolelist); router.post('/api/users/createroledata',tokenParser, controller.users.createRoleData); diff --git a/gm-server/app/service/users.ts b/gm-server/app/service/users.ts index 2836489bb..ea92b5a9b 100644 --- a/gm-server/app/service/users.ts +++ b/gm-server/app/service/users.ts @@ -4,6 +4,22 @@ import { HeroModel } from '@db/Hero'; import { EquipModel } from '@db/Equip'; import { ItemModel } from '@db/Item'; import { CounterModel } from '@db/Counter'; +import { ActionPointModel } from '@db/ActionPoint'; +import { BattleDropModel } from '@db/BattleDrop'; +import { BattleRecordModel } from '@db/BattleRecord'; +import { BattleSweepRecordModel } from '@db/BattleSweepRecord'; +import { DailyRecordModel } from '@db/DailyRecord'; +import { EventRecordModel } from '@db/EventRecord'; +import { ExpeditionPointModel } from '@db/ExpeditionPoint'; +import { ExpeditionRecordModel } from '@db/ExpeditionRecord'; +import { ExpeditionWarRecordModel } from '@db/ExpeditionWarRecord'; +import { HangUpRecordModel } from '@db/HangUpRecord'; +import { HangUpSpdUpRecModel } from '@db/HangUpSpdUpRec'; +import { HeroSoulModel } from '@db/HeroSoul'; +import { ScriptItemModel } from '@db/ScriptItem'; +import { SearchRecordModel } from '@db/SearchRecord'; +import { TowerRecordModel } from '@db/TowerRecord'; +import { TowerTaskRecModel } from '@db/TowerTaskRec'; import { Service } from 'egg'; import Counter from '@db/Counter'; @@ -75,6 +91,34 @@ export default class GMUsers extends Service { } } + public async deleteRole(roleId: string) { + console.log('enter Auth deleteRole'); + const ctx = this.ctx; + await ActionPointModel.deleteAccount(roleId); + await BattleDropModel.deleteAccount(roleId); + await BattleRecordModel.deleteAccount(roleId); + await BattleSweepRecordModel.deleteAccount(roleId); + await DailyRecordModel.deleteAccount(roleId); + await EquipModel.deleteAccount(roleId); + await EventRecordModel.deleteAccount(roleId); + await ExpeditionPointModel.deleteAccount(roleId); + await ExpeditionRecordModel.deleteAccount(roleId); + await ExpeditionWarRecordModel.deleteAccount(roleId); + await HangUpSpdUpRecModel.deleteAccount(roleId); + await HangUpRecordModel.deleteAccount(roleId); + await HeroModel.deleteAccount(roleId); + await HeroSoulModel.deleteAccount(roleId); + await ItemModel.deleteAccount(roleId); + await RoleModel.deleteAccount(roleId); + await ScriptItemModel.deleteAccount(roleId); + await SearchRecordModel.deleteAccount(roleId); + await TowerTaskRecModel.deleteAccount(roleId); + await TowerRecordModel.deleteAccount(roleId); + + return ctx.service.utils.resResult(STATUS.SUCCESS); + } + + /** * 根据类型等搜索玩家 diff --git a/shared/db/ActionPoint.ts b/shared/db/ActionPoint.ts index 281e22d5e..65e05bdf7 100644 --- a/shared/db/ActionPoint.ts +++ b/shared/db/ActionPoint.ts @@ -27,6 +27,11 @@ export default class ActionPoint extends BaseModel { let result = await ActionPointModel.findOneAndUpdate({roleId}, { ap, refTime }, {upsert: true, new: true}).lean(lean); return result||{}; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await ActionPointModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const ActionPointModel = getModelForClass(ActionPoint); diff --git a/shared/db/BattleDrop.ts b/shared/db/BattleDrop.ts index ff69f09e8..0629fcd57 100644 --- a/shared/db/BattleDrop.ts +++ b/shared/db/BattleDrop.ts @@ -33,6 +33,11 @@ export default class BattleDrop extends BaseModel { const result = await BattleDropModel.findOneAndUpdate({roleId, battleId, gid}, {$set: params}).lean(lean); return result; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await BattleDropModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const BattleDropModel = getModelForClass(BattleDrop); diff --git a/shared/db/BattleRecord.ts b/shared/db/BattleRecord.ts index bc9334186..ff94db890 100644 --- a/shared/db/BattleRecord.ts +++ b/shared/db/BattleRecord.ts @@ -72,6 +72,10 @@ export default class BattleRecord extends BaseModel { return result; } + public static async deleteAccount(roleId: string, lean = true) { + let result = await BattleRecordModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const BattleRecordModel = getModelForClass(BattleRecord); diff --git a/shared/db/BattleSweepRecord.ts b/shared/db/BattleSweepRecord.ts index a3d9b0aa1..42ff8d79c 100644 --- a/shared/db/BattleSweepRecord.ts +++ b/shared/db/BattleSweepRecord.ts @@ -27,6 +27,10 @@ export default class BattleSweepRecord extends BaseModel { return result; } + public static async deleteAccount(roleId: string, lean = true) { + let result = await BattleSweepRecordModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const BattleSweepRecordModel = getModelForClass(BattleSweepRecord); diff --git a/shared/db/DailyRecord.ts b/shared/db/DailyRecord.ts index 29382cdc6..91913244c 100644 --- a/shared/db/DailyRecord.ts +++ b/shared/db/DailyRecord.ts @@ -38,6 +38,11 @@ export default class DailyRecord extends BaseModel { const result = await DailyRecordModel.findOneAndUpdate({ roleId, type }, {$inc: { count } }, {new: true, upsert: true}).lean(lean); return result; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await DailyRecordModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const DailyRecordModel = getModelForClass(DailyRecord); diff --git a/shared/db/Equip.ts b/shared/db/Equip.ts index 2b1e9d2bd..e87d62add 100644 --- a/shared/db/Equip.ts +++ b/shared/db/Equip.ts @@ -57,6 +57,11 @@ export default class Equip extends BaseModel { const equip = await EquipModel.findOneAndUpdate({ _id: equipId }, {hid}, {new: true}).lean(lean); return equip; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await EquipModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const EquipModel = getModelForClass(Equip); diff --git a/shared/db/EventRecord.ts b/shared/db/EventRecord.ts index 0c22f3b18..ede6e949f 100644 --- a/shared/db/EventRecord.ts +++ b/shared/db/EventRecord.ts @@ -85,6 +85,10 @@ export default class EventRecord extends BaseModel { return result; } + public static async deleteAccount(roleId: string, lean = true) { + let result = await EventRecordModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const EventRecordModel = getModelForClass(EventRecord); diff --git a/shared/db/ExpeditionPoint.ts b/shared/db/ExpeditionPoint.ts index 7d67cb52a..8381949e0 100644 --- a/shared/db/ExpeditionPoint.ts +++ b/shared/db/ExpeditionPoint.ts @@ -38,6 +38,11 @@ export default class ExpeditionPoint extends BaseModel { ).lean(lean); return result; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await ExpeditionPointModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const ExpeditionPointModel = getModelForClass(ExpeditionPoint); diff --git a/shared/db/ExpeditionRecord.ts b/shared/db/ExpeditionRecord.ts index 49af7752c..723c756a0 100644 --- a/shared/db/ExpeditionRecord.ts +++ b/shared/db/ExpeditionRecord.ts @@ -70,6 +70,11 @@ export default class ExpeditionRecord extends BaseModel { return result; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await ExpeditionRecordModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const ExpeditionRecordModel = getModelForClass(ExpeditionRecord); diff --git a/shared/db/ExpeditionWarRecord.ts b/shared/db/ExpeditionWarRecord.ts index a321974de..482a1c9bf 100644 --- a/shared/db/ExpeditionWarRecord.ts +++ b/shared/db/ExpeditionWarRecord.ts @@ -111,6 +111,11 @@ export default class ExpeditionWarRecord extends BaseModel { const result = await ExpeditionWarRecordModel.findOneAndUpdate({ expeditionCode, expeditionId }, {received, reward}, {new: true}).lean(lean); return result; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await ExpeditionWarRecordModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const ExpeditionWarRecordModel = getModelForClass(ExpeditionWarRecord); diff --git a/shared/db/HangUpRecord.ts b/shared/db/HangUpRecord.ts index 554b3fc6a..1dbe81c3f 100644 --- a/shared/db/HangUpRecord.ts +++ b/shared/db/HangUpRecord.ts @@ -49,6 +49,11 @@ export default class HangUpRecord extends BaseModel { const newRec = await HangUpRecordModel.findOneAndUpdate({roleId, startLv: endLv}, update, {upsert: true, new: true}).lean(lean); return newRec; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await HangUpRecordModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const HangUpRecordModel = getModelForClass(HangUpRecord); diff --git a/shared/db/HangUpSpdUpRec.ts b/shared/db/HangUpSpdUpRec.ts index 5f39e60d8..61a425845 100644 --- a/shared/db/HangUpSpdUpRec.ts +++ b/shared/db/HangUpSpdUpRec.ts @@ -24,6 +24,11 @@ export default class HangUpSpdUpRec extends BaseModel { return rec; } + public static async deleteAccount(roleId: string, lean = true) { + let result = await HangUpSpdUpRecModel.deleteMany({roleId}).lean(lean); + return result||{}; + } + } export const HangUpSpdUpRecModel = getModelForClass(HangUpSpdUpRec); diff --git a/shared/db/Hero.ts b/shared/db/Hero.ts index d9abbcd73..612981c77 100644 --- a/shared/db/Hero.ts +++ b/shared/db/Hero.ts @@ -92,6 +92,12 @@ export default class Hero extends BaseModel { ]); return ce[0].ce; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await HeroModel.deleteMany({roleId}).lean(lean); + return result||{}; + } + } export const HeroModel = getModelForClass(Hero); diff --git a/shared/db/HeroSoul.ts b/shared/db/HeroSoul.ts index cb61467b2..96b18d690 100644 --- a/shared/db/HeroSoul.ts +++ b/shared/db/HeroSoul.ts @@ -46,6 +46,10 @@ export default class HeroSoul extends BaseModel { return item; } + public static async deleteAccount(roleId: string, lean = true) { + let result = await HeroSoulModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const HeroSoulModel = getModelForClass(HeroSoul); diff --git a/shared/db/Item.ts b/shared/db/Item.ts index 51f737441..94c359a68 100644 --- a/shared/db/Item.ts +++ b/shared/db/Item.ts @@ -44,6 +44,10 @@ export default class Item extends BaseModel { return item; } + public static async deleteAccount(roleId: string, lean = true) { + let result = await ItemModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const ItemModel = getModelForClass(Item); diff --git a/shared/db/Role.ts b/shared/db/Role.ts index f0337b5d6..41a35f25c 100644 --- a/shared/db/Role.ts +++ b/shared/db/Role.ts @@ -176,6 +176,11 @@ export default class Role extends BaseModel { let role = await RoleModel.findOneAndUpdate({roleId}, {$set: { exp, lv }}, {new: true}).lean(lean); return role; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await RoleModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const RoleModel = getModelForClass(Role); diff --git a/shared/db/ScriptItem.ts b/shared/db/ScriptItem.ts index e98f44704..1bd8c9d1c 100644 --- a/shared/db/ScriptItem.ts +++ b/shared/db/ScriptItem.ts @@ -44,6 +44,11 @@ export default class ScriptItem extends BaseModel { return item; } + public static async deleteAccount(roleId: string, lean = true) { + let result = await ScriptItemModel.deleteMany({roleId}).lean(lean); + return result||{}; + } + } export const ScriptItemModel = getModelForClass(ScriptItem); diff --git a/shared/db/SearchRecord.ts b/shared/db/SearchRecord.ts index 2862de057..63c08377e 100644 --- a/shared/db/SearchRecord.ts +++ b/shared/db/SearchRecord.ts @@ -26,6 +26,12 @@ export default class SearchRecord extends BaseModel { batchCode: string; // 本批派遣任务唯一标识 @prop({ required: true, default: [] }) tasks: Array; + + + public static async deleteAccount(roleId: string, lean = true) { + let result = await SearchRecordModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const SearchRecordModel = getModelForClass(SearchRecord); diff --git a/shared/db/TowerRecord.ts b/shared/db/TowerRecord.ts index 1aebfc237..9c7cf88ac 100644 --- a/shared/db/TowerRecord.ts +++ b/shared/db/TowerRecord.ts @@ -72,6 +72,12 @@ export default class TowerRecord extends BaseModel { {new: true}).lean(lean); return rec; } + + + public static async deleteAccount(roleId: string, lean = true) { + let result = await TowerRecordModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const TowerRecordModel = getModelForClass(TowerRecord); diff --git a/shared/db/TowerTaskRec.ts b/shared/db/TowerTaskRec.ts index 180d1417b..a3391c159 100644 --- a/shared/db/TowerTaskRec.ts +++ b/shared/db/TowerTaskRec.ts @@ -94,6 +94,11 @@ export default class TowerTaskRec extends BaseModel { } return recs; } + + public static async deleteAccount(roleId: string, lean = true) { + let result = await TowerTaskRecModel.deleteMany({roleId}).lean(lean); + return result||{}; + } } export const TowerTaskRecModel = getModelForClass(TowerTaskRec);