活动:每日充值
This commit is contained in:
@@ -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[] = []) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user