团购:debug接口
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { Application, BackendSession, HandlerService, } from "pinus";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { STATUS, ITEM_CHANGE_REASON, GROUP_SHOP_PRICE_STATUS, PUSH_ROUTE, } from "../../../consts";
|
||||
import { getGroupShopData, getGroupShopDataShow, getGroupShopPriceStatus } from "../../../services/activity/groupShopService";
|
||||
import { STATUS, ITEM_CHANGE_REASON, GROUP_SHOP_PRICE_STATUS, PUSH_ROUTE, ACTIVITY_TYPE, } from "../../../consts";
|
||||
import { getGroupShopData, getGroupShopDataShow, getGroupShopPriceStatus, getGroupShopServerData, refundGroupShop } from "../../../services/activity/groupShopService";
|
||||
import { addItems, getGoldObject, handleCost } from "../../../services/role/rewardService";
|
||||
import { ActivityGroupShopUserRecModel, GroupShopBuyRecord } from "../../../db/ActivityGroupShopUserRec";
|
||||
import { ActivityGroupShopRecModel, GroupShopRecord } from "../../../db/ActivityGroupShopRec";
|
||||
import { pick } from "underscore";
|
||||
import { addRoleToGroupShopChannel, leaveGroupShopChannel } from "../../../services/chatChannelService";
|
||||
import { sendMessageToGroupShopWithSuc } from "../../../services/pushService";
|
||||
import { getActivitiesByType } from "../../../services/activity/activityService";
|
||||
import { GroupShopData } from "../../../domain/activityField/groupShopField";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -103,4 +105,48 @@ export class GroupShopHandler {
|
||||
nextDiscount
|
||||
});
|
||||
}
|
||||
|
||||
async debugRefund(msg: {}, session: BackendSession) {
|
||||
await refundGroupShop(true);
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
async debugSetSum(msg: { id: number, sum: number }, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
let { id = 0, sum = 0 } = msg;
|
||||
let activities = await getActivitiesByType(serverId, ACTIVITY_TYPE.GROUP_SHOP);
|
||||
if(activities.length <= 0) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
for(let activityData of activities) {
|
||||
let recs = await ActivityGroupShopRecModel.debugSetSum(activityData.activityId, id, sum);
|
||||
let playerData = new GroupShopData(activityData, 0, 0);
|
||||
playerData.setRecords(recs);
|
||||
|
||||
let items = id == 0? playerData.items: [playerData.findItemById(id)];
|
||||
for(let item of items) {
|
||||
if(!item) continue;
|
||||
let nextDiscount = item.getCurDiscount();
|
||||
// 推送频道
|
||||
await sendMessageToGroupShopWithSuc(PUSH_ROUTE.GROUP_SHOP_UPDATE, { activityId: activityData.activityId, id, curDiscount: nextDiscount });
|
||||
}
|
||||
}
|
||||
let playerData = await getGroupShopDataShow(activities[0].activityId, roleId);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { playerData });
|
||||
}
|
||||
|
||||
async debugClearCnt(msg: { }, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
|
||||
let activities = await getActivitiesByType(serverId, ACTIVITY_TYPE.GROUP_SHOP);
|
||||
if(activities.length <= 0) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
for(let activityData of activities) {
|
||||
await ActivityGroupShopUserRecModel.clearCnt(activityData.activityId, roleId);
|
||||
}
|
||||
|
||||
let playerData = await getGroupShopDataShow(activities[0].activityId, roleId);
|
||||
return resResult(STATUS.SUCCESS, { playerData });
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import { getActivityById } from "./activityService";
|
||||
*/
|
||||
export async function getGroupShopData(activityId: number, roleId: string) {
|
||||
let activityData = await getActivityById(activityId);
|
||||
if(!activityData) return null
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
|
||||
let playerData = new GroupShopData(activityData, createTime, 0);
|
||||
@@ -76,16 +77,16 @@ export async function setGroupShopToSetSum(arr: { activityId: number, itemId: nu
|
||||
}
|
||||
}
|
||||
|
||||
export async function refundGroupShop() {
|
||||
export async function refundGroupShop(isDebug = false) {
|
||||
let activities = await ActivityModel.findActivityByType(ACTIVITY_TYPE.GROUP_SHOP);
|
||||
|
||||
for(let activityData of activities) {
|
||||
let hasRefund = await ActivityGroupShopRefundModel.check(activityData.activityId);
|
||||
if(!hasRefund) continue;
|
||||
if(!isDebug && !hasRefund) continue;
|
||||
|
||||
let recs = new Map<string, { itemId: number, diff: number }[]>();
|
||||
let playerData = await getGroupShopServerData(activityData);
|
||||
if(playerData.endTime >= Date.now()) continue;
|
||||
if(!isDebug && playerData.endTime >= Date.now()) continue;
|
||||
|
||||
let items = playerData.items||[];
|
||||
for(let item of items) {
|
||||
|
||||
@@ -106,6 +106,8 @@ export function checkRouteParam(route: string, msg: any) {
|
||||
case 'activity.treasureHuntHandler.getTreasureHuntActivity':
|
||||
case 'activity.vipRechargeMoneyHandler.getVipRechargeMoneyActivity':
|
||||
case 'activity.yuanbaoShopHandler.getShopActivity':
|
||||
case 'activity.groupShopHandler.getGroupShopPage':
|
||||
case 'activity.groupShopHandler.leaveGroupShopPage':
|
||||
{
|
||||
if(!checkNaturalNumbers(msg.activityId)) return false;
|
||||
break;
|
||||
@@ -406,6 +408,12 @@ export function checkRouteParam(route: string, msg: any) {
|
||||
if(msg.count < 0 && msg.count > 100) return false
|
||||
break;
|
||||
}
|
||||
case 'activity.groupShopHandler.buy':
|
||||
{
|
||||
let { activityId, price, id, buyCnt } = msg;
|
||||
if(!checkNaturalNumbers(activityId, price, id, buyCnt)) return false;
|
||||
break;
|
||||
}
|
||||
case "battle.barrageHandler.getBarrageList":
|
||||
{
|
||||
if(!checkNaturalStrings(msg.rid)) return false;
|
||||
@@ -1638,6 +1646,9 @@ export function checkRouteParam(route: string, msg: any) {
|
||||
case "guild.cityActivityHandler.debugStartHitGate":
|
||||
case "guild.cityActivityHandler.debugStopHitGate":
|
||||
case "guild.cityActivityHandler.debugTestAutoDeclare":
|
||||
case "activity.groupShopHandler.debugRefund":
|
||||
case "activity.groupShopHandler.debugSetSum":
|
||||
case "activity.groupShopHandler.debugClearCnt":
|
||||
{
|
||||
if (msg.magicWord !== DEBUG_MAGIC_WORD || !isDevelopEnv()) return false;
|
||||
break;
|
||||
|
||||
@@ -804,7 +804,13 @@ async function ladderDailyReward() {
|
||||
|
||||
// —————————————— 团购定时器 start —————————————— //
|
||||
async function initGroupShopSchedule() {
|
||||
initSumSchedule();
|
||||
scheduleJob('groupShopRefund', '0 30 5 * * ?', () => {
|
||||
refundGroupShop();
|
||||
});
|
||||
}
|
||||
|
||||
async function initSumSchedule() {
|
||||
let activities = await ActivityModel.findActivityByType(ACTIVITY_TYPE.GROUP_SHOP);
|
||||
let scheduleMap = new Map<number, { activityId: number, itemId: number, sum: number }[]>(); // 时间 => data
|
||||
for(let activity of activities) {
|
||||
@@ -825,8 +831,6 @@ async function initGroupShopSchedule() {
|
||||
await setGroupShopToSetSum(arr);
|
||||
});
|
||||
}
|
||||
|
||||
scheduleJob('groupShopRefund', '0 30 5 * * ?', refundGroupShop);
|
||||
}
|
||||
|
||||
// —————————————— 团购定时器 end —————————————— //
|
||||
Reference in New Issue
Block a user