Revert "fix:"

This reverts commit 4fc0da4a70.
This commit is contained in:
xcy 2023-12-18 20:06:40 +08:00
parent 893008c1e7
commit fe898ca42c
6 changed files with 110 additions and 211 deletions

View File

@ -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<ReqOpen, ResOpen>) {
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] || []]))
});
}

View File

@ -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<ReqReceive, ResReceive>) {
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;
}

View File

@ -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()
});

30
src/path_shop_redis2db.ts Normal file
View File

@ -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()});

View File

@ -8,5 +8,8 @@ export type ReqOpen = {
};
export type ResOpen = {
payIds: string[];
payNum: number;
receive: {
[k: string]: number[];
};
};

View File

@ -0,0 +1,13 @@
import { prizeType } from '../../type';
/**
*
*/
export type ReqReceive = {
k: string;
};
export type ResReceive = {
prize: prizeType[];
};