init
This commit is contained in:
parent
4ba9b9f504
commit
a189f77303
20
src/api_s2c/event/zhoumolibao/ApiOpen.ts
Normal file
20
src/api_s2c/event/zhoumolibao/ApiOpen.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import {ApiCall} from "tsrpc";
|
||||||
|
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/zhoumolibao/PtlOpen";
|
||||||
|
import {PayFun} from "../../../public/pay";
|
||||||
|
import {HuoDongFun} from "../../../public/huodongfun";
|
||||||
|
|
||||||
|
|
||||||
|
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
|
||||||
|
|
||||||
|
let data = await G.mongodb.cEvent('zhoumolibao').findOne({uid: call.uid, type: 'zhoumolibao'})
|
||||||
|
|
||||||
|
let _hd = (await HuoDongFun.gethdList(call, 9))[0]
|
||||||
|
|
||||||
|
let payIds = _hd?.data?.gift?.filter(i => i.payId)?.map(i => i.payId)
|
||||||
|
|
||||||
|
call.succ({
|
||||||
|
record: data?.record || {},
|
||||||
|
buyLog: await PayFun.getPayLogs(call.uid, payIds)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
25
src/api_s2c/event/zhoumolibao/ApiReceive.ts
Normal file
25
src/api_s2c/event/zhoumolibao/ApiReceive.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import {ApiCall} from "tsrpc";
|
||||||
|
import {ReqReceive, ResReceive} from "../../../shared/protocols/event/zhoumolibao/PtlReceive";
|
||||||
|
import {HuoDongFun} from "../../../public/huodongfun";
|
||||||
|
import {PlayerFun} from "../../../public/player";
|
||||||
|
|
||||||
|
export default async function (call: ApiCall<ReqReceive, ResReceive>) {
|
||||||
|
// 查询活动是否有当前领奖的免费选项
|
||||||
|
let _hd = (await HuoDongFun.gethdList(call, 9))[0]
|
||||||
|
let gift = _hd?.data?.gift?.find(i => i.free && i.id == call.req.id)
|
||||||
|
if (!gift) return call.errorCode(-1)
|
||||||
|
|
||||||
|
// 取奖励列表,判断是否有可领取奖励
|
||||||
|
let data = await G.mongodb.cEvent('zhoumolibao').findOne({uid: call.uid, type: 'zhoumolibao'})
|
||||||
|
let rec = data.record[call.req.id]
|
||||||
|
if (rec && rec >= gift?.buyNum) return call.errorCode(-2)
|
||||||
|
|
||||||
|
await PlayerFun.sendPrize(call, gift.prize);
|
||||||
|
|
||||||
|
await G.mongodb.cEvent('zhoumolibao').updateOne({uid: call.uid, type: 'zhoumolibao'}, {
|
||||||
|
$inc: {[`record.${gift.id}`]: 1}
|
||||||
|
},{ upsert: true })
|
||||||
|
|
||||||
|
call.succ({})
|
||||||
|
|
||||||
|
}
|
@ -9,7 +9,7 @@ async function connGameLogDB() {
|
|||||||
}else{
|
}else{
|
||||||
logDBUrl = "mongodb://root:lyMaple525458@10.0.1.20:27017/heijiao_gamelog?authSource=admin";
|
logDBUrl = "mongodb://root:lyMaple525458@10.0.1.20:27017/heijiao_gamelog?authSource=admin";
|
||||||
}
|
}
|
||||||
let client = await MongoClient.connect(logDBUrl);
|
let client = await MongoClient.connect(logDBUrl,{maxPoolSize:10});
|
||||||
logDB = client.db(`gameLog${G.config.serverId}`);
|
logDB = client.db(`gameLog${G.config.serverId}`);
|
||||||
return logDB;
|
return logDB;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import {ResOpen as ResOpenZhanLing} from '../shared/protocols/event/zhanling/Ptl
|
|||||||
import {ResOpen as ResOpenZhoulibao} from '../shared/protocols/event/zhoulibao/PtlOpen';
|
import {ResOpen as ResOpenZhoulibao} from '../shared/protocols/event/zhoulibao/PtlOpen';
|
||||||
import {ResOpen as ResOpenZixuanlibao} from '../shared/protocols/event/zixuanlibao/PtlOpen';
|
import {ResOpen as ResOpenZixuanlibao} from '../shared/protocols/event/zixuanlibao/PtlOpen';
|
||||||
import {ResOpen as ResOpenKaifujingsai} from '../shared/protocols/kaifujingsai/PtlOpen';
|
import {ResOpen as ResOpenKaifujingsai} from '../shared/protocols/kaifujingsai/PtlOpen';
|
||||||
|
import {ResOpen as ResOpenZhoumolibao} from '../shared/protocols/event/zhoumolibao/PtlOpen';
|
||||||
|
|
||||||
export type eventType = {
|
export type eventType = {
|
||||||
shouchong: {
|
shouchong: {
|
||||||
@ -45,7 +46,8 @@ export type eventType = {
|
|||||||
xianshizhaomu: ResOpenXianshizhaomu & { refreshTime: number; };
|
xianshizhaomu: ResOpenXianshizhaomu & { refreshTime: number; };
|
||||||
qirichongzhi: Omit<ResOpenQirichongzhi, 'finished'>;
|
qirichongzhi: Omit<ResOpenQirichongzhi, 'finished'>;
|
||||||
jierihuodong: Omit<ResOpenJierihuodong, 'taskFinish'> & { refreshTime: number; };
|
jierihuodong: Omit<ResOpenJierihuodong, 'taskFinish'> & { refreshTime: number; };
|
||||||
kaifujingsai: ResOpenKaifujingsai
|
kaifujingsai: ResOpenKaifujingsai;
|
||||||
|
zhoumolibao: ResOpenZhoumolibao;
|
||||||
} & {
|
} & {
|
||||||
[k: `${number}jijin`]: ResOpenYuedujijin;
|
[k: `${number}jijin`]: ResOpenYuedujijin;
|
||||||
[k: `yangchengmubiao${number}`]: yangchengmubiao;
|
[k: `yangchengmubiao${number}`]: yangchengmubiao;
|
||||||
|
@ -37,6 +37,7 @@ export class HuoDongFun {
|
|||||||
let openTime = PublicShared.getToDayZeroTime(G.openTime)
|
let openTime = PublicShared.getToDayZeroTime(G.openTime)
|
||||||
let _sDay = Number((G.time - openTime) / 86400)
|
let _sDay = Number((G.time - openTime) / 86400)
|
||||||
|
|
||||||
|
// ttype为0 根据开服时间计算,ttype为1,根据用户注册时间计算
|
||||||
let _where = {
|
let _where = {
|
||||||
$or: [
|
$or: [
|
||||||
{
|
{
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
IndexDescription,
|
IndexDescription,
|
||||||
IndexSpecification,
|
IndexSpecification,
|
||||||
MongoClient,
|
MongoClient,
|
||||||
|
MongoClientOptions,
|
||||||
ObjectId,
|
ObjectId,
|
||||||
OptionalId
|
OptionalId
|
||||||
} from 'mongodb';
|
} from 'mongodb';
|
||||||
@ -16,6 +17,7 @@ import {MongodbCollections} from './module/mongodb';
|
|||||||
import {HuoDongFun} from './public/huodongfun';
|
import {HuoDongFun} from './public/huodongfun';
|
||||||
import {zbsGroup} from './api_s2c/hbzb/zbs/fun';
|
import {zbsGroup} from './api_s2c/hbzb/zbs/fun';
|
||||||
import {clusterRunOnce} from './clusterUtils';
|
import {clusterRunOnce} from './clusterUtils';
|
||||||
|
import { PublicShared } from './shared/public/public';
|
||||||
|
|
||||||
const indexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] }> = {
|
const indexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] }> = {
|
||||||
item: [
|
item: [
|
||||||
@ -349,9 +351,37 @@ const indexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] }> =
|
|||||||
};
|
};
|
||||||
|
|
||||||
const crossIndexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] }> = {
|
const crossIndexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] }> = {
|
||||||
|
email: [
|
||||||
|
{
|
||||||
|
key: {sid: 1}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {uid: 1}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
fightLog: [
|
||||||
|
{
|
||||||
|
key: {uid: 1, type: 1}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {uid: 1}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {ttl: 1}, expireAfterSeconds: 7 * 24 * 3600
|
||||||
|
}
|
||||||
|
],
|
||||||
hbzb_user_cross: [
|
hbzb_user_cross: [
|
||||||
{
|
{
|
||||||
key: {uid: 1}, unique: true
|
key: {uid: 1}, unique: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {jifen: 1}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {rank: 1}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {zbsgroup: 1}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
hbzb_user_zbs: [
|
hbzb_user_zbs: [
|
||||||
@ -377,13 +407,52 @@ const crossIndexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[]
|
|||||||
rankList: [
|
rankList: [
|
||||||
{
|
{
|
||||||
key: {type: 1, idKey: 1}, unique: true
|
key: {type: 1, idKey: 1}, unique: true
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
key: {valArr: -1}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
wzry_fight: [
|
||||||
|
{
|
||||||
|
key: {jifen: 1}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {uid: 1}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {zkey: 1}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
wzry_user_cross: [
|
||||||
|
{
|
||||||
|
key: {jifen: 1}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {uid: 1}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {zkey: 1}
|
||||||
|
},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function initMongoDB() {
|
export async function initMongoDB() {
|
||||||
|
//mongodb连接数说明:https://blog.csdn.net/for_cxc/article/details/116859714
|
||||||
|
//可结合查看:node_modules\mongodb\lib\connection_string.js
|
||||||
|
//maxPoolSize默认值:100
|
||||||
|
|
||||||
|
let option:MongoClientOptions;
|
||||||
|
//跨服只有1个,直接采用默认配置就行
|
||||||
|
if(G.argv.serverType != 'cross'){
|
||||||
|
if(PublicShared.getOpenServerDay() > 3){
|
||||||
|
option = {
|
||||||
|
maxPoolSize: 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log('connect mongodb ......');
|
console.log('connect mongodb ......');
|
||||||
let client = await MongoClient.connect(G.argv.serverType == 'cross' ? G.config.crossMongodbUrl : G.config.mongodbUrl);
|
let client = await MongoClient.connect(G.argv.serverType == 'cross' ? G.config.crossMongodbUrl : G.config.mongodbUrl, option);
|
||||||
G.mongodb = new _mongodb(client.db(G.config.dbName || ''));
|
G.mongodb = new _mongodb(client.db(G.config.dbName || ''));
|
||||||
console.log('connect mongodb succ');
|
console.log('connect mongodb succ');
|
||||||
|
|
||||||
@ -391,7 +460,9 @@ export async function initMongoDB() {
|
|||||||
if (G.argv.serverType != 'cross') {
|
if (G.argv.serverType != 'cross') {
|
||||||
console.log('connect crossmongodb ......');
|
console.log('connect crossmongodb ......');
|
||||||
//本服里,维持住跟跨服数据库的链接
|
//本服里,维持住跟跨服数据库的链接
|
||||||
let crossClient = await MongoClient.connect(G.config.crossMongodbUrl);
|
let crossClient = await MongoClient.connect(G.config.crossMongodbUrl,{
|
||||||
|
maxPoolSize:10
|
||||||
|
});
|
||||||
G.crossmongodb = new _mongodb(crossClient.db(G.config.corssDBName || ""));
|
G.crossmongodb = new _mongodb(crossClient.db(G.config.corssDBName || ""));
|
||||||
console.log('connect crossmongodb succ');
|
console.log('connect crossmongodb succ');
|
||||||
}
|
}
|
||||||
|
16
src/shared/protocols/event/zhoumolibao/PtlOpen.ts
Normal file
16
src/shared/protocols/event/zhoumolibao/PtlOpen.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* 周末礼包
|
||||||
|
*/
|
||||||
|
export type ReqOpen = {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ResOpen = {
|
||||||
|
record:{
|
||||||
|
[k: string]: number;
|
||||||
|
}
|
||||||
|
buyLog:{
|
||||||
|
[k: string]: number;
|
||||||
|
}
|
||||||
|
};
|
10
src/shared/protocols/event/zhoumolibao/PtlReceive.ts
Normal file
10
src/shared/protocols/event/zhoumolibao/PtlReceive.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* 周末礼包领奖
|
||||||
|
*/
|
||||||
|
export interface ReqReceive {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResReceive {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user