diff --git a/game-server/app/servers/activity/handler/treasureHuntHandler.ts b/game-server/app/servers/activity/handler/treasureHuntHandler.ts index 98b5e8d68..49d4bc236 100644 --- a/game-server/app/servers/activity/handler/treasureHuntHandler.ts +++ b/game-server/app/servers/activity/handler/treasureHuntHandler.ts @@ -1,13 +1,14 @@ import { Application, BackendSession } from 'pinus'; import { resResult } from '../../../pubUtils/util'; import { STATUS, } from '../../../consts'; -import { getPlayerTreasureHuntData, getTreasureHuntData, getPlayerTreasureHuntShopData, getPlayerTreasureHuntTaskData, getPlayerTreasureHuntTreasureShopData, getPlayerTreasureHuntChallengeData } from '../../../services/treasureHuntService'; +import { getPlayerTreasureHuntData, getTreasureHuntData, getPlayerTreasureHuntShopData, getPlayerTreasureHuntTaskData, getPlayerTreasureHuntTreasureShopData, getPlayerTreasureHuntChallengeData, getPlayerTreasureHuntFirstPageData } from '../../../services/treasureHuntService'; import { ActivityTreasureHuntShopModel } from '../../../db/ActivityTreasureHuntShop'; import { ActivityTreasureHuntTaskModel } from '../../../db/ActivityTreasureHuntTask'; import { handleCost } from '../../../services/rewardService'; import { addReward, stringToConsumeParam, stringToRewardParam } from '../../../services/giftPackageService'; import { RewardParam } from '../../../domain/activityField/rewardField'; import { ActivityTreasureHuntTreasureShopModel } from '../../../db/ActivityTreasureHuntTreasureShop'; +import { ActivityTreasureHuntFirstPageModel } from '../../../db/ActivityTreasureHuntFirstPage'; export default function (app: Application) { @@ -43,6 +44,47 @@ export class TreasureHuntHandler { return resResult(STATUS.SUCCESS, playerData); } + /** +* @description 寻宝骑兵获取首页的奖励 +* @param {BackendSession} session +* @memberof TreasureHuntHandler +*/ + async getFirstPageReward(msg: { activityId: number }, session: BackendSession) { + const { activityId } = msg; + const roleId = session.get('roleId'); + const serverId = session.get('serverId'); + const sid = session.get('sid'); + const roleName = session.get('roleName'); + const funcs: number[] = session.get('funcs'); + + let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId); + if (!activityData) { + return resResult(STATUS.ACTIVITY_MISSING, {}); + } + if (activityId !== huntActivityId) { + return resResult(STATUS.ACTIVITY_MISSING, {}); + } + + let playerData = await getPlayerTreasureHuntFirstPageData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,); + if (!playerData) return resResult(STATUS.ACTIVITY_MISSING); + + if (playerData.firstPage.isReceive) { + return resResult(STATUS.ACTIVITY_REWARDED); + } + + //添加领取记录 + await ActivityTreasureHuntFirstPageModel.receiveReward(serverId, activityId, roleId, huntRoundIndex); + + let rewardParamArr: Array = stringToRewardParam(playerData.firstPage.reward); + let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr) + + playerData.firstPage.isReceive = true; + return resResult(STATUS.SUCCESS, Object.assign(result, { + param: { activityId }, + item: playerData.firstPage, + })); + } + /** * @description 寻宝骑兵购买每日商店中的商品 * @param {BackendSession} session @@ -147,8 +189,8 @@ export class TreasureHuntHandler { * @param {BackendSession} session * @memberof TreasureHuntHandler */ - async challenge(msg: { activityId: number, cellIndex: number }, session: BackendSession) { - const { activityId, cellIndex } = msg; + async challenge(msg: { activityId: number }, session: BackendSession) { + const { activityId } = msg; const roleId = session.get('roleId'); const serverId = session.get('serverId'); const sid = session.get('sid'); @@ -165,10 +207,17 @@ export class TreasureHuntHandler { let playerData = await getPlayerTreasureHuntChallengeData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,); if (!playerData) return resResult(STATUS.ACTIVITY_MISSING); + let challengeData = playerData.challenge; + //消耗资源 + let consumeStr = challengeData.consume; + let consume = stringToConsumeParam(consumeStr) + let resourceResult = await handleCost(roleId, sid, consume); + if (!resourceResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH); + let warId = playerData.challenge.randomGK(); - return resResult(STATUS.SUCCESS, Object.assign({}, { - param: { activityId, cellIndex }, + return resResult(STATUS.SUCCESS, Object.assign({ warId }, { + param: { activityId }, })); } diff --git a/game-server/app/servers/order/handler/orderHandler.ts b/game-server/app/servers/order/handler/orderHandler.ts index 0e1ecf12b..77f8fbc77 100644 --- a/game-server/app/servers/order/handler/orderHandler.ts +++ b/game-server/app/servers/order/handler/orderHandler.ts @@ -186,6 +186,7 @@ export class orderHandler { //推送 this.app.channelService.pushMessageByUids('onOrder', resResult(STATUS.SUCCESS, { data: result.data, + price: price, }), [{ uid: roleId, sid: sid }]); //活动统计 await addRechargeMoney(roleId, serverId, price); @@ -256,6 +257,7 @@ export class orderHandler { //推送 this.app.channelService.pushMessageByUids('onOrder', resResult(STATUS.SUCCESS, { data: result.data, + price: price, }), [{ uid: roleId, sid: sid }]); //活动统计 await addRechargeMoney(roleId, serverId, price); diff --git a/game-server/app/services/treasureHuntService.ts b/game-server/app/services/treasureHuntService.ts index afddce284..89fbd9633 100644 --- a/game-server/app/services/treasureHuntService.ts +++ b/game-server/app/services/treasureHuntService.ts @@ -4,6 +4,7 @@ import { ActivityModel, ActivityModelType } from '../db/Activity'; import { ActivityTreasureHuntShopModel, ActivityTreasureHuntShopModelType } from '../db/ActivityTreasureHuntShop'; import { ActivityTreasureHuntTaskModel, ActivityTreasureHuntTaskModelType } from '../db/ActivityTreasureHuntTask'; import { ActivityTreasureHuntTreasureShopModel, ActivityTreasureHuntTreasureShopModelType } from '../db/ActivityTreasureHuntTreasureShop'; +import { ActivityTreasureHuntFirstPageModel, ActivityTreasureHuntFirstPageModelType } from '../db/ActivityTreasureHuntFirstPage'; import { ServerlistModel } from '../db/Serverlist'; import { ServerTempModel, ServerTempModelType } from '../db/ServerTemp'; import { TreasureHuntData } from '../domain/activityField/treasureHuntField'; @@ -44,6 +45,8 @@ export async function getPlayerTreasureHuntData(activityId: number, serverId: nu playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;; playerData.roundIndex = huntRoundIndex; + let playerTreasureFirstPageecord: ActivityTreasureHuntFirstPageModelType = await ActivityTreasureHuntFirstPageModel.findData(serverId, activityId, roleId, huntRoundIndex); + playerData.firstPage.setPlayerFirstPageRecord(playerTreasureFirstPageecord); let playerShopRecord: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findTreasureData(activityId, roleId, huntRoundIndex, playerData.todayIndex); playerData.shop.setPlayerShopRecords(playerShopRecord); let playerTaskRecord: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.findDataByRoundIndex(serverId, activityId, roleId, huntRoundIndex); @@ -54,6 +57,20 @@ export async function getPlayerTreasureHuntData(activityId: number, serverId: nu return playerData; } +export async function getPlayerTreasureHuntFirstPageData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) { + let activityData: ActivityModelType = await ActivityModel.findActivity(activityId); + + let playerData = new TreasureHuntData(activityData); + playerData.beginTime = moment(huntBeginTime).valueOf(); + playerData.endTime = moment(huntEndTime).valueOf(); + playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;; + playerData.roundIndex = huntRoundIndex; + + let playerTreasureFirstPageecord: ActivityTreasureHuntFirstPageModelType = await ActivityTreasureHuntFirstPageModel.findData(serverId, activityId, roleId, huntRoundIndex); + playerData.firstPage.setPlayerFirstPageRecord(playerTreasureFirstPageecord); + return playerData; +} + export async function getPlayerTreasureHuntShopData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) { let activityData: ActivityModelType = await ActivityModel.findActivity(activityId); diff --git a/shared/db/ActivityTreasureHunt.ts b/shared/db/ActivityTreasureHunt.ts deleted file mode 100644 index b0d63cf4f..000000000 --- a/shared/db/ActivityTreasureHunt.ts +++ /dev/null @@ -1,91 +0,0 @@ -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, keyof ActivityTreasureHunt> { } -export type ActivityTreasureHuntTypeParam = Partial; // 将所有字段变成可选项 \ No newline at end of file diff --git a/shared/db/ActivityTreasureHuntFirstPage.ts b/shared/db/ActivityTreasureHuntFirstPage.ts new file mode 100644 index 000000000..3ba459e76 --- /dev/null +++ b/shared/db/ActivityTreasureHuntFirstPage.ts @@ -0,0 +1,40 @@ +import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose'; + + + + +/** + * 活动系统 - 寻宝骑兵-首页奖励 +*/ +@index({ roleId: 1 }) + +export default class Activity_Treasure_Hunt_First_Page { + @prop({ required: true }) + serverId: number; // 区Id + @prop({ required: true }) + activityId: number; // 活动Id + @prop({ required: true }) + roleId: string; // 用户Id + @prop({ required: true }) + roundIndex: number; // 回合数 + @prop({ required: true }) + isReceive: boolean; // 是否领取 + + //根据活动id查询活动数据 + public static async findData(serverId: number, activityId: number, roleId: string, roundIndex: number) { + let result: ActivityTreasureHuntFirstPageModelType = await ActivityTreasureHuntFirstPageModel.findOne({ serverId, roleId, activityId, roundIndex }).lean(true); + return result; + } + + //领取奖励的记录 + public static async receiveReward(serverId: number, activityId: number, roleId: string, roundIndex: number,) { + let result: ActivityTreasureHuntFirstPageModelType = await ActivityTreasureHuntFirstPageModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex }, + { $set: { isReceive: true } }, { upsert: true, new: true }).lean(true); + return result; + } +} + +export const ActivityTreasureHuntFirstPageModel = getModelForClass(Activity_Treasure_Hunt_First_Page); + +export interface ActivityTreasureHuntFirstPageModelType extends Pick, keyof Activity_Treasure_Hunt_First_Page> { } +export type ActivityTreasureHuntFirstPageModelTypeParam = Partial; // 将所有字段变成可选项 \ No newline at end of file diff --git a/shared/db/ActivityTreasureHuntTask.ts b/shared/db/ActivityTreasureHuntTask.ts index 86125fba0..237b28a64 100644 --- a/shared/db/ActivityTreasureHuntTask.ts +++ b/shared/db/ActivityTreasureHuntTask.ts @@ -19,47 +19,12 @@ export default class Activity_Treasure_Hunt_Task extends ActivityGrowth { return result; } - // //根据活动统计完成任务次数 - // public static async setTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, type: number, count: number, lean = true) { - // let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex, type }, - // { $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean); - // return result; - // } - - // //根据活动统计完成任务次数 - // public static async addTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, type: number, addCount: number, lean = true) { - // let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex, type }, - // { $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean); - // return result; - // } - - // //根据活动记录统计数据 - // public static async addTaskRecord(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, type: number, data: string,) { - // let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex, type }, - // { $set: { data: data } }, { upsert: true, new: true }).lean(true); - // return result; - // } - - - // //根据活动id查询活动数据 - // public static async findTaskData(serverId: number, activityId: number, roleId: string, roundIndex: number) { - // let result: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.find({ serverId, roleId, activityId }).lean(true); - // return result; - // } - //查询第几天的活动数据 public static async findDataByRoundIndex(serverId: number, activityId: number, roleId: string, roundIndex: number) { let result: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.find({ serverId, roleId, activityId, roundIndex }).lean(true); return result; } - //查询第几天某个的活动数据 - // public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, type: number,) { - // let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOne({ serverId, roleId, activityId, roundIndex, cellIndex, type }).lean(true); - // return result; - // } - - //删除活动领取记录 public static async deleteActivity(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number) { await ActivityTreasureHuntTaskModel.deleteMany({ serverId, roleId, activityId, roundIndex, cellIndex }); diff --git a/shared/domain/activityField/treasureHuntField.ts b/shared/domain/activityField/treasureHuntField.ts index 031ebaa9a..62716e6bd 100644 --- a/shared/domain/activityField/treasureHuntField.ts +++ b/shared/domain/activityField/treasureHuntField.ts @@ -1,9 +1,41 @@ +import { random } from 'underscore'; import { ActivityModelType } from '../../db/Activity'; import { ActivityTreasureHuntShopModelType } from '../../db/ActivityTreasureHuntShop'; import { ActivityTreasureHuntTaskModelType } from '../../db/ActivityTreasureHuntTask'; import { ActivityTreasureHuntTreasureShopModelType } from '../../db/ActivityTreasureHuntTreasureShop'; +import { ActivityTreasureHuntFirstPageModelType } from '../../db/ActivityTreasureHuntFirstPage'; +import { splitString } from '../../pubUtils/util'; import { ActivityBase } from './activityField'; + +// 进入活动首页的数据 +export class TreasureHuntFirstPageData { + name: string = '';//页签名字 + index: number = 0;//下标 + reward: string = '';//奖励 + + isReceive: boolean = false;//是否领取 + + public setPlayerFirstPageRecord(record: ActivityTreasureHuntFirstPageModelType) { + this.isReceive = false; + if (!record) { + return; + } + this.isReceive = record.isReceive ? record.isReceive : false; + } + + public initData(data: any) { + this.name = data.name; + this.index = data.index; + this.reward = data.reward; + this.isReceive = false; + } + + constructor(data: any) { + this.initData(data) + } +} + /************************************************************/ //购买价格 export class ConsumeData { @@ -160,15 +192,21 @@ export class TreasureHuntChallengeData { name: string = '';//页签名字 index: number = 0;//下标 consume: string = '';//消耗 - count: number = 0;//碎片需求量 - fixReward: string = '';//消耗 - jackpotReward: string = '';//消耗 + warid: string = '';//随机的关卡号 + fixReward: string = '';//客户端显示奖励 + jackpotReward: string = '';//客户端显示奖励 + + public randomGK() { + let gkArray = splitString(this.warid, '&'); + let index = random(gkArray.length - 1); + return gkArray[index]; + } public initData(data: any) { this.name = data.name; this.index = data.index; this.consume = data.consume; - this.count = data.count; + this.warid = data.warid; this.fixReward = data.fixReward; this.jackpotReward = data.jackpotReward; } @@ -247,6 +285,7 @@ export class TreasureHuntData extends ActivityBase { name: string = '';//活动名字 day: string = '';//活动持续时间 roundIndex = 0;//周期数 + firstPage: TreasureHuntFirstPageData = null;//首页奖励 shop: TreasureHuntShopData = null; //每日物资 tasks: TreasureHuntTaskData = null; //寻宝备战 challenge: TreasureHuntChallengeData = null;//寻宝大冒险 @@ -259,10 +298,26 @@ export class TreasureHuntData extends ActivityBase { this.day = dataObj.day; let arr = dataObj.data; - this.shop = new TreasureHuntShopData(arr[0]); - this.tasks = new TreasureHuntTaskData(arr[1]); - this.challenge = new TreasureHuntChallengeData(arr[2]); - this.treasureShop = new TreasureHuntTreasureShopData(arr[3]); + { + let index = arr.findIndex(obj => { return obj.index === 1 }); + this.firstPage = new TreasureHuntFirstPageData(arr[index]); + } + { + let index = arr.findIndex(obj => { return obj.index === 2 }); + this.shop = new TreasureHuntShopData(arr[index]); + } + { + let index = arr.findIndex(obj => { return obj.index === 3 }); + this.tasks = new TreasureHuntTaskData(arr[index]); + } + { + let index = arr.findIndex(obj => { return obj.index === 4 }); + this.challenge = new TreasureHuntChallengeData(arr[index]); + } + { + let index = arr.findIndex(obj => { return obj.index === 5 }); + this.treasureShop = new TreasureHuntTreasureShopData(arr[index]); + } } constructor(activityData: ActivityModelType) {