diff --git a/src/api_s2c/event/chuanshuozhilu/ApiOpen.ts b/src/api_s2c/event/chuanshuozhilu/ApiOpen.ts index 27dd5d5..a1d648d 100644 --- a/src/api_s2c/event/chuanshuozhilu/ApiOpen.ts +++ b/src/api_s2c/event/chuanshuozhilu/ApiOpen.ts @@ -12,11 +12,37 @@ export default async function (call: ApiCall) { // 无此活动 return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 }) } - let db = await G.mongodb.cEvent(`chuanshuozhilu${call.req.hdid}`).findOne({ uid: call.uid, type: `chuanshuozhilu${call.req.hdid}` }); + let _info = db?.info || {} + // 如果初始没有数据,就判断玩家是否有活动对应的影响,生成一下初始化数据 + if (!db) { + + let _dbType: `chuanshuozhilu${number}` = `chuanshuozhilu${call.req.hdid}` + const hid = _hdinfo.data.hid + let heros = await G.mongodb.collection("hero").find({uid: call.uid, heroId: hid}) + .sort({ "zhanli": -1 }).limit(1).toArray(); + + if (heros) { + let hero = heros[0] + const lv = hero.lv || 0 + const jieji = hero.jieji || 0 + let setInfo = {"lv": lv, "jieji": jieji} + await G.mongodb.cEvent(_dbType).updateOne( + { uid: call.uid, type: _dbType }, + { $set: G.mongodb.createTreeObj({ key: `info.${hid}`, val: setInfo})}, + { upsert: true} + ) + if (!cache[call.uid]) cache[call.uid] = {hid:{}}; + if (!cache[call.uid][hid]) cache[call.uid][hid] = setInfo; + _info[hid] = setInfo + G.server.sendMsgByUid(call.uid, 'msg_s2c/HongDianChange', ['huodonghd']); + } + + } + call.succ({ - info: db?.info || {}, + info: _info, hdinfo: _hdinfo }); } diff --git a/src/fix_patch/patch_20240110.ts b/src/fix_patch/patch_20240110.ts index 1597954..9bfeeec 100644 --- a/src/fix_patch/patch_20240110.ts +++ b/src/fix_patch/patch_20240110.ts @@ -1,8 +1,44 @@ +import { ReqEmail } from "../monopoly/protocols/PtlEmail"; import { patchInit } from "../patch"; +import { MsgEmail } from "../shared/protocols/msg_s2c/MsgEmail"; +import { PublicShared } from "../shared/public/public"; class Path { + async addEmail(email: ReqEmail & { createTime?: number; }) { + let { prize, uid, ...e } = email; + let lng = await G.redis.rawGet(`user:lng:${uid}`) + + let sendEmail: MsgEmail = { + _id: null, + uid: uid, + type: e.type, + title: e.lngTitle ? (e.lngTitle[lng] || e.lngTitle['ja']) : e.title, + content: e.lngContent ? (e.lngContent[lng] || e.lngContent['ja']) : e.content, + createTime: e.createTime || G.time, + contentInsertArr: e.contentInsertArr || [] + }; + + if (prize?.length > 0) { + sendEmail.prizeData = { + prize: email.prize, + isGet: false + }; + } + + if (email.g123log && Object.keys(email.g123log).length > 0) sendEmail.g123log = email.g123log; + + if (email.lngTitle) { + sendEmail.lngTitle = email.lngTitle + sendEmail.lngContent = email.lngContent + } + + await G.mongodb.collection('email').insertOne({ + ttl: new Date(), ...G.mongodb.conversionIdObj(sendEmail) + }); + } + async fun1(a: any) { let taskType = 2; let users = await G.mongodb.collection('user').find({ loginTime: { $gte: 1704643200 } }).toArray(); @@ -13,18 +49,58 @@ class Path { }, { projection: { taskid: 1 } }).toArray()).map(i => i.taskid); if (unFinishTask.length >= 2) { - unFinishTask.sort().slice(1); + let deltask = unFinishTask.sort().slice(1); await G.mongodb.collection("task").deleteOne({ - uid: user.uid, taskid: { $in: unFinishTask } + uid: user.uid, taskid: { $in: deltask } }); - console.log(`删除玩家${user.uid}任务:${unFinishTask}`); + console.log(`删除玩家${user.uid}任务:${deltask}`); + } + } + } + /** + * 补发玩家终身卡奖励 + */ + async fun2(a: any) { + let logs = await G.mongodb.collection("payLogNew").find( + { key: "zhongshenka", del_time: { $exists: false } }, { projection: { _id: 0, } } + ).toArray(); + + if (logs.length == 0) { + console.log("没有终身卡数据,不发放终身卡"); + return + } + + let wzt = PublicShared.getToWeekMondayZeroTime(); + let con = G.gc.payEmail.zhongshenka.filter(e => e.day == 7)[0]; + for (let i = 0; i < logs.length; i++) { + + // 查询玩家邮件 + let emails = await G.mongodb.collection('email').find({ + uid: logs[i].uid, title: con.title, createTime: { $gte: wzt } + }).toArray(); + + + if (emails.length == 0) { + // 发送邮件 + this.addEmail({ + uid: logs[i].uid, + type: "system", + title: con.title, + content: con.content, + contentInsertArr: [], + createTime: G.time, + prize: con.prize, + }) + console.log("发放终身卡", logs[i].uid); + } else { + console.log("本周已发送过 不发放终身卡", logs[i].uid); } } } - async run() { await this.fun1(1); + await this.fun2(1); } }