⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 salesdb.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 4 页
字号:
						completedAuction.match = pendingAuction;						pendingAuction.match = completedAuction;						break;					end				end			end			-- If we didn't find a likely expired auction, then choose the			-- oldest unmatched auction.			if (pendingAuction.match == nil) then				for completedIndex = 1, table.getn(completedAuctions) do					local completedAuction = completedAuctions[completedIndex];					if (completedAuction.match == nil) then						completedAuction.match = pendingAuction;						pendingAuction.match = completedAuction;						break;					end				end			end		end		-- Check for unmatched pending auctions.		local unmatchedPendingAuctionCount = 0;		for pendingIndex = 1, table.getn(pendingAuctions) do			local pendingAuction = pendingAuctions[pendingIndex];			if (pendingAuction.match == nil) then				unmatchedPendingAuctionCount = unmatchedPendingAuctionCount + 1;			end		end		-- Check for unmatched completed auctions.		local unmatchedCompletedAuctionCount = 0;		for completedIndex = 1, table.getn(completedAuctions) do			local completedAuction = completedAuctions[completedIndex];			if (completedAuction.match == nil) then				unmatchedCompletedAuctionCount = unmatchedCompletedAuctionCount + 1;			end		end		-- Reconcile the lists if all auctions match or discrepencies are		-- allowed!		if (discrepencesAllowed or unmatchedPendingAuctionCount == 0 or unmatchedCompletedAuctionCount == 0) then			-- Time to log some sales! We iterate through the pending			-- list in reverse since we will be deleting items from			-- it.			debugPrint("Begin reconciling auction list for "..item);			for pendingIndex = table.getn(pendingAuctions), 1, -1 do				local pendingAuction = pendingAuctions[pendingIndex];				if (pendingAuction.match ~= nil) then					-- Reconcile the matching auctions.					reconcileMatchingAuctions(item, pendingAuctions, pendingAuction, completedAuctions, pendingAuction.match);					auctionsReconciled = auctionsReconciled + 1;				end			end			debugPrint("End reconciling auction list for "..item.." ("..auctionsReconciled.." reconciled)");		else			debugPrint("Not reconciling auctions for "..item.." due to discrepencies");		end	else		debugPrint("No reconcilable auctions for "..item);	end	return auctionsReconciled;end--------------------------------------------------------------------------------- Performs auction reconcilation by removing the pending and complete auctions-- and adding a sale.---- WARNING: The pendingAuction and completedAuction will be removed from-- their lists.-------------------------------------------------------------------------------function reconcileMatchingAuctions(item, pendingAuctions, pendingAuction, completedAuctions, completedAuction)	-- Remove the pending and completed auctions	deletePendingAuction(item, pendingAuction.index, "reconciled", pendingAuctions);	deleteCompletedAuction(item, completedAuction.index, "reconciled", completedAuctions);	-- Add a sale (success or failure).	local net;	local price;	if (completedAuction.price) then		net = math.floor(completedAuction.price * (1 - pendingAuction.consignmentPercent));	else		net = -pendingAuction.deposit;	end	addSale(completedAuction.time, completedAuction.result, item, pendingAuction.quantity, pendingAuction.bid, pendingAuction.buyout, net, completedAuction.price, completedAuction.isBuyout, completedAuction.buyer);end--------------------------------------------------------------------------------- Compare two auctions based on match count.-------------------------------------------------------------------------------function compareMatchCount(auction1, auction2)	local count1 = table.getn(auction1.matches);	local count2 = table.getn(auction2.matches);	if (count1 == count2) then		return (auction1.time > auction2.time);	end	return (count1 > count2);end--------------------------------------------------------------------------------- Compares two auctions based on time.-------------------------------------------------------------------------------function compareTime(auction1, auction2)	return (auction1.time > auction2.time);end--------------------------------------------------------------------------------- Checks if the completed auction could be the pending auction.-------------------------------------------------------------------------------function doesPendingAuctionMatchCompletedAuction(pendingAuction, completedAuction)	-- Fudge time that we add to the duration of auctions. This accounts for	-- mail delivery lag and additional auction duration due to bidding.	local AUCTION_DURATION_CUSHION = (12 * 60 * 60); -- 12 hours	-- Check if seller ids match.	if (pendingAuction.sellerId ~= nil and 		completedAuction.sellerId ~= nil and		completedAuction.sellerId ~= pendingAuction.sellerId) then		return false;	end	-- Check if auction completed in a time frame that makes sense for the	-- the post time.	if (pendingAuction.time > completedAuction.time or 		pendingAuction.time + (pendingAuction.runTime * 60) + AUCTION_DURATION_CUSHION < completedAuction.time) then		return false;	end	--	-- If the auction did not sell via buyout, check if the completion time--	-- comes after the run time.--	if ((completedAuction.result == AUCTION_SOLD) and--		(completedAuction.isBuyout ~= nil and--		(not completedAuction.isBuyout) and--		(pendingAuction.time + (pendingAuction.runTime * 60) > completedAuction.time) then--		return false;--	end	--	-- If the auction expired, check if the completion time comes after the--	-- run time.--	if ((completedAuction.result == AUCTION_EXPIRED) and--		(pendingAuction.time + (pendingAuction.runTime * 60) > completedAuction.time)) then--		return false;--	end		-- Check if the quantities match.	if (pendingAuction.quantity ~= nil and 		completedAuction.quantity ~= nil and		completedAuction.quantity ~= pendingAuction.quantity) then		return false;	end		-- Check if the deposits match.	if (pendingAuction.deposit ~= nil and 		completedAuction.deposit ~= nil and		completedAuction.deposit ~= pendingAuction.deposit) then		return false;	end		-- Check if the price is outside the bid and buyout range.	if ((completedAuction.result == AUCTION_SOLD) and		(completedAuction.price ~= nil) and		(pendingAuction.bid ~= nil) and		(pendingAuction.buyout ~= nil) and		(completedAuction.price < pendingAuction.bid or pendingAuction.buyout < completedAuction.price)) then		return false;	end	-- If its a buyout, check if the sale price does not match the buyout price.		if ((completedAuction.result == AUCTION_SOLD) and		(completedAuction.isBuyout ~= nil) and		(completedAuction.isBuyout) and		(completedAuction.price ~= nil) and		(pendingAuction.buyout ~= nil) and		(pendingAuction.buyout ~= completedAuction.price)) then		return false;	end	-- If its a not buyout, check if the sale price matches the buyout price.		if ((completedAuction.result == AUCTION_SOLD) and		(completedAuction.isBuyout ~= nil) and		(not completedAuction.isBuyout) and		(completedAuction.price ~= nil) and		(pendingAuction.buyout ~= nil) and		(pendingAuction.buyout == completedAuction.price)) then		return false;	end	-- If we made it this far, its a possible match!	return true;end--------------------------------------------------------------------------------- Checks if all pending auctions in the list match each other. All pending-- auctions must have been started within a 5 minute period of time to be-- considered matches.-------------------------------------------------------------------------------function doesPendingAuctionListMatch(pendingAuctions)	local match = (table.getn(pendingAuctions) > 0);	if (match) then		local pendingAuction = pendingAuctions[1];		local firstAuctionTime = pendingAuction.time;		local lastAuctionTime = pendingAuction.time;		local quantity = pendingAuction.quantity;		local bid = pendingAuction.bid;		local buyout = pendingAuction.buyout;		local deposit = pendingAuction.deposit;		local sellerId = pendingAuction.sellerId;		for index = 2, table.getn(pendingAuctions) do			local pendingAuction = pendingAuctions[index];			if (quantity ~= pendingAuction.quantity or				bid ~= pendingAuction.bid or				buyout ~= pendingAuction.buyout or				deposit ~= pendingAuction.deposit or				sellerId ~= pendingAuction.sellerId) then				match = false;				break;			elseif (pendingAuction.time < firstAuctionTime) then				firstAuctionTime = pendingAuction.time;			elseif (pendingAuction.time > lastAuctionTime) then				lastAuctionTime = pendingAuction.time;			end		end		if (match) then			local auctionTimeSpread = lastAuctionTime - firstAuctionTime;			match = (auctionTimeSpread < (5 * 60));		end	end	return match;	end--------------------------------------------------------------------------------- Gets the number of pending auctions that match the completed auction.-------------------------------------------------------------------------------function getPendingAuctionMatchCount(item, completedAuction)	local pendingAuctions = getPendingAuctionsForItem(		item, 		function(pendingAuction)			return doesPendingAuctionMatchCompletedAuction(pendingAuction, completedAuction);		end);	return table.getn(pendingAuctions);end--=============================================================================-- Utility functions--=============================================================================--------------------------------------------------------------------------------------------------------------------------------------------------------------function debugPrint(message)	BeanCounter.DebugPrint("[BeanCounter.SalesDB] "..message);end--[[--------------------------------------------------------------------------------------------------------------------------------------------------------------function testme1()	resetDatabase();	local MINUTE = 60;	local HOUR = MINUTE * 60;	local DAY = HOUR * 24;	addPendingAuction(2, "Silver Bar", 1, 1500, 2000, 1440, 110, 0.05);	addPendingAuction(4, "Silver Bar", 1, 2000, 2000, 1440, 110, 0.05);	addPendingAuction(6, "Silver Bar", 2, 3500, 4000, 1440, 220, 0.05);	addPendingAuction(8, "Silver Bar", 2, 4000, 4500, 1440, 220, 0.05);	addPendingAuction(10, "Silver Bar", 1, 3500, 4000, 1440, 110, 0.05);	printPendingAuctions();	printCompletedAuctions();	printSales();	addExpiredAuction(DAY + 40, "Silver Bar", 1);	addSuccessfulAuction(HOUR * 4, "Silver Bar", 2010, 2000, true, 110, 100, "Sucker");	addSuccessfulAuction(HOUR * 3, "Silver Bar", 2010, 2000, true, 110, 100, "Sucker");	addSuccessfulAuction(HOUR * 4, "Silver Bar", 4020, 4000, true, 220, 200, "Sucker");	addSuccessfulAuction(HOUR * 5, "Silver Bar", 4495, 4500, true, 220, 225, "Sucker");	reconcileAuctionsForItem("Silver Bar", DAY * 2);	printPendingAuctions();	printCompletedAuctions();	printSales();end--]]--------------------------------------------------------------------------------- Public API-------------------------------------------------------------------------------BeanCounter.Sales = {	AddPendingAuction = addPendingAuction;	GetPendingAuctionItems = getPendingAuctionItems;	GetPendingAuctionsForItem = getPendingAuctionsForItem;	AddSuccessfulAuction = addSuccessfulAuction;	AddExpiredAuction = addExpiredAuction;	AddCanceledAuction = addCanceledAuction;	GetSoldItems = getSoldItems;	GetSalesForItem = getSalesForItem;	ReconcileAuctions = reconcileAuctions;	PrintPendingAuctions = printPendingAuctions;	PrintCompletedAuctions = printCompletedAuctions;	PrintSales = printSales;	ResetDatabase = resetDatabase;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -