From fe898ca42c65ca2d49fb0f53f2134753c7a0deec Mon Sep 17 00:00:00 2001 From: xcy <871622040@qq.com> Date: Mon, 18 Dec 2023 20:06:40 +0800 Subject: [PATCH] Revert "fix:" This reverts commit 4fc0da4a702ae4fdf94363da1ff6f0b7a36c716f. --- 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, 110 insertions(+), 211 deletions(-) create mode 100644 src/api_s2c/event/shouchong/ApiReceive.ts delete mode 100644 src/patch_reset_shouchong.ts create mode 100644 src/path_shop_redis2db.ts create 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 a93d02c..010d12f 100644 --- a/src/api_s2c/event/shouchong/ApiOpen.ts +++ b/src/api_s2c/event/shouchong/ApiOpen.ts @@ -1,14 +1,11 @@ -import {ApiCall} from "tsrpc"; -import {ReqOpen, ResOpen} from "../../../shared/protocols/event/shouchong/PtlOpen"; -import {PayFun} from "../../../public/pay"; +import { ApiCall } from "tsrpc"; +import { ReqOpen, ResOpen } from "../../../shared/protocols/event/shouchong/PtlOpen"; export default async function (call: ApiCall) { - let payIds = []; - for (let k in G.gc.shouchong) { - payIds.push(G.gc.shouchong[k].payid) - } + let data = await G.mongodb.cEvent('shouchong').findOne({ uid: call.uid, type: 'shouchong' }); - let pays = await PayFun.getPayLogs(call.uid, payIds) - - call.succ({payIds: Object.keys(pays)}); + call.succ({ + payNum: call.conn.gud.payExp / 10, + receive: Object.fromEntries(Object.keys(G.gc.shouchong).map(k => [k, data?.receive?.[k] || []])) + }); } \ No newline at end of file diff --git a/src/api_s2c/event/shouchong/ApiReceive.ts b/src/api_s2c/event/shouchong/ApiReceive.ts new file mode 100644 index 0000000..6e29d12 --- /dev/null +++ b/src/api_s2c/event/shouchong/ApiReceive.ts @@ -0,0 +1,56 @@ +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 deleted file mode 100644 index 4f08542..0000000 --- a/src/patch_reset_shouchong.ts +++ /dev/null @@ -1,200 +0,0 @@ -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 new file mode 100644 index 0000000..ab437f2 --- /dev/null +++ b/src/path_shop_redis2db.ts @@ -0,0 +1,30 @@ +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 36c207e..cad5f93 100644 --- a/src/shared/protocols/event/shouchong/PtlOpen.ts +++ b/src/shared/protocols/event/shouchong/PtlOpen.ts @@ -8,5 +8,8 @@ export type ReqOpen = { }; export type ResOpen = { - payIds: string[]; + payNum: number; + receive: { + [k: string]: number[]; + }; }; \ No newline at end of file diff --git a/src/shared/protocols/event/shouchong/PtlReceive.ts b/src/shared/protocols/event/shouchong/PtlReceive.ts new file mode 100644 index 0000000..45af650 --- /dev/null +++ b/src/shared/protocols/event/shouchong/PtlReceive.ts @@ -0,0 +1,13 @@ +import { prizeType } from '../../type'; + + +/** + * 领取 + */ +export type ReqReceive = { + k: string; +}; + +export type ResReceive = { + prize: prizeType[]; +}; \ No newline at end of file