活动:首充活动接口
This commit is contained in:
@@ -18,6 +18,7 @@ export enum ACTIVITY_TYPE {
|
||||
GROWTH_FUND_MAIN_ELITE_VIP = 11, // 精英成长基金(高阶)
|
||||
THIRTY_DAYS = 12, // 30日目标活动
|
||||
SELF_SERVICE_SHOP = 13, // 自选商店
|
||||
FIRST_GIFT = 14, // 首充礼包
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,4 +46,14 @@ export enum GIFT_PACKAGE_TYPE {
|
||||
export enum SELF_SERVICE_SHOP_CELL_TYPE {
|
||||
SPECIAL = 1, // 特殊
|
||||
NORMAL = 2, // 普通
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 活动首充礼包的状态
|
||||
*/
|
||||
export enum FIRST_GIFT_STATE {
|
||||
NOT_OPEN = 0, // 未开启
|
||||
OPEN = 1, // 开启中
|
||||
CLOSED = 2, //结束
|
||||
}
|
||||
@@ -349,6 +349,8 @@ export const STATUS = {
|
||||
ACTIVITY_GROWTH_FUND_END: { code: 50012, simStr: '成长基金活动结束' },
|
||||
ACTIVITY_NEED_BUY: { code: 50013, simStr: '成长基金需要购买' },
|
||||
ACTIVITY_THIRTY_DAYS_END: { code: 50014, simStr: '30日活动结束' },
|
||||
ACTIVITY_FIRST_GIFT_NOT_OPEN: { code: 50015, simStr: '首充没开' },
|
||||
ACTIVITY_FIRST_GIFT_END: { code: 50016, simStr: '首充结束' },
|
||||
// GM后台相关状态 60000 - 69999
|
||||
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
||||
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },
|
||||
|
||||
46
shared/db/ActivityFirstGift.ts
Normal file
46
shared/db/ActivityFirstGift.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 首个礼包
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class ActivityFirstGift extends BaseModel {
|
||||
@prop({ required: true })
|
||||
acvitityId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户Id
|
||||
@prop({ required: true })
|
||||
days: Array<number>; // 领取过的奖励
|
||||
|
||||
|
||||
//添加领取记录
|
||||
public static async addRecord(acvitityId: number, roleId: string, index: number) {
|
||||
let result: ActivityFirstGiftModelType = await ActivityFirstGiftModel.findOneAndUpdate({ roleId, acvitityId, },
|
||||
{ $push: { days: index } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//可以领取首充礼包,充值时间记录
|
||||
public static async begin(acvitityId: number, roleId: string) {
|
||||
let result: ActivityFirstGiftModelType = await ActivityFirstGiftModel.findOneAndUpdate({ roleId, acvitityId },
|
||||
{}, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findData(acvitityId: number, roleId: string) {
|
||||
let result: ActivityFirstGiftModelType = await ActivityFirstGiftModel.findOne({ roleId, acvitityId }, {}).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(acvitityId: number, roleId: string, roundIndex: number, index: number,) {
|
||||
await ActivityFirstGiftModel.deleteMany({ roleId, acvitityId, index, roundIndex });
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityFirstGiftModel = getModelForClass(ActivityFirstGift);
|
||||
|
||||
export interface ActivityFirstGiftModelType extends Pick<DocumentType<ActivityFirstGift>, keyof ActivityFirstGift> { }
|
||||
export type ActivityFirstGiftModelTypeParam = Partial<ActivityFirstGiftModelType>; // 将所有字段变成可选项
|
||||
78
shared/domain/activityField/firstGiftField.ts
Normal file
78
shared/domain/activityField/firstGiftField.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { FIRST_GIFT_STATE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityFirstGiftModelType } from '../../db/ActivityFirstGift';
|
||||
import { deltaDays } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
// 首充礼包的数据
|
||||
export class FirstGiftItem {
|
||||
index: number; // 第几天,从1开始
|
||||
name: string; //名称
|
||||
gift: number; //礼包id
|
||||
|
||||
isReceive: boolean = false; //是否领取过奖励
|
||||
|
||||
constructor(data: any) {
|
||||
this.name = data.name;
|
||||
this.index = data.index;
|
||||
this.gift = data.gift;
|
||||
}
|
||||
}
|
||||
|
||||
// 30天任务活动数据
|
||||
export class FirstGiftData extends ActivityBase {
|
||||
state: number = FIRST_GIFT_STATE.NOT_OPEN;//活动状态
|
||||
list: Array<FirstGiftItem> = [];//奖励
|
||||
days: number = 0;//展示天数
|
||||
|
||||
//全部领取完成
|
||||
public isComplete() {
|
||||
for (let i = 0; i < this.list.length; i++) {
|
||||
if (!this.list[i].isReceive) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//奖励内容
|
||||
public findFirstGiftItem(index: number): FirstGiftItem {
|
||||
let listIndex = this.list.findIndex(obj => { return obj && obj.index == index });
|
||||
if (listIndex != -1) {
|
||||
return this.list[listIndex];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//解析玩家任务领取记录
|
||||
public setPlayerRecords(data: ActivityFirstGiftModelType) {
|
||||
this.todayIndex = 0;
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
this.todayIndex = deltaDays(data.createdAt, new Date) + 1;
|
||||
this.state = (this.todayIndex <= this.days) ? FIRST_GIFT_STATE.OPEN : FIRST_GIFT_STATE.CLOSED;
|
||||
|
||||
let daysNum = data.days ? data.days : [];
|
||||
for (let obj of this.list) {
|
||||
if (daysNum.indexOf(obj.index) !== -1) {
|
||||
obj.isReceive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let dataObj = JSON.parse(data);
|
||||
this.days = dataObj.days;
|
||||
|
||||
let arr = dataObj.data;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new FirstGiftItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
super(activityData)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user