%%%---------------------------------------------------------------------
%%% 拍卖行相关record定义
%%%---------------------------------------------------------------------

%% 拍卖配置
-record (base_auction_goods, {
	goods_id	= 0, 					%% 物品id
	server_lv_min = 0, 					%% 最小世界等级
	server_lv_max = 0, 					%% 最大世界等级
	type 		= 0,            		%% 商品大类
	guild_price_type = 0, 				%% 公会拍卖价格类型: ?TYPE_GOLD|?TYPE_BGOLD
	guild_base_price = 0, 				%% 公会拍卖基础价
	guild_add_price = 0,				%% 公会拍卖单次加价
	guild_one_price = 0,				%% 公会拍卖一口价
	world_price_type = 0, 				%% 世界拍卖价格类型: ?TYPE_GOLD|?TYPE_BGOLD
	world_base_price = 0, 				%% 世界拍卖基础价
	world_add_price = 0,				%% 世界拍卖单次加价
	world_one_price = 0,				%% 世界拍卖一口价

	personal_base_price = 0, 			%% 个人拍卖价格
	personal_one_price = 0, 			%% 个人拍卖一口价
	%% 以下配置字段待删除
	gold_type 	= 0,					%% 消耗钻石类型
	price_add_ratio = 0, 				%% 竞拍加价比例（百分制）
	server_lv 	= 0, 					%% 服务器等级
	price_types = [], 					%% 世界价格类型 [{开服起始天数, 开服结束天数, 价格类型(1钻石,2绑钻)}]
	world_price = 0 					%% 世界拍卖价格
}).

%% 系统拍卖时间配置
-record (base_auction_time, {
	id 			= 0,					%% 系统id
	time 		= {0,0,0}, 				%% 开始时间{小时,分钟,秒}
	sys_goods 	= [] 					%% 系统物品[{物品类型id,数量}...]
}).

%% 系统拍卖活动
-record (base_auction_act, {
	opday_slot	= {0,0}, 				%% 开服天数{开服起始天数，开服结束天数}
	cfg_id 		= 0,					%% 场次ID
	sys_goods 	= [], 					%% 系统物品[{物品类型id,数量,概率}...]
	start_time 	= {0,0,0}, 				%% 开始时间{小时,分钟,秒}
	end_time 	= {0,0,0} 				%% 结束时间{小时,分钟,秒}
}).

%% 拍卖常量配置
-record(base_auction_keyvalues, {
    id = 0,                         	%% 常量Id
    value = 0,                      	%% 常量值
    about = ""                      	%% 常量描述
}).

%% -------------------------------- %% --------------------------------

-record (status_auction, {
	auto_id 	= 0, 					%% 拍卖确认框提示id
	goods_list	= [] 					%% 待确认拍卖物[{id, {type,goods_id,num}}] 注：普通物品id为auto_id，英灵装备id为物品唯一id
}).

%% 拍卖场次
-record (auction, {
	auction_id 	= 0,  					%% 拍卖会场次
	auction_type= 0,					%% 拍卖类型
	cfg_id 		= 0,					%% 拍卖会配置Id
	module_id 	= 0,					%% 功能id
	auction_status=0, 					%% 拍卖会状态
	time 		= 0, 					%% 拍卖会开始时间戳
	last_time   = 0, 					%% 场次更新时间
	guild_award_map = #{},				%% 公会奖励信息 				#{guild_id => award_status}
	delay_guild_map = #{}, 				%% 竞价延时的帮派               #{guild_id => {delay_num, endtime} }
	to_world_list 	= [], 				%% 延时流入世界的物品（同一场拍卖不同时间结束的未拍卖物品，统一流入世界）
	estimate_bonus_map= #{}, 			%% 各公会预计分红总额 			#{guild_id => estimate_bonus }
	act_join_num_map= #{}, 				%% 对应活动开启时各公会参与人数 #{guild_id => join_num }
	goods_num = 0 						%% 拍卖物数量，与#auction_goods.goods_num不同 注：用于个人拍卖，统计一场拍卖剩余拍卖物数量
}).

