好友:一键申请提示
This commit is contained in:
@@ -37,7 +37,7 @@ export default class FriendApply extends BaseModel {
|
||||
public static async getApplyList(roleId: string) {
|
||||
const list: FriendApplyType[] = await FriendApplyModel.find({ roleId }, { _id: 0 })
|
||||
// .select(select)
|
||||
.populate('friend', ROLE.SHOW_SIMPLE, 'Role')
|
||||
.populate('friend', ROLE.SHOW_FRIEND_APPLY_LIST, 'Role')
|
||||
.lean({ getters: true });
|
||||
return list;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ export default class FriendApply extends BaseModel {
|
||||
public static async getApplyListByCode(applyCodeList: string[]) {
|
||||
const list: FriendApplyType[] = await FriendApplyModel.find({ applyCode: { $in: applyCodeList } }, { _id: 0 })
|
||||
// .select(select)
|
||||
.populate('friend', ROLE.SHOW_SIMPLE, 'Role')
|
||||
.populate('friend', ROLE.SHOW_FRIEND_APPLY_LIST, 'Role')
|
||||
.lean({ getters: true });
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ export default class FriendPoint extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
cnt: number; // 当天获取的点数
|
||||
@prop({ required: true, default: 0 })
|
||||
sendCnt: number; // 当天赠送的点数
|
||||
@prop({ required: true, default: 0 })
|
||||
type: number; // 情谊点统计的类型,不同功能都可能有每日获取上限
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,12 +41,17 @@ export default class FriendRelation extends BaseModel {
|
||||
|
||||
|
||||
// 获取列表
|
||||
public static async findFriendByRole(roleId: string) {
|
||||
const result: FriendRelationType = await FriendRelationModel.findOne({ roleId })
|
||||
.populate('friends.role', ROLE.SHOW_SIMPLE, 'Role')
|
||||
.populate('friends.friendShip', null, 'FriendShip')
|
||||
public static async findFriendByRole(roleId: string, populate = true) {
|
||||
let document = FriendRelationModel.findOne({ roleId })
|
||||
.lean({ getters: true, virtuals: true });
|
||||
|
||||
if (populate) {
|
||||
document
|
||||
.populate('friends.role', ROLE.SHOW_SIMPLE, 'Role')
|
||||
.populate('friends.friendShip', null, 'FriendShip');
|
||||
}
|
||||
|
||||
let result: FriendRelationType = await document;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ export default class FriendShip extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 查询关系
|
||||
public static async deleteAccount(roleId: string) {
|
||||
let result = await FriendShipModel.deleteMany({ $or: [{ roleIdA: roleId }, { roleIdB: roleId }] });
|
||||
return result;
|
||||
|
||||
@@ -222,6 +222,8 @@ export default class Role extends BaseModel {
|
||||
friendCnt: number; // 好友人数
|
||||
@prop({ required: true, default: 0 })
|
||||
blockCnt: number; // 黑名单人数
|
||||
@prop({ required: true, default: 0 })
|
||||
recFrdApplyCnt: number; // 玩家收取好友申请数量
|
||||
|
||||
public static async findAllByUid(uid: number, lean = true) {
|
||||
const role: RoleType[] = await RoleModel.find({ 'userInfo.uid': uid }).select('roleId roleName serverId').lean(lean);
|
||||
@@ -445,11 +447,25 @@ export default class Role extends BaseModel {
|
||||
}
|
||||
|
||||
// 获取好友推荐列表
|
||||
public static async getRecommedList(roleId: string, minLv: number, maxLv: number, time: number) {
|
||||
const result = await RoleModel.find({ loginTime: { $gt: time }, lv: { $gte: minLv, $lte: maxLv }, roleId: { $ne: roleId } }, { _id: 0 })
|
||||
.select(ROLE.SHOW_SIMPLE)
|
||||
public static async getRecommedList(minLv: number, maxLv: number, time: number) {
|
||||
const result = await RoleModel.find({ loginTime: { $gt: time }, lv: { $gte: minLv, $lte: maxLv } }, { _id: 0 })
|
||||
.select(ROLE.SHOW_FRIEND_APPLY_LIST)
|
||||
.sort({quitTime: -1, lv: -1, ce: -1})
|
||||
.limit(100).lean({ getters: true });
|
||||
.limit(200).lean({ getters: true });
|
||||
return result;
|
||||
}
|
||||
|
||||
// 查询玩家
|
||||
public static async searchByNameOrId(value: string) {
|
||||
const result = await RoleModel.find({
|
||||
$or: [
|
||||
{ roleName: { $regex: new RegExp(value.toString(), 'i') } },
|
||||
{ roleId: value }
|
||||
]
|
||||
}, { _id: 0 })
|
||||
.select(ROLE.SHOW_FRIEND_APPLY_LIST)
|
||||
.sort({quitTime: -1, lv: -1, ce: -1})
|
||||
.limit(200).lean({ getters: true });
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -467,7 +483,13 @@ export default class Role extends BaseModel {
|
||||
|
||||
// 增加好友数量
|
||||
public static async increaseFriendCnt(roleId: string, inc: number, max: number) {
|
||||
const result = await RoleModel.findOneAndUpdate({ roleId, friendCnt: {$lt: max}}, {$inc: { friendCnt: inc }}, {new: true}).lean();
|
||||
const result = await RoleModel.findOneAndUpdate({ roleId, friendCnt: {$lte: max - inc}}, {$inc: { friendCnt: inc }}, {new: true}).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
// 增加好友申请数量
|
||||
public static async increaseFriendApplyCnt(roleId: string, inc: number, max: number) {
|
||||
const result = await RoleModel.findOneAndUpdate({ roleId, recFrdApplyCnt: {$lte: max - inc}}, {$inc: { recFrdApplyCnt: inc }}, {new: true}).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user