From 14796bb06b2a08fdbe1a28145a087254a49dc9b5 Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Wed, 10 Jan 2024 14:29:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat=EF=BC=9A=E9=BB=84=E6=97=97=E9=85=92?= =?UTF-8?q?=E9=A6=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/event/huangqijiuguan/ApiZhaoMu.ts | 2 +- src/api_s2c/event/huangqijiuguan/fun.ts | 38 +++++++++-- src/globalListener.ts | 13 ++-- src/public/scheduler/scheduler_newDay.ts | 66 ++++++++++--------- 4 files changed, 75 insertions(+), 44 deletions(-) diff --git a/src/api_s2c/event/huangqijiuguan/ApiZhaoMu.ts b/src/api_s2c/event/huangqijiuguan/ApiZhaoMu.ts index b672a94..0b22e98 100644 --- a/src/api_s2c/event/huangqijiuguan/ApiZhaoMu.ts +++ b/src/api_s2c/event/huangqijiuguan/ApiZhaoMu.ts @@ -19,7 +19,7 @@ export default async function (call: ApiCall) { let prize = []; let mydata = await HQJGFun.getMydata(call, call.req.hdid); - for (let n = 0; n < call.req.num; n++) { + for (let n = 1; n <= call.req.num; n++) { let num = mydata.zhaomu.num + n; let baodi = hd.data.baodi.filter(x => x.num == num); if (baodi.length > 0) { diff --git a/src/api_s2c/event/huangqijiuguan/fun.ts b/src/api_s2c/event/huangqijiuguan/fun.ts index 1ee383d..abf61a9 100644 --- a/src/api_s2c/event/huangqijiuguan/fun.ts +++ b/src/api_s2c/event/huangqijiuguan/fun.ts @@ -214,10 +214,13 @@ export default class HQJGFun { /** * 每日伤害等级奖励结算 */ - static async dayDpsLvPrize() { + static async dayDpsLvPrize(time: number) { + console.log( + "黄旗酒馆 每日伤害等级奖励结算 开始执行。。。" + ) // 取stime小于当前时间的最后一条数据 let hdinfo = await G.mongodb.collection("hdinfo").find({ - htype: this.htype, stime: { $lte: G.time } + htype: this.htype, stime: { $lte: time } }, { sort: { stime: -1 } }).limit(1).toArray(); // 没有活动数 @@ -227,6 +230,7 @@ export default class HQJGFun { let hd = hdinfo[0]; let hdid = hdinfo[0].hdid; + // 活动结束 if (hd.etime < G.time - 300) { return } @@ -260,17 +264,26 @@ export default class HQJGFun { contentInsertArr: [lvprize.lv], }) } + console.log( + "黄旗酒馆 每日伤害等级奖励结算 执行完成!!!" + ) }) } /** * 最大伤害排行奖励结算 */ - static async endDpsRankPrize() { - // 取stime小于当前时间的最后一条数据 + static async endDpsRankPrize(time: number) { + console.log( + "黄旗酒馆 最大伤害排行奖励结算 开始执行。。。" + ) + let today = PublicShared.getToDayZeroTime(time + 300); + let yesterday = PublicShared.getToDayZeroTime(time - 300); + + // 查询昨天23:59:00或者今天00:00:00结束的活动 let hdinfo = await G.mongodb.collection("hdinfo").find({ - htype: this.htype, stime: { $lte: G.time } - }, { sort: { stime: -1 } }).limit(1).toArray(); + htype: this.htype, rtime: { $gt: yesterday, $lte: today } + }).toArray(); // 没有活动数 if (hdinfo.length <= 0) { @@ -279,7 +292,7 @@ export default class HQJGFun { let hd = hdinfo[0]; let hdid = hdinfo[0].hdid; - if (hd.etime < G.time - 300) { + if (hd.data.sendrank) { return } @@ -306,5 +319,16 @@ export default class HQJGFun { contentInsertArr: [rank], }) } + // 标记已发送 + await G.mongodb.collection("hdinfo").updateOne( + { hdid: hdid }, { $set: { "data.sendrank": true } } + ); + + console.log( + "黄旗酒馆 最大伤害排行奖励结算 执行结束!!!" + ) } } + +G.on("NEW_DAY", HQJGFun.dayDpsLvPrize.bind(HQJGFun)); +G.on("NEW_DAY", HQJGFun.endDpsRankPrize.bind(HQJGFun)); \ No newline at end of file diff --git a/src/globalListener.ts b/src/globalListener.ts index 68bc8c8..d031e4f 100644 --- a/src/globalListener.ts +++ b/src/globalListener.ts @@ -15,13 +15,14 @@ import { ZhanLingTasks } from './public/zhanling'; import { player } from './shared/protocols/user/type'; import { PublicShared } from './shared/public/public'; import { setGud } from './public/gud'; -import {checkResetBuyLog} from "./api_s2c/event/zhoumolibao/ApiOpen"; -import {Christmasfun} from "./api_s2c/event/christmas/fun"; -import {PushGiftFun} from "./public/pushgift"; -import {LeiChongLiBaoBuyGift} from "./api_s2c/event/leichonglibao/ApiReceive"; +import { checkResetBuyLog } from "./api_s2c/event/zhoumolibao/ApiOpen"; +import { PushGiftFun } from "./public/pushgift"; +import { LeiChongLiBaoBuyGift } from "./api_s2c/event/leichonglibao/ApiReceive"; import { HongDianChange } from './api_s2c/hongdian/fun'; export type gEventType = { + /**新的一天 */ + NEW_DAY: (time: number) => void; /**玩家断开连接 */ PLAYER_DISCONNECT: (uid: string) => void; /**玩家修改名字 */ @@ -165,7 +166,7 @@ export function addListener() { XstaskFun.uidTask[uid] = null; delete XstaskFun.uidTask[uid]; } - setGud(uid,{ logoutTime: G.time }); + setGud(uid, { logoutTime: G.time }); G.mongodb.collection('user').updateOne({ uid: uid }, { $set: { logoutTime: G.time } }); }); @@ -177,7 +178,7 @@ export function addListener() { } }); - G.on('PLAYER_PAY', async (player, payId, payArgs,call) => { + G.on('PLAYER_PAY', async (player, payId, payArgs, call) => { let conf: any = await PayFun.getConf(payId, payArgs); ActionLog.addDayLog(player.uid, { key: 'pay', val: conf.payExp[0].n }); ActionLog.addRetainLog(player.uid, { key: 'pay', val: conf.payExp[0].n }); diff --git a/src/public/scheduler/scheduler_newDay.ts b/src/public/scheduler/scheduler_newDay.ts index 4ca793b..7c6ae72 100644 --- a/src/public/scheduler/scheduler_newDay.ts +++ b/src/public/scheduler/scheduler_newDay.ts @@ -4,6 +4,7 @@ import { Wjjl } from "../../module/collection_wjjl"; import { ZhanLingTasks } from "../zhanling"; import { setGud } from '../gud'; import { EmailFun } from '../email'; +import { clusterRunOnce } from '../../clusterUtils'; export class SchedulerNewDayLocalCtor extends Scheduler { @@ -23,6 +24,41 @@ export class SchedulerNewDayLocalCtor extends Scheduler { } async start() { + + clusterRunOnce(async () => { + //这个定时器会被每个进程都启动,这是这部分逻辑,应该只执行1次 + + // 每周一,发放终身卡 + (async () => { + if (PublicShared.getWeek(G.time) == 1) { + let logs = await G.mongodb.collection("payLogNew").find( + { key: "zhongshenka", del_time: { $exists: false } }, { projection: { _id: 0, } } + ).toArray(); + + if (logs.length == 0) { + console.log("没有终身卡数据,不发放终身卡"); + } + let con = G.gc.payEmail.zhongshenka.filter(e => e.day == 7)[0]; + for (let i = 0; i < logs.length; i++) { + console.log("发放终身卡", logs[i].uid); + // 发送邮件 + EmailFun.addEmail({ + uid: logs[i].uid, + type: "system", + title: con.title, + content: con.content, + contentInsertArr: [], + createTime: G.time, + prize: con.prize, + }) + } + } + })() + + // 转点刷新事件 + G.emit('NEW_DAY', G.time); + }) + let users = Object.values(G.server.uid_connections) if (users.length) { for (let item of users) { @@ -55,35 +91,5 @@ export class SchedulerNewDayLocalCtor extends Scheduler { } G.server.broadcastClusterMsg('msg_s2c/NewDay', { time: this.zeroTime }); } - - (async () => { - // 每周一,发放终身卡 - if (PublicShared.getWeek(G.time) != 1) { - console.log("不是周一,不发放终身卡", PublicShared.getWeek(G.time)); - return - }; - - let logs = await G.mongodb.collection("payLogNew").find( - { key: "zhongshenka", del_time: { $exists: false } }, { projection: { _id: 0, } } - ).toArray(); - - if (logs.length == 0) { - console.log("没有终身卡数据,不发放终身卡"); - } - let con = G.gc.payEmail.zhongshenka.filter(e => e.day == 7)[0]; - for (let i = 0; i < logs.length; i++) { - console.log("发放终身卡", logs[i].uid); - // 发送邮件 - EmailFun.addEmail({ - uid: logs[i].uid, - type: "system", - title: con.title, - content: con.content, - contentInsertArr: [], - createTime: G.time, - prize:con.prize, - }) - } - })() } } From 273b1865c32c17ccdd45dd7b45e019d796d30178 Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Wed, 10 Jan 2024 17:53:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=E9=BB=84=E6=97=97=E9=85=92=E9=A6=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/event/huangqijiuguan/ApiFight.ts | 2 +- src/api_s2c/event/huangqijiuguan/ApiOpen.ts | 3 +-- src/api_s2c/event/huangqijiuguan/ApiRecDpsPrize.ts | 3 +-- .../event/huangqijiuguan/ApiZhaoMuPrizeRec.ts | 14 ++++++++++---- src/api_s2c/event/huangqijiuguan/fun.ts | 6 +++--- .../event/huangqijiuguan/PtlZhaoMuPrizeRec.ts | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/api_s2c/event/huangqijiuguan/ApiFight.ts b/src/api_s2c/event/huangqijiuguan/ApiFight.ts index fa547a2..b7f1085 100644 --- a/src/api_s2c/event/huangqijiuguan/ApiFight.ts +++ b/src/api_s2c/event/huangqijiuguan/ApiFight.ts @@ -6,7 +6,7 @@ import { fightResult } from "../../../shared/fightControl/fightType"; import { FightFun } from "../../../public/fight"; export default async function (call: ApiCall) { - let hd = await HuoDongFun.getHdidInfo(call, call.req.hdid); + let hd = await HQJGFun.HdInfo(call, call.req.hdid); if (!hd) { // 无此活动 diff --git a/src/api_s2c/event/huangqijiuguan/ApiOpen.ts b/src/api_s2c/event/huangqijiuguan/ApiOpen.ts index 0d799d2..660ba47 100644 --- a/src/api_s2c/event/huangqijiuguan/ApiOpen.ts +++ b/src/api_s2c/event/huangqijiuguan/ApiOpen.ts @@ -1,10 +1,9 @@ import HQJGFun from "./fun"; import { ApiCall } from "tsrpc"; -import { HuoDongFun } from "../../../public/huodongfun"; import { ReqOpen, ResOpen } from "../../../shared/protocols/event/huangqijiuguan/PtlOpen"; export default async (call: ApiCall) => { - let hd = await HuoDongFun.getHdidInfo(call, call.req.hdid); + let hd = await HQJGFun.HdInfo(call, call.req.hdid); if (!hd || Object.keys(hd).length <= 0) { // 无此活动 return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 }) diff --git a/src/api_s2c/event/huangqijiuguan/ApiRecDpsPrize.ts b/src/api_s2c/event/huangqijiuguan/ApiRecDpsPrize.ts index 25b3438..888b3b3 100644 --- a/src/api_s2c/event/huangqijiuguan/ApiRecDpsPrize.ts +++ b/src/api_s2c/event/huangqijiuguan/ApiRecDpsPrize.ts @@ -1,11 +1,10 @@ import { ApiCall } from "tsrpc"; import HQJGFun, { Data } from "./fun"; -import { HuoDongFun } from "../../../public/huodongfun"; import { ReqRecDpsPrize, ResRecDpsPrize } from "../../../shared/protocols/event/huangqijiuguan/PtlRecDpsPrize"; import { PlayerFun } from "../../../public/player"; export default async function (call: ApiCall) { - let hd = await HuoDongFun.getHdidInfo(call, call.req.hdid); + let hd = await HQJGFun.HdInfo(call, call.req.hdid); if (!hd) { // 无此活动 diff --git a/src/api_s2c/event/huangqijiuguan/ApiZhaoMuPrizeRec.ts b/src/api_s2c/event/huangqijiuguan/ApiZhaoMuPrizeRec.ts index f0b7f8f..6107988 100644 --- a/src/api_s2c/event/huangqijiuguan/ApiZhaoMuPrizeRec.ts +++ b/src/api_s2c/event/huangqijiuguan/ApiZhaoMuPrizeRec.ts @@ -14,13 +14,19 @@ export default async function (call: ApiCall mydata.zhaomu.num || mydata.zhaomu.prize.includes(rec)) { + let con = hd.data.choukajiangli[rec.idx]; + + if (con.num > mydata.zhaomu.num || mydata.zhaomu.prize.includes(rec.idx)) { continue } - mydata.zhaomu.prize.push(rec); - prize = prize.concat(con.prize); + if (con.dlz) { + prize.push(con.dlz[rec.sec]); + } else { + prize = prize.concat(con.prize); + } + + mydata.zhaomu.prize.push(rec.idx); } if (prize.length <= 0) { diff --git a/src/api_s2c/event/huangqijiuguan/fun.ts b/src/api_s2c/event/huangqijiuguan/fun.ts index abf61a9..175420b 100644 --- a/src/api_s2c/event/huangqijiuguan/fun.ts +++ b/src/api_s2c/event/huangqijiuguan/fun.ts @@ -26,7 +26,7 @@ export interface Data { chouka: { a: string, t: string, n: number, p: number, gailv: number, cishu: number }[] - choukajiangli: { num: number, prize: any[] }[] + choukajiangli: { num: number, prize?: any[], dlz: { [k: string]: atn } }[] baodi: { num: number, prize: any[] }[] @@ -151,14 +151,14 @@ export default class HQJGFun { } /** 获取活动数据 */ - static async HdInfo(call: ApiCall, hdid?: number): Promise { + static async HdInfo(call: ApiCall, hdid?: number): Promise { if (!hdid) { let hdlist = await HuoDongFun.gethdList( call, this.htype ); return hdlist.length > 0 ? hdlist[0] : null } else { - return await HuoDongFun.getHdidInfo(call, hdid) as ReqAddHuoDong + return await HuoDongFun.getHdidInfo(call, hdid) as any as ReqAddHuoDong & { data: Data } } } diff --git a/src/shared/protocols/event/huangqijiuguan/PtlZhaoMuPrizeRec.ts b/src/shared/protocols/event/huangqijiuguan/PtlZhaoMuPrizeRec.ts index 4cfdace..d5a6eba 100644 --- a/src/shared/protocols/event/huangqijiuguan/PtlZhaoMuPrizeRec.ts +++ b/src/shared/protocols/event/huangqijiuguan/PtlZhaoMuPrizeRec.ts @@ -2,7 +2,7 @@ import { PlayerData } from "../../../../api_s2c/event/huangqijiuguan/fun" export interface ReqZhaoMuPrizeRec { hdid: number - recid: number[] + recid: { idx: number, sec: string }[] } export interface ResZhaoMuPrizeRec {