好友:一键申请提示

This commit is contained in:
luying
2021-02-02 19:47:57 +08:00
parent 5da98956b9
commit 1fb4e7b9be
12 changed files with 245 additions and 37 deletions

View File

@@ -2,6 +2,7 @@
export enum ROLE {
// 玩家列表显示基础数据
SHOW_SIMPLE = 'roleId roleName ce headHid sHid lv title job quitTime vLv guildName',
SHOW_FRIEND_APPLY_LIST = 'roleId roleName ce headHid sHid lv title job quitTime vLv guildName friendCnt recFrdApplyCnt',
HANDLE_APPLY = 'roleId friendCnt lv',
GET_LV = 'lv',

View File

@@ -243,7 +243,8 @@ export const FUNCS_ID = {
}
export const FRIEND_DROP_TYPE = {
COM_BATTLE: 1
COM_BATTLE: 1,
SEND_GIFT: 2
}
// 每日情谊点上限
@@ -362,3 +363,10 @@ export const MAIL_TYPE = {
};
export const CHAT_SERVER = 'chat-server-1';
export enum FRIEND_RELATION_TYPE {
NORMAL = 1,
HAS_FRIEND = 2,
HAS_BLOCKED = 3,
MYSELF = 4
}

View File

@@ -231,7 +231,7 @@ export const STATUS = {
EQUIP_NOT_EQUIPED_HERO: { code: 30509, simStr: '装备不能被该武将穿戴' },
EQUIP_LEVEL_LIMIT: { code: 30510, simStr: '装备穿戴等级限制' },
EQUIP_NOT_MATCH_JEWEL: { code: 30511, simStr: '装备不能镶嵌该宝石' },
//全局养成30600-30799
//全局养成30600-30699
ROLE_REACH_MAX_TITLE_LEVEL: { code: 30600, simStr: '玩家已达到最高的爵位' },
ROLE_TERAPH_NOT_STRENGTHEN: { code: 30601, simStr: '玩家神像不能强化' },
ROLE_TERAPH_NOT_QUILITY: { code: 30602, simStr: '玩家神像不能进阶' },
@@ -241,6 +241,14 @@ export const STATUS = {
ROLE_SCHOOL_POSITION_UNLOCK_NOT_NEED: { code: 30605, simStr: '该位置已解锁' },
ROLE_SCROLL_REACH_MAX: { code: 30606, simStr: '已经升到可以升的最高等级' },
// 好友30700-30799
FRIEND_MY_CNT_MAX: { code: 30700, simStr: '好友数量已达上限' },
FRIEND_THEY_CNT_MAX: { code: 30701, simStr: '玩家好友已满' },
FRIEND_HAS_ADD: { code: 30702, simStr: '该玩家已是您的好友' },
FRIEND_HAS_BLOCKED: { code: 30703, simStr: '该玩家在您的黑名单' },
FRIEND_YOURSELF: { code: 30704, simStr: '不能添加自己为好友' },
FRIEND_HIS_APPLY_MAX: { code: 30705, simStr: '该玩家申请达上限' },
FRIEND_SHIP_CREATE_ERROR: { code: 30706, simStr: '创建失败' },
// 社交相关状态 40000 - 49999

View File

@@ -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;
}

View File

@@ -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; // 情谊点统计的类型,不同功能都可能有每日获取上限
/**

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -21,11 +21,30 @@ export class FriendParams {
}
}
export class FriendRecommendParams extends FriendParams {
friendCnt: number = 0;
recFrdApplyCnt: number = 0;
type: number;
constructor(role: RoleType) {
super(role);
if(role.friendCnt) this.friendCnt = role.friendCnt;
if(role.recFrdApplyCnt) this.recFrdApplyCnt = role.recFrdApplyCnt;
}
setType(type: number) {
this.type = type;
}
}
export class FriendApplyParams extends FriendParams {
applyCode: string;
friendCnt: number = 0;
constructor(applyCode: string, role: RoleType) {
super(role);
this.applyCode = applyCode;
if(role.friendCnt) this.friendCnt = role.friendCnt;
}
}
@@ -35,8 +54,8 @@ export class FriendListParam extends FriendParams {
quitTime: number = 0;
friendValue: number = 0;
friendLv: number = 1;
canReceive: boolean = false;
canSend: boolean = false;
canReceive: boolean = false; // 初始没人送肯定不能领取
canSend: boolean = true; // 初始可以赠送
constructor(role: RoleType, friendship: FriendShipType) {
super(role);

View File

@@ -324,6 +324,10 @@ export function resResult(status: { code: number, simStr: string }, data = null,
return { code, msg: customMsg || simStr, data };
}
export function getResStr(status: { code: number, simStr: string }) {
return status.simStr;
}
// 消除 js 浮点计算bug
export const cal = {