军团:修改个人功勋→个人活跃

This commit is contained in:
luying
2021-01-25 09:43:03 +08:00
parent bb2f17089e
commit c4a106745b
11 changed files with 130 additions and 53 deletions
@@ -1,8 +1,8 @@
import { Application, BackendSession, pinus, ChannelService } from 'pinus';
import { resResult, getRandEelm, reduceCe } from '../../../pubUtils/util';
import { resResult, getRandEelm, reduceCe, getRefTime } from '../../../pubUtils/util';
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE, GUILD_STRUCTURE, GUILD_REC_TYPE, GUILD_STRUCTURE_NAME, MAIL_TYPE } from '../../../consts';
import { UserGuildModel } from '../../../db/UserGuild';
import { checkAuth, joinGuild, getGuildWithRefActive, getUserGuildWithRefActive, addGuildActive, message } from '../../../services/guildService';
import { checkAuth, joinGuild, getGuildWithRefActive, getUserGuildWithRefActive, addGuildActive, message, settleGuildWeekly } from '../../../services/guildService';
import { GuildModel, GuildType } from '../../../db/Guild';
import { RoleModel, RoleType } from '../../../db/Role';
import { ARMY } from '../../../pubUtils/dicParam';
@@ -227,7 +227,7 @@ export class GuildHandler {
const serverId = session.get('serverId');
const sid = session.get('sid');
let userGuild = await getUserGuildWithRefActive(roleId, 'honour job auth guildCode receivedActive');
let userGuild = await getUserGuildWithRefActive(roleId, 'job auth guildCode receivedActive activeRecord activeDaily activeWeekly');
if(!userGuild) {
return resResult(STATUS.SUCCESS, { hasGuild: false })
};
@@ -495,7 +495,7 @@ export class GuildHandler {
let select = ['role', 'job'];
const checkDetailResult = await checkAuth(GUILD_OPERATE.GET_MEMBER_LIST_DETAIL, roleId, code);
if(checkDetailResult) {
select.push('auth', 'honourWeekly honourUpdateTime');
select.push('auth', 'activeWeekly activeUpdateTime');
}
let list = await UserGuildModel.getListByGuild(code, select.join(' '), { auth: 1 });
console.log('**', JSON.stringify(list))
@@ -508,11 +508,11 @@ export class GuildHandler {
let leader = result.shift();
result.sort((a, b) => {
if(sort == 'honour') {
if(b.honourWeekly == a.honourWeekly) {
return a.honourUpdateTime - b.honourUpdateTime
if(sort == 'active') {
if(b.activeWeekly == a.activeWeekly) {
return a.activeUpdateTime - b.activeUpdateTime
} else {
return b.honourWeekly - a.honourWeekly
return b.activeWeekly - a.activeWeekly
}
} else if (sort == 'loginTime') {
return b.loginTime - a.loginTime;
@@ -640,7 +640,7 @@ export class GuildHandler {
return resResult(STATUS.GUILD_LEADER_LOGIN);
}
// 上周周功勋最高的人
const topUserGuild = await UserGuildModel.findTopHonour(code, 'auth role roleId');
const topUserGuild = await UserGuildModel.findTopActive(code, 'auth role roleId');
if (!topUserGuild) {
return resResult(STATUS.GUILD_MEMBER_NOT_FOUND);
}
@@ -740,7 +740,8 @@ export class GuildHandler {
const checkResult = await checkAuth(GUILD_OPERATE.GET_REC, roleId, code);
if (!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
const list = await GuildRecModel.getGuildRec(code);
let startTime = getRefTime(new Date(), 0, -3);
const list = await GuildRecModel.getGuildRec(code, startTime.getTime());
return resResult(STATUS.SUCCESS, { list });
}
@@ -826,16 +827,33 @@ export class GuildHandler {
// debug接口: 添加公会活跃值
async debugAddActive(msg: { code: string, active: number }, session: BackendSession) {
async debugAddActive(msg: { code: string, active: number, id: number }, session: BackendSession) {
const roleId = session.get('roleId');
const serverId = session.get('serverId');
const { code, active } = msg;
const { code, active, id } = msg;
const guild = await addGuildActive(code, serverId, active);
if(!guild) return resResult(STATUS.GUILD_NOT_FOUND);
let userGuild = await UserGuildModel.getMyGuild(roleId, 'activeRecord receivedActive');
let {activeRecord} = userGuild;
let curActiveRecord = activeRecord.find(cur => cur.id == id);
if( curActiveRecord ) {
curActiveRecord.count ++;
} else {
activeRecord.push({id, count: 1});
}
userGuild = await UserGuildModel.updateInfo(roleId, { activeRecord, activeDaily: userGuild.activeDaily + active, activeWeekly: userGuild.activeWeekly + active})
let { activeDaily, activeWeekly } = guild;
return resResult(STATUS.SUCCESS, { activeDaily, activeWeekly });
return resResult(STATUS.SUCCESS, { activeDaily, activeWeekly, myInfo: userGuild });
}
// debug接口: 调用定时任务
async debugWeeklyRask(msg: { }, session: BackendSession) {
await settleGuildWeekly();
return resResult(STATUS.SUCCESS);
}
}
+64 -9
View File
@@ -1,7 +1,7 @@
import { gameData } from "../pubUtils/data";
import { gameData, getGuildActiveWeekReward } from "../pubUtils/data";
import { GuildModel, GuildType } from "../db/Guild";
import { resResult, shouldRefreshWeek, shouldRefresh } from "../pubUtils/util";
import { STATUS, GUILD_OPERATE, MAIL_TYPE } from "../consts";
import { STATUS, GUILD_OPERATE, MAIL_TYPE, GUILD_AUTH, GUILD_JOB } from "../consts";
import { RoleModel, RoleType } from "../db/Role";
import { UserGuildModel, UserGuildType } from "../db/UserGuild";
import { UserGuildApplyModel } from "../db/UserGuildApply";
@@ -12,6 +12,8 @@ import { GuildRecType } from "../db/GuildRec";
import { MailModel } from "../db/Mail";
import { RewardInter } from "../pubUtils/interface";
import { getRedis } from "./redisService";
import { ARMY } from "../pubUtils/dicParam";
import { sendMail } from "./mailService";
/**
* @description 检查该玩家是否有权限做操作
@@ -121,14 +123,14 @@ export async function addGuildActive(guildCode: string, serverId: number, active
export async function getUserGuildWithRefActive(roleId: string, select: string) {
let userGuild = await UserGuildModel.getMyGuild(roleId, select? select + ' +refTimeDaily': '+refTimeDaily');
if(!userGuild) return false;
let { receivedActive, refTimeDaily } = userGuild;
let { receivedActive, refTimeDaily, activeDaily, activeRecord } = userGuild;
const now = new Date();
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
if(isRefDaily) {
receivedActive = 0; refTimeDaily = now;
receivedActive = 0; refTimeDaily = now; activeDaily = 0; activeRecord = [];
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily }, select);
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily, activeDaily, activeRecord }, select);
if(!userGuild) return false;
}
@@ -141,15 +143,68 @@ export async function getUserGuildWithRefActive(roleId: string, select: string)
*/
export async function settleGuildWeekly() {
console.log('————— settleGuildWeekly —————');
const guildList = await GuildModel.findAllGuild('code activeWeekly');
const guildList = await GuildModel.findAllGuild('code activeWeekly memberCnt');
for(let { code, activeWeekly, memberCnt } of guildList) {
const userGuildList = await UserGuildModel.getListByGuild(code, 'roleId auth activeWeekly', { activeWeekly: -1, activeUpdateTime: 1 });
let activeMemberCnt = 0; // 活跃度高于100的成员人数
let otherMemberNum = 0; // 除了大将军以外从活跃高到底成员人数,用户计算活跃排名百分比
let jobCnt = new Map<number, number>();
let members = new Map<string, {job: number, active: boolean}>();
for(let {roleId, auth, activeWeekly} of userGuildList) {
let active = false;
let job = 0;
if(activeWeekly > 100) {
activeMemberCnt ++;
active = true;
}
if(auth == GUILD_AUTH.LEADER) {
job = GUILD_JOB.DAJIANGJUN;
} else if (activeWeekly <= 100) {
job = GUILD_JOB.SHIBING;
} else {
otherMemberNum++;
for(let [id, {rankProportion}] of gameData.guildPosition) {
let rankCnt = Math.ceil(memberCnt * rankProportion / 100);
console.log('*', id, memberCnt, rankProportion, otherMemberNum, rankCnt)
job = id;
if(otherMemberNum < rankCnt) break;
}
}
await UserGuildModel.updateInfo(roleId, { job, activeWeekly: 0 });
if(!jobCnt.has(job)) jobCnt.set(job, 0);
jobCnt.set(job, jobCnt.get(job) + 1);
members.set(roleId, {job, active});
}
for(let { code, activeWeekly } of guildList) {
// 转换周活跃奖励
const userGuildList = await UserGuildModel.getListByGuild(code, 'honourWeekly', { honourWeekly: -1, honourUpdateTime: 1 });
let allWeeklyReward = getGuildActiveWeekReward(activeWeekly);
let ratio = 1;
let averageBase = ratio * ( 1- ARMY.ARMY_POSITION_WEEKREWARD) / 100; // 70% 活跃值高于100均分
let positionBase = ratio * ARMY.ARMY_POSITION_WEEKREWARD / 100; // 30% 职位均分
for(let [roleId, {job, active}] of members) {
let myAverageRatio = active? (averageBase / activeMemberCnt): 0;
let jobActiveRatio = gameData.guildPosition.get(job).activeRatio / 100;
let myJobRewardRatio = positionBase * jobActiveRatio / jobCnt.get(job);
let reward = allWeeklyReward.map(cur => {
return {
id: cur.id,
count: Math.ceil(cur.count * (myAverageRatio + myJobRewardRatio))
}
});
await sendMail(MAIL_TYPE.GUILD_ACTIVE_REWARD, roleId, '系统', [], reward);
}
await GuildModel.updateInfo(code, { activeWeekly: 0 }, {});
}
await SystemConfigModel.updateSystemConfig({settleGuildWeeklyTime: nowSeconds()}); // 记录一下
console.log('————— settleGuildWeekly结束 —————');
}
export const message = {
+1 -1
View File
@@ -4,7 +4,7 @@ import { getRedis } from "./redisService";
import { pinus } from "pinus";
import { gameData } from "../pubUtils/data";
export async function sendMail(operate: number, toRoleId: string, sendName: string, params: string[], goods: RewardInter[] = []) {
export async function sendMail(operate: number, toRoleId: string, sendName: string = '系统', params: string[] = [], goods: RewardInter[] = []) {
let content = getContent( operate, params);
let mail = await MailModel.addMail({roleId: toRoleId, goods, sendName, mailId: 1, content});