Merge branch 'master' of gitlab.trgame.cn:zyztech/zyz_server
This commit is contained in:
@@ -32,9 +32,12 @@ export enum USER_GUILD_SELECT {
|
||||
}
|
||||
|
||||
export enum GUILD_SELECT {
|
||||
ENTRY = 'guildCode lv memberCnt'
|
||||
// 初始登录
|
||||
ENTRY = 'guildCode lv memberCnt',
|
||||
// 获得邀请列表
|
||||
INVITED_MEMBER = '_id code isMemberMax +invitedMembers +inviteTime'
|
||||
}
|
||||
|
||||
export enum FRIEND_SHIP_SELECT {
|
||||
GET_FRIEND_VALUE = 'friendValue friendLv'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ export enum DATA_NAME {
|
||||
GUILD = 'Guild',
|
||||
GUILD_REFINE = 'GuildRefine',
|
||||
GUILD_ASSIST_REFINE = 'GuildAssistRefine',
|
||||
UP_STRUCTURE = 'GuildStructure',
|
||||
JOIN_GUILD = 'JoinGuild',
|
||||
REFRESH_ACTIVE = 'GuildRefActive',
|
||||
WEEKLY_GUILD_SUM = 'WeeklyGuildSum', // 每周结算活跃和奖励
|
||||
|
||||
@@ -42,6 +42,13 @@ export default class FriendApply extends BaseModel {
|
||||
return list;
|
||||
}
|
||||
|
||||
// 获取自己发出的申请列表
|
||||
public static async getSentApplyList(roleId: string, time: Date) {
|
||||
const list: FriendApplyType[] = await FriendApplyModel.find({ frdRoleId: roleId, updatedAt: { $gt: time } }, { _id: 0 })
|
||||
.lean({ getters: true });
|
||||
return list;
|
||||
}
|
||||
|
||||
// 根据applyCode获得申请
|
||||
public static async getApplyListByCode(applyCodeList: string[]) {
|
||||
const list: FriendApplyType[] = await FriendApplyModel.find({ applyCode: { $in: applyCodeList } }, { _id: 0 })
|
||||
|
||||
@@ -2,9 +2,10 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
|
||||
import Role, { RoleType } from './Role';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE } from '../consts';
|
||||
import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE, GUILD_SELECT } from '../consts';
|
||||
import { getCurWeekTime, nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { reduceCe } from '../pubUtils/util';
|
||||
import { now } from 'underscore';
|
||||
|
||||
class Structure {
|
||||
@prop({ required: true })
|
||||
@@ -71,13 +72,18 @@ export default class Guild extends BaseModel {
|
||||
guildCe: number; // 总战力
|
||||
|
||||
@prop({ required: true, type: String, default: [], select: false })
|
||||
members: string[]; // 军团成员的roleId,用于增加战力的时候加入总战力
|
||||
members: string[]; // 军团成员的roleId,用于增加战力的时候加入总战力
|
||||
|
||||
@prop({ required: true, type: String, default: [], select: false })
|
||||
invitedMembers: string[]; // 今天已邀请的玩家
|
||||
@prop({ required: true, default: new Date(), select: false })
|
||||
inviteTime: Date; // 今天已邀请的玩家
|
||||
|
||||
@prop({ required: true, type: Structure, default: getInitStructure(), _id: false })
|
||||
structure: Structure[]
|
||||
|
||||
@prop({ required: true, default: GUILD_STATUS.RUNNING, enum: GUILD_STATUS })
|
||||
status: number;
|
||||
status: number; // 军团状态
|
||||
|
||||
@prop({ required: true, default: 1, select: false })
|
||||
serverId: number; // 分服
|
||||
@@ -182,12 +188,12 @@ export default class Guild extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async upStructure(code: string, id: number, select?: string) {
|
||||
public static async upStructure(code: string, id: number, cost: number, select?: string) {
|
||||
if (id == GUILD_STRUCTURE.ARMY_CENTER) {
|
||||
const result: GuildType = await GuildModel.findOneAndUpdate({ code, 'structure.id': id }, { $inc: { 'structure.$.lv': 1, lv: 1 }, $set: { isMemberMax: false } }, { new: true }).select(select).lean();
|
||||
const result: GuildType = await GuildModel.findOneAndUpdate({ code, 'structure.id': id, fund: { $gte: cost } }, { $inc: { 'structure.$.lv': 1, lv: 1, fund: -1 * cost }, $set: { isMemberMax: false } }, { new: true }).select(select).lean();
|
||||
return result;
|
||||
} else {
|
||||
const result: GuildType = await GuildModel.findOneAndUpdate({ code, 'structure.id': id }, { $inc: { 'structure.$.lv': 1 } }, { new: true }).select(select).lean();
|
||||
const result: GuildType = await GuildModel.findOneAndUpdate({ code, 'structure.id': id, fund: { $gte: cost } }, { $inc: { 'structure.$.lv': 1, fund: -1 * cost } }, { new: true }).select(select).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -212,6 +218,21 @@ export default class Guild extends BaseModel {
|
||||
const result = await GuildModel.findOneAndUpdate({ code, status: GUILD_STATUS.RUNNING, serverId, resetTrainTime:{$ne:time}},{$set: {trainId: 1, resetTrainTime: time, trainLv}}, {new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 记录已邀请过的人
|
||||
public static async recordInvitedMember(code: string, serverId: number, roleIds: string[], shouldRefresh: boolean) {
|
||||
let result: GuildType;
|
||||
if(shouldRefresh) {
|
||||
result = await GuildModel.findOneAndUpdate( { code, serverId }, { $set: { invitedMembers: roleIds, inviteTime: new Date() }}, { new: true})
|
||||
.select(GUILD_SELECT.INVITED_MEMBER)
|
||||
.lean();
|
||||
} else {
|
||||
result = await GuildModel.findOneAndUpdate( { code, serverId }, { $push: { invitedMembers: { $each: roleIds } }, $set: { inviteTime: new Date() }}, { new: true})
|
||||
.select(GUILD_SELECT.INVITED_MEMBER)
|
||||
.lean();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const GuildModel = getModelForClass(Guild);
|
||||
|
||||
@@ -27,7 +27,7 @@ export default class GuildRec extends BaseModel {
|
||||
|
||||
public static async createGuildRec(roleId: string, guildCode: string, type: number, params: string[]) {
|
||||
const doc = new GuildRecModel();
|
||||
const update = Object.assign(doc.toJSON(), { roleId, guildCode, type, params });
|
||||
const update = Object.assign(doc.toJSON(), { roleId, guildCode, type, params, createTime: nowSeconds() });
|
||||
delete update._id;
|
||||
const recCode = genCode(10);
|
||||
const result: GuildRecType = await GuildRecModel.findOneAndUpdate({ recCode }, update, { upsert: true, new: true }).lean();
|
||||
|
||||
@@ -439,10 +439,15 @@ export default class Role extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取未加入公会且登录时间在三天内的人
|
||||
/**
|
||||
* 获取未加入公会且登录时间在三天内的人
|
||||
* @param time
|
||||
* @param serverId
|
||||
* @param invitedMembers 当天已邀请过的人
|
||||
*/
|
||||
public static async getInviteList(time: number, serverId: number) {
|
||||
const result = await RoleModel.find({ loginTime: { $gt: time }, hasGuild: false, serverId })
|
||||
.select('roleId roleName ce headHid sHid lv title job quitTime')
|
||||
.select({roleId: 1, roleName: 1,ce: 1,headHid: 1,sHid: 1,lv: 1,title: 1,job: 1,quitTime: 1, _id: 0})
|
||||
.sort({quitTime: -1, lv: -1, ce: -1})
|
||||
.limit(100).lean({getters: true});
|
||||
return result;
|
||||
|
||||
@@ -46,8 +46,8 @@ export default class UserGuildApply extends BaseModel {
|
||||
}
|
||||
|
||||
// 根据唯一code批量删除
|
||||
public static async deleteApplyByApplyCode(applyCodeList: string[]) {
|
||||
const result = await UserGuildApplyModel.deleteMany({ applyCode: { $in: applyCodeList}, type: GUILD_APPLY_TYPE.APPLY });
|
||||
public static async deleteByApplyCode(applyCodeList: string[]) {
|
||||
const result = await UserGuildApplyModel.deleteMany({ applyCode: { $in: applyCodeList} });
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ export default class UserGuildApply extends BaseModel {
|
||||
}
|
||||
|
||||
// 查询公会收到的申请
|
||||
public static async getListByGuild(code: string, lastApplyCode: string) {
|
||||
public static async findApplyByGuild(code: string, lastApplyCode: string) {
|
||||
let condition = { guildCode: code, type: GUILD_APPLY_TYPE.APPLY };
|
||||
if(lastApplyCode) {
|
||||
const lastApply = await this.findByCode(lastApplyCode);
|
||||
@@ -85,7 +85,7 @@ export default class UserGuildApply extends BaseModel {
|
||||
}
|
||||
|
||||
// 查询玩家的邀请列表
|
||||
public static async getListByRole(roleId: string, lastApplyCode: string) {
|
||||
public static async findInviteByRole(roleId: string, lastApplyCode: string) {
|
||||
let condition = { roleId, type: GUILD_APPLY_TYPE.INVITE };
|
||||
if(lastApplyCode) {
|
||||
const lastApply = await this.findByCode(lastApplyCode);
|
||||
|
||||
@@ -20,7 +20,7 @@ let arr = JSON.parse(str);
|
||||
export const dicGuildActiveDayReward = new Map<number, DicGuildActiveDayReward>();
|
||||
|
||||
arr.forEach(o => {
|
||||
o.reward = parseGoodStr(o.reward)
|
||||
o.reward = parseGoodStr(o.Reward)
|
||||
dicGuildActiveDayReward.set(o.id, o);
|
||||
});
|
||||
arr = undefined;
|
||||
@@ -293,6 +293,15 @@ export function getRandEelm(source: Array<any> = [], cnt = 1): Array<any> {
|
||||
return source.filter((_item, idx) => idxs.has(idx));
|
||||
}
|
||||
|
||||
/**
|
||||
* 不改变原数组长度,将内部元素打乱
|
||||
* @param source
|
||||
*/
|
||||
export function sortArrRandom(source = []) {
|
||||
let arr = deepCopy(source);
|
||||
return arr.sort(() => { return Math.random()-0.5; });
|
||||
}
|
||||
|
||||
/**
|
||||
* 在给定数值的浮动范围中随机一个值
|
||||
* @param base 基础数值
|
||||
|
||||
Reference in New Issue
Block a user