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(); for (let i = 0; i < users.length; i++) { let user = users[i]; let unFinishTask = (await G.mongodb.collection('task').find({ uid: user.uid, type: taskType, finish: 0 }, { projection: { taskid: 1 } }).toArray()).map(i => i.taskid); if (unFinishTask.length >= 2) { let deltask = unFinishTask.sort().slice(1); await G.mongodb.collection("task").deleteOne({ uid: user.uid, taskid: { $in: deltask } }); 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); } } async function main() { await patchInit() let patch = new Path(); await patch.run(); console.log("逻辑执行完成,等待退出"); setTimeout(function () { console.log('结束程序'); process.exit(); }, 3000); } main();