From 4fc0da4a702ae4fdf94363da1ff6f0b7a36c716f Mon Sep 17 00:00:00 2001 From: xcy <871622040@qq.com> Date: Fri, 15 Dec 2023 15:14:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=A6=96=E5=85=85=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=B8=8E=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/event/shouchong/ApiOpen.ts | 17 +- src/api_s2c/event/shouchong/ApiReceive.ts | 56 ----- src/patch_reset_shouchong.ts | 200 ++++++++++++++++++ src/path_shop_redis2db.ts | 30 --- .../protocols/event/shouchong/PtlOpen.ts | 5 +- .../protocols/event/shouchong/PtlReceive.ts | 13 -- 6 files changed, 211 insertions(+), 110 deletions(-) delete mode 100644 src/api_s2c/event/shouchong/ApiReceive.ts create mode 100644 src/patch_reset_shouchong.ts delete mode 100644 src/path_shop_redis2db.ts delete mode 100644 src/shared/protocols/event/shouchong/PtlReceive.ts diff --git a/src/api_s2c/event/shouchong/ApiOpen.ts b/src/api_s2c/event/shouchong/ApiOpen.ts index 010d12f..a93d02c 100644 --- a/src/api_s2c/event/shouchong/ApiOpen.ts +++ b/src/api_s2c/event/shouchong/ApiOpen.ts @@ -1,11 +1,14 @@ -import { ApiCall } from "tsrpc"; -import { ReqOpen, ResOpen } from "../../../shared/protocols/event/shouchong/PtlOpen"; +import {ApiCall} from "tsrpc"; +import {ReqOpen, ResOpen} from "../../../shared/protocols/event/shouchong/PtlOpen"; +import {PayFun} from "../../../public/pay"; export default async function (call: ApiCall) { - let data = await G.mongodb.cEvent('shouchong').findOne({ uid: call.uid, type: 'shouchong' }); + let payIds = []; + for (let k in G.gc.shouchong) { + payIds.push(G.gc.shouchong[k].payid) + } - call.succ({ - payNum: call.conn.gud.payExp / 10, - receive: Object.fromEntries(Object.keys(G.gc.shouchong).map(k => [k, data?.receive?.[k] || []])) - }); + let pays = await PayFun.getPayLogs(call.uid, payIds) + + call.succ({payIds: Object.keys(pays)}); } \ No newline at end of file diff --git a/src/api_s2c/event/shouchong/ApiReceive.ts b/src/api_s2c/event/shouchong/ApiReceive.ts deleted file mode 100644 index 6e29d12..0000000 --- a/src/api_s2c/event/shouchong/ApiReceive.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { ApiCall } from "tsrpc"; -import { PlayerFun } from '../../../public/player'; -import { ReqReceive, ResReceive } from "../../../shared/protocols/event/shouchong/PtlReceive"; -import { PublicShared } from '../../../shared/public/public'; -import { HongDianChange } from "../../hongdian/fun"; - -export default async function (call: ApiCall) { - - let conf = G.gc.shouchong[call.req.k]; - - if (!conf) return call.error(globalThis.lng.pata_getprize_1); - - let data = await G.mongodb.cEvent('shouchong').findOne({ uid: call.uid, type: 'shouchong' }); - - let recArr = data?.receive?.[call.req.k] || []; - - if (call.conn.gud.payExp < conf.paynum) return call.error(globalThis.lng.event_kfkh_9); - - if (recArr.length >= conf.prize.length) return call.error(globalThis.lng.event_kfkh_3); - - if (recArr.slice(-1)[0] && PublicShared.getToDayZeroTime() < recArr.slice(-1)[0]) return call.error(globalThis.lng.event_kfkh_10); - - await PlayerFun.sendPrize(call, conf.prize[recArr.length]); - await G.mongodb.cEvent('shouchong').updateOne( - { uid: call.uid, type: 'shouchong' }, - { $push: G.mongodb.createTreeObj({ key: 'receive', k: call.req.k, val: G.time }) }, - { upsert: true } - ); - - let recLen = data != null ? Object.values(data.receive).map(arr => arr.length).reduce((a, b) => a + b) + 1 : 1; - let allLen = Object.values(G.gc.shouchong).map(conf => conf.prize.length as number).reduce((a, b) => a + b); - if (data && recLen >= allLen) { - G.mongodb.collection('syncBtns').updateOne({ uid: call.uid }, { $set: { 'shouchong.active': false } }, { upsert: true }); - } - HongDianChange.sendChangeKey(call.uid, ['shouchong']) - - call.succ({ - prize: conf.prize[recArr.length] - }); -} - -export async function getShouChongRedPoint(call: ApiCall) { - let res = { show: false }; - let data = await G.mongodb.cEvent('shouchong').findOne({ uid: call.uid, type: 'shouchong' }); - - for (let [id, conf] of Object.entries(G.gc.shouchong)) { - let rec = data?.receive?.[id] || []; - if (call.conn.gud.payExp / 10 < conf.paynum || rec.length >= conf.prize.length) continue; - if (rec.length == 0 || rec.slice(-1)[0] < PublicShared.getToDayZeroTime(G.time)) { - res = { show: true }; - break; - } - } - - return res; -} \ No newline at end of file diff --git a/src/patch_reset_shouchong.ts b/src/patch_reset_shouchong.ts new file mode 100644 index 0000000..4f08542 --- /dev/null +++ b/src/patch_reset_shouchong.ts @@ -0,0 +1,200 @@ +import {ctor} from './global'; +import {initMongoDB} from './setMongodb'; +import {EmailFun} from "./public/email"; + +const shouchong = { + "shouchong1": { + "paynum": 6, + "cartoon": { + "hero": 5001 + }, + "prize": [ + [ + { + "a": "hero", + "t": "5001", + "n": 1 + }, + { + "a": "attr", + "t": "jinbi", + "n": 100000 + } + ], + [ + { + "a": "item", + "t": "12", + "n": 200 + }, + { + "a": "attr", + "t": "jinbi", + "n": 200000 + } + ], + [ + { + "a": "item", + "t": "12", + "n": 200 + }, + { + "a": "attr", + "t": "jinbi", + "n": 300000 + } + ] + ] + }, + "shouchong2": { + "paynum": 30, + "cartoon": { + "img": 5001 + }, + "prize": [ + [ + { + "a": "equip", + "t": "1009", + "n": 1 + }, + { + "a": "equip", + "t": "2009", + "n": 1 + } + ], + [ + { + "a": "equip", + "t": "3009", + "n": 1 + }, + { + "a": "item", + "t": "2", + "n": 1000 + } + ], + [ + { + "a": "equip", + "t": "4009", + "n": 1 + }, + { + "a": "item", + "t": "2", + "n": 1000 + } + ] + ] + }, + "shouchong3": { + "paynum": 98, + "cartoon": { + "hero": 5002 + }, + "prize": [ + [ + { + "a": "hero", + "t": "5002", + "n": 1 + }, + { + "a": "item", + "t": "4", + "n": 10 + } + ], + [ + { + "a": "equip", + "t": "1010", + "n": 1 + }, + { + "a": "item", + "t": "2", + "n": 2000 + } + ], + [ + { + "a": "equip", + "t": "3010", + "n": 1 + }, + { + "a": "item", + "t": "2", + "n": 2000 + } + ] + ] + } +} + +async function start() { + //连接mongodb + await initMongoDB(); + let users = await G.mongodb.collection("user").find({}, { + projection: {uid: 1, payExp: 1} + }).toArray() + + for (let i = 0; i < users.length; i++) { + let user = users[i]; + let data = await G.mongodb.cEvent("shouchong").findOne({uid: user.uid}); + + let send_prize = []; + for (let key in shouchong) { + // 充值不足 + if (user.payExp < shouchong[key]["paynum"] * 10) { + continue + } + + // 奖励已经领取完毕 + if (data && data.receive[key] && data.receive[key].length >= shouchong[key]["prize"].length) { + continue + } + + // 补发未领取奖励 + for (let i = 0; i < shouchong[key]["prize"].length; i++) { + if (data.receive[key][i]) { + continue + } + data.receive[key][i] = G.time; + send_prize.concat(shouchong[key]["prize"][i]); + } + } + if (send_prize.length <= 0) continue; + + let title = "首充未领取奖励补发"; + let content = "首充未领取奖励补发"; + + // 设置奖励发放记录 + await G.mongodb.cEvent("shouchong").updateOne({ + uid: user.uid + }, {"$set": {receive: data.receive}}); + + // 发放邮件 + await EmailFun.addEmail({ + uid: user.uid, + type: "system", + title: title, + content: content, + prize: send_prize, + }) + } +} + +//定义全局变量 +ctor(); +//启动服务 +start().then(() => { + process.exit() +}); + + diff --git a/src/path_shop_redis2db.ts b/src/path_shop_redis2db.ts deleted file mode 100644 index ab437f2..0000000 --- a/src/path_shop_redis2db.ts +++ /dev/null @@ -1,30 +0,0 @@ -import {ctor} from './global'; -import {initMongoDB} from './setMongodb'; -import {initRedis} from './setRedis'; - -async function start() { - //连接mongodb - await initMongoDB(); - //连接redis - await initRedis(); - - let shopdata = await G.redis.get("shop") - - for (let uid in shopdata) { - for (let shopId in shopdata[uid]) { - - await G.mongodb.collection("shop").updateOne( - {uid: uid.slice(1), shopId: shopId.slice(1)}, - {$set: shopdata[uid][shopId]}, {upsert: true} - ) - console.log(`玩家${uid.slice(1)}商店${shopId.slice(1)}数据写入成功!!`) - } - } -} - -//定义全局变量 -ctor(); -//启动服务 -start().then(() => {process.exit()}); - - diff --git a/src/shared/protocols/event/shouchong/PtlOpen.ts b/src/shared/protocols/event/shouchong/PtlOpen.ts index cad5f93..36c207e 100644 --- a/src/shared/protocols/event/shouchong/PtlOpen.ts +++ b/src/shared/protocols/event/shouchong/PtlOpen.ts @@ -8,8 +8,5 @@ export type ReqOpen = { }; export type ResOpen = { - payNum: number; - receive: { - [k: string]: number[]; - }; + payIds: string[]; }; \ No newline at end of file diff --git a/src/shared/protocols/event/shouchong/PtlReceive.ts b/src/shared/protocols/event/shouchong/PtlReceive.ts deleted file mode 100644 index 45af650..0000000 --- a/src/shared/protocols/event/shouchong/PtlReceive.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { prizeType } from '../../type'; - - -/** - * 领取 - */ -export type ReqReceive = { - k: string; -}; - -export type ResReceive = { - prize: prizeType[]; -}; \ No newline at end of file