好友:拉黑
This commit is contained in:
@@ -41,20 +41,42 @@ export default class FriendRelation extends BaseModel {
|
||||
|
||||
|
||||
// 获取列表
|
||||
public static async findFriendByRole(roleId: string, populate = true) {
|
||||
public static async findFriendByRole(roleId: string, populateType: number) {
|
||||
let document = FriendRelationModel.findOne({ roleId })
|
||||
.lean({ getters: true, virtuals: true });
|
||||
|
||||
if (populate) {
|
||||
if (populateType == 1) {
|
||||
document
|
||||
.populate('friends.role', ROLE.SHOW_SIMPLE, 'Role')
|
||||
.populate('friends.friendShip', null, 'FriendShip');
|
||||
} else if (populateType == 2) {
|
||||
document
|
||||
.populate('blacklist.role', ROLE.SHOW_SIMPLE, 'Role')
|
||||
}
|
||||
|
||||
let result: FriendRelationType = await document;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async moveFromFriend(roleId: string, friend: RoleType, friendShip: FriendShipType, toBlack: boolean ) {
|
||||
let update = {
|
||||
$pull: { friends: { roleId: friend.roleId } }
|
||||
}
|
||||
if(toBlack) {
|
||||
update['$push'] = { blacklist: { roleId: friend.roleId, role: friend._id, friendShip: friendShip? friendShip._id: null } };
|
||||
}
|
||||
|
||||
let result: FriendRelationType = await FriendRelationModel.findOneAndUpdate({ roleId }, update, { new: true });
|
||||
return result
|
||||
}
|
||||
|
||||
public static async removeFromBlack(roleId: string, frdRoleId: string ) {
|
||||
let result: FriendRelationType = await FriendRelationModel.findOneAndUpdate({ roleId }, {
|
||||
$pull: { blacklist: { roleId: frdRoleId } }
|
||||
}, { new: true });
|
||||
return result
|
||||
}
|
||||
|
||||
public static async deleteAccount(roleId: string) {
|
||||
let result = await FriendRelationModel.deleteMany({ roleId });
|
||||
await FriendRelationModel.updateMany({}, { $pull: { friends: { roleId }, blacklist: { roleId } }});
|
||||
|
||||
@@ -69,16 +69,24 @@ export default class FriendShip extends BaseModel {
|
||||
public static async createFriendShip(roleIdList: string[]) {
|
||||
if (roleIdList.length != 2) return false;
|
||||
let { roleIdA, roleIdB, roleIds } = this.getRoleIds(roleIdList);
|
||||
console.log(roleIdA, roleIdB, roleIds)
|
||||
|
||||
const doc = new FriendShipModel();
|
||||
const update = Object.assign(doc.toJSON(), { roleIdA, roleIdB, roleIds });
|
||||
|
||||
const result: FriendShipType = await FriendShipModel.findOneAndUpdate({ roleIds }, update, { upsert: true, new: true }).lean();
|
||||
const result: FriendShipType = await FriendShipModel.findOneAndUpdate({ roleIds }, { $setOnInsert: update }, { upsert: true, new: true }).lean();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 清空亲密度
|
||||
public static async clearValue(roleIdList: string[]) {
|
||||
if (roleIdList.length != 2) return false;
|
||||
let { roleIds } = this.getRoleIds(roleIdList);
|
||||
|
||||
const result: FriendShipType = await FriendShipModel.findOneAndUpdate({ roleIds }, { $set: { friendValue: 0 } }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
// 查询关系
|
||||
public static async deleteAccount(roleId: string) {
|
||||
let result = await FriendShipModel.deleteMany({ $or: [{ roleIdA: roleId }, { roleIdB: roleId }] });
|
||||
|
||||
@@ -353,6 +353,7 @@ export default class Role extends BaseModel {
|
||||
const role: RoleType = await RoleModel.findOneAndUpdate({roleId}, {$inc: {towerTaskCnt: num}}, {new: true}).lean(lean);
|
||||
return role;
|
||||
}
|
||||
|
||||
// 派遣任务增加刷新次数
|
||||
public static async increaseTowerRefCnt(roleId: string, num: number, lean = true) {
|
||||
const role: RoleType = await RoleModel.findOneAndUpdate({roleId}, {$inc: {towerTaskReCnt: num}}, {new: true}).lean(lean);
|
||||
@@ -482,8 +483,12 @@ export default class Role extends BaseModel {
|
||||
}
|
||||
|
||||
// 增加好友数量
|
||||
public static async increaseFriendCnt(roleId: string, inc: number, max: number) {
|
||||
const result = await RoleModel.findOneAndUpdate({ roleId, friendCnt: {$lte: max - inc}}, {$inc: { friendCnt: inc }}, {new: true}).lean();
|
||||
public static async increaseFriendCnt(roleId: string, inc: number, max?: number) {
|
||||
let condition = { roleId };
|
||||
if(max) {
|
||||
condition['friendCnt'] = {$lte: max - inc};
|
||||
}
|
||||
const result = await RoleModel.findOneAndUpdate(condition, {$inc: { friendCnt: inc }}, {new: true}).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -492,6 +497,12 @@ export default class Role extends BaseModel {
|
||||
const result = await RoleModel.findOneAndUpdate({ roleId, recFrdApplyCnt: {$lte: max - inc}}, {$inc: { recFrdApplyCnt: inc }}, {new: true}).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
// 增加黑名单数量
|
||||
public static async increaseBlockCnt(roleId: string, blockCnt: number, friendCnt: number, maxBlockCnt: number) {
|
||||
const result = await RoleModel.findOneAndUpdate({ roleId, blockCnt: {$lte: maxBlockCnt - blockCnt}}, {$inc: { blockCnt, friendCnt }}, {new: true}).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const RoleModel = getModelForClass(Role);
|
||||
|
||||
Reference in New Issue
Block a user