%%-----------------------------------------------------------------------------
%% @Module  :       lib_custom_act_api
%% @Author  :       Czc
%% @Email   :       389853407@qq.com
%% @Created :       2018-01-05
%% @Description:    定制活动API
%%-----------------------------------------------------------------------------
-module(lib_custom_act_api).

-include("custom_act.hrl").
-include("server.hrl").
-include("def_fun.hrl").
-include("def_event.hrl").
-include("rec_event.hrl").
-include("predefine.hrl").
-include("def_module.hrl").
-include("common.hrl").
-include("def_goods.hrl").
-include("figure.hrl").

-export([
    reload_custom_act_cfg/0
    , is_open_act/1
    , is_open_act/2
    , manual_close_act/3
    , get_open_subtype_ids/1
    , get_open_custom_act_infos/1
    , get_open_custom_act_infos/2
    , get_custom_act_open_info_by_actids/1
    , login/1
    , handle_event/2
    , get_act_name/2
    , load_custom_act_reward/1
    , handle_merge/0
    , player_daily_update_12/1
    , send_forgot_rewards/1
    , send_forgot_rewards_common/1
    , gm_set_act_open_wlv/3
    , make_role_info_for_check/3
    , is_need_daily_update/2
    , calc_got_reward_times/3
    , custom_act_consume_about/2
    , midnight_delay_refresh_act/1
    , log_recharge_consume_act/6
    , log_recharge_consume_act_do/8
    ]).
%% 消费活动实时更新
handle_event(Player, #event_callback{type_id = ?EVENT_MONEY_CONSUME, data = Data})  ->
    %% 注意：bgold、fgold之类的消费，也可能由gold补足，活动统计也要计入这部分gold
    #callback_money_cost{
        consume_type = ConsumeType,
        money_type = MoneyType,
        args = OldMoneyMap} = Data,
    case data_produce_type:is_consume_for_act(ConsumeType) of
        1 ->
            AllActTypes = [
                ?CUSTOM_ACT_TYPE_CONSUME,
                ?CUSTOM_ACT_TYPE_DAILY_CHARGE_CONSUME,
                ?CUSTOM_ACT_TYPE_LUCKY_TURNTABLE,
                ?CUSTOM_ACT_TYPE_ADVENTURE_ROLE,
                ?CUSTOM_ACT_TYPE_HI_POINT_2,
                ?CUSTOM_ACT_TYPE_HI_POINT
            ],
            lists:foreach(fun(ActType) ->
                        handle_event_consume(Player, MoneyType, ActType, OldMoneyMap)
                end, AllActTypes),
            #player_status{bgold = Bgold, gold = NewGold} = Player,
            case MoneyType of
                ?TYPE_GOLD ->
                    OldGold = maps:get(old_gold, OldMoneyMap, NewGold),
                    lib_role_legion:trigger_task(Player, ?MOD_CONSUME, 0, OldGold - NewGold);
                ?TYPE_BGOLD ->
                    OldGold = maps:get(old_bgold, OldMoneyMap, Bgold),
                    lib_role_legion:trigger_task(Player, ?MOD_CONSUME, 1, OldGold - Bgold);
                _ -> skip
            end;
        _ ->
            skip
    end,
    {ok, Player};
