✨ feat(db): 修改role表数据库操作方式
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Application, BackendSession, ChannelService, HandlerService, } from "pinus";
|
||||
import { resResult, getRandEelm, getResStr, shouldRefresh, sortArrRandom, checkRoleIsRobot, getRobotSysType, makeRobotId, parseNumberList } from "../../../pubUtils/util";
|
||||
import { STATUS, ROLE_SELECT, FRIEND_DROP_TYPE, FRIEND_RELATION_TYPE, POPULATE_TYPE, BLOCK_OPEATE, CONSUME_TYPE, ITID, HERO_SELECT, REDIS_KEY, MSG_SOURCE, MSG_TYPE, TASK_TYPE, ROBOT_SYS_TYPE, ITEM_CHANGE_REASON, PUSH_ROUTE } from "../../../consts";
|
||||
import { RoleModel, RoleType } from "../../../db/Role";
|
||||
import Role, { RoleType } from "../../../db/Role";
|
||||
import { getTimeFun, getZeroPointD } from "../../../pubUtils/timeUtil";
|
||||
import { FriendApplyModel } from "../../../db/FriendApply";
|
||||
import { FriendListParam, FriendRecommendParams, BlackListParam, FriendValueListParam, HeroDetailParam } from "../../../domain/roleField/friend";
|
||||
@@ -50,10 +50,10 @@ export class FriendHandler {
|
||||
|
||||
const day = <number>getTimeFun().getBeforeHour(FRIEND.FRIEND_RECONMMEND_ACTIVETIME);
|
||||
|
||||
const { lv, serverId: myServerId } = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_MY_SERVER);
|
||||
const { lv, serverId: myServerId } = await Role.findByRoleId(roleId, ROLE_SELECT.GET_MY_SERVER);
|
||||
let nums = parseNumberList(FRIEND.FRIEND_RECONMMEND_LEVEL);
|
||||
let max = Math.max(...nums);
|
||||
let allList = await RoleModel.getRecommedList(lv - max, lv + max, day);
|
||||
let allList = await Role.getRecommedList(lv - max, lv + max, day);
|
||||
let sortedNum = nums.sort((a, b) => a - b);
|
||||
for(let num of sortedNum) {
|
||||
allList = allList.filter(cur => cur.lv >= lv - num && cur.lv <= lv + num);
|
||||
@@ -116,7 +116,7 @@ export class FriendHandler {
|
||||
let roleId: string = session.get('roleId');
|
||||
|
||||
let { value } = msg;
|
||||
let allList = await RoleModel.searchByNameOrId(value);
|
||||
let allList = await Role.searchByNameOrId(value);
|
||||
let myFriendRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.NOT);
|
||||
|
||||
let list = new Array<FriendRecommendParams>();
|
||||
@@ -140,7 +140,7 @@ export class FriendHandler {
|
||||
let roleId: string = session.get('roleId');
|
||||
let roleIds = msg.roleIds;
|
||||
|
||||
const role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_ROLE_ID);
|
||||
const role = await Role.findByRoleId(roleId, ROLE_SELECT.GET_ROLE_ID);
|
||||
let myFriendRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.NOT);
|
||||
|
||||
let str = '', resultRoleIds = new Array<string>();
|
||||
@@ -156,7 +156,7 @@ export class FriendHandler {
|
||||
let hisRelation = await FriendRelationModel.findFriendByRole(hisRoleId, POPULATE_TYPE.NOT);
|
||||
let hisType = getRecommendType(hisRelation, hisRoleId, roleId);
|
||||
if(hisType == FRIEND_RELATION_TYPE.NORMAL) {
|
||||
let incResult = await RoleModel.increaseFriendApplyCnt(hisRoleId, 1, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
let incResult = await Role.increaseFriendApplyCnt(hisRoleId, 1, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
if (!incResult) {
|
||||
str = getResStr(STATUS.FRIEND_HIS_APPLY_MAX); continue;
|
||||
}
|
||||
@@ -197,7 +197,7 @@ export class FriendHandler {
|
||||
|
||||
let { applyCodeList, isPass } = msg;
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let role = await Role.findByRoleId(roleId);
|
||||
let roles = new Array<RoleType>();
|
||||
let friendCnt = role.friendCnt;
|
||||
|
||||
@@ -258,7 +258,7 @@ export class FriendHandler {
|
||||
}
|
||||
|
||||
let deleteCount = await FriendApplyModel.deleteApply(resultApplyCodeList);
|
||||
role = await RoleModel.increaseFriendApplyCnt(roleId, -1 * deleteCount, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
role = await Role.increaseFriendApplyCnt(roleId, -1 * deleteCount, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
roles.push(role);
|
||||
// 任务
|
||||
await checkTaskWithRoles(roleId, sid, TASK_TYPE.FRIEND_NUM, roles);
|
||||
@@ -279,7 +279,7 @@ export class FriendHandler {
|
||||
public async getFriendList(msg: {}, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let role = await Role.findByRoleId(roleId);
|
||||
let res = await getFriendList(role);
|
||||
|
||||
return resResult(STATUS.SUCCESS, res);
|
||||
@@ -289,7 +289,7 @@ export class FriendHandler {
|
||||
public async getBlackList(msg: {}, session: BackendSession) {
|
||||
let roleId: string = session.get('roleId');
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let role = await Role.findByRoleId(roleId);
|
||||
let list = new Array<BlackListParam>();
|
||||
let myRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.BLACKLIST);
|
||||
let blacklist = myRelation ? myRelation.blacklist : [];
|
||||
@@ -327,7 +327,7 @@ export class FriendHandler {
|
||||
const serverId = session.get('serverId');
|
||||
let { roleId: hisRoleId, type } = msg;
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let role = await Role.findByRoleId(roleId);
|
||||
let friend: RoleType;
|
||||
|
||||
let str = '', list = new Array<BlackListParam>(), frdRoleIds = new Array<string>(), blackRoleIds = new Array<string>();
|
||||
@@ -341,11 +341,11 @@ export class FriendHandler {
|
||||
return resResult(STATUS.FRIEND_BLACK_HAS_ADD);
|
||||
}
|
||||
|
||||
role = await RoleModel.increaseBlockCnt(roleId, 1, curFriend ? -1 : 0, FRIEND.FRIEND_BLACKLIST_MAX); // 增加黑名单人数
|
||||
role = await Role.increaseBlockCnt(roleId, 1, curFriend ? -1 : 0, FRIEND.FRIEND_BLACKLIST_MAX); // 增加黑名单人数
|
||||
if (!role) {
|
||||
return resResult(STATUS.FRIEND_BLACK_MAX)
|
||||
}
|
||||
friend = await RoleModel.increaseFriendCnt(hisRoleId, curFriend ? -1 : 0); // 对方好友减少
|
||||
friend = await Role.increaseFriendCnt(hisRoleId, curFriend ? -1 : 0); // 对方好友减少
|
||||
|
||||
let friendShip: FriendShipType;
|
||||
if (!!curFriend) {
|
||||
@@ -359,8 +359,8 @@ export class FriendHandler {
|
||||
await delPrivateMsg(roleId, hisRoleId);
|
||||
|
||||
let { myRecApplyCount, hisRecApplyCount } = await FriendApplyModel.deleteApplyByRoles(roleId, hisRoleId); // 删除双方的申请
|
||||
if(myRecApplyCount > 0) await RoleModel.increaseFriendApplyCnt(roleId, -1 * myRecApplyCount, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
if(hisRecApplyCount > 0) await RoleModel.increaseFriendApplyCnt(roleId, -1 * hisRecApplyCount, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
if(myRecApplyCount > 0) await Role.increaseFriendApplyCnt(roleId, -1 * myRecApplyCount, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
if(hisRecApplyCount > 0) await Role.increaseFriendApplyCnt(roleId, -1 * hisRecApplyCount, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
|
||||
let param = new BlackListParam(friend);
|
||||
let { isOnline, sid } = await getRoleOnlineInfo(friend.roleId);
|
||||
@@ -388,11 +388,11 @@ export class FriendHandler {
|
||||
return resResult(STATUS.FRIEND_NOT_FOUND);
|
||||
}
|
||||
|
||||
role = await RoleModel.increaseFriendCnt(roleId, -1); // 减少好友
|
||||
role = await Role.increaseFriendCnt(roleId, -1); // 减少好友
|
||||
if (!role) {
|
||||
return resResult(STATUS.FRIEND_NOT_FOUND)
|
||||
}
|
||||
friend = await RoleModel.increaseFriendCnt(hisRoleId, -1); // 对方好友减少
|
||||
friend = await Role.increaseFriendCnt(hisRoleId, -1); // 对方好友减少
|
||||
|
||||
let friendShip: FriendShipType;
|
||||
|
||||
@@ -413,7 +413,7 @@ export class FriendHandler {
|
||||
return resResult(STATUS.FRIEND_BLACK_NOT_FOUND);
|
||||
}
|
||||
|
||||
role = await RoleModel.increaseBlockCnt(roleId, -1, 0, 100); // 黑名单人数减
|
||||
role = await Role.increaseBlockCnt(roleId, -1, 0, 100); // 黑名单人数减
|
||||
if (!role) {
|
||||
return resResult(STATUS.FRIEND_BLACK_MAX)
|
||||
}
|
||||
@@ -421,14 +421,14 @@ export class FriendHandler {
|
||||
|
||||
if (type == BLOCK_OPEATE.REMOVE_AND_APPLY) {
|
||||
// 申请好友
|
||||
friend = await RoleModel.increaseFriendApplyCnt(hisRoleId, 1, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
friend = await Role.increaseFriendApplyCnt(hisRoleId, 1, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
if (!friend) {
|
||||
str = getResStr(STATUS.FRIEND_HIS_APPLY_MAX);
|
||||
} else {
|
||||
let hisRelation = await FriendRelationModel.findFriendByRole(hisRoleId, POPULATE_TYPE.NOT);
|
||||
let hisType = getRecommendType(hisRelation, hisRoleId, roleId);
|
||||
if(hisType == FRIEND_RELATION_TYPE.NORMAL) {
|
||||
let incResult = await RoleModel.increaseFriendApplyCnt(hisRoleId, 1, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
let incResult = await Role.increaseFriendApplyCnt(hisRoleId, 1, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||
if (incResult) {
|
||||
let apply = await FriendApplyModel.createApply(hisRoleId, role);
|
||||
let hisOnlineInfo = await getRoleOnlineInfo(hisRoleId);
|
||||
@@ -482,7 +482,7 @@ export class FriendHandler {
|
||||
}
|
||||
let canSendList = await sortByBeSentHeart(roleId, arr);
|
||||
|
||||
let { lv } = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_LV);
|
||||
let { lv } = await Role.findByRoleId(roleId, ROLE_SELECT.GET_LV);
|
||||
let dicFriendLv = getDicFriendByLv(lv);
|
||||
if (!dicFriendLv) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
@@ -552,7 +552,7 @@ export class FriendHandler {
|
||||
}
|
||||
let canReceiveList = await sortByBeSentHeart(roleId, arr);
|
||||
|
||||
let { lv } = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_LV);
|
||||
let { lv } = await Role.findByRoleId(roleId, ROLE_SELECT.GET_LV);
|
||||
let dicFriendLv = getDicFriendByLv(lv);
|
||||
if (!dicFriendLv) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
@@ -648,7 +648,7 @@ export class FriendHandler {
|
||||
let { roleId: targetRoleId } = msg;
|
||||
let isRobot = checkRoleIsRobot(targetRoleId);
|
||||
if(isRobot) {
|
||||
let role = await RoleModel.findByRoleId(roleId, null, true);
|
||||
let role = await Role.findByRoleId(roleId, null, true);
|
||||
let sysType = getRobotSysType(targetRoleId);
|
||||
let addObj: any = { roleId: makeRobotId(''), roleName: '', guildName: '' };
|
||||
if(sysType == ROBOT_SYS_TYPE.COM_BTL) {
|
||||
@@ -666,7 +666,7 @@ export class FriendHandler {
|
||||
return resResult(STATUS.SUCCESS, {...param, isRobot });
|
||||
} else {
|
||||
|
||||
let role = await RoleModel.findByRoleId(targetRoleId, null, true);
|
||||
let role = await Role.findByRoleId(targetRoleId, null, true);
|
||||
let myFriendRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.NOT);
|
||||
|
||||
let type = getRecommendType(myFriendRelation, roleId, role.roleId);
|
||||
@@ -689,7 +689,7 @@ export class FriendHandler {
|
||||
let result: PlayerDetail;
|
||||
|
||||
let dbHeroes = await HeroModel.findAndSortByCe(oppoRoleId);
|
||||
let role = await RoleModel.findByRoleId(oppoRoleId, null, true);
|
||||
let role = await Role.findByRoleId(oppoRoleId, null, true);
|
||||
if(!role) return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
|
||||
let { topLineupCe, towerLv, showLineup } = role;
|
||||
@@ -731,7 +731,7 @@ export class FriendHandler {
|
||||
|
||||
let { roleId: hisRoleId, hids } = msg;
|
||||
|
||||
let role = await RoleModel.findByRoleId(hisRoleId, 'title');
|
||||
let role = await Role.findByRoleId(hisRoleId, 'title');
|
||||
if (!role) return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
|
||||
let roleCe = await RoleCeModel.findByRoleId(hisRoleId);
|
||||
|
||||
Reference in New Issue
Block a user