军团:退出后捐献次数保留
This commit is contained in:
@@ -143,23 +143,26 @@ export default class UserGuild extends BaseModel {
|
||||
}
|
||||
|
||||
public static async createUserGuild(guildCode: string, role: RoleType, isLeader: boolean) {
|
||||
const lastGuild = await UserGuildModel.findMyLastGuild(role.roleId);
|
||||
const lastGuild = await UserGuildModel.findMyLastGuild(role.roleId, '+refTimeDaily');
|
||||
let { receiveBoxs = [], donateCnt = 0, receivedActive = [], encourageCnt = 0, bossChallengeCnt = 0, receivedWishPool = [], refTimeDaily, refBossTime } = lastGuild||{};
|
||||
|
||||
|
||||
|
||||
const doc = new UserGuildModel();
|
||||
let job = isLeader? GUILD_JOB.DAJIANGJUN: GUILD_JOB.SHIBING;
|
||||
let auth = isLeader? GUILD_AUTH.LEADER: GUILD_AUTH.MEMBER;
|
||||
const update = Object.assign(doc.toJSON(), { guildCode, roleId: role.roleId, role: role._id, job, auth, receiveBoxs, donateCnt, receivedActive, encourageCnt, bossChallengeCnt, receivedWishPool, refTimeDaily, refBossTime });
|
||||
delete update._id;
|
||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId: role.roleId, guildCode, status: USER_GUILD_STATUS.ON }, update, { upsert: true, new: true })
|
||||
|
||||
const result: UserGuildType = await UserGuildModel.findOneAndUpdate({ roleId: role.roleId, guildCode, status: USER_GUILD_STATUS.ON }, { $set: update }, { upsert: true, new: true })
|
||||
.select('activeDaily activeRecord activeWeekly activeUpdateTime job auth receivedActive guildCode')
|
||||
.lean();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findMyLastGuild(roleId: string) {
|
||||
const userGuild = await UserGuildModel.findOne({ roleId, status: { $ne: USER_GUILD_STATUS.ON } }).sort({ updatedAt: -1 }).lean();
|
||||
public static async findMyLastGuild(roleId: string, select: string) {
|
||||
const userGuild = await UserGuildModel.findOne({ roleId, status: { $ne: USER_GUILD_STATUS.ON } }).select(select).sort({ updatedAt: -1 }).lean();
|
||||
return userGuild;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user