Merge branch 'feature/xiaofeijingsai' into dev

This commit is contained in:
dy 2023-12-22 14:11:02 +08:00
commit 8710d7d04f
5 changed files with 158 additions and 64 deletions

View File

@ -1,16 +1,15 @@
import {ApiCall} from "tsrpc"; import {ApiCall} from "tsrpc";
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/xiaofeijingsai/PtlOpen"; import {ReqOpen, ResOpen} from "../../../shared/protocols/event/xiaofeijingsai/PtlOpen";
import {PayFun} from "../../../public/pay";
import {HuoDongFun} from "../../../public/huodongfun"; import {HuoDongFun} from "../../../public/huodongfun";
import {PublicShared} from "../../../shared/public/public";
/** /**
* *
* redis缓存3分钟 * redis缓存120秒
* *
* @param call * @param call
*/ */
export default async function (call: ApiCall<ReqOpen, ResOpen>) { export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let ioList = await G.ioredis.get(`rank:xiaofeijingsai`); let ioList = await G.ioredis.get(`rank:xiaofeijingsai`);
if (ioList) { if (ioList) {
let myData = await getMyData(call, JSON.parse(ioList)) let myData = await getMyData(call, JSON.parse(ioList))
@ -31,18 +30,42 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let list: any = rmbuse.map(i => ({...i, total: R.negate(i.total)})) let list: any = rmbuse.map(i => ({...i, total: R.negate(i.total)}))
let users = await G.mongodb.collection('user').find({uid: {$in: list.map(i => i._id)}}).toArray()
list = list.map(i => ({...i, player: users.find(v => v.uid == i._id)})) let rankList = sortRankList(_hd.data.rank, list)
let users = await G.mongodb.collection('user').find({uid: {$in: rankList.map(i => i._id).filter(i => i._id != 'system')}}).toArray()
rankList = rankList.map(i => ({...i, player: users.find(v => v.uid == i._id) || {}}))
// 活动结束前半小时缓存过期时间改为10秒 // 活动结束前半小时缓存过期时间改为10秒
let exTime = (G.time + 1800) > _hd.etime ? 10 : 180 let exTime = (G.time + 1800) > _hd.etime ? 10 : 180
G.ioredis.setex(`rank:xiaofeijingsai`, exTime, JSON.stringify(list)); G.ioredis.setex(`rank:xiaofeijingsai`, exTime, JSON.stringify(rankList));
let myData = await getMyData(call, list, _hd) let myData = await getMyData(call, rankList, _hd)
call.succ({list, myData}) call.succ({list: rankList, myData})
}
/**
* system占位
* @param rank
* @param list
*/
export function sortRankList(rank, list) {
let rankList = []
let ccc = 0
rank.map(i => {
for (let k = i.rank[0] - 1; k < i.rank[1]; k++) {
if (list[k]?.total >= i.need[0].n) {
rankList.push({...list[k - ccc], rank: k})
} else {
rankList.push({_id: 'system', total: 0, rank: k, player: {}})
ccc += 1
}
}
})
return R.sort((a, b) => a.rank - b.rank)(rankList)
} }
// 获取自己的信息 // 获取自己的信息
@ -53,10 +76,16 @@ async function getMyData(call, rankList, _hd?) {
if (!_hd) { if (!_hd) {
_hd = (await HuoDongFun.gethdList(call, 11))[0] _hd = (await HuoDongFun.gethdList(call, 11))[0]
} }
let a = await G.mongodb.collection('rmbuse').aggregate([ let myCut = (await G.mongodb.collection('rmbuse').aggregate([
{$match: {uid: call.uid, isAdd: false, cTime: {$gte: _hd.stime, $lte: _hd.etime}}}, {$match: {uid: call.uid, isAdd: false, cTime: {$gte: _hd.stime, $lte: _hd.etime}}},
{$group: {_id: "$uid", total: {$sum: "$change"}}} {$group: {_id: "$uid", total: {$sum: "$change"}}}
]).toArray() ]).toArray())[0]
let myUser = await G.mongodb.collection('user').findOne({uid: call.uid}) let myUser = await G.mongodb.collection('user').findOne({uid: call.uid})
return {player: myUser, ...a}
if (!myCut) {
myCut = {_id: myUser.uid, total: 0}
}
return {player: myUser, ...myCut, rank: -1}
} }

View File

