拍卖:优化

This commit is contained in:
luying
2021-10-27 16:39:55 +08:00
parent b03802136b
commit 0dde8fd09a
9 changed files with 146 additions and 68 deletions

View File

@@ -247,7 +247,6 @@ export class ChatRemote {
public async pushCurrentTime(serverId: number, time: number) {
let roomId = groupRoomId(CHANNEL_PREFIX.WORLD, serverId);
let channel = this.channelService.getChannel(roomId, false);
console.log('*********', roomId, channel);
if (!channel) return { result: false, serverId };
channel.pushMessage('onPushCurrentTime', resResult(STATUS.SUCCESS, { time }));

View File

@@ -21,6 +21,7 @@ import { ActivityGroupTypeModel } from '../../../db/ActivityGroupType';
import { GuildActivityCityModel } from '../../../db/GuildActivityCity';
import { GuildActivityRecordModel } from '../../../db/GuildActivityRec';
import { getTimeFunM } from '../../../pubUtils/timeUtil';
import { sendUngotDividend } from '../../../services/auctionService';
let timer: NodeJS.Timer;
export default function (app: Application) {
return new GmHandler(app);
@@ -385,6 +386,7 @@ export class GmHandler {
let time = <number>getTimeFunM().getAfterDayWithHour(0);
pinus.app.rpc.guild.guildActivityRemote.setCurrentTime.broadcast(time);
await pushCurrentTime(time);
await sendUngotDividend();
}, startActivity * 1000 + endActivity * 1000 + startGuildAuction * 1000 + endGuildAuction * 1000 + startWorldAuction * 1000 + endWorldAuction * 1000 + startNextDay * 1000)
return resResult(STATUS.SUCCESS, {
startActivity: startTimes[0],

View File

@@ -4,7 +4,7 @@ import { AUCTION_STAGE, DEBUG_MAGIC_WORD, STATUS, CURRENCY_BY_TYPE, CURRENCY_TYP
import { LotModel } from "../../../db/Lot";
import { ItemReward } from "../../../domain/dbGeneral";
import { resResult } from "../../../pubUtils/util";
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus, getAuction, pushAuctionOver } from "../../../services/auctionService";
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus, getAuction, pushAuctionOver, treatSingleLotTime, treatLotsTime } from "../../../services/auctionService";
import { addItems, handleCost } from '../../../services/rewardService';
import { getSimpleRoleInfo } from '../../../services/roleService';
import { getRoleOnlineInfo } from '../../../services/redisService';
@@ -125,7 +125,8 @@ export class AuctionHandler {
const dividend = await DividendModel.updateLot(code, gid, newPrice, incPrice, max);
newDividend = await calculateDividend(dividend);
}
return resResult(STATUS.SUCCESS, { lot: newLot, dividend: newDividend });
let newLotResult = await treatSingleLotTime(newLot);
return resResult(STATUS.SUCCESS, { lot: newLotResult, dividend: newDividend });
} catch (e) {
console.log('offer got err:', e);
res.releaseCallback();
@@ -178,7 +179,8 @@ export class AuctionHandler {
const begin = await todayGuildBegin();
const lots = await LotModel.watchingLotsByBegin(serverId, roleId, begin);
const stage = await auctionStage();
return resResult(STATUS.SUCCESS, { lots: stage === AUCTION_STAGE.END ? [] : lots });
let newLots = await treatLotsTime(lots);
return resResult(STATUS.SUCCESS, { lots: stage === AUCTION_STAGE.END ? [] : newLots });
}
async offerRecs(msg: { count: number }, session: BackendSession) {

View File

@@ -51,18 +51,28 @@ export async function officialAuctionLots(session: FrontendOrBackendSession, beg
lots = await LotModel.findWorldLotsByBegin(serverId, begin);
}
return await treatLotsTime(lots);
}
export async function treatLotsTime(lots: LotType[]) {
let result: LotType[] = []
for(let lot of lots) {
result.push(await treatSingleLotTime(lot));
}
return result;
}
export async function treatSingleLotTime(lot: LotType) {
if(dicParam.SERVER_DEBUG_MODE.CURRENT_TIME == 1) {
let current = await getCurrentTime();
if(Math.floor(current/1000) != nowSeconds()) {
lots = lots.map(cur => {
cur.begin.setHours(20, 20, 0, 0);
cur.end.setHours(22, 0, 0, 0);
return {...cur, begin: cur.begin, end: cur.end}
});
lot.begin.setHours(20, 20, 0, 0);
lot.end.setHours(22, 0, 0, 0);
return {...lot, begin: lot.begin, end: lot.end}
}
}
return lots;
return lot
}
// 拍卖行开始时间 今天20:20
@@ -185,7 +195,7 @@ export async function getBossAuctionEnd() {
* @param {number} serverId
* @param {ItemReward[]} rewards
*/
export async function genAuction(guildCode: string, sourceType: number, sourceCode: string, serverId: number, rewards: { goods: RewardInter, basePrice: number, maxPrice: number}[]) {
export async function genAuction(guildCode: string, sourceType: number, sourceCode: string, serverId: number, rewards: { goods: RewardInter, basePrice: number, maxPrice: number, sort: number}[]) {
let begin = await auctionBegin();
let end = await auctionEnd();
if(sourceType == AUCTION_SOURCE.BOSS) { // 军团boss本
@@ -193,13 +203,13 @@ export async function genAuction(guildCode: string, sourceType: number, sourceCo
end = await getBossAuctionEnd();
}
const guildEnd = await guildAuctionEnd();
const lotsData: LotParam[] = rewards.map(({ goods, basePrice, maxPrice }) => {
const lotsData: LotParam[] = rewards.map(({ goods, basePrice, maxPrice, sort }) => {
const { id, count } = goods;
const code = genCode(LOT_CODE_LEN);
return {
auctionStage: AUCTION_STAGE.DEFAULT, sourceType,
sourceCode, serverId, guildCode, code, gid: id, count, begin, end, status: LOT_STATUS.DEFAULT,
maxPrice, curPrice: basePrice,
maxPrice, curPrice: basePrice, sort
}
});
const lots = await LotModel.createRecs(lotsData);
@@ -283,11 +293,25 @@ export async function startGuildAuction() {
}
}
export async function sendLotsRewardToMlail(lots: LotType[]) {
let lotByRole = new Map<string, RewardInter[]>();
for(let lot of lots) {
if(!lotByRole.has(lot.curBuyer)) {
lotByRole.set(lot.curBuyer, []);
}
lotByRole.get(lot.curBuyer).push({ id: lot.gid, count: lot.count });
}
for(let [roleId, goods ] of lotByRole) {
await sendMailByContent(MAIL_TYPE.AUTION_REWARD, roleId, { goods });
}
}
export async function startWorldAuction() {
try {
console.log('schedule startWorldAuction called:', new Date());
const begin = await todayGuildBegin();
await LotModel.setLotSoldByBegin(begin);
let lots = await LotModel.setLotSoldByBegin(begin); // 正在竞拍的拍品
await sendLotsRewardToMlail(lots);
await LotModel.updateUnSoldLotsStageByBegin(begin, AUCTION_STAGE.WORLD);
await DividendModel.updateDividendsStatus(begin, DIVIDEND_STATUS.END);
@@ -308,7 +332,8 @@ export async function stopAuction() {
try {
console.log('schedule stopAuction called:', new Date());
const begin = await todayGuildBegin();
await LotModel.setLotSoldByBegin(begin);
let lots = await LotModel.setLotSoldByBegin(begin); // 正在竞拍的拍品
await sendLotsRewardToMlail(lots);
await LotModel.updateLotsStageByBegin(begin, AUCTION_STAGE.END);
if(dicParam.SERVER_DEBUG_MODE.CURRENT_TIME == 1) {

View File

@@ -8,6 +8,7 @@ import { BID_REC_COUNT, GUILD_LOTS_REC_COUNT, LOT_STATUS } from '../consts';
* 竞拍物品表
**/
@modelOptions({ schemaOptions: { id: false } })
@index({ sort: 1 })
@index({ code: 1 })
@index({ guildCode: 1, begin: -1 })
@index({ serverId: 1, begin: -1, watchingRoles: 1 })
@@ -44,6 +45,8 @@ export default class Lot extends BaseModel {
end: Date; // 竞拍结束时间
@prop({ required: true, default: 0 })
status: number; // 拍品状态0无人竞拍1竞拍中2已竞拍3一口价
@prop({ required: true, default: 0 })
sort: number; // 排序
public static async createRec(data: LotParam) {
const code = genCode(8);
@@ -63,27 +66,27 @@ export default class Lot extends BaseModel {
}
public static async findLots(codes: string[]) {
const result = await LotModel.find({ code: {$in: codes} }).select('-_id -__v').lean();
const result = await LotModel.find({ code: {$in: codes} }).sort({ sort: 1 }).select('-_id -__v').lean();
return result;
}
public static async findGuildLotsByBegin(guildCode: string, begin: Date) {
const results = await LotModel.find({ guildCode, begin }).select('-_id -__v').lean();
const results = await LotModel.find({ guildCode, begin }).sort({ sort: 1 }).select('-_id -__v').lean();
return results;
}
public static async findWorldLotsByBegin(serverId: number, begin: Date) {
const results = await LotModel.find({ serverId, begin }).select('-_id -__v').lean();
const results = await LotModel.find({ serverId, begin }).sort({ sort: 1 }).select('-_id -__v').lean();
return results;
}
public static async findWatchingLotsByBegin(roleId: string, serverId: number, begin: Date) {
const results = await LotModel.find({ serverId, begin, watchingRoles: roleId }, { new: true }).select('-_id -__v').lean();
const results = await LotModel.find({ serverId, begin, watchingRoles: roleId }, { new: true }).sort({ sort: 1 }).select('-_id -__v').lean();
return results;
}
public static async recentGuildLots(guildCode: string, count = GUILD_LOTS_REC_COUNT ) {
const results = await LotModel.find({ guildCode }).sort({ _id: -1 }).limit(count).select('-_id -__v').lean();
const results = await LotModel.find({ guildCode }).sort({ _id: -1 }).limit(count).sort({ sort: 1 }).select('-_id -__v').lean();
return results;
}
@@ -104,12 +107,12 @@ export default class Lot extends BaseModel {
}
public static async watchingLotsByBegin(serverId: number, roleId: string, begin: Date) {
const results: LotType[] = await LotModel.find({ serverId, begin, watchingRoles: roleId }).select('-_id -__v').lean();
const results: LotType[] = await LotModel.find({ serverId, begin, watchingRoles: roleId }).sort({ sort: 1 }).select('-_id -__v').lean();
return results;
}
public static async recentBidLots(serverId: number, roleId: string, count = BID_REC_COUNT) {
const results: LotType[] = await LotModel.find({ serverId, 'bidRoles.roleId': roleId }).select('-_id -__v').sort({ _id: -1 }).limit(count).lean();
const results: LotType[] = await LotModel.find({ serverId, 'bidRoles.roleId': roleId }).sort({ sort: 1 }).select('-_id -__v').sort({ _id: -1 }).limit(count).lean();
return results;
}
@@ -129,7 +132,8 @@ export default class Lot extends BaseModel {
}
public static async setLotSoldByBegin(begin: Date) {
const results = await LotModel.updateMany({ begin, status: LOT_STATUS.ING }, { status: LOT_STATUS.SOLD }).select('-_id -__v').lean();
const results: LotType[] = await LotModel.find({ begin, status: LOT_STATUS.ING }).sort({ sort: 1 }).select('-_id -__v').lean();
await LotModel.updateMany({ begin, status: LOT_STATUS.ING }, { status: LOT_STATUS.SOLD });
return results;
}
}

View File

@@ -597,13 +597,13 @@ export function getGuildAuctionRewards(aid: number, rank: number) {
export function getAuctionRewardByPoolId(poolId: number) {
let pools = gameData.auctionPool.get(poolId);
let rewards: { goods: RewardInter, basePrice: number, maxPrice: number }[] = [];
let rewards: { goods: RewardInter, basePrice: number, maxPrice: number, sort: number }[] = [];
for(let { count, basicPool } of pools) {
let { rewardBasicPool, basePrice, maxPrice } = basicPool
let { rewardBasicPool, basePrice, maxPrice, sort } = basicPool
for(let i = 0; i < count; i++) {
let result = getRandEelmWithWeight(rewardBasicPool);
if(result && result.dic) {
rewards.push({ goods: pick(result.dic, ['id', 'count']), basePrice, maxPrice });
rewards.push({ goods: pick(result.dic, ['id', 'count']), basePrice, maxPrice, sort });
}
}
}

View File

@@ -13,6 +13,7 @@ export interface DicAuctionBasicPool {
readonly rewardBasicPool: AuctionBasicPool[];
readonly basePrice: number;
readonly maxPrice: number;
readonly sort: number; // 排序
}
export interface DicAuctionReward {

View File

@@ -6,7 +6,8 @@
"totalCount": 8,
"itid": 25,
"basePrice": "31002&800",
"maxPrice": "31002&1500"
"maxPrice": "31002&1500",
"sort": 3
},
{
"id": 2,
@@ -15,7 +16,8 @@
"totalCount": 22,
"itid": 25,
"basePrice": "31002&1500",
"maxPrice": "31002&3000"
"maxPrice": "31002&3000",
"sort": 2
},
{
"id": 3,
@@ -24,7 +26,8 @@
"totalCount": 31,
"itid": 25,
"basePrice": "31002&3000",
"maxPrice": "31002&5000"
"maxPrice": "31002&5000",
"sort": 1
},
{
"id": 4,
@@ -33,7 +36,8 @@
"totalCount": 6,
"itid": 40,
"basePrice": "31002&800",
"maxPrice": "31002&1500"
"maxPrice": "31002&1500",
"sort": 5
},
{
"id": 5,
@@ -42,7 +46,8 @@
"totalCount": 6,
"itid": 40,
"basePrice": "31002&400",
"maxPrice": "31002&800"
"maxPrice": "31002&800",
"sort": 4
},
{
"id": 6,
@@ -51,7 +56,8 @@
"totalCount": 6,
"itid": 40,
"basePrice": "31002&300",
"maxPrice": "31002&600"
"maxPrice": "31002&600",
"sort": 7
},
{
"id": 7,
@@ -60,7 +66,8 @@
"totalCount": 6,
"itid": 40,
"basePrice": "31002&150",
"maxPrice": "31002&200"
"maxPrice": "31002&200",
"sort": 6
},
{
"id": 8,
@@ -69,7 +76,8 @@
"totalCount": 6,
"itid": 28,
"basePrice": "31002&2000",
"maxPrice": "31002&4000"
"maxPrice": "31002&4000",
"sort": 8
},
{
"id": 9,
@@ -78,7 +86,8 @@
"totalCount": 6,
"itid": 28,
"basePrice": "31002&1000",
"maxPrice": "31002&2000"
"maxPrice": "31002&2000",
"sort": 9
},
{
"id": 10,
@@ -87,7 +96,8 @@
"totalCount": 42,
"itid": 41,
"basePrice": "31002&5000",
"maxPrice": "31002&7000"
"maxPrice": "31002&7000",
"sort": 10
},
{
"id": 11,
@@ -96,7 +106,8 @@
"totalCount": 42,
"itid": 41,
"basePrice": "31002&3000",
"maxPrice": "31002&6000"
"maxPrice": "31002&6000",
"sort": 11
},
{
"id": 12,
@@ -105,7 +116,8 @@
"totalCount": 1,
"itid": 38,
"basePrice": "31002&800",
"maxPrice": "31002&1600"
"maxPrice": "31002&1600",
"sort": 12
},
{
"id": 13,
@@ -114,7 +126,8 @@
"totalCount": 1,
"itid": 38,
"basePrice": "31002&800",
"maxPrice": "31002&1600"
"maxPrice": "31002&1600",
"sort": 13
},
{
"id": 14,
@@ -123,7 +136,8 @@
"totalCount": 7,
"itid": 38,
"basePrice": "31002&800",
"maxPrice": "31002&1600"
"maxPrice": "31002&1600",
"sort": 14
},
{
"id": 15,
@@ -132,7 +146,8 @@
"totalCount": 6,
"itid": 38,
"basePrice": "31002&800",
"maxPrice": "31002&1600"
"maxPrice": "31002&1600",
"sort": 15
},
{
"id": 16,
@@ -141,6 +156,7 @@
"totalCount": 5,
"itid": 38,
"basePrice": "31002&800",
"maxPrice": "31002&1600"
"maxPrice": "31002&1600",
"sort": 16
}
]

79
shared/resource/jsons/dic_zyz_gk_pvp.json Executable file → Normal file
View File

@@ -5,53 +5,82 @@
"bg_img_id": 107,
"warType": 9,
"gk_name": "地图1",
"mapseid": "50101&50201&50202",
"victoryInfoInUI": "5回合内杀死2个敌军",
"loseInfoInUI": "5回合内未杀死2个敌军",
"pvpVictoryCondition": "111&5&2&",
"turnLimted": 10
"turnLimted": 10,
"needPrepare": 1,
"selectView": 1
},
{
"war_id": 4502,
"dispatchJsonId": 4502,
"bg_img_id": 542,
"bg_img_id": 107,
"warType": 9,
"gk_name": "地图2",
"victoryInfoInUI": "我军死亡武将不超过2人",
"loseInfoInUI": "我军阵亡武将超出2人",
"pvpVictoryCondition": "102&2&",
"turnLimted": 10
"gk_name": "地图1",
"mapseid": "50101&50201&50202",
"victoryInfoInUI": "5回合内杀死2个敌军",
"loseInfoInUI": "5回合内未杀死2个敌军",
"pvpVictoryCondition": "111&5&2&",
"turnLimted": 10,
"needPrepare": 1,
"selectView": 0
},
{
"war_id": 4503,
"dispatchJsonId": 4503,
"bg_img_id": 543,
"bg_img_id": 542,
"warType": 9,
"gk_name": "地图3",
"victoryInfoInUI": "我军全员生存",
"loseInfoInUI": "我军有武将阵亡",
"pvpVictoryCondition": "102&0&",
"turnLimted": 10
"gk_name": "地图2",
"mapseid": "50306&50307&50401",
"victoryInfoInUI": "我军死亡武将不超过2人",
"loseInfoInUI": "我军阵亡武将超出2人",
"pvpVictoryCondition": "102&2&",
"turnLimted": 10,
"needPrepare": 1,
"selectView": 1
},
{
"war_id": 4504,
"dispatchJsonId": 4504,
"bg_img_id": 501,
"bg_img_id": 542,
"warType": 9,
"gk_name": "地图4",
"victoryInfoInUI": "10回合内获得胜利",
"loseInfoInUI": "10回合内未能击杀全部敌军",
"pvpVictoryCondition": "106&10&",
"turnLimted": 10
"gk_name": "地图2",
"mapseid": "50306&50307&50401",
"victoryInfoInUI": "我军死亡武将不超过2人",
"loseInfoInUI": "我军阵亡武将超出2人",
"pvpVictoryCondition": "102&2&",
"turnLimted": 10,
"needPrepare": 1,
"selectView": 0
},
{
"war_id": 4505,
"dispatchJsonId": 4505,
"bg_img_id": 1003,
"bg_img_id": 543,
"warType": 9,
"gk_name": "地图5",
"victoryInfoInUI": "同一名武将击杀3名敌军",
"loseInfoInUI": "未有同一名武将击杀3名敌军",
"pvpVictoryCondition": "400&3&",
"turnLimted": 10
"gk_name": "地图3",
"mapseid": "50205&50206&50207",
"victoryInfoInUI": "我军全员生存",
"loseInfoInUI": "我军有武将阵亡",
"pvpVictoryCondition": "102&0&",
"turnLimted": 10,
"needPrepare": 1,
"selectView": 1
},
{
"war_id": 4506,
"dispatchJsonId": 4505,
"bg_img_id": 543,
"warType": 9,
"gk_name": "地图3",
"mapseid": "50205&50206&50207",
"victoryInfoInUI": "我军全员生存",
"loseInfoInUI": "我军有武将阵亡",
"pvpVictoryCondition": "102&0&",
"turnLimted": 10,
"needPrepare": 1,
"selectView": 0
}
]