%%%--------------------------------------
%%% @Module  : custom_act_draw_record.hrl
%%% @Author  : lhy
%%% @Created : 2019-06-01
%%% @Description:  定制活动抽奖记录
%%%--------------------------------------

-record(draw_record, {
	    draw_record_local = #{},    %% 本服抽奖记录 {Type, SubType} => [#draw_role{}|........]
	    draw_record_kf = #{}        %% 跨服抽奖记录 {Type, SubType} => [#kf_draw_role{}|........]
	}).

-record(draw_role, {
	    type = 0,            %% 活动类型
	    sub_type = 0,        %% 活动子类型
	    role_id = 0,         %% 玩家id
	    grade_id = 0,        %% 奖励档次id
	    time = 0             %% 时间
	}).

-record(kf_draw_role, {
	    type = 0,            %% 活动类型
	    sub_type = 0,        %% 活动子类型
	    role_id = 0,         %% 玩家id
	    server_id = 0,       %% 服务器id
        platform = "",       %% 平台名字
        server_num = 0,      %% 所在的服标示
        name = "",           %% 名字
	    grade_id = 0,        %% 奖励档次id
	    time = 0             %% 时间
	}).

-record(draw_record_state, {
	    draw_maps = #{}        %% {Type, SubType} => [#draw_role{}|.....]
	}).

%% 跨服分区
-record(kf_draw_record_state, {
	    zone_max_id = #{},     %% ZoneType => ZoneMaxId
	    zone_maps = #{}        %% {ZoneType, ZoneId} => [{Type, SubType} => [#kf_draw_role{}|.....]] 全服默认为{0,0}
	}).

%% ------------------------------- 自定义添加 ----------------------------------------
%% 活动记录上限
-define(WISH_RECORD_NUM_LIMIT, 20).   %% 欢乐许愿 许愿记录上限

%% --------------------------------------------- db local ------------------------------------------------------
-define(sql_custom_act_draw_record_delete,
	    <<"delete from `draw_record_act_local` where type=~p and sub_type = ~p ">>).
-define(sql_custom_act_draw_record_insert,
	    <<"insert into `draw_record_act_local` set type=~p, sub_type=~p, role_id=~p, grade_id=~p, time=~p">>).
-define(sql_custom_act_draw_record_role_select,
	    <<"select `type`, `sub_type`, `role_id`, `grade_id`, `time` from `draw_record_act_local` where `role_id`=~p ORDER BY id DESC">>).
-define(sql_custom_act_draw_record_select,
	    <<"select `type`, `sub_type`, `role_id`, `grade_id`, `time` from `draw_record_act_local` ORDER BY id DESC">>).

%% --------------------------------------------- db kf -----------------------------------------------------------
-define(sql_custom_act_draw_record_kf_select,
	    <<"select `type`, `sub_type`, `role_id`, `server_id`,`platform`,`server_num`, `name`, `grade_id`, `time` from `draw_record_kf_act` where `type`=~p and `server_id`=~p ORDER BY id DESC">>).
-define(sql_custom_act_draw_record_kf_whole_select,
	    <<"select `type`, `sub_type`, `role_id`, `server_id`,`platform`,`server_num`, `name`, `grade_id`, `time` from `draw_record_kf_act` where `type`=~p ORDER BY id DESC">>).
-define(sql_custom_act_draw_record_role_kf_insert,
	    <<"insert into `draw_record_kf_act` set type=~p, sub_type=~p, role_id=~p, server_id=~p,platform='~s',server_num=~p, name='~ts', grade_id=~p, time=~p">>).
-define(sql_custom_act_draw_record_role_kf_delete,
	    <<"delete from `draw_record_kf_act` where type=~p and sub_type = ~p and server_id = ~p">>).
-define(sql_custom_act_draw_record_role_kf_whole_delete,
	    <<"delete from `draw_record_kf_act` where type=~p and sub_type = ~p">>).

%% ---------------------------------------------- db kf_local --------------------------------------------------------
-define(sql_kf_draw_record_local_insert,
	    <<"insert into `draw_record_kf_act_local` set type=~p, sub_type=~p, role_id=~p, grade_id=~p, time=~p">>).
-define(sql_custom_act_draw_record_role_kf_select,
	    <<"select `type`, `sub_type`, `role_id`, `grade_id`, `time` from `draw_record_kf_act_local` where `role_id`=~p ORDER BY id DESC">>).
-define(sql_kf_draw_record_local_delete,
	    <<"delete from `draw_record_kf_act_local` where type=~p and sub_type = ~p ">>).