@ -37,7 +37,8 @@ export type schedulerType =
| 'hbzb_zbs_clear' | 'hbzb_zbs_clear'
| 'hbzb_zbs_group' | 'hbzb_zbs_group'
| 'wzry_zuanshi16to8' | 'wzry_zuanshi16to8'
| "cross_email_pull"; | "cross_email_pull"
| "xiaofeijingsai_local_ctor";
export class SchedulerManage { export class SchedulerManage {
static logTime = false; static logTime = false;
@ -102,7 +103,7 @@ export abstract class Scheduler {
} }
init(){ init() {
Scheduler.schedulers.push(this); Scheduler.schedulers.push(this);
this.read().then(_ => { this.read().then(_ => {
this.log(`state: 准备完毕 预计下次执行时间:${new Date(this.startTime * 1000).format("YYYY-MM-DD hh:mm:ss")}`); this.log(`state: 准备完毕 预计下次执行时间:${new Date(this.startTime * 1000).format("YYYY-MM-DD hh:mm:ss")}`);

View File

@ -0,0 +1,68 @@
import {Scheduler, schedulerType} from './scheduler';
import {PublicShared} from "../../shared/public/public";
import {Wjjl} from "../../module/collection_wjjl";
import {ZhanLingTasks} from "../zhanling";
import {setGud} from '../gud';
import {HuoDongFun} from "../huodongfun";
import {EmailFun} from "../email";
import {sortRankList} from "../../api_s2c/event/xiaofeijingsai/ApiOpen";
export class SchedulerXiaofeijingsaiLocalCtor extends Scheduler {
id: schedulerType = 'xiaofeijingsai_local_ctor';
time = 300;
name = '消费竞赛定时器发奖';
type: 'day' | 'week' = 'day';
// todo 测试
// get nextTime() {
// return G.time + 60;
// }
async read() {
await this.ctorStartTime();
this.isReady = false;
}
async start() {
let _hd = (await G.mongodb.collection('hdinfo').find({
htype: 11,
ttype: 0,
etime: {$lt: G.time, $gt: 99999999},
isSendPrize: {$or: [{$exists: false}, {$eq: false}]},
}).sort({etime: -1}).limit(1).toArray())[0]
if (!_hd) return
let limit = _hd.data?.rank?.slice(-1)?.[0]?.rank?.slice(-1)?.[0] || 100
let rmbuse = await G.mongodb.collection('rmbuse').aggregate([
{$match: {isAdd: false, cTime: {$gte: _hd.stime, $lte: _hd.etime}}},
{$group: {_id: "$uid", total: {$sum: "$change"}}},
{$sort: {total: 1}},
{$limit: limit}
]).toArray()
let list: any = rmbuse.map(i => ({...i, total: R.negate(i.total)}))
let ranklist = sortRankList(_hd.data.rank, list)
R.forEach(i => {
let users = R.slice(i.rank[0] - 1, i.rank[1])(ranklist)
users.map(v=>{
EmailFun.addEmail({
uid: v._id,
type: 'system',
title: 'email.titel',
content: 'email.content',
prize: i.prize,
// contentInsertArr: [conf.ph[0] + index]
});
})
})(_hd.data.rank)
await G.mongodb.collection('hdinfo').findOneAndUpdate({hdid: _hd.hdid}, {$set: {isSendPrize: true}})
console.log(_hd)
}
}

View File

@ -6,6 +6,13 @@ export type ReqOpen = {
}; };
export type ResOpen = { export type ResOpen = {
list: { _id: string, total: number, player: any }[] list: data[]
myData: { _id: string, total: number, player: any } myData: data
}; };
type data = {
_id: string,
total: number,
rank: number,
player: any
}

View File

@ -10801,30 +10801,8 @@ export const serviceProto: ServiceProto<ServiceType> = {
"type": { "type": {
"type": "Array", "type": "Array",
"elementType": { "elementType": {
"type": "Interface", "type": "Reference",
"properties": [ "target": "event/xiaofeijingsai/PtlOpen/data"
{
"id": 0,
"name": "_id",
"type": {
"type": "String"
}
},
{
"id": 1,
"name": "total",
"type": {
"type": "Number"
}
},
{
"id": 2,
"name": "player",
"type": {
"type": "Any"
}
}
]
} }
} }
}, },
@ -10832,30 +10810,41 @@ export const serviceProto: ServiceProto<ServiceType> = {
"id": 1, "id": 1,
"name": "myData", "name": "myData",
"type": { "type": {
"type": "Interface", "type": "Reference",
"properties": [ "target": "event/xiaofeijingsai/PtlOpen/data"
{ }
"id": 0, }
"name": "_id", ]
"type": { },
"type": "String" "event/xiaofeijingsai/PtlOpen/data": {
} "type": "Interface",
}, "properties": [
{ {
"id": 1, "id": 0,
"name": "total", "name": "_id",
"type": { "type": {
"type": "Number" "type": "String"
} }
}, },
{ {
"id": 2, "id": 1,
"name": "player", "name": "total",
"type": { "type": {
"type": "Any" "type": "Number"
} }
} },
] {
"id": 2,
"name": "rank",
"type": {
"type": "Number"
}
},
{
"id": 3,
"name": "player",
"type": {
"type": "Any"
} }
} }
] ]