活动:后台修改
This commit is contained in:
@@ -20,7 +20,8 @@ export class ActivityRemote {
|
|||||||
private channelService: ChannelService;
|
private channelService: ChannelService;
|
||||||
private activityByServer: Map<number, number[]> = new Map(); // serverId => activityId[];
|
private activityByServer: Map<number, number[]> = new Map(); // serverId => activityId[];
|
||||||
private activities: Map<number, ActivityModelType> = new Map(); // activityId => activity
|
private activities: Map<number, ActivityModelType> = new Map(); // activityId => activity
|
||||||
private activityByType: Map<number, Map<number, number[]>> = new Map(); // serverId => type => activityId[]
|
private activityByType: Map<number, Map<number, number[]>> = new Map(); // serverId => type => activityId[];
|
||||||
|
private groupToServer: Map<number, number[]> = new Map(); // group => serverId[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重载json资源
|
* 重载json资源
|
||||||
@@ -31,20 +32,19 @@ export class ActivityRemote {
|
|||||||
|
|
||||||
private async loadActivities() {
|
private async loadActivities() {
|
||||||
let servers = await ServerlistModel.getAllServerList();
|
let servers = await ServerlistModel.getAllServerList();
|
||||||
let groupToServer = new Map<number, number[]>();
|
|
||||||
for(let { serverId, activityGroupId } of servers) {
|
for(let { serverId, activityGroupId } of servers) {
|
||||||
for(let groupId of activityGroupId) {
|
for(let groupId of activityGroupId) {
|
||||||
if(!groupToServer.has(groupId)) {
|
if(!this.groupToServer.has(groupId)) {
|
||||||
groupToServer.set(groupId, []);
|
this.groupToServer.set(groupId, []);
|
||||||
}
|
}
|
||||||
groupToServer.get(groupId).push(serverId);
|
this.groupToServer.get(groupId).push(serverId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let activities = await ActivityModel.findOpenAndComingActivityes();
|
let activities = await ActivityModel.findOpenAndComingActivityes();
|
||||||
for(let activity of activities) {
|
for(let activity of activities) {
|
||||||
this.activities.set(activity.activityId, activity);
|
this.activities.set(activity.activityId, activity);
|
||||||
let servers = groupToServer.get(activity.activityId)||[];
|
let servers = this.groupToServer.get(activity.activityId)||[];
|
||||||
for(let serverId of servers) {
|
for(let serverId of servers) {
|
||||||
if(!this.activityByServer.has(serverId)) {
|
if(!this.activityByServer.has(serverId)) {
|
||||||
this.activityByServer.set(serverId, []);
|
this.activityByServer.set(serverId, []);
|
||||||
@@ -66,6 +66,62 @@ export class ActivityRemote {
|
|||||||
this.app.set('activities', this.activities);
|
this.app.set('activities', this.activities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async updateActivities(activities: ActivityModelType[]) {
|
||||||
|
for(let activity of activities) {
|
||||||
|
let { activityId, groupId, type } = activity;
|
||||||
|
// 'activities'
|
||||||
|
this.activities.set(activityId, activity);
|
||||||
|
let serverIds = this.groupToServer.get(groupId)||[]; // 现在这个group对应的serverIds
|
||||||
|
// 'activityByServer' & 'activityByType'
|
||||||
|
// 将原来的都删掉,再塞入
|
||||||
|
for(let [serverId, activityIds] of this.activityByServer) {
|
||||||
|
let index = activityIds.indexOf(activityId);
|
||||||
|
if(index != -1) this.activityByServer.get(serverId).splice(index);
|
||||||
|
}
|
||||||
|
for(let [serverId, typeToActivities] of this.activityByType) {
|
||||||
|
for(let [type, activityIds] of typeToActivities) {
|
||||||
|
let index = activityIds.indexOf(activityId);
|
||||||
|
if(index != -1) this.activityByType.get(serverId).get(type).splice(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 塞入
|
||||||
|
for(let serverId of serverIds) {
|
||||||
|
if(!this.activityByServer.has(serverId)) {
|
||||||
|
this.activityByServer.set(serverId, []);
|
||||||
|
}
|
||||||
|
this.activityByServer.get(serverId).push(activityId);
|
||||||
|
|
||||||
|
if(!this.activityByType.has(serverId)) {
|
||||||
|
this.activityByType.set(serverId, new Map());
|
||||||
|
}
|
||||||
|
if(!this.activityByType.get(serverId).has(type)) {
|
||||||
|
this.activityByType.get(serverId).set(type, []);
|
||||||
|
}
|
||||||
|
this.activityByType.get(serverId).get(type).push(activityId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteActivities(activityIds: number[]) {
|
||||||
|
for(let activityId of activityIds) {
|
||||||
|
// 'activities'
|
||||||
|
this.activities.delete(activityId);
|
||||||
|
// 'activityByServer' & 'activityByType'
|
||||||
|
// 将原来的都删掉
|
||||||
|
for(let [serverId, activityIds] of this.activityByServer) {
|
||||||
|
let index = activityIds.indexOf(activityId);
|
||||||
|
if(index != -1) this.activityByServer.get(serverId).splice(index);
|
||||||
|
}
|
||||||
|
for(let [serverId, typeToActivities] of this.activityByType) {
|
||||||
|
for(let [type, activityIds] of typeToActivities) {
|
||||||
|
let index = activityIds.indexOf(activityId);
|
||||||
|
if(index != -1) this.activityByType.get(serverId).get(type).splice(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public getActivityById(activityId: number) {
|
public getActivityById(activityId: number) {
|
||||||
return _getActivityById(activityId);
|
return _getActivityById(activityId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import { ServerlistModel } from '../../../db/Serverlist';
|
|||||||
import { getWorldChannelSid } from '../../../services/chatService';
|
import { getWorldChannelSid } from '../../../services/chatService';
|
||||||
import { MaintenanceModel } from '../../../db/Maintenance';
|
import { MaintenanceModel } from '../../../db/Maintenance';
|
||||||
import { initMaintenance, stopMaintenance } from '../../../services/gmService';
|
import { initMaintenance, stopMaintenance } from '../../../services/gmService';
|
||||||
|
import { checkActivityEditable, checkActivityGroupType } from '../../../services/activity/activityService';
|
||||||
|
import { ActivityModel } from '../../../db/Activity';
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
return new GmHandler(app);
|
return new GmHandler(app);
|
||||||
}
|
}
|
||||||
@@ -214,4 +216,52 @@ export class GmHandler {
|
|||||||
}
|
}
|
||||||
return resResult(STATUS.SUCCESS);
|
return resResult(STATUS.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateActivity(msg: { activityId: number|string, groupId: number, beginTime: number, endTime: number, type: number, data: string }, session: BackendSession) {
|
||||||
|
const { activityId, groupId, beginTime, endTime, type, data } = msg;
|
||||||
|
const uid = session.get('uid');
|
||||||
|
if (!type || !data) {
|
||||||
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
|
}
|
||||||
|
let aids: number[] = [];
|
||||||
|
if (typeof activityId == 'number') {
|
||||||
|
aids.push(activityId);
|
||||||
|
} else {
|
||||||
|
activityId.split(',').forEach(aidStr => {
|
||||||
|
aids.push(parseInt(aidStr));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let activities = await ActivityModel.findActivityByIds(aids);
|
||||||
|
let checkTimeResult = await checkActivityEditable(activities);
|
||||||
|
if(!checkTimeResult) return resResult(STATUS.GM_CAN_NOT_EDIT_ACT);
|
||||||
|
let checkGroup = await checkActivityGroupType(groupId, activities);
|
||||||
|
if(!checkGroup) return resResult(STATUS.GM_ACTIVITY_NOT_FIT_GROUP_TYPE);
|
||||||
|
|
||||||
|
activities = await ActivityModel.addActivity(aids, groupId, beginTime ? new Date(beginTime) : undefined, endTime ? new Date(endTime) : undefined, type, data, uid);
|
||||||
|
|
||||||
|
let activityServers = pinus.app.getServersByType('activity');
|
||||||
|
for(let server of activityServers) {
|
||||||
|
pinus.app.rpc.activity.activityRemote.updateActivities.toServer(server.id, activities);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resResult(STATUS.SUCCESS, {
|
||||||
|
activity: activities
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteActivity(msg: { activityId: number}, session: BackendSession) {
|
||||||
|
const { activityId } = msg;
|
||||||
|
const uid = session.get('uid');
|
||||||
|
|
||||||
|
const result = await ActivityModel.deleteActivity(activityId, uid);
|
||||||
|
if (!result) {
|
||||||
|
return resResult(STATUS.ACTIVITY_MISSING);
|
||||||
|
}
|
||||||
|
let activityServers = pinus.app.getServersByType('activity');
|
||||||
|
for(let server of activityServers) {
|
||||||
|
pinus.app.rpc.activity.activityRemote.deleteActivities.toServer(server.id, [activityId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resResult(STATUS.SUCCESS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ACTIVITY_TYPE } from '../../consts';
|
import { ACTIVITY_TYPE, STATUS } from '../../consts';
|
||||||
import { getPlayerFirstGiftData } from './firstGiftService';
|
import { getPlayerFirstGiftData } from './firstGiftService';
|
||||||
import { getPlayerSignInData, } from './signInService';
|
import { getPlayerSignInData, } from './signInService';
|
||||||
import { getPlayerGrowthFundData, } from './growthFundService';
|
import { getPlayerGrowthFundData, } from './growthFundService';
|
||||||
@@ -26,8 +26,11 @@ import { getPlayerNewHeroGiftsData } from './newHeroGiftsService';
|
|||||||
import { getPlayerNewHeroGKData } from './newHeroGKService';
|
import { getPlayerNewHeroGKData } from './newHeroGKService';
|
||||||
import { getPlayerNewHeroGachaData } from './newHeroGachaService';
|
import { getPlayerNewHeroGachaData } from './newHeroGachaService';
|
||||||
import { pinus } from 'pinus';
|
import { pinus } from 'pinus';
|
||||||
import { ActivityModelType } from '../../db/Activity';
|
import { ActivityModel, ActivityModelType } from '../../db/Activity';
|
||||||
import { getRandSingleEelm } from '../../pubUtils/util';
|
import { getRandSingleEelm } from '../../pubUtils/util';
|
||||||
|
import { SignInData } from '../../domain/activityField/signInField';
|
||||||
|
import { ActivityGroupModel } from '../../db/ActivityGroup';
|
||||||
|
import { ActivityGroupTypeModel } from '../../db/ActivityGroupType';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取活动数据
|
* 获取活动数据
|
||||||
@@ -251,4 +254,48 @@ export function _getActivities() {
|
|||||||
result.push(activity);
|
result.push(activity);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function checkActivityEditable(activities: ActivityModelType[]) {
|
||||||
|
let now = new Date();
|
||||||
|
|
||||||
|
if(pinus.app.get('env') == 'production') {
|
||||||
|
for(let activity of activities) {
|
||||||
|
if(!activity || (activity.beginTime < now && activity.endTime > now)) {
|
||||||
|
|
||||||
|
if(activity.type == ACTIVITY_TYPE.SIGN_IN || activity.type == ACTIVITY_TYPE.SIGN_IN_VIP) {
|
||||||
|
// 签到活动的不显示期内也可以编辑
|
||||||
|
let signInObj = new SignInData(activity, 0);
|
||||||
|
if(signInObj.beginTime < now.getTime() && signInObj.endTime > now.getTime() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function checkActivityGroupType(groupId: number, activities: ActivityModelType[]) {
|
||||||
|
|
||||||
|
let activityGroup = await ActivityGroupModel.findGroupData(groupId);
|
||||||
|
if(!activityGroup) return false;
|
||||||
|
if(activityGroup.type != 0) {
|
||||||
|
let activityGroupType = await ActivityGroupTypeModel.findByGroupType(activityGroup.type);
|
||||||
|
if(!activityGroupType) return false;
|
||||||
|
let dic = activityGroupType.activityTypes;
|
||||||
|
for(let { type } of activities) {
|
||||||
|
let index = dic.findIndex(cur => cur.activityType == type);
|
||||||
|
if(index == -1) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
dic.splice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user