init 元旦活动

This commit is contained in:
dy 2023-12-25 13:48:18 +08:00
parent f8298f08e9
commit 00804fa8c1
25 changed files with 1048 additions and 269 deletions

View File

@ -0,0 +1,16 @@
import {ApiCall} from "tsrpc";
import {ReqDMOpen, ResDMOpen} from "../../../shared/protocols/event/yuandan/PtlDMOpen";
import {HuoDongFun} from "../../../public/huodongfun";
import {PayFun} from "../../../public/pay";
export default async function (call: ApiCall<ReqDMOpen, ResDMOpen>) {
let data = await G.mongodb.cEvent('yuandandamo').findOne({uid: call.uid, type: 'yuandandamo'})
let _hd = (await HuoDongFun.gethdList(call, 14))[0]
let payIds = _hd?.data?.gift?.filter(i => i.payId)?.map(i => i.payId)
call.succ({
record: data?.record || {}
})
}

View File

@ -0,0 +1,27 @@
import {ApiCall} from "tsrpc";
import {ReqDMRec, ResDMRec} from "../../../shared/protocols/event/yuandan/PtlDMRec";
import {HuoDongFun} from "../../../public/huodongfun";
import {PlayerFun} from "../../../public/player";
import {HongDianChange} from "../../hongdian/fun";
export default async function (call: ApiCall<ReqDMRec, ResDMRec>) {
// 查询活动是否有当前领奖的免费选项
let _hd = (await HuoDongFun.gethdList(call, 14))[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('yuandandamo').findOne({uid: call.uid, type: 'yuandandamo'})
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('yuandandamo').updateOne({uid: call.uid, type: 'yuandandamo'}, {
$inc: {[`record.${gift.id}`]: 1},
}, {upsert: true})
call.succ({})
HongDianChange.sendChangeKey(call.uid, ['yuandan']);
}

View File

@ -0,0 +1,17 @@
import {ApiCall} from "tsrpc";
import {ReqDZOpen, ResDZOpen} from "../../../shared/protocols/event/yuandan/PtlDZOpen";
import {HuoDongFun} from "../../../public/huodongfun";
import {PayFun} from "../../../public/pay";
export default async function (call: ApiCall<ReqDZOpen, ResDZOpen>) {
let data = await G.mongodb.cEvent('yuandandingzhi').findOne({uid: call.uid, type: 'yuandandingzhi'})
let _hd = (await HuoDongFun.gethdList(call, 14))[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)
})
}

View File

