活动:每日兑换铜币活动
This commit is contained in:
@@ -22,6 +22,8 @@ import { checkActivityTask } from '../../../services/taskService';
|
|||||||
import { treasureHuntActivity } from '../../../services/treasureHuntService';
|
import { treasureHuntActivity } from '../../../services/treasureHuntService';
|
||||||
import { getSelfServiceShopActivityData } from '../../../services/selfServiceShopActivityService';
|
import { getSelfServiceShopActivityData } from '../../../services/selfServiceShopActivityService';
|
||||||
import { ActivitySelfServiceGoodsModel } from '../../../db/ActivitySelfServiceGoods';
|
import { ActivitySelfServiceGoodsModel } from '../../../db/ActivitySelfServiceGoods';
|
||||||
|
import { dailyMealActivity } from '../../../services/dailyMealService';
|
||||||
|
import { dailyCoinActivity } from '../../../services/dailyCoinService';
|
||||||
// import { ActivityDailyChallengesModel } from '../../../db/ActivityDailyChallenges';
|
// import { ActivityDailyChallengesModel } from '../../../db/ActivityDailyChallenges';
|
||||||
// import { isComplete } from '../../../pubUtils/taskUtil';
|
// import { isComplete } from '../../../pubUtils/taskUtil';
|
||||||
|
|
||||||
@@ -440,17 +442,29 @@ export class ActivityHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// //每日领取免费午饭、晚饭活动
|
//每日领取免费午饭、晚饭活动
|
||||||
// {
|
{
|
||||||
// let data = await sevenDaysActivity(serverId, roleId, ACTIVITY_TYPE.DAILY_MEAL);
|
let data = await dailyMealActivity(serverId, roleId);
|
||||||
// if (data) {
|
if (data) {
|
||||||
// playerActivityArray.push({
|
playerActivityArray.push({
|
||||||
// type: ACTIVITY_TYPE.DAILY_MEAL,
|
type: ACTIVITY_TYPE.DAILY_MEAL,
|
||||||
// activityId: data.activityId,
|
activityId: data.activityId,
|
||||||
// data,
|
data,
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
//每日兑换铜币活动
|
||||||
|
{
|
||||||
|
let data = await dailyCoinActivity(serverId, roleId);
|
||||||
|
if (data) {
|
||||||
|
playerActivityArray.push({
|
||||||
|
type: ACTIVITY_TYPE.DAILY_COIN,
|
||||||
|
activityId: data.activityId,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return resResult(STATUS.SUCCESS, { playerActivityArray });
|
return resResult(STATUS.SUCCESS, { playerActivityArray });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import { Application, BackendSession } from 'pinus';
|
||||||
|
import { resResult } from '../../../pubUtils/util';
|
||||||
|
import { STATUS } from '../../../consts';
|
||||||
|
import { handleCost } from '../../../services/rewardService';
|
||||||
|
import { getPlayerDailyCoinData, mergeData } from '../../../services/dailyCoinService';
|
||||||
|
import { DailyCoinItem } from '../../../domain/activityField/dailyCoinField';
|
||||||
|
import { ActivityDailyCoinModel } from '../../../db/ActivityDailyCoin';
|
||||||
|
import { addReward, stringToConsumeParam, stringToRewardParam } from '../../../services/giftPackageService';
|
||||||
|
import { RewardParam } from '../../../domain/activityField/rewardField';
|
||||||
|
import { ItemInter } from '../../../pubUtils/interface';
|
||||||
|
|
||||||
|
|
||||||
|
export default function (app: Application) {
|
||||||
|
return new DailyCoinHandler(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DailyCoinHandler {
|
||||||
|
constructor(private app: Application) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/************************每日兑换铜币****************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取每日铜币活动数据
|
||||||
|
* @param {{ activityId: number}} msg
|
||||||
|
* @param {BackendSession} session
|
||||||
|
* @memberof DailyCoinHandler
|
||||||
|
*/
|
||||||
|
async getDailyCoinActivity(msg: { activityId: number }, session: BackendSession) {
|
||||||
|
const { activityId } = msg;
|
||||||
|
const roleId = session.get('roleId');
|
||||||
|
const serverId = session.get('serverId');
|
||||||
|
|
||||||
|
let playerData = await getPlayerDailyCoinData(activityId, serverId, roleId)
|
||||||
|
|
||||||
|
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||||
|
|
||||||
|
return resResult(STATUS.SUCCESS, playerData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 兑换
|
||||||
|
* @param {{ activityId: number, count:number}} msg
|
||||||
|
* @param {BackendSession} session
|
||||||
|
* @memberof DailyCoinHandler
|
||||||
|
*/
|
||||||
|
async exchangeCoin(msg: { activityId: number, count: number }, session: BackendSession) {
|
||||||
|
const { activityId, count } = msg;
|
||||||
|
const roleId = session.get('roleId');
|
||||||
|
const serverId = session.get('serverId');
|
||||||
|
const sid = session.get('sid');
|
||||||
|
const roleName = session.get('roleName');
|
||||||
|
const funcs = session.get('funcs');
|
||||||
|
|
||||||
|
let playerData = await getPlayerDailyCoinData(activityId, serverId, roleId)
|
||||||
|
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||||
|
let curIndex = playerData.exchangeCount;
|
||||||
|
if (curIndex + count > playerData.list.length) {
|
||||||
|
return resResult(STATUS.ACTIVITY_MAX_COUNT);
|
||||||
|
}
|
||||||
|
let allConsume: Array<ItemInter> = []
|
||||||
|
let allReward: Array<RewardParam> = [];
|
||||||
|
for (let i = 1; i <= count; i++) {
|
||||||
|
let index = curIndex + i;
|
||||||
|
console.log('第几次抽奖', index)
|
||||||
|
let item: DailyCoinItem = playerData.findItem(index);
|
||||||
|
if (item.consume) {//消耗资源
|
||||||
|
let consume = stringToConsumeParam(item.consume)
|
||||||
|
allConsume = allConsume.concat(consume)
|
||||||
|
}
|
||||||
|
let rate = item.getRate()//翻几倍
|
||||||
|
let baseRewardParamArr: Array<RewardParam> = stringToRewardParam(item.baseReward);
|
||||||
|
console.log('基础奖励翻倍', JSON.stringify(baseRewardParamArr), rate)
|
||||||
|
for (let reward of baseRewardParamArr) {
|
||||||
|
reward.count = reward.count * rate;
|
||||||
|
}
|
||||||
|
allReward = allReward.concat(baseRewardParamArr);
|
||||||
|
if (item.extraReward) {//额外奖励
|
||||||
|
let extraRewardParamArr: Array<RewardParam> = stringToRewardParam(item.extraReward);
|
||||||
|
console.log('额外奖励', JSON.stringify(extraRewardParamArr))
|
||||||
|
allReward = allReward.concat(extraRewardParamArr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let newConsume = mergeData(allConsume);
|
||||||
|
let newReward = mergeData(allReward);
|
||||||
|
console.log('所有消耗', JSON.stringify(newConsume))
|
||||||
|
console.log('所有奖励', JSON.stringify(newReward))
|
||||||
|
|
||||||
|
//检查资源
|
||||||
|
let consumeResult = await handleCost(roleId, sid, newConsume);
|
||||||
|
if (!consumeResult) return resResult(STATUS.ACTIVITY_RES_NOT_ENOUGH);
|
||||||
|
|
||||||
|
//免费期间
|
||||||
|
let result = await addReward(roleId, roleName, sid, serverId, funcs, newReward)
|
||||||
|
await ActivityDailyCoinModel.addExchangeRecord(serverId, activityId, roleId, playerData.beginTime, count);
|
||||||
|
|
||||||
|
let exchangeCount = playerData.exchangeCount + count;
|
||||||
|
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||||
|
param: { activityId, count },
|
||||||
|
item: { exchangeCount },
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,10 +11,10 @@ import moment = require('moment');
|
|||||||
|
|
||||||
|
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
return new DailyLunchHandler(app);
|
return new DailyMealHandler(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DailyLunchHandler {
|
export class DailyMealHandler {
|
||||||
constructor(private app: Application) {
|
constructor(private app: Application) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,9 +25,9 @@ export class DailyLunchHandler {
|
|||||||
* @description 获取每日午饭/晚饭活动数据
|
* @description 获取每日午饭/晚饭活动数据
|
||||||
* @param {{ activityId: number}} msg
|
* @param {{ activityId: number}} msg
|
||||||
* @param {BackendSession} session
|
* @param {BackendSession} session
|
||||||
* @memberof DailyLunchHandler
|
* @memberof DailyMealHandler
|
||||||
*/
|
*/
|
||||||
async getDailyLunchActivity(msg: { activityId: number }, session: BackendSession) {
|
async getDailyMealActivity(msg: { activityId: number }, session: BackendSession) {
|
||||||
const { activityId } = msg;
|
const { activityId } = msg;
|
||||||
const roleId = session.get('roleId');
|
const roleId = session.get('roleId');
|
||||||
const serverId = session.get('serverId');
|
const serverId = session.get('serverId');
|
||||||
@@ -43,7 +43,7 @@ export class DailyLunchHandler {
|
|||||||
* @description 领取奖励
|
* @description 领取奖励
|
||||||
* @param {{ activityId: number}} msg
|
* @param {{ activityId: number}} msg
|
||||||
* @param {BackendSession} session
|
* @param {BackendSession} session
|
||||||
* @memberof DailyLunchHandler
|
* @memberof DailyMealHandler
|
||||||
*/
|
*/
|
||||||
async getDailyMealReward(msg: { activityId: number, type: number }, session: BackendSession) {
|
async getDailyMealReward(msg: { activityId: number, type: number }, session: BackendSession) {
|
||||||
const { activityId, type } = msg;
|
const { activityId, type } = msg;
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import { Application, BackendSession } from 'pinus';
|
import { Application, BackendSession } from 'pinus';
|
||||||
import { decodeArrayListStr, deltaDays, resResult, splitString } from '../../../pubUtils/util';
|
import { resResult, splitString } from '../../../pubUtils/util';
|
||||||
import { STATUS, ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts';
|
import { STATUS, } from '../../../consts';
|
||||||
import { SelfServiceShopData, SelfServiceShopItem, SelfServiceShopItemInfo } from '../../../domain/activityField/selfServiceShopField';
|
import { SelfServiceShopData } from '../../../domain/activityField/selfServiceShopField';
|
||||||
import { addItems, handleCost } from '../../../services/rewardService';
|
import { handleCost } from '../../../services/rewardService';
|
||||||
import { ActivitySelfServiceShopModel, ActivitySelfServiceShopModelType } from '../../../db/ActivitySelfServiceShop';
|
import { ActivitySelfServiceShopModel, ActivitySelfServiceShopModelType } from '../../../db/ActivitySelfServiceShop';
|
||||||
import { ActivitySelfServiceModel, ActivitySelfServiceModelType } from '../../../db/ActivitySelfService';
|
import { ActivitySelfServiceModel } from '../../../db/ActivitySelfService';
|
||||||
import { ActivitySelfServiceGoodsModel, ActivitySelfServiceGoodsModelType } from '../../../db/ActivitySelfServiceGoods';
|
import { ActivitySelfServiceGoodsModel } from '../../../db/ActivitySelfServiceGoods';
|
||||||
import moment = require('moment');
|
import { ActivityModel, ActivityModelType } from '../../../db/Activity';
|
||||||
import Activity, { ActivityModel, ActivityModelType } from '../../../db/Activity';
|
|
||||||
import { addSelfServiceShopGiftReward, getSelfServiceShopActivityData, getPlayerActivityData } from '../../../services/selfServiceShopActivityService';
|
import { addSelfServiceShopGiftReward, getSelfServiceShopActivityData, getPlayerActivityData } from '../../../services/selfServiceShopActivityService';
|
||||||
import { addReward, stringToConsumeParam, stringToRewardParam } from '../../../services/giftPackageService';
|
import { addReward, stringToConsumeParam, stringToRewardParam } from '../../../services/giftPackageService';
|
||||||
import { random } from 'underscore';
|
import { random } from 'underscore';
|
||||||
@@ -73,17 +72,17 @@ export class SelfServiceShopHandler {
|
|||||||
let consumeResult = await handleCost(roleId, sid, consume);
|
let consumeResult = await handleCost(roleId, sid, consume);
|
||||||
if (!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
if (!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||||
|
|
||||||
let result = await addSelfServiceShopGiftReward(roleId, roleName, sid, serverId, funcs, activityId, roundIndex, index);
|
let result = await addSelfServiceShopGiftReward(roleId, roleName, sid, serverId, funcs, activityId, roundIndex, index, item);
|
||||||
return resResult(STATUS.SUCCESS, Object.assign(result, {}));
|
return resResult(STATUS.SUCCESS, Object.assign(result, {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 操作礼包
|
* @description 操作礼包
|
||||||
* @param {{ data:Array<{activityId: number, roundIndex: number, index: number, cellIndex: number, gift: number, rewardIndex: number}>}} msg
|
* @param {{ data:Array<{activityId: number, roundIndex: number, index: number, cellIndex: number, rewardIndex: number}>}} msg
|
||||||
* @param {BackendSession} session
|
* @param {BackendSession} session
|
||||||
* @memberof SelfServiceShopHandler
|
* @memberof SelfServiceShopHandler
|
||||||
*/
|
*/
|
||||||
async saveGood(msg: { data: Array<{ activityId: number, roundIndex: number, index: number, cellIndex: number, gift: number, rewardIndex: number }> }, session: BackendSession) {
|
async saveGood(msg: { data: Array<{ activityId: number, roundIndex: number, index: number, cellIndex: number, rewardIndex: number }> }, session: BackendSession) {
|
||||||
const { data } = msg;
|
const { data } = msg;
|
||||||
const roleId = session.get('roleId');
|
const roleId = session.get('roleId');
|
||||||
const serverId = session.get('serverId');
|
const serverId = session.get('serverId');
|
||||||
@@ -92,7 +91,7 @@ export class SelfServiceShopHandler {
|
|||||||
const funcs: number[] = session.get('funcs');
|
const funcs: number[] = session.get('funcs');
|
||||||
|
|
||||||
for (let obj of data) {
|
for (let obj of data) {
|
||||||
await ActivitySelfServiceGoodsModel.addGoods(obj.activityId, roleId, obj.roundIndex, obj.index, obj.cellIndex, obj.gift, obj.rewardIndex);
|
await ActivitySelfServiceGoodsModel.addGoods(obj.activityId, roleId, obj.roundIndex, obj.index, obj.cellIndex, obj.rewardIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resResult(STATUS.SUCCESS, { data });
|
return resResult(STATUS.SUCCESS, { data });
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import { ACTIVITY_TYPE, DAILY_MEAL_TYPE } from '../consts';
|
||||||
|
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||||
|
import { ActivityDailyCoinModel, ActivityDailyCoinModelType } from '../db/ActivityDailyCoin';
|
||||||
|
import { ServerlistModel } from '../db/Serverlist';
|
||||||
|
import { DailyCoinData } from '../domain/activityField/dailyCoinField';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取活动数据
|
||||||
|
*
|
||||||
|
* @param {number} serverId 区Id
|
||||||
|
* @param {number} activityId 活动Id
|
||||||
|
* @param {string} roleId 角色Id
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export async function dailyCoinActivity(serverId: number, roleId: string) {
|
||||||
|
let { activityGroupId } = await ServerlistModel.findByServerId(serverId);
|
||||||
|
let activityDataArray: ActivityModelType[] = await ActivityModel.findOpenActivityByType(activityGroupId, ACTIVITY_TYPE.DAILY_COIN, new Date());
|
||||||
|
if (activityDataArray.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let activityData: ActivityModelType = activityDataArray[0];
|
||||||
|
let playerData = new DailyCoinData(activityData);
|
||||||
|
|
||||||
|
let playerRecord: ActivityDailyCoinModelType = await ActivityDailyCoinModel.findData(serverId, activityData.activityId, roleId, playerData.beginTime);
|
||||||
|
playerData.setPlayerRecords(playerRecord);
|
||||||
|
return playerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家玩家活动数据
|
||||||
|
*
|
||||||
|
* @param {number} serverId 区Id
|
||||||
|
* @param {number} activityId 活动Id
|
||||||
|
* @param {string} roleId 角色Id
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export async function getPlayerDailyCoinData(activityId: number, serverId: number, roleId: string) {
|
||||||
|
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||||
|
let playerData = new DailyCoinData(activityData);
|
||||||
|
|
||||||
|
let playerRecord: ActivityDailyCoinModelType = await ActivityDailyCoinModel.findData(serverId, activityData.activityId, roleId, playerData.beginTime);
|
||||||
|
playerData.setPlayerRecords(playerRecord);
|
||||||
|
return playerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function mergeData(data: any[]) {
|
||||||
|
let newDate = [];
|
||||||
|
for (let item of data) {
|
||||||
|
let index = newDate.findIndex(obj => { return obj.id === item.id });
|
||||||
|
if (index != -1) {
|
||||||
|
newDate[index].count += item.count;
|
||||||
|
} else {
|
||||||
|
newDate = newDate.concat(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newDate;
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ export async function useGiftPackage(roleId: string, roleName: string, sid: stri
|
|||||||
if (!giftPackageData) {
|
if (!giftPackageData) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
console.log('dddddddddddddd', giftID, JSON.stringify(giftPackageData))
|
||||||
let giftType = giftPackageData.type;//礼包类型
|
let giftType = giftPackageData.type;//礼包类型
|
||||||
let reward = giftPackageData.reward;//奖励内容,数组
|
let reward = giftPackageData.reward;//奖励内容,数组
|
||||||
switch (giftType) {
|
switch (giftType) {
|
||||||
@@ -100,6 +101,8 @@ function rewardItemData(reward: Array<RewardParam>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getSelectedReward(giftData: DicGiftPackage, selected: Array<number>): Array<RewardParam> {
|
export function getSelectedReward(giftData: DicGiftPackage, selected: Array<number>): Array<RewardParam> {
|
||||||
|
console.log('bbbbbbbbbbbbbbbbbbb', JSON.stringify(selected), JSON.stringify(giftData))
|
||||||
|
|
||||||
let selectedReward: Array<RewardParam> = [];
|
let selectedReward: Array<RewardParam> = [];
|
||||||
for (let i = 0; i < selected.length; i++) {
|
for (let i = 0; i < selected.length; i++) {
|
||||||
let index = selected[i];
|
let index = selected[i];
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE, REFRESH_TIME, STATUS } from '../consts';
|
import { ACTIVITY_TYPE, REFRESH_TIME, STATUS } from '../consts';
|
||||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||||
import { ActivitySelfServiceGoodsModel, ActivitySelfServiceGoodsModelType } from '../db/ActivitySelfServiceGoods';
|
import { ActivitySelfServiceGoodsModel, ActivitySelfServiceGoodsModelType } from '../db/ActivitySelfServiceGoods';
|
||||||
import { ActivitySelfServiceShopModel, ActivitySelfServiceShopModelType } from '../db/ActivitySelfServiceShop';
|
import { ActivitySelfServiceShopModel, ActivitySelfServiceShopModelType } from '../db/ActivitySelfServiceShop';
|
||||||
import { ActivitySelfServiceModel, ActivitySelfServiceModelType } from '../db/ActivitySelfService';
|
import { ActivitySelfServiceModel } from '../db/ActivitySelfService';
|
||||||
import { ServerlistModel } from '../db/Serverlist';
|
import { ServerlistModel } from '../db/Serverlist';
|
||||||
import { RewardParam } from '../domain/activityField/rewardField';
|
import { RewardParam } from '../domain/activityField/rewardField';
|
||||||
import { SelfServiceShopData, SelfServiceShopItem } from '../domain/activityField/selfServiceShopField';
|
import { SelfServiceShopData, SelfServiceShopItem } from '../domain/activityField/selfServiceShopField';
|
||||||
import { gameData } from '../pubUtils/data';
|
import { gameData } from '../pubUtils/data';
|
||||||
import { addReward, getSelectedReward } from './giftPackageService';
|
import { addReward, getSelectedReward, stringToRewardParam } from './giftPackageService';
|
||||||
import moment = require('moment');
|
import moment = require('moment');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,11 +57,9 @@ export async function getPlayerActivityData(activityId: number, serverId: number
|
|||||||
challengeBeginTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').toDate();
|
challengeBeginTime = moment(new Date()).startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').toDate();
|
||||||
challengeEndTime = moment(challengeBeginTime).add(1, 'd').toDate()
|
challengeEndTime = moment(challengeBeginTime).add(1, 'd').toDate()
|
||||||
} else {
|
} else {
|
||||||
console.log("dddddddddddddddd", curDate.hour(), curDate.hours())
|
|
||||||
challengeBeginTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').toDate();
|
challengeBeginTime = moment(new Date()).startOf('d').add(REFRESH_TIME, 'h').toDate();
|
||||||
challengeEndTime = moment(challengeBeginTime).add(1, 'd').toDate()
|
challengeEndTime = moment(challengeBeginTime).add(1, 'd').toDate()
|
||||||
}
|
}
|
||||||
console.log("dddddddddddddddd", challengeBeginTime, challengeEndTime)
|
|
||||||
let records = (playerSelfServerData && playerSelfServerData.challengeRecords) ? playerSelfServerData.challengeRecords : [];
|
let records = (playerSelfServerData && playerSelfServerData.challengeRecords) ? playerSelfServerData.challengeRecords : [];
|
||||||
for (let record of records) {
|
for (let record of records) {
|
||||||
console.log(challengeBeginTime, challengeEndTime, record.time)
|
console.log(challengeBeginTime, challengeEndTime, record.time)
|
||||||
@@ -85,16 +83,17 @@ export async function getPlayerActivityData(activityId: number, serverId: number
|
|||||||
* @param {number} priceType 价格类型
|
* @param {number} priceType 价格类型
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export async function addSelfServiceShopGiftReward(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[], activityId: number, roundIndex: number, index: number) {
|
|
||||||
|
export async function addSelfServiceShopGiftReward(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[], activityId: number, roundIndex: number, index: number, item: SelfServiceShopItem) {
|
||||||
let playerGoods: ActivitySelfServiceGoodsModelType[] = await ActivitySelfServiceGoodsModel.findDataByIndex(activityId, roleId, roundIndex, index);
|
let playerGoods: ActivitySelfServiceGoodsModelType[] = await ActivitySelfServiceGoodsModel.findDataByIndex(activityId, roleId, roundIndex, index);
|
||||||
|
|
||||||
let rewardArray: Array<RewardParam> = [];
|
let rewardArray: Array<RewardParam> = [];
|
||||||
for (let obj of playerGoods) {
|
for (let obj of playerGoods) {
|
||||||
let giftID = obj.gift;
|
|
||||||
let selectedIndex = obj.rewardIndex;
|
let selectedIndex = obj.rewardIndex;
|
||||||
let giftPackageData = gameData.giftPackage.get(giftID);
|
let cellIndex = obj.cellIndex;
|
||||||
let selectedReward: Array<RewardParam> = getSelectedReward(giftPackageData, [selectedIndex])
|
let giftData = item.findCellIndex(cellIndex);
|
||||||
rewardArray = rewardArray.concat(selectedReward)
|
let rewards: Array<RewardParam> = stringToRewardParam(giftData.gift);
|
||||||
|
rewardArray = rewardArray.concat(rewards[selectedIndex])
|
||||||
}
|
}
|
||||||
let goodsStr = '';
|
let goodsStr = '';
|
||||||
for (let obj of rewardArray) {
|
for (let obj of rewardArray) {
|
||||||
@@ -102,7 +101,7 @@ export async function addSelfServiceShopGiftReward(roleId: string, roleName: str
|
|||||||
}
|
}
|
||||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardArray);
|
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardArray);
|
||||||
//购买记录
|
//购买记录
|
||||||
console.log('dddddddd', rewardArray.length, serverId, activityId, roleId, roundIndex, index, goodsStr)
|
console.log('dddddddd', rewardArray.length, serverId, activityId, roleId, roundIndex, index, goodsStr, JSON.stringify(item))
|
||||||
await ActivitySelfServiceShopModel.addBuyRecord(serverId, activityId, roleId, roundIndex, index, goodsStr);
|
await ActivitySelfServiceShopModel.addBuyRecord(serverId, activityId, roleId, roundIndex, index, goodsStr);
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -141,7 +140,7 @@ export async function makeSelfServerShop(roleId: string, roleName: string, sid:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let result = await addSelfServiceShopGiftReward(roleId, roleName, sid, serverId, funcs, activityId, playerData.roundIndex, item.index);
|
let result = await addSelfServiceShopGiftReward(roleId, roleName, sid, serverId, funcs, activityId, playerData.roundIndex, item.index, item);
|
||||||
item.buyCount += 1;
|
item.buyCount += 1;
|
||||||
return {
|
return {
|
||||||
code: 0,
|
code: 0,
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export enum ACTIVITY_TYPE {
|
|||||||
FOURTEEN_DAY = 28, // 十四天乐活动
|
FOURTEEN_DAY = 28, // 十四天乐活动
|
||||||
COMMON_SEVEN_DAY = 29, // 通用七天乐活动
|
COMMON_SEVEN_DAY = 29, // 通用七天乐活动
|
||||||
DAILY_MEAL = 30, // 每日领取免费午饭、晚饭活动
|
DAILY_MEAL = 30, // 每日领取免费午饭、晚饭活动
|
||||||
|
DAILY_COIN = 31, // 每日兑换铜钱
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import BaseModel from './BaseModel';
|
||||||
|
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 活动系统 - 每日兑换铜币
|
||||||
|
*/
|
||||||
|
@index({ roleId: 1 })
|
||||||
|
|
||||||
|
export default class Activity_Daily_Coin extends BaseModel {
|
||||||
|
@prop({ required: true })
|
||||||
|
serverId: number; // 服id
|
||||||
|
@prop({ required: true })
|
||||||
|
activityId: number; // 活动Id
|
||||||
|
@prop({ required: true })
|
||||||
|
roleId: string; // 用户Id
|
||||||
|
@prop({ required: true })
|
||||||
|
beginTime: number; // 开始统计的时间
|
||||||
|
@prop({ required: true })
|
||||||
|
exchangeCount: number; // 兑换次数
|
||||||
|
|
||||||
|
|
||||||
|
//兑换记录
|
||||||
|
public static async addExchangeRecord(serverId: number, activityId: number, roleId: string, beginTime: number, count: number) {
|
||||||
|
let result = await ActivityDailyCoinModel.findOneAndUpdate({ serverId, activityId, roleId, beginTime }, { $inc: { exchangeCount: count } }, { upsert: true, new: true }).lean(true)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据活动时间查询活动数据
|
||||||
|
public static async findData(serverId: number, activityId: number, roleId: string, beginTime: number) {
|
||||||
|
let result: ActivityDailyCoinModelType = await ActivityDailyCoinModel.findOne({
|
||||||
|
serverId, roleId, activityId, beginTime,
|
||||||
|
}).lean(true);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除活动兑换记录
|
||||||
|
public static async deleteActivity(serverId: number, activityId: number, roleId: string, beginTime: number) {
|
||||||
|
await ActivityDailyCoinModel.deleteMany({ serverId, roleId, activityId, beginTime });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ActivityDailyCoinModel = getModelForClass(Activity_Daily_Coin);
|
||||||
|
|
||||||
|
export interface ActivityDailyCoinModelType extends Pick<DocumentType<Activity_Daily_Coin>, keyof Activity_Daily_Coin> { }
|
||||||
|
export type ActivityDailyCoinModelTypeParam = Partial<ActivityDailyCoinModelType>; // 将所有字段变成可选项
|
||||||
@@ -18,21 +18,19 @@ export default class Activity_Self_Service_Goods extends BaseModel {
|
|||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
cellIndex: number; // 第几个坑位从1开始
|
cellIndex: number; // 第几个坑位从1开始
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
gift: number; // 礼包id
|
|
||||||
@prop({ required: true })
|
|
||||||
rewardIndex: number; // 礼包中第几项奖励
|
rewardIndex: number; // 礼包中第几项奖励
|
||||||
|
|
||||||
|
|
||||||
//添加选中的物品
|
//添加选中的物品
|
||||||
public static async addGoods(activityId: number, roleId: string, roundIndex: number, index: number, cellIndex: number, gift: number, rewardIndex: number) {
|
public static async addGoods(activityId: number, roleId: string, roundIndex: number, index: number, cellIndex: number, rewardIndex: number) {
|
||||||
let result: ActivitySelfServiceGoodsModelType = await ActivitySelfServiceGoodsModel.findOneAndUpdate({ roleId, activityId, roundIndex, index, cellIndex },
|
let result: ActivitySelfServiceGoodsModelType = await ActivitySelfServiceGoodsModel.findOneAndUpdate({ roleId, activityId, roundIndex, index, cellIndex },
|
||||||
{ $set: { gift, rewardIndex } }, { upsert: true, new: true }).lean(true);
|
{ $set: { rewardIndex } }, { upsert: true, new: true }).lean(true);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async findData(activityId: number, roleId: string, roundIndex: number, lean = true) {
|
public static async findData(activityId: number, roleId: string, roundIndex: number, lean = true) {
|
||||||
let result: ActivitySelfServiceGoodsModelType[] = await ActivitySelfServiceGoodsModel.find({ roleId, activityId, roundIndex }, {
|
let result: ActivitySelfServiceGoodsModelType[] = await ActivitySelfServiceGoodsModel.find({ roleId, activityId, roundIndex }, {
|
||||||
index: 1, cellIndex: 1, gift: 1, rewardIndex: 1, _id: -1
|
index: 1, cellIndex: 1, rewardIndex: 1, _id: -1
|
||||||
}).lean(lean);
|
}).lean(lean);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import moment = require('moment');
|
||||||
|
import { random } from 'underscore';
|
||||||
|
import { REFRESH_TIME, TASK_TYPE } from '../../consts';
|
||||||
|
import { ActivityModelType } from '../../db/Activity';
|
||||||
|
import { ActivityDailyCoinModelType } from '../../db/ActivityDailyCoin';
|
||||||
|
import { ActivityBase } from './activityField';
|
||||||
|
|
||||||
|
|
||||||
|
// 每次配置数据
|
||||||
|
export class DailyCoinItem {
|
||||||
|
index: number; // 第几次从1开始
|
||||||
|
baseReward: string; //基础奖励
|
||||||
|
extraReward: string; //额外奖励
|
||||||
|
exchangeRate: number; // 兑换比例 1元宝兑换多少铜币
|
||||||
|
double: number; // 双倍概率 0.25
|
||||||
|
fiveTimes: number; // 5倍概率 0.05
|
||||||
|
consume: string; //补签消耗资源
|
||||||
|
|
||||||
|
public getRate() {
|
||||||
|
let ran = (random(99) + 1) * 0.01;//[1,100]
|
||||||
|
ran -= this.double;
|
||||||
|
if (ran <= 0) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
ran -= this.fiveTimes;
|
||||||
|
if (ran <= 0) {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(data: any) {
|
||||||
|
this.index = data.index;
|
||||||
|
this.baseReward = data.baseReward;
|
||||||
|
this.extraReward = data.extraReward;
|
||||||
|
this.exchangeRate = data.exchangeRate;
|
||||||
|
this.double = data.double;
|
||||||
|
this.fiveTimes = data.fiveTimes;
|
||||||
|
this.consume = data.consume;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 每日兑换铜币活动数据
|
||||||
|
export class DailyCoinData extends ActivityBase {
|
||||||
|
list: Array<DailyCoinItem> = [];
|
||||||
|
name: string = '';//名字
|
||||||
|
exchangeCount: number = 0;//已经兑换次数
|
||||||
|
|
||||||
|
public findItem(index: number) {
|
||||||
|
let itemIndex = this.list.findIndex(obj => { return obj.index === index });
|
||||||
|
return (itemIndex != -1) ? this.list[itemIndex] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//解析玩家领取记录
|
||||||
|
public setPlayerRecords(data: ActivityDailyCoinModelType) {
|
||||||
|
this.exchangeCount = data && data.exchangeCount ? data.exchangeCount : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public initData(data: string) {
|
||||||
|
this.exchangeCount = 0;
|
||||||
|
let dataObj = JSON.parse(data);
|
||||||
|
let arr = dataObj;
|
||||||
|
for (let obj of arr) {
|
||||||
|
this.list.push(new DailyCoinItem(obj))
|
||||||
|
}
|
||||||
|
let curDate = moment(new Date());
|
||||||
|
if (curDate.hour() < REFRESH_TIME) {
|
||||||
|
this.beginTime = curDate.startOf('d').add(-1, 'd').add(REFRESH_TIME, 'h').valueOf();
|
||||||
|
this.endTime = moment(this.beginTime).add(1, 'd').valueOf();
|
||||||
|
} else {
|
||||||
|
this.beginTime = curDate.startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||||
|
this.endTime = moment(this.beginTime).add(1, 'd').valueOf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(activityData: ActivityModelType) {
|
||||||
|
super(activityData)
|
||||||
|
this.initData(activityData.data)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,6 +31,11 @@ export class SelfServiceShopItem {
|
|||||||
|
|
||||||
buyCount: number = 0; //已经购买次数
|
buyCount: number = 0; //已经购买次数
|
||||||
|
|
||||||
|
public findCellIndex(cellIndex: number) {
|
||||||
|
let index = this.data.findIndex(obj => { return obj && obj.cellIndex === cellIndex });
|
||||||
|
return (index != -1) ? this.data[index] : null;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(cellData: any) {
|
constructor(cellData: any) {
|
||||||
this.index = cellData.index;
|
this.index = cellData.index;
|
||||||
this.name = cellData.name;
|
this.name = cellData.name;
|
||||||
|
|||||||
Reference in New Issue
Block a user