活动:寻宝骑兵活动接口

This commit is contained in:
qiaoxin
2021-05-25 21:38:23 +08:00
parent bd78b30cee
commit ebeb22f630
9 changed files with 538 additions and 6 deletions

View 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>; // 将所有字段变成可选项

View 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
View 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>; // 将所有字段变成可选项