@ -0,0 +1,27 @@
import {ApiCall} from "tsrpc";
import {ReqDZRec, ResDZRec} from "../../../shared/protocols/event/yuandan/PtlDZRec";
import {HuoDongFun} from "../../../public/huodongfun";
import {PlayerFun} from "../../../public/player";
import {HongDianChange} from "../../hongdian/fun";
export default async function (call: ApiCall<ReqDZRec, ResDZRec>) {
// 查询活动是否有当前领奖的免费选项
let _hd = (await HuoDongFun.gethdList(call, 14))[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('yuandandingzhi').findOne({uid: call.uid, type: 'yuandandingzhi'})
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('yuandandingzhi').updateOne({uid: call.uid, type: 'yuandandingzhi'}, {
$inc: {[`record.${gift.id}`]: 1},
}, {upsert: true})
call.succ({})
HongDianChange.sendChangeKey(call.uid, ['yuandan']);
}

View File

@ -0,0 +1,28 @@
import {ApiCall} from "tsrpc";
import {ReqExchange, ResExchange} from "../../../shared/protocols/event/yuandan/PtlExchange";
import {HuoDongFun} from "../../../public/huodongfun";
import {PlayerFun} from "../../../public/player";
import {HongDianChange} from "../../hongdian/fun";
export default async function (call: ApiCall<ReqExchange, ResExchange>) {
// 查询活动是否有当前领奖的免费选项
let _hd = (await HuoDongFun.gethdList(call, 14))[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('yuandanduihuan').findOne({uid: call.uid, type: 'yuandanduihuan'})
let rec = data?.record?.[call.req.id]
if (rec && rec >= gift?.buyNum) return call.errorCode(-2)
await PlayerFun.sendPrize(call, gift.prize);
await PlayerFun.cutNeed(call, gift.prize)
await G.mongodb.cEvent('yuandanduihuan').updateOne({uid: call.uid, type: 'yuandanduihuan'}, {
$inc: {[`record.${gift.id}`]: 1},
}, {upsert: true})
call.succ({})
HongDianChange.sendChangeKey(call.uid, ['yuandan']);
}

View File

@ -0,0 +1,10 @@
import {ApiCall} from "tsrpc";
import {ReqExchangeOpen, ResExchangeOpen} from "../../../shared/protocols/event/yuandan/PtlExchangeOpen";
export default async function (call: ApiCall<ReqExchangeOpen, ResExchangeOpen>) {
let data = await G.mongodb.cEvent('yuandanduihuan').findOne({uid: call.uid, type: 'yuandanduihuan'})
call.succ({
record: data?.record || {},
})
}

View File

@ -0,0 +1,40 @@
import { ApiCall } from "tsrpc";
import { ReqTaskRec, ResTaskRec } from "../../../shared/protocols/event/christmas/PtlTaskRec";
import {Christmasfun} from "./fun";
import {HongDianChange} from "../../hongdian/fun";
import {PlayerFun} from "../../../public/player";
export default async function (call: ApiCall<ReqTaskRec, ResTaskRec>) {
let initCon = await Christmasfun.getCon(call)
let taskid = call.req.taskid;
let _con = initCon[call.req.hdid].data.task[taskid];
if (!_con) {
// 任务id 不存在
return call.error('', { code: -1, message: globalThis.lng.yangchengmubiao_2 })
}
let _mydata = await Christmasfun.getMyData(call, call.req.hdid)
if (_mydata.taskval[taskid] < _con.pval) {
// 任务未完成
return call.error('', { code: -2, message: globalThis.lng.yangchengmubiao_3 })
}
if (_mydata.taskfinish.includes(taskid)) {
// 任务已领取
return call.error('', { code: -3, message: globalThis.lng.yangchengmubiao_4 })
}
_mydata.taskfinish.push(taskid)
let _addval = _con.addval
let _setData = {}
_mydata["val"] += _addval
_setData["val"] = _mydata.val
_setData["taskfinish"] = _mydata.taskfinish
await Christmasfun.setMyData(call.uid, call.req.hdid, { $set: _setData })
let _prize = _con.prize
await PlayerFun.sendPrize(call, _prize);
let changedata = { mydata: _mydata, prize: _prize}
// 推送红点
HongDianChange.sendChangeKey(call.uid, ['huodonghd']);
call.succ(changedata);
}

View File

View File

@ -0,0 +1,16 @@
import {ApiCall} from "tsrpc";
import {ReqZLOpen, ResZLOpen} from "../../../shared/protocols/event/yuandan/PtlZLOpen";
import {HuoDongFun} from "../../../public/huodongfun";
import {PayFun} from "../../../public/pay";
export default async function (call: ApiCall<ReqZLOpen, ResZLOpen>) {
let data = await G.mongodb.cEvent('yuandanzengli').findOne({uid: call.uid, type: 'yuandanzengli'})
let _hd = (await HuoDongFun.gethdList(call, 14))[0]
let payIds = _hd?.data?.gift?.filter(i => i.payId)?.map(i => i.payId)
call.succ({
record: data?.record || {},
})
}

View File

@ -0,0 +1,27 @@
import {ApiCall} from "tsrpc";
import {ReqZLRec, ResZLRec} from "../../../shared/protocols/event/yuandan/PtlZLRec";
import {HuoDongFun} from "../../../public/huodongfun";
import {PlayerFun} from "../../../public/player";
import {HongDianChange} from "../../hongdian/fun";
export default async function (call: ApiCall<ReqZLRec, ResZLRec>) {
// 查询活动是否有当前领奖的免费选项
let _hd = (await HuoDongFun.gethdList(call, 14))[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('yuandandamo').findOne({uid: call.uid, type: 'yuandandamo'})
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('yuandandamo').updateOne({uid: call.uid, type: 'yuandandamo'}, {
$inc: {[`record.${gift.id}`]: 1},
}, {upsert: true})
call.succ({})
HongDianChange.sendChangeKey(call.uid, ['yuandan']);
}

View File

@ -0,0 +1,214 @@
import {ApiCall} from 'tsrpc';
import {ReqAddHuoDong} from '../../../monopoly/protocols/PtlAddHuoDong';
import {HuoDongFun} from '../../../public/huodongfun';
import {christmas} from '../../../shared/protocols/event/christmas/PtlOpen';
import {PublicShared} from '../../../shared/public/public';
import {PlayerFun} from "../../../public/player";
export class Yuandanfun {
/**配置 */
static async getCon(call: ApiCall) {
let _con: { [id: string]: ReqAddHuoDong } = {}
let _hd = await HuoDongFun.gethdList(call, 8)
for (let index = 0; index < _hd.length; index++) {
const element = _hd[index];
if (element && element._id) delete element._id
_con[element.hdid] = element
}
return _con
}
/**获取所有符合时间的活动 */
static async gethdids(call: ApiCall) {
let _hdids = []
let _hd = await HuoDongFun.gethdList(call, 8)
for (let index = 0; index < _hd.length; index++) {
const element = _hd[index];
_hdids.push(element.hdid)
}
return _hdids
}
/**获取我的数据 */
static async getMyData(call: ApiCall, hdid: number) {
let db: any = await G.mongodb.cEvent(`christmas${hdid}`).findOne({
uid: call.uid,
type: `christmas${hdid}`,
hdid: hdid
});
if (!db) {
db = await this.initData(call, hdid)
await G.mongodb.cEvent(`christmas${hdid}`).updateOne(
{uid: call.uid, type: `christmas${hdid}`, hdid: hdid},
{$set: db},
{upsert: true}
)
}
let {_id, ..._myData} = db
if (!PublicShared.chkSameDate(_myData.refresh, G.time)) {
// 刷新每日任务
_myData = await this.refreTask(call, _myData, hdid)
}
return _myData
}
/**初始数据 */
static async initData(call: ApiCall, hdid: number) {
let _initCon = await this.getCon(call)
let _con = _initCon[hdid]
let _r: christmas = {
type: `christmas${hdid}`,
uid: call.uid,
hdid: hdid,
taskval: await this.getTaskVal(call, hdid),
taskfinish: [],
refresh: G.time,
gamenum: 0,
pt: [],
gj: [],
pay: false,
select: {},
val: 0,
qiandao: [],
libao: {}
}
return _r
}
/**设置数据 */
static async setMyData(uid: string, hdid: number, set: {}) {
await G.mongodb.cEvent(`christmas${hdid}`).updateOne(
{uid: uid, type: `christmas${hdid}`, hdid: hdid},
set
)
}
/**获取所有taskid 及对应的值 */
static async getTaskVal(call: ApiCall, hdid: number) {
let _initCon = await this.getCon(call)
let _tasks = _initCon[hdid].data.task
let _res = {}
for (let index = 0; index < Object.keys(_tasks).length; index++) {
const element = Object.keys(_tasks)[index];
let _tmp = _tasks[element]
_tmp["id"] = element
// 每日登录直接完成
if (element == "1") {
_res[element] = 1
} else {
_res[element] = 0
}
}
return _res
}
/**刷新每日任务 */
static async refreTask(call: ApiCall, mydata: christmas, hdid: number) {
let _initCon = await this.getCon(call)
let _con = _initCon[hdid].data.task
if (!_con) return mydata
mydata.taskfinish = []
mydata.taskval = await this.getTaskVal(call, hdid)
mydata.refresh = G.time
mydata.gamenum = 0
mydata.libao = {}
await this.setMyData(call.uid, hdid, {
$set: {
refresh: mydata.refresh,
taskfinish: mydata.taskfinish,
taskval: mydata.taskval,
gamenum: mydata.gamenum,
libao: mydata.libao
}
})
return mydata
}
static async payChristmas(payid, call: any) {
let _hd = await HuoDongFun.gethdList(call, 8)
for (let index = 0; index < _hd.length; index++) {
const hdinfo = _hd[index];
const _hdid = hdinfo.hdid
if (payid == hdinfo.data.zlpayid) {
let _mydata = await Yuandanfun.getMyData(call, _hdid)
if (_mydata.pay) continue
await this.setMyData(call.uid, _hdid, {$set: {pay: true}})
// let _prize = hdinfo.data.zlpayprize
// await PlayerFun.sendPrize(call, _prize);
} else {
const libaos = hdinfo.data.libao
for (let index = 0; index < Object.keys(libaos).length; index++) {
const lbid = Object.keys(libaos)[index];
let _tmp = libaos[lbid]
if (_tmp['payid'] != payid) continue
let _mydata = await Yuandanfun.getMyData(call, _hdid)
let _buyNum = _mydata.libao[lbid] || 0
if (_buyNum >= _tmp["buynum"]) continue
_mydata.libao[lbid] = _buyNum + 1
this.setMyData(call.uid, _hdid, {$set: {libao: _mydata.libao}})
let _select = _mydata.select[lbid] || {}
let _prize: atn[] = _tmp["basep"]
for (let key in _select) {
_prize.push(_tmp["dlz"][parseInt(key)][_select[key]])
}
await PlayerFun.sendPrize(call, _prize);
break
}
}
}
}
/**设置任务 */
static async setTaskVal(call: ApiCall, stype: number, val: number, chkCall: Function, chkval: number = 0, isinc: number = 0, alchangeVal: Function, arg) {
let hdids = await this.gethdids(call)
if (hdids.length <= 0) return // 活动过期,不计数
let _initCon = await this.getCon(call)
for (let index = 0; index < hdids.length; index++) {
const hdid = hdids[index];
// let _mydata = await Christmasfun.getMyData(call, hdid)
let _tasks = _initCon[hdid].data.task
let _setData = {
$inc: {},
$set: {}
}
let isset = 0
for (let indextask = 0; indextask < Object.keys(_tasks).length; indextask++) {
const ele = Object.keys(_tasks)[indextask];
// 具体任务配置
let _taskCon = _tasks[ele]
if (_taskCon.stype != stype) continue
let _pval = _taskCon.pval
// 不符合任务要求
if (!(await chkCall(_taskCon["cond"], chkval, arg))) continue
// 根据需求改写
val = await alchangeVal(call, _taskCon, val, arg)
isset = 1
if (isinc == 1) { // 累加
_setData["$inc"][`taskval.${ele}`] = val
} else {
_setData["$set"][`taskval.${ele}`] = val
}
}
// 设置任务
if (isset == 1) {
await G.mongodb.collection('event').updateMany(
{uid: call.uid, type: {$regex: "christmas"}, hdid: parseInt(hdid)},
_setData
)
}
}
}
}

View File

@ -44,10 +44,10 @@ export function clusterPublish(key: string, data: any) {
* N个进程中使
*/
export function clusterRunOnce(fun) {
console.log(`${process.pid}环境变量pm_id===>${process.env.pm_id}`);
// console.log(`${process.pid}环境变量pm_id===>${process.env.pm_id}`);
if (process.env.pm_id == null || process.env.pm_id === '0') {
//非pm2启动的或是pm2下启动的第一个进程
console.log("run clusterRunOnce1 ===>", process.pid)
// console.log("run clusterRunOnce1 ===>", process.pid)
fun();
return;
}
@ -56,7 +56,7 @@ export function clusterRunOnce(fun) {
if (firstPid == process.pid) {
//pm2的其中一个进程
console.log("run clusterRunOnce2 ===>", process.pid)
// console.log("run clusterRunOnce2 ===>", process.pid)
fun();
return;
}

View File

@ -57,6 +57,11 @@ export type eventType = {
payForDiamond: {
[time: number]: number
}
yuandandingzhi: ResOpenZhoumolibao & { refreshTime: number; };
yuandanduihuan: ResOpenZhoumolibao & { refreshTime: number; };
yuandandamo: ResOpenZhoumolibao & { refreshTime: number; };
yuandanzengli: ResOpenZhoumolibao & { refreshTime: number; };
} & {
[k: `${number}jijin`]: ResOpenYuedujijin;
[k: `yangchengmubiao${number}`]: yangchengmubiao;
@ -67,6 +72,7 @@ export type eventType = {
[k: `leijichongzhi${number}`]: Omit<ResOpenLeijichongzhi, 'payNum'>;
[k: `qiridenglu${number}`]: Pick<ResOpenQiridenglu, 'recPrize'>;
[k: `leichonglibao${number}`]: ResOpenLeiChongLiBao & { opentime: number };
[k: `yuandan${number}`]: christmas;
};
export type CollectionEvent<T extends keyof eventType> = {

View File

@ -239,6 +239,15 @@ export class PayFun {
console.log("Christmasfun.payChristmas Error", e);
}
/**
* payArgs里传入自选项
* check里判断拦截自选项的奖励
*/
if (payArgs.selectPrize) {
prize.push(...payArgs.selectPrize)
}
let isReplaceConf = await this.checkBuysAfterPay(uid, payId, conf, payArgs, player)
if (isReplaceConf) {
let prizePayId = `zuanshi_${conf.money}`

View File

@ -0,0 +1,13 @@
/**
*
*/
export type ReqDMOpen = {
};
export type ResDMOpen = {
record:{
[k: string]: any;
}
};

View File

@ -0,0 +1,11 @@
/**
*
*/
export type ReqDMRec = {
id: string
}
export type ResDMRec = {
}

View File

@ -0,0 +1,16 @@
/**
*
*/
export type ReqDZOpen = {
};
export type ResDZOpen = {
record:{
[k: string]: any;
}
buyLog:{
[k: string]: any;
}
};

View File

@ -0,0 +1,10 @@
/**
*
*/
export type ReqDZRec = {
id: string
}
export type ResDZRec = {
}

View File

@ -0,0 +1,11 @@
/**
*
*/
export type ReqExchange = {
id: string
}
export type ResExchange = {
}

View File

@ -0,0 +1,12 @@
/**
*
*/
export type ReqExchangeOpen = {
}
export type ResExchangeOpen = {
record:{
[k: string]: any;
}
}

View File

@ -0,0 +1,13 @@
/**
*
*/
export type ReqZLOpen = {
};
export type ResZLOpen = {
record:{
[k: string]: any;
}
};

View File

@ -0,0 +1,11 @@
/**
*
*/
export type ReqZLRec = {
id: string
}
export type ResZLRec = {
}

View File

@ -1,10 +1,10 @@
/**
*
*/
export interface ReqReceive {
export type ReqReceive = {
id: string
}
export interface ResReceive {
export type ResReceive = {
}

View File

@ -54,7 +54,8 @@ export type hongdianKey =
| 'zhoumolibao'
| 'pobinglibao'
| 'payForDiamond'
| 'leichonglibao';
| 'leichonglibao'
| 'yuandan';
export type hongdianVal = {
show?: boolean;
// 看功能需要

File diff suppressed because it is too large Load Diff