活动:每日充值

This commit is contained in:
luying
2022-03-04 09:47:24 +08:00
parent 17b5071d66
commit 8649cb82b7
8 changed files with 171 additions and 131 deletions
+2 -1
View File
@@ -431,7 +431,7 @@ export const STATUS = {
ACTIVITY_FIRST_GIFT_END: { code: 50016, simStr: '首充结束' },
ACTIVITY_NEW_PLAYER_LIMIT_PACKAGE_END: { code: 50017, simStr: '新手礼包结束' },
ACTIVITY_RECHARGE_MONEY_ERROR: { code: 50018, simStr: '充值数据错误' },
ACTIVITY_RECHARGE_MONEY_NO_REWARD: { code: 50019, simStr: '没有可领取的奖励' },
ACTIVITY_RECHARGE_TICKET_NOT_ENOUGH: { code: 50019, simStr: '签数不足' },
ACTIVITY_SIGNIN_VIP_CONDITION: { code: 50020, simStr: '开启条件不足' },
ACTIVITY_SIGNIN_EXPIRE: { code: 50021, simStr: '签到过期,补签' },
ACTIVITY_POP_UP_SHOP_EXPIRE: { code: 50022, simStr: '弹出商店过期' },
@@ -447,6 +447,7 @@ export const STATUS = {
MONOPOLY_BANK_SAVE_MAX: { code: 50032, simStr: '超过最大限制数量' },
NOT_GIFTPACKAGE: { code: 50033, simStr: '非礼包类型' },
SHOP_CLOSED: { code: 50034, simStr: '停业' },
ACTIVITY_RECHARGE_ITEM_NOT_ENOUGH: { code: 50035, simStr: '商品不足' },
// GM后台相关状态 60000 - 69999
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },
+6 -13
View File
@@ -19,31 +19,24 @@ export default class Activity_Recharge_Money extends BaseModel {
@prop({ required: true })
RMB: number; // 充值金额
@prop({ required: true })
index: number; // 第几个格子
poolId: number; // 奖池唯一id
@prop({ required: true })
reward: string; // 领取奖励内容
@prop({ required: true })
rewardTime: Date; // 领取奖励时间
@prop({ required: true })
isEnd: boolean; // 结束
//添加领取记录
public static async addRecord(_id: string, id: number, reward: string) {
public static async addRecord(_id: string, poolId: number, reward: string) {
console.log(_id, poolId, reward)
let result: ActivityRechargeMoneyModelType = await ActivityRechargeMoneyModel.findOneAndUpdate({ _id },
{ $set: { index: id, reward, rewardTime: new Date() } },
{ $set: { poolId, reward, rewardTime: new Date() } },
{ upsert: true, new: true }).lean(true);
return result;
}
//本轮结束
public static async setEndState(serverId: number, roleId: string, _ids: string[]) {
await ActivityRechargeMoneyModel.updateMany({ serverId, roleId, _id: { $in: _ids } },
{ $set: { isEnd: true } }, { multi: true, });
}
//查询
public static async findData(serverId: number, roleId: string) {
let result: ActivityRechargeMoneyModelType[] = await ActivityRechargeMoneyModel.find({ serverId, roleId, isEnd: { $ne: true } }).lean(true);
public static async findDataByTime(serverId: number, roleId: string, beginTime: Date, endTime: Date) {
let result: ActivityRechargeMoneyModelType[] = await ActivityRechargeMoneyModel.find({ serverId, roleId, beginTime: { $gte: beginTime }, endTime: { $lte: endTime } }).sort({ beginTime: 1 }).lean(true);
return result;
}
@@ -21,7 +21,7 @@ interface TurntableFloorInDb { // 保底,每sum次必出count个头奖,头
interface TurntableBoxInDb {
count: number; // 次数
reward: string; // 奖励 type&id&count
rewards: string; // 奖励 type&id&count
}
interface TurntableInDb {
@@ -54,13 +54,13 @@ export class LuckyTurntablePool {
export class LuckyTurntableBox {
count: number; // 次数
reward: string; // 奖励
rewards: string; // 奖励
isReceived: boolean = false; // 是否已领取
constructor(data: TurntableBoxInDb) {
this.count = data.count;
this.reward = data.reward;
this.rewards = data.rewards;
}
public setReceived(box: number[] = []) {
+128 -54
View File
@@ -2,86 +2,160 @@ import moment = require('moment');
import { random } from 'underscore';
import { ActivityModelType } from '../../db/Activity';
import { ActivityRechargeMoneyModelType } from '../../db/ActivityRechargeMoney';
import { getRandEelmWithWeight, getRandSingleEelm } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
interface RechargeMoneyPoolInDb {
id: number; // 奖池项唯一id
gid: number;
count: number;
quality: number; // 物品的品级,相同的品级平分概率,不同品级直接按percent来做概率
}
interface RechargeMoneyWeightInDb {
quality: number; // pool中的品级
weight: number; // 权重,先随机出这个品级的物品的概率,然后再平均随机出这个品级下的物品
}
interface RechargeMoneyPercentInDb {
todayIndex: number; // 第几天,和前面排名奖励的填法一样,如第1天、第2-10天,只需填todayIndex=1和10的两项
data: RechargeMoneyWeightInDb[]; // 这一天的权重
}
interface RechargeMoneyInDb {
pool: RechargeMoneyPoolInDb[];
minPrice: number;
percent: RechargeMoneyPercentInDb[];
}
// 充值记录
export class RechargeMoneyItem {
_id: string; //mongodb
id: number; //商品id
name: string; //商品名称
reward: string; //奖励
export class RechargeMoneyPool {
id: number; // 卡池id
gid: number;
count: number;
quality: number; // 物品的品级
rewardTime: Date; //领奖时间
hasGet: boolean = false; // 是否已经获取过了
constructor(data: any) {
constructor(data: RechargeMoneyPoolInDb) {
this.id = data.id;
this.name = data.name;
this.reward = data.reward;
this.rewardTime = null;
this.gid = data.gid;
this.count = data.count;
this.quality = data.quality;
}
setHasGet(hasGet: boolean) {
this.hasGet = hasGet;
}
}
export class RechargeMoneyWeight {
quality: number;
weight: number;
constructor(data: RechargeMoneyWeightInDb) {
this.quality = data.quality;
this.weight = data.weight;
}
}
export class RechargeMoneyPercent {
todayIndex: number;
data: RechargeMoneyWeight[] = [];
constructor(data: RechargeMoneyPercentInDb) {
this.todayIndex = data.todayIndex;
for(let obj of data.data) {
this.data.push(new RechargeMoneyWeight(obj));
}
}
}
// 累计充值数据
export class RechargeMoneyData extends ActivityBase {
list: Array<RechargeMoneyItem> = [];//记录
days: number = 0;
price: number = 0;
private map: Map<number, number> = new Map(); // poolId => index
private percentMap: Map<number, number> = new Map(); // todayIndex => 的index
pool: RechargeMoneyPool[] = [];
minPrice: number = 0;
percent: RechargeMoneyPercent[] = [];
totalCount: number = 0;//一共可领取次
receiveCount: number = 0;//已经领取次数
ticketCnt: number = 0; // 签
recordArr: ActivityRechargeMoneyModelType[] = [];
recordArray: ActivityRechargeMoneyModelType[] = [];
//当前回合最后一个
public isLast() {
let items = this.list.filter(obj => { return obj && !obj.rewardTime });
return items.length === 1;
private findItemFromPool(poolId: number) {
let index = this.map.get(poolId);
return this.pool[index];
}
public randomReward(): RechargeMoneyItem {
let items = this.list.filter(obj => { return obj && (!obj.rewardTime || obj.rewardTime == undefined) })
if (items.length == 0) {
return null;
private findTodayPercent() {
let index = this.percentMap.get(this.todayIndex);
return this.percent[index];
}
public pull() {
let percent = this.findTodayPercent();
if(!percent) return false;
let randPercent = percent.data.filter(cur => {
let hasAllGet = true;
for(let { quality, hasGet } of this.pool) {
if(quality == cur.quality && !hasGet) hasAllGet = false;
}
return !hasAllGet;
});
if(randPercent.length <=0) return false; // 全部抽完了
let qualityResult = getRandEelmWithWeight(randPercent);
if(!qualityResult) return false;
let elems: RechargeMoneyPool[] = [];
for(let pool of this.pool) {
if(pool && !pool.hasGet && pool.quality == qualityResult.dic.quality) {
elems.push(pool);
}
}
let index = random(items.length - 1);
return items[index];
let result = getRandSingleEelm(elems);
return result;
}
//解析玩家购买记录
public setPlayerRecords(data: ActivityRechargeMoneyModelType[]) {
this.todayIndex = 0;
if (!data) {
return;
}
this.recordArray = data.filter(obj => {
return obj.RMB >= this.price;
}).sort((a, b) => {
return moment(a.beginTime).valueOf() - moment(b.beginTime).valueOf()
})
if (!data) return;
this.totalCount = this.recordArray.length;
this.receiveCount = 0;
for (let item of this.list) {
let index = this.recordArray.findIndex(obj => { return obj.index === item.id })
if (index != -1) {
this.receiveCount++;
item.rewardTime = this.recordArray[index].rewardTime;
for(let record of data) {
if(record.RMB >= this.minPrice) {
if(!record.rewardTime) {
this.ticketCnt++;
this.recordArr.push(record);
}
}
if(record.poolId) {
let pool = this.findItemFromPool(record.poolId);
if(pool) pool.setHasGet(true);
}
}
}
public initData(data: string) {
let dataObj = JSON.parse(data);
this.days = dataObj.days;
this.price = dataObj.price;
let arr = dataObj.data;
for (let obj of arr) {
this.list.push(new RechargeMoneyItem(obj))
public getShowResult() {
return {
...this.getBaseKeys(),
ticketCnt: this.ticketCnt,
pool: this.pool,
}
}
public initData(data: string) {
let dataObj: RechargeMoneyInDb = JSON.parse(data);
console.log(dataObj);
for(let pool of dataObj.pool) {
let obj = new RechargeMoneyPool(pool);
this.pool.push(obj);
this.map.set(obj.id, this.pool.length - 1);
}
this.minPrice = dataObj.minPrice;
for(let percent of dataObj.percent) {
let obj = new RechargeMoneyPercent(percent);
this.percent.push(obj);
this.percentMap.set(obj.todayIndex, this.percent.length - 1);
}
this.list = this.list.sort((a, b) => {
return a.id - b.id
})
}
constructor(activityData: ActivityModelType, createTime: number) {