活动:寻宝骑兵活动接口
This commit is contained in:
91
shared/db/ActivityTreasureHunt.ts
Normal file
91
shared/db/ActivityTreasureHunt.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { ORDER_STATE } from '../consts';
|
||||
|
||||
/**
|
||||
* 玩家寻宝猎人活动数据
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class ActivityTreasureHunt extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
serverId: number; // 区号
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户id
|
||||
@prop({ required: true })
|
||||
activityId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
roundIndex: number; // 周期Id
|
||||
|
||||
|
||||
|
||||
//保存平台订单号
|
||||
public static async saveOrderID(roleId: string, localOrderID: string, aliOrderID: string) {
|
||||
let result: ActivityTreasureHuntType = await ActivityTreasureHuntModel.findOneAndUpdate({ roleId, localOrderID },
|
||||
{ $set: { orderID: aliOrderID } },
|
||||
{ new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//校验订单
|
||||
public static async check(roleId: string, localOrderID: string, message: string = '') {
|
||||
let result: ActivityTreasureHuntType = await ActivityTreasureHuntModel.findOneAndUpdate({ roleId, localOrderID, state: { $ne: ORDER_STATE.RESULT_SUCCESS } },
|
||||
{ $set: { state: ORDER_STATE.CHECK_ORDER, message } },
|
||||
{ new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//订单支付失败
|
||||
public static async fail(roleId: string, localOrderID: string, message: string = '') {
|
||||
let result: ActivityTreasureHuntType = await ActivityTreasureHuntModel.findOneAndUpdate({ roleId, localOrderID, state: { $ne: ORDER_STATE.RESULT_SUCCESS } },
|
||||
{ $set: { state: ORDER_STATE.RESULT_FAIL, message } },
|
||||
{ new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//订单支付成功
|
||||
public static async success(roleId: string, localOrderID: string, message: string = '') {
|
||||
let result: ActivityTreasureHuntType = await ActivityTreasureHuntModel.findOneAndUpdate({ roleId, localOrderID, state: { $ne: ORDER_STATE.RESULT_SUCCESS } },
|
||||
{ $set: { state: ORDER_STATE.RESULT_SUCCESS, message } },
|
||||
{ new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询订单详情
|
||||
public static async findOrderByProductID(productID: string, roleId: string, activityId: number) {
|
||||
let result: ActivityTreasureHuntType[] = await ActivityTreasureHuntModel.find({ productID, roleId, activityId }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询订单详情
|
||||
public static async findPlayerOrder(productID: string, roleId: string, activityId: number, limit: number) {
|
||||
let result: ActivityTreasureHuntType[] = await ActivityTreasureHuntModel.find({ productID, roleId, activityId }, {}).limit(limit).sort({ createdAt: -1 }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询订单详情
|
||||
public static async findOrderByActivityID(activityId: number, roleId: string,) {
|
||||
let result: ActivityTreasureHuntType[] = await ActivityTreasureHuntModel.find({ activityId, roleId }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询订单详情
|
||||
public static async findOrder(localOrderID: string) {
|
||||
let result: ActivityTreasureHuntType = await ActivityTreasureHuntModel.findOne({ localOrderID }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//新增订单
|
||||
public static async applyOrder(serverId: number, roleId: string, productID: string, localOrderID: string, orderID: string, price: number, payType: number, activityId: number, message: string = '') {
|
||||
let result: ActivityTreasureHuntType = await ActivityTreasureHuntModel.findOneAndUpdate({ serverId, roleId, productID, localOrderID, orderID, payType, activityId },
|
||||
{ $set: { price, state: ORDER_STATE.APPLY, message } },
|
||||
{ upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityTreasureHuntModel = getModelForClass(ActivityTreasureHunt);
|
||||
|
||||
export interface ActivityTreasureHuntType extends Pick<DocumentType<ActivityTreasureHunt>, keyof ActivityTreasureHunt> { }
|
||||
export type ActivityTreasureHuntTypeParam = Partial<ActivityTreasureHuntType>; // 将所有字段变成可选项
|
||||
26
shared/db/ActivityTreasureHuntShop.ts
Normal file
26
shared/db/ActivityTreasureHuntShop.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import ActivityShop from './ActivityShop';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 活动系统 - 寻宝猎人-商店
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class Activity_Treasure_Hunt_Shop extends ActivityShop {
|
||||
@prop({ required: true })
|
||||
dayIndex: number; // 第几天
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findTreasureData(serverId: number, activityId: number, roleId: string, roundIndex: number, dayIndex: number) {
|
||||
let result: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findOne({ roleId, activityId, roundIndex, dayIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityTreasureHuntShopModel = getModelForClass(Activity_Treasure_Hunt_Shop);
|
||||
|
||||
export interface ActivityTreasureHuntShopModelType extends Pick<DocumentType<Activity_Treasure_Hunt_Shop>, keyof Activity_Treasure_Hunt_Shop> { }
|
||||
export type ActivityTreasureHuntShopModelTypeParam = Partial<ActivityTreasureHuntShopModelType>; // 将所有字段变成可选项
|
||||
45
shared/db/ServerTemp.ts
Normal file
45
shared/db/ServerTemp.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 数据变量记录
|
||||
*/
|
||||
@index({ activityId: 1 })
|
||||
|
||||
export default class ServerTemp extends BaseModel {
|
||||
@prop({ required: true })
|
||||
serverId: number; // 服Id
|
||||
|
||||
@prop({ required: true })
|
||||
huntActivityId: number; // 寻宝骑兵-活动Id
|
||||
@prop({ required: true })
|
||||
huntBeginTime: Date; // 寻宝骑兵-开启时间
|
||||
@prop({ required: true })
|
||||
huntEndTime: Date; // 寻宝骑兵-结束时间
|
||||
@prop({ required: true })
|
||||
huntRoundIndex: number; // 寻宝骑兵-周期数
|
||||
|
||||
//更新寻宝猎人活动数据
|
||||
public static async updateTreasureHuntData(serverId: number, huntActivityId: number, huntBeginTime: Date, huntEndTime: Date, huntRoundIndex: number) {
|
||||
let result: ServerTempModelType = await ServerTempModel.findOneAndUpdate({ serverId },
|
||||
{ $set: { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询当前服务器的数据
|
||||
public static async findData(serverId: number) {
|
||||
let result: ServerTempModelType = await ServerTempModel.findOne({ serverId }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动
|
||||
public static async deleteActivity(serverId: number) {
|
||||
let result = await ServerTempModel.deleteMany({ serverId });
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const ServerTempModel = getModelForClass(ServerTemp);
|
||||
|
||||
export interface ServerTempModelType extends Pick<DocumentType<ServerTemp>, keyof ServerTemp> { }
|
||||
export type ServerTempModelTypeParam = Partial<ServerTempModelType>; // 将所有字段变成可选项
|
||||
@@ -9,6 +9,9 @@ export class ShopItem {
|
||||
reward: string; //任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
countMax: number = 0; //可购买的最大次数,0表示不限制
|
||||
name: string; //名字
|
||||
price: number; //价格
|
||||
productID: string; //商品id
|
||||
imageName: string;
|
||||
|
||||
buyCount: number = 0; //购买过的次数
|
||||
|
||||
@@ -17,6 +20,10 @@ export class ShopItem {
|
||||
this.reward = data.reward;
|
||||
this.countMax = data.countMax;
|
||||
this.name = data.name;
|
||||
this.price = data.price;
|
||||
this.productID = data.productID;
|
||||
this.imageName = data.imageName;
|
||||
this.buyCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
139
shared/domain/activityField/treasureHuntField.ts
Normal file
139
shared/domain/activityField/treasureHuntField.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { UserOrderModelType } from '../../db/UserOrder';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
/************************************************************/
|
||||
//购买价格
|
||||
export class ConsumeData {
|
||||
count: number; // 第几次购买,1开始
|
||||
consume: string; //消耗资源 "2&31002&400"
|
||||
|
||||
constructor(data: any) {
|
||||
this.count = data.count;
|
||||
this.consume = data.consume;
|
||||
}
|
||||
}
|
||||
|
||||
// 商品的数据
|
||||
export class TreasureHuntShopItem {
|
||||
cellIndex: number; // 第几个,从1开始
|
||||
name: string; //名称
|
||||
price: number; // 价格RMB 每次购买价格不变
|
||||
productID: string; // 商品id
|
||||
reward: string; //奖励
|
||||
countMax: number; //最大购买次数
|
||||
imageName: string;
|
||||
consume: ConsumeData[]; //每次购买价格不同
|
||||
|
||||
buyCount: number = 0; //购买过的次数
|
||||
|
||||
constructor(data: any) {
|
||||
this.cellIndex = data.cellIndex;
|
||||
this.name = data.name;
|
||||
this.price = data.price;
|
||||
this.productID = data.productID;
|
||||
this.reward = data.reward;
|
||||
this.countMax = data.countMax;
|
||||
this.imageName = data.imageName;
|
||||
this.consume = [];
|
||||
for (let obj of data.data) {
|
||||
this.consume.push(new ConsumeData(obj))
|
||||
}
|
||||
this.buyCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 商店数据
|
||||
export class TreasureHuntShopData {
|
||||
name: string = '';//页签名字
|
||||
list: Array<TreasureHuntShopItem> = [];//商品
|
||||
|
||||
public initData(data: any) {
|
||||
this.name = data.name;
|
||||
let arr = data.data;
|
||||
for (let obj of arr) {
|
||||
console.log(JSON.stringify(obj))
|
||||
this.list.push(new TreasureHuntShopItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.initData(data)
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
|
||||
// 寻宝备战的数据
|
||||
// export class TreasureHuntShopItem {
|
||||
// cellIndex: number; // 第几个,从1开始
|
||||
// name: string; //名称
|
||||
// price: number; // 价格RMB 每次购买价格不变
|
||||
// productID: string; // 商品id
|
||||
// reward: string; //奖励
|
||||
// countMax: number; //最大购买次数
|
||||
// imageName: string;
|
||||
// consume: ConsumeData[]; //每次购买价格不同
|
||||
|
||||
// buyCount: number = 0; //购买过的次数
|
||||
|
||||
// constructor(data: any) {
|
||||
// this.cellIndex = data.cellIndex;
|
||||
// this.name = data.name;
|
||||
// this.price = data.price;
|
||||
// this.productID = data.productID;
|
||||
// this.reward = data.reward;
|
||||
// this.countMax = data.countMax;
|
||||
// this.imageName = data.imageName;
|
||||
// this.consume = [];
|
||||
// for (let obj of data.imageName) {
|
||||
// this.consume.push(new ConsumeData(obj))
|
||||
// }
|
||||
// this.buyCount = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 寻宝备战数据
|
||||
// export class TreasureHuntShopData {
|
||||
// name: string = '';//页签名字
|
||||
// index: number = 0;//下标
|
||||
// list: Array<TreasureHuntShopItem> = [];//商品
|
||||
|
||||
// public initData(data: any) {
|
||||
// this.name = data.name;
|
||||
// this.index = data.index;
|
||||
// let arr = data.data;
|
||||
// for (let obj of arr) {
|
||||
// this.list.push(new TreasureHuntShopItem(obj))
|
||||
// }
|
||||
// }
|
||||
|
||||
// constructor(data: any) {
|
||||
// this.initData(data)
|
||||
// }
|
||||
// }
|
||||
|
||||
/************************************************************/
|
||||
|
||||
// 商店数据
|
||||
export class TreasureHuntData extends ActivityBase {
|
||||
name: string = '';//活动名字
|
||||
day: string = '';//活动持续时间
|
||||
roundIndex = 0;//周期数
|
||||
shop: TreasureHuntShopData = null;
|
||||
|
||||
public initData(data: any) {
|
||||
let dataObj = JSON.parse(data);
|
||||
this.name = dataObj.name;
|
||||
this.day = dataObj.day;
|
||||
|
||||
let arr = dataObj.data;
|
||||
this.shop = new TreasureHuntShopData(arr[0]);
|
||||
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
super(activityData)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user