%% 处理玩家充值成功之后需要通知客户端更新的定制活动信息
handle_event(PS0, #event_callback{type_id = ?EVENT_RECHARGE, data = Data})  ->
    %% 普通的通用状态处理活动，全量刷新
    ActTypeList = [],
    ActInfoL = get_custom_act_open_info_by_actids(ActTypeList),
    NowTime = utime:unixtime(),
    F = fun(ActInfo) ->
        case ActInfo of
            #act_info{etime = Etime} = ActInfo when NowTime < Etime ->
                lib_custom_act:send_reward_status(PS0, ActInfo);
            _ -> skip
        end
    end,
    lists:foreach(F, ActInfoL),
    %% 每日累充消费活动
    DCCActs = get_open_custom_act_infos(?CUSTOM_ACT_TYPE_DAILY_CHARGE_CONSUME, NowTime),
    custom_act_pellet:refresh_act_list_status(PS0, recharge, DCCActs),
    %% 每日单笔充值
    PS = custom_act_single_recharge:refresh_act_list_status(PS0, NowTime, Data),
    #callback_recharge_data{gold = Gold} = Data,
    lib_role_legion:trigger_task(PS, ?MOD_RECHARGE, 0, Gold),
    %% 嗨点类
    case mod_hi_point:get_open_hi_act() of
        [_|_] = HPActs ->
            [
                mod_hi_point:refresh_recharge(PS#player_status.id, HActType, HActSub,
                    lib_recharge_data:get_my_recharge_between(PS#player_status.id, HSTime, HETime)
                )
                || #act_info{key = {HActType, HActSub}, stime = HSTime, etime = HETime} <- HPActs
            ];
        _ ->
            ok
    end,
    case get_open_custom_act_infos(?CUSTOM_ACT_TYPE_ADVENTURE_ROLE, NowTime) of
        [_|_] = ActInfos ->
            [
                custom_act_adventure:refresh_recharge(PS#player_status.id, HActSub,
                    lib_recharge_data:get_my_recharge_between(PS#player_status.id, HSTime, HETime)
                )
                || #act_info{key = {_, HActSub}, stime = HSTime, etime = HETime} <- ActInfos
            ];
        _ ->
            ok
    end,
    case get_open_custom_act_infos(?CUSTOM_ACT_TYPE_LUCKY_TURNTABLE, NowTime) of
        [_|_] = LuckActs ->
            lib_lucky_turntable:handle_event_recharge(PS, LuckActs, Data);
        _ ->
            ok
    end,
    case get_open_custom_act_infos(?CUSTOM_ACT_TYPE_RECHARGE_RANK, NowTime) of
        [_|_] = RRActs ->
            MergeTime = util:get_merge_time(),
            [
                lib_consume_rank_act:refresh_recharge(RSubType, PS,
                    lib_recharge_data:get_my_recharge_between(PS#player_status.id, max(RSTime, MergeTime), RETime)
                )
                || #act_info{key = {_, RSubType}, stime = RSTime, etime = RETime} <- RRActs
            ];
        _ ->
            ok
    end,
    case get_open_custom_act_infos(?CUSTOM_ACT_TYPE_RECHARGE_CONSUME, NowTime) of
        [_|_] = RCActs ->
            [
                lib_custom_act_do_recharge_consume:send_info(PS, SubType)
                || #act_info{key = {_, SubType}} <- RCActs];
        _ ->
            ok
    end,
    case get_open_custom_act_infos(?CUSTOM_ACT_TYPE_DAILY_CHARGE_CYCLE, NowTime) of
        [_|_] = DCActs ->
            NewPlayer = lib_recharge_cumulation:handle_recharge_act(PS, DCActs),
            {ok, NewPlayer};
        _ ->
            {ok, PS}
    end;
handle_event(Player, #event_callback{type_id = ?EVENT_ZERO_CLOCK}) ->
    %% 随机延迟再检查各活动状态刷新（避免全部玩家同一时刻执行操作）
    DelayMS = urand:rand(30000, 90000),
    Msg = {'mod', ?MODULE, midnight_delay_refresh_act, []},
    erlang:send_after(DelayMS, Player#player_status.pid, Msg),
    %% （如果有需要不能延迟的，单独处理）
    {ok, Player};
handle_event(Player, _) ->
    {ok, Player}.

%% 零点随机延迟后执行
%% 不保证执行：如果玩家在回调之前下线，则无法执行到
midnight_delay_refresh_act(Player) ->
    NowTime = utime:unixtime(),
    custom_act_pellet:midnight_delay_refresh_act(Player, NowTime),
    Player.

%% 消费活动更新
handle_event_consume(Player, MoneyType, ActType, OldMoneyMap) ->
    case lib_custom_act_api:get_open_custom_act_infos(ActType) of
        [_|_] = ActInfos ->
            handle_event_consume_2(Player, MoneyType, ActType, ActInfos, OldMoneyMap);
        _ ->
            skip
    end.
handle_event_consume_2(Player, MoneyType, ?CUSTOM_ACT_TYPE_CONSUME, ActInfos, _OldMoneyMap) ->
    [
        case MoneyType =:= ?TYPE_GOLD of
            true ->
                pp_custom_act:handle(33104, Player, [Type, SubType]);
            false ->
                skip
        end ||
        #act_info{key = {Type, SubType}} <- ActInfos
    ];
handle_event_consume_2(Player, MoneyType, ?CUSTOM_ACT_TYPE_RECHARGE_CONSUME, ActInfos, _OldMoneyMap) ->
    [
        case lib_custom_act_util:keyfind_act_condition(Type, SubType, money_type) of
            {money_type, ActMoneyType} ->
                case MoneyType of
                    ActMoneyType ->
                        pp_custom_act:handle(33164, Player, [SubType]);
                    _ ->
                        skip
                end;
            _R ->
                skip
        end  ||
        #act_info{key = {Type, SubType}} <- ActInfos
    ];
handle_event_consume_2(Player, MoneyType, ?CUSTOM_ACT_TYPE_CONSUME_RANK, _ConsumeActs, _OldMoneyMap) ->
    if
        MoneyType =:= ?TYPE_GOLD; MoneyType =:= ?TYPE_BGOLD  ->
            lib_consume_rank_act:refresh_consume(Player);
        true -> skip
    end;
handle_event_consume_2(Player, MoneyType, ?CUSTOM_ACT_TYPE_CONTINUE_CONSUME, ActInfos, _OldMoneyMap) ->
    if
        MoneyType =:= ?TYPE_GOLD; MoneyType =:= ?TYPE_BGOLD  ->
            F = fun
                (Type, SubType) ->
                    pp_custom_act:handle(33104, Player, [Type, SubType]),
                    pp_custom_act:handle(33143, Player, [SubType])
            end,
            [F(Type, SubType)|| #act_info{key = {Type, SubType}} <- ActInfos];
        true -> skip
    end;
handle_event_consume_2(Player, MoneyType, ?CUSTOM_ACT_TYPE_DAILY_CHARGE_CONSUME, ActInfos, OldMoneyMap) ->
    NeedRefresh = case MoneyType of
        ?TYPE_GOLD -> true;
        _ ->
            #player_status{gold = NowGold} = Player,
            case maps:get(gold, OldMoneyMap, undefined) of
                undefined -> true;
                OldGold when OldGold > NowGold -> true;
                _ -> false
            end
    end,
    % ?INFO("NeedRefresh:~w, MoneyType:~w, OldMoneyMap:~w", [NeedRefresh, MoneyType, OldMoneyMap]),
    case NeedRefresh of
        true  ->
            %% 每日累充消费 活动状态刷新
            custom_act_pellet:refresh_act_list_status(Player, consume, ActInfos);
        false ->
            ignore
    end;
handle_event_consume_2(Player, ?TYPE_GOLD, ?CUSTOM_ACT_TYPE_LUCKY_TURNTABLE, ActInfos, OldMoneyMap) ->
    lib_lucky_turntable:handle_event_consume(Player, ActInfos, OldMoneyMap),
    ok;
handle_event_consume_2(Player, ?TYPE_GOLD, ?CUSTOM_ACT_TYPE_ADVENTURE_ROLE, ActInfos, OldMoneyMap) ->
    custom_act_adventure:refresh_consume(Player, ActInfos, OldMoneyMap),
    ok;
handle_event_consume_2(Player, ?TYPE_GOLD, ?CUSTOM_ACT_TYPE_HI_POINT, ActInfos, OldMoneyMap) ->
    mod_hi_point:refresh_consume(Player, ActInfos, OldMoneyMap),
    ok;
handle_event_consume_2(Player, ?TYPE_GOLD, ?CUSTOM_ACT_TYPE_HI_POINT_2, ActInfos, OldMoneyMap) ->
    mod_hi_point:refresh_consume(Player, ActInfos, OldMoneyMap),
    ok;
handle_event_consume_2(_Player, _MoneyType, _, _ConsumeActs, _OldMoneyMap) ->
    ok.

%% 定制活动热更之后后台调用接口
reload_custom_act_cfg() ->
    lib_custom_act_dynamic_compile:dynamic_compile_cfg(),
    case util:is_cls() of
        true ->
            mod_custom_act_kf:apply_cast(reload_act_list, []);
        _ ->
            mod_custom_act:apply_cast(reload_act_list, [])
    end.

% %%--------------------------------------------------
% %% 后台关闭定制活动
% %% @param  Type       活动主类型
% %% @param  SubType    活动子类型
% %% @param  IsExtraAct 是否是额外定制活动 0: 不是 1: 是
% %% @return            description
% %%--------------------------------------------------
manual_close_act(Type, SubType, IsExtraAct) ->
    RealSubType = ?IF(IsExtraAct == 1, SubType + ?EXTRA_CUSTOM_ACT_SUB_ADD, SubType),
    case ets:lookup(?ETS_CUSTOM_ACT, {Type, RealSubType}) of
     [ActInfo|_] when is_record(ActInfo, act_info) ->
         NowTime = utime:unixtime(),
         lib_custom_act:act_end(?CUSTOM_ACT_STATUS_MANUAL_CLOSE, ActInfo, NowTime),
         ok;
     _ -> skip
    end.

%% 玩家登录
login(PlayerStatus) ->
    #player_status{id = RoleId} = PlayerStatus,
    StatusCustomAct = load_custom_act_reward(RoleId),
    lib_custom_act_data:load_custom_act_data(RoleId),
    PlayerStatus#player_status{status_custom_act = StatusCustomAct}.
load_custom_act_reward(RoleId) ->
    List = db:get_all(io_lib:format(?select_custom_act_reward_receive, [RoleId])),
    F = fun([Type, SubType, Grade, ReceiveTimes, Utime], AccMap) ->
        RewardStatus = #reward_status{receive_times = ReceiveTimes, utime = Utime},
        maps:put({Type, SubType, Grade}, RewardStatus, AccMap)
        end,
    RewardMap = lists:foldl(F, #{}, List),
    #status_custom_act{
        reward_map = RewardMap,
        custom_act_personal = custom_act_personal:login(RoleId)
    }.

%%--------------------------------------------------
%% 活动是否开启
%% @param  Type 活动主类型
%% @return      true|false
%%--------------------------------------------------
is_open_act(Type) ->
    OpenSubList = lib_custom_act_util:get_open_subtype_list(Type),
    OpenSubList =/= [].

%%--------------------------------------------------
%% 活动是否开启
%% @param  Type    活动主类型
%% @param  SubType 活动子类型
%% @return         true|false
%%--------------------------------------------------
is_open_act(Type, SubType) ->
    NowTime = utime:unixtime(),
    case ets:lookup(?ETS_CUSTOM_ACT, {Type, SubType}) of
        [#act_info{etime = Etime}|_] when Etime > NowTime -> true;
        _ -> false
    end.

%%--------------------------------------------------
%% 获取活动开启的子类型列表
%% @param  Type    活动主类型
%% @return         [SubType]
%%--------------------------------------------------
get_open_subtype_ids(Type) ->
    NowTime = utime:unixtime(),
    List = lib_custom_act_util:get_open_subtype_list(Type, NowTime),
    [SubType || #act_info{key = {_Type, SubType}} <- List].

%% 批量获取开启的活动信息
get_custom_act_open_info_by_actids(ActIds) ->
    NowTime = utime:unixtime(),
    Fun = fun(ActId, TL) -> get_open_custom_act_infos(ActId, NowTime) ++ TL end,
    lists:foldl(Fun, [], ActIds).

get_open_custom_act_infos(Type) ->
    NowTime = utime:unixtime(),
    get_open_custom_act_infos(Type, NowTime).

get_open_custom_act_infos(Type, NowTime) ->
    lib_custom_act_util:get_open_subtype_list(Type, NowTime).

get_act_name(Type, SubType) ->
    case lib_custom_act_util:get_act_cfg_info(Type, SubType) of
        #custom_act_cfg{name = Name} -> Name;
        _ -> <<>>
    end.
%% 合服处理
%% 需要根据类型处理的接口：
%%      - get_act_roles(ActInfo)
%%      - calc_got_reward_times(RwStatus, ActInfo, GradeId)
%%      - check_has_rewards_for_merge(RoleId, ActInfo, RwCfg, GotTimes)
handle_merge() ->
    ActList = lib_custom_act_util:get_custom_act_open_list(),
    AllRoles = db:get_all("SELECT `id`, `sex`, `lv` FROM `player_low` WHERE 1"),
    WLv = util:get_world_lv(),
    AllRoleParam = [{RoleId, #reward_param{player_lv = Lv, sex = Sex, wlv = WLv}} || [RoleId, Sex, Lv] <- AllRoles],
    handle_merge(ActList, AllRoleParam).
handle_merge([#act_info{key = {Type, SubType}} = ActInfo|T], AllRoles) ->
    AllGradeIds = lib_custom_act_util:get_act_reward_grade_list(Type, SubType),
    [calc_reward_before_merge(ActInfo, GradeId, RoleId, RwParam) || GradeId <- AllGradeIds, {RoleId, RwParam} <- AllRoles],
    handle_merge(T, AllRoles);
handle_merge([_|T], AllRoles) ->
    handle_merge(T, AllRoles);
handle_merge([], _AllRoles) -> ok.

calc_reward_before_merge(#act_info{key = {Type, SubType}} = ActInfo, GradeId, RoleId, RwParam) ->
    case lib_custom_act_util:get_act_reward_cfg_info(Type, SubType, GradeId) of
        RwCfg when is_record(RwCfg, custom_act_reward_cfg) ->
            RwStatus
                = case get({load_custom_act_reward, RoleId}) of
                      undefined ->
                          V = lib_custom_act_api:load_custom_act_reward(RoleId),
                          put({load_custom_act_reward, RoleId}, V),
                          V;
                      V ->
                          V
                  end,
            GotTimes = calc_got_reward_times(RwStatus, ActInfo, GradeId),
            case check_has_rewards_for_merge(RoleId, ActInfo, RwCfg, GotTimes) of
                {ok, RwTimes} ->
                    #act_info{wlv = Wlv} = ActInfo,
                    case calc_rewards(RoleId, RwStatus, RwCfg, RwParam#reward_param{wlv = Wlv}, GotTimes, RwTimes, []) of
                        {ok, [_|_] = _Rewards, NewGotTimes} ->
                            NewRwStatus = lib_custom_act:update_receive_times_map(RoleId, RwStatus, Type, SubType, GradeId, NewGotTimes),
                            % send_act_reward(RoleId, Rewards, RwCfg, Wlv, 335, 336),
                            put({load_custom_act_reward, RoleId}, NewRwStatus);
                        _ ->
                            ok
                    end;
                _ ->
                    ok
            end;
        _ ->
            ok
    end.

%% 获取领奖次数
calc_got_reward_times(StatusCustomAct, ActInfo, GradeId) ->
    lib_custom_act_dispatcher:calc_got_reward_times(StatusCustomAct, ActInfo, GradeId).

calc_rewards(RoleId, RwStatus, RwCfg, RwParam, GotTimes, RwTimes, Rewards) when RwTimes > 0 ->
    ThisRewards = lib_custom_act_util:count_act_reward(RwParam, RwCfg),
    AccRewards = lib_goods_api:make_reward_unique(ThisRewards ++ Rewards),
    calc_rewards(RoleId, RwStatus, RwCfg, RwParam, GotTimes + 1, RwTimes - 1, AccRewards);
calc_rewards(_RoleId, _RwStatus, _RwCfg, _RwParam, GotTimes, _RwTimes, Rewards) ->
    {ok, Rewards, GotTimes}.

%% 合服检测发奖励
check_has_rewards_for_merge(RoleId, ActInfo, RwCfg, GotTimes) ->
    lib_custom_act_dispatcher:check_has_rewards_for_merge(RoleId, ActInfo, RwCfg, GotTimes).

%% 检测活动结束时是否有忘记领取的奖励
check_has_rewards_for_forget(RoleId, ActInfo, RwCfg, GotTimes) ->
    lib_custom_act_dispatcher:check_has_rewards_for_forget(RoleId, ActInfo, RwCfg, GotTimes).

player_daily_update_12(Player) -> %% 12点更新界面
    lib_custom_act_do_normal:player_daily_update_12(Player).

%% 是否有需要更新的
is_need_daily_update(Player, ActInfo) -> lib_custom_act_dispatcher:is_need_daily_update(Player, ActInfo).

%% 尝试发送玩家未领取的奖励
%% 需要根据类型处理的接口：
%%      - get_act_roles(ActInfo)
%%      - calc_got_reward_times(RwStatus, ActInfo, GradeId)
%%      - check_has_rewards_for_forget(RoleId, ActInfo, RwCfg, GotTimes)
send_forgot_rewards(ActInfo) ->
    lib_custom_act_dispatcher:send_forgot_rewards(ActInfo).

send_forgot_rewards_common(ActInfo) ->
    case get_act_roles(ActInfo) of
        [] -> ok;
        RoleIds ->
            spawn(
                fun() ->
                    [
                        begin
                            send_forgot_rewards(RoleId, ActInfo),
                            timer:sleep(500)
                        end
                        || RoleId <- RoleIds
                    ]
                end
            )
    end.

%% 获取参与活动的玩家
get_act_roles(ActInfo) -> lib_custom_act_dispatcher:get_act_roles(ActInfo).

send_forgot_rewards(RoleId, #act_info{key = {Type, SubType}} = ActInfo) ->
    case load_player_rwparam(RoleId) of
        undefined ->
            ok;
        RwParam ->
            GradeIds = lib_custom_act_util:get_act_reward_grade_list(Type, SubType),
            RwStatus = load_custom_act_reward(RoleId),
            [try_send_forgot_reward(RoleId, ActInfo, RwStatus, RwParam, GradeId) || GradeId <- GradeIds]
    end.
try_send_forgot_reward(RoleId, ActInfo, RwStatus, RwParam, GradeId) ->
    #act_info{wlv = Wlv, key = {Type, SubType}} = ActInfo,
    case lib_custom_act_util:get_act_reward_cfg_info(Type, SubType, GradeId) of
        RwCfg when is_record(RwCfg, custom_act_reward_cfg) ->
            GotTimes = calc_got_reward_times(RwStatus, ActInfo, GradeId),
            case check_has_rewards_for_forget(RoleId, ActInfo, RwCfg, GotTimes) of
                {ok, RwTimes} ->
                    case calc_rewards(RoleId, RwStatus, RwCfg, RwParam#reward_param{wlv = Wlv}, GotTimes, RwTimes, []) of
                        {ok, [_|_] = _Rewards, NewGotTimes} ->
                            lib_custom_act:update_receive_times_map(RoleId, RwStatus, Type, SubType, GradeId, NewGotTimes),
                            % send_act_reward(RoleId, Rewards, RwCfg, Wlv, 3310047, 3310047);
                            ok;
                        _ -> ok
                    end;
                _ -> ok
            end;
        _ -> ok
    end.

load_player_rwparam(RoleId) ->
    SQL = io_lib:format("SELECT `sex`, `lv` FROM `player_low` WHERE `id` = ~p", [RoleId]),
    case db:get_row(SQL) of
        [Sex, Lv] ->
            #reward_param{player_lv = Lv, sex = Sex};
        _ ->
            undefined
    end.

make_role_info_for_check(RoleId, Type, SubType) ->
    lib_custom_act_dispatcher:make_role_info_for_check(Type, SubType, RoleId).

gm_set_act_open_wlv(ActId, SubId, WLv) ->
    case ets:lookup(?ETS_CUSTOM_ACT, {ActId, SubId}) of
        [#act_info{} = ActInfo|_] ->
            ets:insert(?ETS_CUSTOM_ACT, ActInfo#act_info{wlv = WLv});
        _ -> skip
    end.

%% ---------------------------------------------------------------------------
%% @doc 定制活动消耗内容固定格式
-spec custom_act_consume_about(Type, SubType) -> String when
    Type        :: integer(),
    SubType     :: integer(),
    String      :: string().
%% ---------------------------------------------------------------------------
custom_act_consume_about(Type, SubType) ->
    io_lib:format("type: ~w subtype: ~w", [Type, SubType]).

%% 充值活动领取日志
log_recharge_consume_act(Player, #act_info{key = {Type, _}} = ActInfo, Grade, IsMail, Award, Now)
    when Type =:= ?CUSTOM_ACT_TYPE_RECHARGE
    orelse Type =:= ?CUSTOM_ACT_TYPE_SINGLE_RECHARGE
    orelse Type =:= ?CUSTOM_ACT_THEME_FIRST_RECHARGE
    ->
    #player_status{
        id = RoleId,
        figure = #figure{name = Name, vip = Vip}
    } = Player,
    #act_info{key = {Type, SubType}, stime = Stime, etime = ETime} = ActInfo,
    Charge = lib_recharge_data:get_my_recharge_between(RoleId, Stime, ETime),
    lib_log_api:log_recharge_consume_act(
        [RoleId, Name, Type, SubType, Grade, Charge, 0, IsMail, util:term_to_bitstring(Award), Vip, Now]
    );
%% 消费活动领取日志
log_recharge_consume_act(Player, #act_info{key = {Type, _}} = ActInfo, Grade, IsMail, Award, Now)
    when Type =:= ?CUSTOM_ACT_TYPE_CONSUME
    ->
    #player_status{
        id = RoleId,
        figure = #figure{name = Name, vip = Vip}
    } = Player,
    #act_info{key = {Type, SubType}, stime = Stime, etime = ETime} = ActInfo,
    Consume = lib_consume_data:get_gold_consume_between(RoleId, Stime, ETime),
    lib_log_api:log_recharge_consume_act(
        [RoleId, Name, Type, SubType, Grade, 0, Consume, IsMail, util:term_to_bitstring(Award), Vip, Now]
    );

log_recharge_consume_act(_, _, _, _, _, _) -> ok.

log_recharge_consume_act_do(RoleId, Type, SubType, Charge, Consume, IsMail, Award, Now) ->
    #figure{name = Name, vip = Vip} = lib_role:get_role_figure(RoleId),
    lib_log_api:log_recharge_consume_act(
        [RoleId, Name, Type, SubType, 0, Charge, Consume, IsMail, util:term_to_bitstring(Award), Vip, Now]
    ).
