活动:调整每日优惠的结构
This commit is contained in:
@@ -388,6 +388,7 @@ export const STATUS = {
|
||||
NO_PAY: { code: 70008, simStr: '未支付' },
|
||||
NO_MOTHLY_TICKET_REWARD: { code: 70009, simStr: '没有可领取的月卡奖励' },
|
||||
ACTIVITY_TYPE_ERROR: { code: 70010, simStr: '活动类型错误' },
|
||||
ACTIVITY_NO_PRODUCT: { code: 70011, simStr: '活动数据错误' }
|
||||
ACTIVITY_NO_PRODUCT: { code: 70011, simStr: '活动数据错误' },
|
||||
ERROR_TYPE: { code: 70012, simStr: '未知活动类型' },
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 购买记录
|
||||
*/
|
||||
|
||||
export class BuyRecord {
|
||||
@prop({ required: true })
|
||||
id: number; //物品id标识
|
||||
@prop({ required: true })
|
||||
time: Date; //购买时间
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 每日特惠礼包RMB购买4挡,一次性支付购买7天,每天只能领取当天的礼包奖励
|
||||
*/
|
||||
@@ -16,18 +28,46 @@ export default class Activity_Daily_RMB_Gifts extends BaseModel {
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户Id
|
||||
@prop({ required: true })
|
||||
id: number; // 领取的商品id
|
||||
beginTime: Date; // 开始时间
|
||||
@prop({ required: true })
|
||||
isBuy: boolean; // 是否已经购买过
|
||||
@prop({ required: true })
|
||||
records: BuyRecord[]; // 领取记录
|
||||
|
||||
//添加领取记录
|
||||
public static async addRecord(serverId: number, activityId: number, roleId: string, id: number) {
|
||||
await ActivityDailyRMBGiftsModel.insertMany(
|
||||
{ serverId, roleId, activityId, id }
|
||||
)
|
||||
public static async receiveRecord(serverId: number, activityId: number, roleId: string, beginTime: Date, ids: number[]) {
|
||||
let data = [];
|
||||
for (let id of ids) {
|
||||
data.push({
|
||||
id,
|
||||
time: new Date()
|
||||
})
|
||||
}
|
||||
let result = await ActivityDailyRMBGiftsModel.findOneAndUpdate(
|
||||
{ serverId, roleId, activityId, beginTime }, { $push: { records: { $each: data } } }, { upsert: true, new: true }
|
||||
).lean(true)
|
||||
return result;
|
||||
}
|
||||
|
||||
//添加购买记录
|
||||
public static async buyRecord(serverId: number, activityId: number, roleId: string, beginTime: Date, isBuy: boolean) {
|
||||
let result = await ActivityDailyRMBGiftsModel.findOneAndUpdate(
|
||||
{ serverId, roleId, activityId, beginTime }, { $set: { isBuy } }, { upsert: true, new: true }
|
||||
).lean(true)
|
||||
return result;
|
||||
}
|
||||
|
||||
//历史领取的记录
|
||||
public static async findRecord(serverId: number, activityId: number, roleId: string, beginTime: Date) {
|
||||
let result: ActivityDailyRMBGiftsModelType[] = await ActivityDailyRMBGiftsModel.find({ serverId, roleId, activityId, createdAt: { $gt: beginTime } }).lean(true);
|
||||
let result: ActivityDailyRMBGiftsModelType = await ActivityDailyRMBGiftsModel.findOne(
|
||||
{ serverId, roleId, activityId, beginTime }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//获取已经购买还没有领取的数据
|
||||
public static async findBuyRecord(serverId: number, activityId: number, roleId: string, beginTime: Date) {
|
||||
let result: ActivityDailyRMBGiftsModelType[] = await ActivityDailyRMBGiftsModel.find(
|
||||
{ serverId, roleId, activityId, beginTime: { $gt: beginTime } }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DAILYRMBGIFTS_DAYS } from '../../consts';
|
||||
import moment = require('moment');
|
||||
import { DAILYRMBGIFTS_DAYS, REFRESH_TIME } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityDailyRMBGiftsModelType } from '../../db/ActivityDailyRMBGifts';
|
||||
import { deltaDays } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
// 商品数据
|
||||
@@ -12,7 +12,6 @@ export class DailyRMBGiftsItem {
|
||||
price: number; //价格
|
||||
reward: string; //奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
|
||||
isBuy: boolean = false; //是否已经购买
|
||||
isReceive: boolean = false; //是否领取过奖励
|
||||
|
||||
constructor(data: any) {
|
||||
@@ -21,6 +20,7 @@ export class DailyRMBGiftsItem {
|
||||
this.name = data.name;
|
||||
this.price = data.price;
|
||||
this.reward = data.reward;
|
||||
this.isReceive = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,17 @@ export class DailyRMBGiftsData extends ActivityBase {
|
||||
price: number = 0;//一次性购买的价格
|
||||
productID: string = '';//一次性购买的商品id
|
||||
list: Array<DailyRMBGiftsItem> = [];//每件商品信息
|
||||
isBuy: boolean = false;//是否一次性购买过
|
||||
|
||||
receiveCount: number = 0;//已经领取次数(一次性购买)
|
||||
unReceiveCount: number = 0;//剩余领取次数(一次性购买)
|
||||
|
||||
public findTodayItem() {
|
||||
let index = this.list.findIndex(obj => { return obj.productID == '' });
|
||||
public unReceiveItem() {
|
||||
return this.list.filter(obj => { return !obj.isReceive });
|
||||
}
|
||||
|
||||
|
||||
public findItem(id: number) {
|
||||
let index = this.list.findIndex(obj => { return obj.id == id });
|
||||
return (index != -1) ? this.list[index] : null
|
||||
}
|
||||
|
||||
@@ -45,36 +51,47 @@ export class DailyRMBGiftsData extends ActivityBase {
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivityDailyRMBGiftsModelType[], endTime: Date) {
|
||||
let isOver = true;
|
||||
public setPlayerRecords(data: ActivityDailyRMBGiftsModelType, unReceiveCount: number) {
|
||||
this.isBuy = false;
|
||||
this.unReceiveCount = 0;
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
let records = data.records ? data.records : [];
|
||||
let isOver = false;
|
||||
for (let item of this.list) {
|
||||
let index = data.findIndex(obj => { obj.id == item.id });
|
||||
let index = records.findIndex(obj => { return obj.id === item.id })
|
||||
if (index != -1) {
|
||||
item.isBuy = true;
|
||||
item.isReceive = true;
|
||||
} else {
|
||||
item.isBuy = false;
|
||||
item.isReceive = false;
|
||||
isOver = false;
|
||||
}
|
||||
if (!item.isReceive) {
|
||||
isOver = true;
|
||||
}
|
||||
}
|
||||
if (endTime) {//DAILYRMBGIFTS_DAYS天内有购买过一次性礼包结束时间
|
||||
if (new Date() < endTime) {
|
||||
for (let item of this.list) {
|
||||
item.isBuy = true;
|
||||
}
|
||||
}
|
||||
this.receiveCount = deltaDays(new Date, endTime) + (isOver ? 0 : 1);
|
||||
|
||||
this.isBuy = data.isBuy;
|
||||
this.unReceiveCount = unReceiveCount;
|
||||
if (this.isBuy && !isOver) {
|
||||
this.unReceiveCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public initData(data: string) {
|
||||
this.isBuy = false;
|
||||
this.unReceiveCount = 0;
|
||||
let dataObj = JSON.parse(data);
|
||||
this.name = dataObj.name;
|
||||
this.day = dataObj.day;
|
||||
this.price = dataObj.price;
|
||||
this.productID = dataObj.productID;
|
||||
let curDate = moment(new Date());
|
||||
if (curDate.hour() < REFRESH_TIME) {
|
||||
this.beginTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.endTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
|
||||
} else {
|
||||
this.beginTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.endTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||
}
|
||||
|
||||
let arr = dataObj.data;
|
||||
for (let obj of arr) {
|
||||
|
||||
Reference in New Issue
Block a user