消费竞赛定时器
This commit is contained in:
parent
6cb39ad523
commit
f17f4182a9
@ -1,16 +1,15 @@
|
||||
import {ApiCall} from "tsrpc";
|
||||
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/xiaofeijingsai/PtlOpen";
|
||||
import {PayFun} from "../../../public/pay";
|
||||
import {HuoDongFun} from "../../../public/huodongfun";
|
||||
import {PublicShared} from "../../../shared/public/public";
|
||||
|
||||
/**
|
||||
* 消费竞赛
|
||||
* redis缓存3分钟
|
||||
* redis缓存120秒
|
||||
* 返回活动日期内的
|
||||
* @param call
|
||||
*/
|
||||
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
|
||||
|
||||
let ioList = await G.ioredis.get(`rank:xiaofeijingsai`);
|
||||
if (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 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秒
|
||||
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) {
|
||||
_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}}},
|
||||
{$group: {_id: "$uid", total: {$sum: "$change"}}}
|
||||
]).toArray()
|
||||
]).toArray())[0]
|
||||
|
||||
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}
|
||||
}
|
@ -37,7 +37,8 @@ export type schedulerType =
|
||||
| 'hbzb_zbs_clear'
|
||||
| 'hbzb_zbs_group'
|
||||
| 'wzry_zuanshi16to8'
|
||||
| "cross_email_pull";
|
||||
| "cross_email_pull"
|
||||
| "xiaofeijingsai_local_ctor";
|
||||
|
||||
export class SchedulerManage {
|
||||
static logTime = false;
|
||||
@ -102,7 +103,7 @@ export abstract class Scheduler {
|
||||
|
||||
}
|
||||
|
||||
init(){
|
||||
init() {
|
||||
Scheduler.schedulers.push(this);
|
||||
this.read().then(_ => {
|
||||
this.log(`state: 准备完毕 预计下次执行时间:${new Date(this.startTime * 1000).format("YYYY-MM-DD hh:mm:ss")}`);
|
||||
|
68
src/public/scheduler/scheduler_xiaofeijingsai.ts
Normal file
68
src/public/scheduler/scheduler_xiaofeijingsai.ts
Normal 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)
|
||||
|
||||
}
|
||||
}
|
@ -6,6 +6,13 @@ export type ReqOpen = {
|
||||
};
|
||||
|
||||
export type ResOpen = {
|
||||
list: { _id: string, total: number, player: any }[]
|
||||
myData: { _id: string, total: number, player: any }
|
||||
};
|
||||
list: data[]
|
||||
myData: data
|
||||
};
|
||||
|
||||
type data = {
|
||||
_id: string,
|
||||
total: number,
|
||||
rank: number,
|
||||
player: any
|
||||
}
|
@ -10541,7 +10541,8 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"name": "limit",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
"optional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -10554,30 +10555,8 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"type": {
|
||||
"type": "Array",
|
||||
"elementType": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "_id",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "total",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "player",
|
||||
"type": {
|
||||
"type": "Any"
|
||||
}
|
||||
}
|
||||
]
|
||||
"type": "Reference",
|
||||
"target": "event/xiaofeijingsai/PtlOpen/data"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -10585,30 +10564,41 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"id": 1,
|
||||
"name": "myData",
|
||||
"type": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "_id",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "total",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "player",
|
||||
"type": {
|
||||
"type": "Any"
|
||||
}
|
||||
}
|
||||
]
|
||||
"type": "Reference",
|
||||
"target": "event/xiaofeijingsai/PtlOpen/data"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"event/xiaofeijingsai/PtlOpen/data": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "_id",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "total",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "rank",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "player",
|
||||
"type": {
|
||||
"type": "Any"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user