%% 拍卖物品
-record (auction_goods, {
	goods_id 	= 0,					%% 拍卖物唯一id
	auction_id 	= 0,  					%% 拍卖会场次
	goods_type  = 0, 					%% 物品类型id
	goods_num 	= 0,					%% 物品数量
	guild_id    = 0, 					%% 公会id
	player_id 	= 0, 					%% 竞拍物品拥有者id
	auction_type= 0,					%% 拍卖类型 	:1公会拍卖，2世界拍卖，3个人拍卖
	cfg_id 		= 0,					%% 拍卖会配置Id
	type 		= 0, 					%% 物品类目	    :用于客户端分类显示，如装备、称号
	module_id 	= 0, 					%% 功能id	    :0为系统拍卖功能id，公会拍卖不为0
	goods_status= 0,		 			%% 拍卖物状态   :1拍卖中，2已拍出
	bonus_tax_rate = 0, 				%% 分红税率 	:百分制，90表示90%用于扣税，剩余10%分红
	next_price  = 0,					%% 下一次竞价   :无人竞价时，读取交易基准价
	now_price   = 0,					%% 当前竞价 	:也即当前拍得最高竞价
	start_time	= 0,					%% 开始拍卖时间
	info_list 	= [],					%% 拍卖详细记录 [#auction_info{}|...]
	delay_num 	= 0 					%% 延时次数
}).

%% 拍卖详细记录
-record (auction_info, {
	player_id 	= 0, 					%% 竞拍人id
	price_type  = 0, 					%% 竞拍类型
	price  		= 0, 					%% 竞价
	price_list  = [], 					%% 竞价详细 [{?TYPE_BGOLD, 0, Num},{?TYPE_GOLD, 0, Num}]
	time 		= 0 					%% 更新时间
}).

%% 拍卖记录
-record (auction_log, {
	module_id 	= 0,					%% 功能id
	goods_type  = 0, 					%% 物品类型id
	goods_num 	= 0, 					%% 物品数量
	money_type 	= 0, 					%% 价格类型
	price  		= 0, 					%% 竞价
	time 		= 0, 					%% 更新时间
	to_world 	= 0 					%% 是否流拍至世界：0否，1是
}).

%% 拍卖状态数据
-record (auction_state, {
	finish_init = 0, 					%% 是否完成数据化 0否，1是
	auction_map = #{}, 					%% 拍卖会场次 	#{ auction_id => #auction{} }
	goods_map   = #{}, 					%% 拍卖物品		#{ goods_id   => #auction_goods{} }
	guild_map 	= #{}, 					%% 公会拍卖目录 #{ guild_id   => [{module_id, [goods_id] } |...] }
	world_map 	= #{}, 					%% 世界拍卖目录 #{ type       => [goods_id|...] }
	guild_log_map = #{}, 				%% 公会拍卖记录 #{ guild_id   => [#auction_log{}|...] } 		注：会日清
	world_log_list= [], 				%% 世界拍卖记录 [ #auction_log{}|...] 							注：会日清
	join_log_map  = #{} 				%% 活动参与日志 #{ module_id => #{player_id => guild_id} }   	注：会日清
}).

%% --------------------------------- %% ---------------------------------
%%% @comment DEBUG_CFG
%% --------------------------------- %% ---------------------------------
% -define(DEBUG_CFG, true).

-ifdef(DEBUG_CFG).
-define(GUILD_NOTICE1_BEFORE,   5*60). 		%% 公会拍卖预告提前时间(秒)
-define(WORLD_NOTICE1_BEFORE,   5*60). 	  	%% 世界拍卖预告提前时间(秒)
-define(GUILD_AUCTION_DURATION,	25*60).   	%% 公会拍卖时长(秒)
-define(WORLD_AUCTION_DURATION,	6*60*60).	%% 世界拍卖时长(秒)
-define(PERSONAL_AUCTION_DURATION,4*60*60).	%% 个人拍卖时长(秒)
-else.
-define(GUILD_NOTICE1_BEFORE,   5*60). 		%% 公会拍卖预告提前时间(秒)
-define(WORLD_NOTICE1_BEFORE,   5*60). 	  	%% 世界拍卖预告提前时间(秒)
-define(GUILD_AUCTION_DURATION,	25*60).   	%% 公会拍卖时长(秒)
-define(WORLD_AUCTION_DURATION,	6*60*60).	%% 世界拍卖时长(秒)
-define(PERSONAL_AUCTION_DURATION,4*60*60).	%% 个人拍卖时长(秒)
-endif.

%% ------------------------------- 常量配置  %% -------------------------------
-define(AUCTION_KV(Id), lib_auction_data:get_keyvalues(Id)).

%% 流拍分红折扣(百分制，60表示只取拍出分红的60%)
-define(AUCTION_KV_NO_SELL_AWARD_RATIO, ?AUCTION_KV(1)).

-define(ADD_PERSONAL_CHARGE,     0.15). 	%% 个人拍卖手续费

-define(CLOSE_AUCTION_NORMAL, 	   1).  	%% 关闭类型：时间到正常结束
-define(CLOSE_AUCTION_FORCE, 	   2).  	%% 关闭类型：秘籍强制结束

%% ----------------------------- auction_type  %% -----------------------------
-define(AUCTION_GUILD, 		      1). 		%% 拍卖会类型：公会拍卖
-define(AUCTION_WORLD, 		      2). 		%% 拍卖会类型：世界拍卖
-define(AUCTION_PERSONAL, 	      3). 		%% 拍卖会类型：个人拍卖

%% ----------------------- #auction_info.price_type  %% -----------------------
-define(PRICE_TYPE_AUCTION,       1).   	%% 竞拍价格类型：普通竞价
-define(PRICE_TYPE_ONE_PRICE,     2).   	%% 竞拍价格类型：一口价
-define(PRICE_TYPE_ADD_PRICE,     3).   	%% 竞拍价格类型：加价    注:当前是出价最高者才可以发加价类型

%% ------------------------ #auction.auction_status  %% -----------------------
-define(AUCTION_STATUS_NOTICE1,   1). 		%% 拍卖会状态：第一轮预告
-define(AUCTION_STATUS_NOTICE2,   2).		%% 拍卖会状态：第二轮预告
% -define(AUCTION_STATUS_NOTICE3,   3).		%% 拍卖会状态：第三轮预告
-define(AUCTION_STATUS_BEGIN,     4).   	%% 拍卖会状态：开拍

%% ---------------------- #auction_goods.goods_status  %% ---------------------
-define(GOODS_STATUS_SELL,		  1). 		%% 拍卖物状态：待拍出
-define(GOODS_STATUS_SELLOUT,	  2). 		%% 拍卖物状态：已拍出

%% ------------------------  #auction.cfg_id %% -------------------------------
-define(DEFAULT_CFG_ID, 		   0).  	%% 默认cfg_id为0

-define (SQL_AUCTION_SELECT,			<<"select `auction_id`, `auction_type`, `cfg_id`, `module_id`, `auction_status`, `time`, `last_time` from `auction` where 1=1">>).
-define (SQL_AUCTION_INFO_SELECT, 		<<"select `goods_id`, `player_id`, `price_type`, `price`, `price_list`, `time` from `auction_info` where 1=1">>).
-define (SEL_AUCTION_GOODS_SELECT,		<<"select `goods_id`, `auction_id`, `goods_type`, `goods_num`, `type`, `auction_type`, `cfg_id`, `guild_id`, `player_id`, `module_id`, `goods_status`, `bonus_tax_rate`, `start_time` from `auction_goods` where 1=1">>).
-define (SQL_AUCTION_LOG_SELECT, 		<<"select `auction_type`, `module_id`, `guild_id`, `goods_type`, `goods_num`, `money_type`, `price`, `time`, `to_world` from `auction_log` where 1=1">>).
-define (SQL_AUCTION_GUILD_AWARD_SELECT,<<"select `auction_id`, `guild_id`, `award_status` from `auction_guild_award` where 1=1">>).

-define (SQL_AUCTION_INSERT,			<<"insert into `auction`(`auction_id`, `auction_type`, `cfg_id`, `module_id`, `auction_status`, `time`, `last_time`) values(~p, ~p, ~p, ~p, ~p, ~p, ~p)">>).
-define (SEL_AUCTION_GOODS_INSERT,		<<"insert into `auction_goods`(`goods_id`, `auction_id`, `goods_type`, `goods_num`, `type`, `auction_type`, `cfg_id`, `guild_id`, `player_id`, `module_id`, `goods_status`, `bonus_tax_rate`, `start_time`) values(~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p)">>).
-define (SQL_AUCTION_INFO_INSERT, 		<<"insert into `auction_info`(`goods_id`, `auction_id`, `player_id`, `price_type`, `price`, `price_list`, `time`) values(~p, ~p, ~p, ~p, ~p, '~s', ~p)">>).
-define (SQL_AUCTION_LOG_INSERT,		<<"insert into `auction_log`(`auction_type`, `module_id`, `guild_id`, `goods_type`, `goods_num`, `money_type`, `price`, `time`, `to_world`) values(~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p, ~p)">>).
-define (SQL_AUCTION_GUILD_AWARD_INSERT,<<"insert into `auction_guild_award`(`auction_id`, `guild_id`, `award_status`, `time`) values(~p, ~p, ~p, ~p) ">>).

-define (SQL_AUCTION_UPDATE,			<<"update `auction` set `auction_status`=~p, `last_time` =~p where `auction_id` = ~p">>).
-define (SQL_AUCTION_GOODS_UPDATE,		<<"update `auction_goods` set `goods_status`=~p, `time` =~p where `goods_id` = ~p">>).

-define (SQL_AUCTION_DELETE, 			<<"delete from `auction` where `auction_id` = ~p">>).
-define (SQL_AUCTION_INFO_DELETE, 		<<"delete from `auction_info` where `auction_id` = ~p">>).
-define (SEL_AUCTION_GOODS_DELETE, 		<<"delete from `auction_goods` where `auction_id` = ~p">>).
-define (SQL_AUCTION_LOG_TRUNCATE, 		<<"truncate table auction_log">>).
-define (SQL_AUCTION_GUILD_AWARD_DELETE,<<"delete from `auction_guild_award` where `auction_id` = ~p">>).
-define (SEL_AUCTION_GOODS_DELETE2,     <<"delete from `auction_goods` where `goods_id` = ~p">>).
-define (SQL_AUCTION_INFO_DELETE2, 		<<"delete from `auction_info` where `goods_id` = ~p">>).

-define (SQL_JOIN_LOG_SELECT, 			<<"select `player_id`, `guild_id` from `join_log` where `module_id` = ~p">>).
-define (SQL_JOIN_LOG_TRUNCATE, 		<<"truncate table `join_log`">>).
-define (SQL_JOIN_LOG_DELETE_GUILD, 	<<"delete from `join_log` where guild_id =~p">>).
-define (SQL_JOIN_LOG_DELETE_MODULE,	<<"delete from `join_log` where `module_id` = ~p">>).
-define (SQL_JOIN_LOG_DELETE_PLAYER, 	<<"delete from `join_log` where player_id =~p">>).
