团购: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 —————————————— //
|
||||
@@ -79,6 +79,18 @@ export default class Activity_Group_Shop_Rec extends BaseModel {
|
||||
).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async debugSetSum(activityId: number, id: number, sum: number) {
|
||||
if(id == 0) {
|
||||
await ActivityGroupShopRecModel.updateMany({ activityId }, { $set: { sum } }, { new: true, upsert: true });
|
||||
let result: ActivityGroupShopRecType[] = await ActivityGroupShopRecModel.find({ activityId }).lean();
|
||||
return result;
|
||||
} else {
|
||||
await ActivityGroupShopRecModel.updateMany({ activityId, id }, { $set: { sum } }, { new: true, upsert: true });
|
||||
let result: ActivityGroupShopRecType[] = await ActivityGroupShopRecModel.find({ activityId, id }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityGroupShopRecModel = getModelForClass(Activity_Group_Shop_Rec);
|
||||
|
||||
@@ -74,8 +74,12 @@ export default class Activity_Group_Shop_User_Rec extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async clearCnt(activityId: number, roleId: string) {
|
||||
await ActivityGroupShopUserRecModel.deleteMany({ roleId, activityId });
|
||||
}
|
||||
|
||||
public static async findByPrice(activityId: number, id: number, price: number) {
|
||||
let result: ActivityGroupShopUserRecType[] = await ActivityGroupShopUserRecModel.find({ activityId, id, 'records.price': { $lt: price } }).lean();
|
||||
let result: ActivityGroupShopUserRecType[] = await ActivityGroupShopUserRecModel.find({ activityId, id, 'records.price': { $gt: price } }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,8 +88,8 @@ export abstract class ActivityBase {
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_TIME_TYPE.DATE_TIME: {
|
||||
this.beginTime = moment(activityData.beginTime).add(this.delayDay, 'd').startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.endTime = moment(activityData.endTime).add(this.delayDay, 'd').startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.beginTime = moment(activityData.beginTime).startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.endTime = moment(activityData.endTime).startOf('d').add(REFRESH_TIME, 'h').valueOf();
|
||||
this.todayIndex = deltaDays(moment(this.beginTime).toDate(), new Date) + 1;
|
||||
|
||||
break;
|
||||
|
||||
@@ -37,7 +37,7 @@ class GroupShopTimer {
|
||||
sum: number; // 如果次数不足sum次则强行设成sum次
|
||||
|
||||
constructor(beginTime: number, id: number, data: GroupShopTimerInDb) {
|
||||
this.time = beginTime + data.time * 60 * 1000;
|
||||
this.time = beginTime + data.time * 60 * 60 * 1000;
|
||||
this.sum = data.sum;
|
||||
this.itemId = id;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ class GroupShopItem {
|
||||
}
|
||||
|
||||
setPlayerCnt(cnt: number) {
|
||||
this.hasBoughtCnt += cnt;
|
||||
this.hasBoughtCnt = cnt;
|
||||
}
|
||||
|
||||
checkBuyCnt(buyCnt: number) {
|
||||
|
||||
Reference in New Issue
Block a user