活动:添加rmb活动类型判断
This commit is contained in:
@@ -111,7 +111,7 @@ export class SignInHandler {
|
||||
if (!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
await ActivitySignInModel.addSignInRecord(activityId, roleId, roundIndex, dayIndex);
|
||||
await ActivitySignInModel.addSignInRecord(activityId, roleId, roundIndex, [dayIndex]);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(signinItemData.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
||||
|
||||
@@ -71,6 +71,9 @@ export async function getPlayerDailyGiftsData(activityId: number, serverId: numb
|
||||
export async function makeDailyRMBGiftsReward(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[],
|
||||
activityId: number, productID: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
if (activityData.type !== ACTIVITY_TYPE.RECHARGE_MONEY) {
|
||||
return null;
|
||||
}
|
||||
let playerData = new DailyRMBGiftsData(activityData);
|
||||
let bigGiftProductID = playerData.productID;
|
||||
if (bigGiftProductID == productID) {//一次性购买7天礼包
|
||||
|
||||
@@ -126,6 +126,9 @@ export async function getPlayerGrowthFundData(activityId: number, serverId: numb
|
||||
export async function makeGrowthFund(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[],
|
||||
activityId: number, productID: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
if (activityData.type !== ACTIVITY_TYPE.GROWTH_FUND_MAIN_VIP && activityData.type !== ACTIVITY_TYPE.GROWTH_FUND_TOWER_VIP && activityData.type !== ACTIVITY_TYPE.GROWTH_FUND_MAIN_ELITE_VIP) {
|
||||
return null;
|
||||
}
|
||||
if (!activityData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -114,6 +114,10 @@ export async function getPlayerMonthlyTicketDayReward(roleId: string, roleName:
|
||||
export async function makeMonthlyTicketReward(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[],
|
||||
activityId: number, productID: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
if (activityData.type !== ACTIVITY_TYPE.MONTHLY_TICKET_1 && activityData.type !== ACTIVITY_TYPE.MONTHLY_TICKET_2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let playerData = new MonthlyTicketData(activityData);
|
||||
|
||||
let endTime = moment(new Date()).startOf('d').add(playerData.days, 'day').toDate();
|
||||
|
||||
@@ -71,6 +71,9 @@ export async function makePopUpShopReward(roleId: string, roleName: string, sid:
|
||||
if (!activityData) {
|
||||
return null;
|
||||
}
|
||||
if (activityData.type !== ACTIVITY_TYPE.POP_UP_SHOP) {
|
||||
return null;
|
||||
}
|
||||
let allTaskData: any[] = JSON.parse(activityData.data);
|
||||
let taskIndex = allTaskData.findIndex(obj => { return obj && obj.data.productID == productID });
|
||||
if (taskIndex == -1) {
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function signInActivity(serverId: number, roleId: string) {
|
||||
}
|
||||
let activityData = activityArray[0];
|
||||
let playerData = new SignInData(activityData);
|
||||
let playerRecords: ActivitySignInModelType[] = await ActivitySignInModel.findData(activityData.activityId, roleId, playerData.roundIndex);
|
||||
let playerRecords: ActivitySignInModelType = await ActivitySignInModel.findData(activityData.activityId, roleId, playerData.roundIndex);
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
return playerData;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ export async function signInVIPActivity(serverId: number, roleId: string) {
|
||||
}
|
||||
let activityData = activityArray[0];
|
||||
let playerData = new SignInData(activityData);
|
||||
let playerRecords: ActivitySignInModelType[] = await ActivitySignInModel.findData(activityData.activityId, roleId, playerData.roundIndex);
|
||||
let playerRecords: ActivitySignInModelType = await ActivitySignInModel.findData(activityData.activityId, roleId, playerData.roundIndex);
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
return playerData;
|
||||
}
|
||||
@@ -69,8 +69,11 @@ export async function signInVIPActivity(serverId: number, roleId: string) {
|
||||
*/
|
||||
export async function getPlayerSignInData(activityId: number, serverId: number, roleId: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
if (activityData.type !== ACTIVITY_TYPE.SIGN_IN_VIP && activityData.type !== ACTIVITY_TYPE.SIGN_IN) {
|
||||
return null;
|
||||
}
|
||||
let playerData = new SignInData(activityData);
|
||||
let playerRecords: ActivitySignInModelType[] = await ActivitySignInModel.findData(activityId, roleId, playerData.roundIndex);
|
||||
let playerRecords: ActivitySignInModelType = await ActivitySignInModel.findData(activityId, roleId, playerData.roundIndex);
|
||||
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
|
||||
@@ -90,6 +93,9 @@ export async function getPlayerSignInData(activityId: number, serverId: number,
|
||||
export async function makeSignInVIP(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[],
|
||||
activityId: number, productID: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
if (activityData.type !== ACTIVITY_TYPE.SIGN_IN_VIP) {
|
||||
return null;
|
||||
}
|
||||
let playerData = new SignInData(activityData);
|
||||
|
||||
await ActivitySignInModel.buyVIP(activityId, roleId, playerData.roundIndex);
|
||||
|
||||
@@ -59,6 +59,9 @@ export async function makeYuanbaoShopReward(roleId: string, roleName: string, si
|
||||
activityId: number, productID: string) {
|
||||
let records = await UserOrderModel.findSuccessOrderByProductID(productID, roleId, activityId);
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
if (activityData.type !== ACTIVITY_TYPE.YUAN_BAO_SHOP) {
|
||||
return null;
|
||||
}
|
||||
let playerData = new YuanBaoShopData(activityData);
|
||||
let item = playerData.findItem(productID);
|
||||
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
|
||||
export class Activity_Sign_In_Record extends BaseModel {
|
||||
@prop({ required: true })
|
||||
dayIndex: number; // 第几天
|
||||
@prop({ required: true })
|
||||
time: Date; // 时间
|
||||
}
|
||||
|
||||
/**
|
||||
* 签到
|
||||
*/
|
||||
@@ -14,45 +22,38 @@ export default class Activity_Sign_In extends BaseModel {
|
||||
@prop({ required: true })
|
||||
roundIndex: number; // 周期数,从活动设置的开始时间计算
|
||||
@prop({ required: true })
|
||||
dayIndex: number; // 第几天 从1开始
|
||||
@prop({ required: true })
|
||||
isReceive: boolean; // 是否领取
|
||||
records: Activity_Sign_In_Record[]; // 领取记录
|
||||
|
||||
//签到记录
|
||||
public static async addSignInRecord(activityId: number, roleId: string, roundIndex: number, dayIndex: number, lean = true) {
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOneAndUpdate({ roleId, activityId, roundIndex, dayIndex },
|
||||
{ $set: { isReceive: true } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async addSignInRecord(activityId: number, roleId: string, roundIndex: number, dayIndexs: number[]) {
|
||||
let records = [];
|
||||
for (let dayIndex of dayIndexs) {
|
||||
let record = new Activity_Sign_In_Record();
|
||||
record.dayIndex = dayIndex;
|
||||
record.time = new Date();
|
||||
records.push(record)
|
||||
}
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOneAndUpdate({ roleId, activityId, roundIndex },
|
||||
{ $push: { records: { $each: records } } }, { new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(activityId: number, roleId: string, roundIndex: number, lean = true) {
|
||||
let result: ActivitySignInModelType[] = await ActivitySignInModel.find({ roleId, activityId, roundIndex }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询第几天的活动数据
|
||||
public static async findDataByDayIndex(activityId: number, roleId: string, roundIndex: number, dayIndex: number, lean = true) {
|
||||
let result: ActivitySignInModelType[] = await ActivitySignInModel.find({ roleId, activityId, roundIndex, dayIndex }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询第几天的活动数据
|
||||
public static async isBuyVip(activityId: number, roleId: string, roundIndex: number) {
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOne({ roleId, activityId, roundIndex, dayIndex: 0 }).lean(true);
|
||||
public static async findData(activityId: number, roleId: string, roundIndex: number) {
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOne({ roleId, activityId, roundIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//购买vip记录
|
||||
public static async buyVIP(activityId: number, roleId: string, roundIndex: number) {
|
||||
let result: ActivitySignInModelType = await ActivitySignInModel.findOneAndUpdate({ roleId, activityId, roundIndex },
|
||||
{ $set: { dayIndex: 0 } }, { upsert: true, new: true }).lean(true);
|
||||
{}, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除签到记录
|
||||
public static async deleteActivity(activityId: number, roleId: string, roundIndex: number, dayIndex: number) {
|
||||
await ActivitySignInModel.deleteMany({ roleId, activityId, roundIndex, dayIndex });
|
||||
public static async deleteActivity(activityId: number, roleId: string, roundIndex: number) {
|
||||
await ActivitySignInModel.deleteMany({ roleId, activityId, roundIndex });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,16 +63,19 @@ export class SignInData extends ActivityBase {
|
||||
}
|
||||
|
||||
//解析玩家签到记录
|
||||
public setPlayerRecords(data: ActivitySignInModelType[]) {
|
||||
public setPlayerRecords(data: ActivitySignInModelType) {
|
||||
this.isVip = false;
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
let records = data.records ? data.records : [];
|
||||
for (let obj of this.list) {
|
||||
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex })
|
||||
let index = records.findIndex(record => { return obj.dayIndex == record.dayIndex })
|
||||
if (index != -1) {
|
||||
obj.isReceive = data[index].isReceive;
|
||||
obj.isReceive = true;
|
||||
}
|
||||
}
|
||||
|
||||
let isBuy = data.findIndex(obj => { return obj.dayIndex == 0 });
|
||||
this.isVip = (isBuy != -1)
|
||||
this.isVip = true
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
|
||||
Reference in New Issue
Block a user