%% ---------------------------------------------------------------------------
%% @doc 小额连充活动。
%% @author zmh
%% @since  20200722
%% ---------------------------------------------------------------------------
-module(custom_act_small_recharge).

-export([
     ask_reward_status/3           %% 拿33104
     ,recharge_resign/2            %% 补签
     ,get_small_recharge_resign/2  %% 获取充值和补签信息
     ,receive_reward/4              %% 领取小额连充活动奖励
     ,handle_event/2                %% 处理充值事件
     ,notify_other_module/2
]).

-export([
]).

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


%% 奖励状态
-define(AWARD_ACTIVATED,           0).         %% 已激活充值任务
-define(AWARD_CAN_GET,             1).         %% 可以领取
-define(AWARD_HAS_GET,             2).         %% 已经领取
-define(AWARD_UNACTIVATED,         3).         %% 未激活

%% ---------------------------------------------------------------------------
%% @doc 获取角色小额连充活动数据
-spec small_recharge_data(Status, Type, SubType) -> Data when
    Status        :: #player_status{},
    Type        :: integer(),
    SubType     :: integer(),
    Data        :: #small_recharge{}.
%% ---------------------------------------------------------------------------
small_recharge_data(_Status, Type, SubType) ->
    #custom_act_data{
        act_data = Data
    } = lib_custom_act_data:custom_act_data(Type, SubType),
    case Data of
        #small_recharge{} ->
            Data;
        _ ->
            #small_recharge{}
    end.

ask_reward_status(Status,Type,SubType)->
    #player_status{sid=Sid}=Status,
    SmallRecharge = small_recharge_data(Status, Type, SubType),
    #small_recharge{award_info=AwardInfos0}=SmallRecharge,
    All = lib_custom_act_util:get_act_reward_grade_list(Type, SubType),
    AwardInfos = to_client_award(All,Type,SubType,AwardInfos0,[]),
    {ok,Bin} = pt_331:write(33104,[Type,SubType,AwardInfos]),
    lib_server_send:send_to_sid(Sid,Bin),
    {ok,Status}.

to_client_award([], _Type, _SubType,_,NAwardInfos)->
    NAwardInfos;
to_client_award([H|T],Type, SubType,AwardInfos0,NAwardInfos)->
    case lib_custom_act_util:get_act_reward_cfg_info(Type,SubType,H) of
        #custom_act_reward_cfg{
            name = Name,
            desc = Desc,
            condition = Condition,
            format = Format,
            reward = Rewards
        }->
            case lists:keyfind(H,#small_award.award_id,AwardInfos0) of
                #small_award{process=CurV,status=CurS}->
                    skip;
                _->
                    CurV = 0, CurS=?AWARD_ACTIVATED
            end,
            ConditionStr = util:term_to_string(Condition),
            RewardStr = util:term_to_string(Rewards),
            Data = {H,Format,CurV,CurS,0,Name,Desc,ConditionStr,RewardStr},
            to_client_award(T,Type,SubType,AwardInfos0,[Data|NAwardInfos]);
        _->
            to_client_award(T,Type,SubType,AwardInfos0,NAwardInfos)
    end.


%% ---------------------------------------------------------------------------
%% @doc 奖励领取状态判断
-spec award_status(Status, AwardCfg) -> Status when
    Status        :: #player_status{} | #small_recharge{},
    AwardCfg    :: #custom_act_reward_cfg{},
    Status      :: integer().
%% ---------------------------------------------------------------------------
award_status(Status = #player_status{}, AwardCfg) ->
    #custom_act_reward_cfg{type = Type, subtype = SubType} = AwardCfg,
    Data = small_recharge_data(Status, Type, SubType),
    award_status(Data, AwardCfg);
award_status(Data = #small_recharge{}, AwardCfg) ->
    #custom_act_reward_cfg{grade = AwardId, condition =_Condition} = AwardCfg,
    #small_recharge{
        award_info = AwardList
    } = Data,
    case lists:keyfind(AwardId, #small_award.award_id, AwardList) of
        #small_award{status = Status} ->
            Status;
        _ ->
            ?AWARD_UNACTIVATED
    end.


%%获取补签信息
get_small_recharge_resign(Status, SubType)->
    #player_status{id=RoleId,sid=Sid}=Status,
    Type = ?CUSTOM_ACT_TYPE_SMALL_RECHARGE,
    ActData = small_recharge_data(Status, Type, SubType),
    #small_recharge{
        resign = OResign,
        retime = Retime
    }=ActData,
    Resign = case utime:is_today(Retime) of
        true->
            OResign;
        _->
            0
    end,
    TodayRecharge = lib_recharge_api:get_today_pay_gold(RoleId),
    {ok,Bin} = pt_331:write(33145,[SubType,TodayRecharge,Resign]),
    lib_server_send:send_to_sid(Sid,Bin).

%%补签
recharge_resign(Status, SubType)->
    Now = utime:unixtime(),
    Type = ?CUSTOM_ACT_TYPE_SMALL_RECHARGE,
    ActInfo = lib_custom_act_util:get_custom_act_open_info(Type,SubType),
    NStatus = act_handle_zero(Status,[ActInfo],Now),
    #player_status{id=RoleId}=NStatus,
    ActData = small_recharge_data(NStatus, Type, SubType),
    #small_recharge{
        resign = OResign,
        retime = Retime,
        award_info = AwardList,
        award_num = AwardNum
    }=ActData,
    Day    = calc_resign_day(AwardList,99),
    Resign = case utime:is_today(Retime) of
        true->
            OResign;
        _->
            0
    end,

    AwardInfo =  lists:keyfind(Day, #small_award.award_id, AwardList),
    case AwardInfo of
        #small_award{status=CurStatus}->
            skip;
        _->
            CurStatus = 0
    end,
    %?INFO("----:~p~n",[{Now,Resign,Max,TodayRecharge}]),
    if
        not is_record(AwardInfo, small_award)->
            {false,?ERRCODE(missing_config)};
        not is_record(ActInfo, act_info) ->
            {false, ?ERRCODE(err331_act_closed)};
        ActInfo#act_info.etime < Now orelse Now < ActInfo#act_info.stime  ->
            {false, ?ERRCODE(err331_act_closed)};
        CurStatus>=?AWARD_CAN_GET->
            {false,?ERRCODE(err331_no_need_resign)};
        true ->
            #act_info{stime=STime,etime=ETime}=ActInfo,
            CurDay = utime:day_span(STime,Now),
            MaxDay = utime:day_span(STime,ETime),
            if
                CurDay<MaxDay->
                    {false,?ERRCODE(err331_no_need_resign)};
                Day>=CurDay ->
                    {false,?ERRCODE(err331_no_need_resign)};
                true->
                    #custom_act_cfg{condition=Cons}=data_custom_act:get_act_info(Type,SubType),
                    case lists:keyfind(sign_cost,1,Cons) of
                        {_,Value}->
                            Cost = [{?TYPE_GOLD,?GOODS_ID_GOLD,Value}],
                            case lib_goods_api:cost_object_list_with_check(NStatus, Cost, small_recharge_resign, "") of
                                {true, NewStatus,_} ->
                                    AwardInfo2 = AwardInfo#small_award{status = ?AWARD_HAS_GET,time=Now},
                                    AwardList2 = lists:keystore(Day,#small_award.award_id,AwardList,AwardInfo2),
                                    NAwardNum  = AwardNum+1,
                                    AwardList3 = check_day_status(Type,SubType,NAwardNum,Now,AwardList2),
                                    NewActData = ActData#small_recharge{award_info = AwardList3,resign=Resign+1,retime=Now,award_num=NAwardNum},
                                    CustomData = #custom_act_data{
                                        type = Type, subtype = SubType, act_data = NewActData
                                    },
                                    lib_custom_act_data:save_custom_data(RoleId, CustomData),
                                    lib_log_api:custom_act_reward_log(NewStatus, Status, Type, SubType, Day,AwardList2),
                                    {ok, NewStatus};
                                {false, Err, _} ->
                                    {false,Err}
                            end;
                        _->
                            {false,?ERRCODE(missing_config)}
                    end
            end
    end.

calc_resign_day([],Day)->
    Day;
calc_resign_day([H|T],Day)->
    case H of
        #small_award{award_id=NDay,status=?AWARD_ACTIVATED} when NDay<Day->
            calc_resign_day(T,NDay);
        _->
            calc_resign_day(T,Day)
    end.


%% ---------------------------------------------------------------------------
%% @doc 领取小额连充活动奖励
receive_reward(Role, Type, SubType, AwardId) ->
    Now = utime:unixtime(),
    ActInfo = lib_custom_act_util:get_custom_act_open_info(Type, SubType),
    Data = #small_recharge{
        award_info = AwardList
    } = small_recharge_data(Role, Type, SubType),
    RewardCfg = lib_custom_act_util:get_act_reward_cfg_info(
        Type, SubType, AwardId
    ),
    NeedLev = lib_module:get_open_lv(?MOD_AC_CUSTOM, Type),
    #player_status{id = RoleId, figure = #figure{lv = RoleLev}, sid = Sid} = Role,
    {
        AwardInfo, AwardListRest
    } = case lists:keytake(AwardId, #small_award.award_id, AwardList) of
        {value, Info, AwardListR} -> {Info, AwardListR};
        _ -> {#small_award{award_id = AwardId}, AwardList}
    end,
    Result = if
        not is_record(ActInfo, act_info) ->
            {false, ?ERRCODE(err331_act_closed)};
        ActInfo#act_info.etime < Now orelse Now < ActInfo#act_info.stime  ->
            {false, ?ERRCODE(err331_act_closed)};
        NeedLev > RoleLev ->
            {false, ?ERRCODE(err331_act_closed)};
        not is_record(RewardCfg, custom_act_reward_cfg) ->
            {false, ?ERRCODE(err331_no_act_reward_cfg)};
        true ->
            Status = award_status(Data, RewardCfg),
            #custom_act_reward_cfg{reward = RewardList} = RewardCfg,
            IsBagFull = lib_goods_api:can_give_goods(Role, RewardList),
            if
                Status =:= ?AWARD_HAS_GET ->
                    {false, ?ERRCODE(err331_already_get_reward)};
                Status =:= ?AWARD_ACTIVATED ->
                    {false, ?ERRCODE(err333_can_not_get)};
                Status =:= ?AWARD_UNACTIVATED ->
                    {false, ?ERRCODE(err333_can_not_get)};
                not IsBagFull ->
                    {false, ?ERRCODE(err150_no_cell)};
                true ->
                    AwardInfo2 = AwardInfo#small_award{status = ?AWARD_HAS_GET},
                    AwardList2 = [AwardInfo2 | AwardListRest],
                    Data2 = Data#small_recharge{award_info = AwardList2},
                    ActData = #custom_act_data{
                        type = Type, subtype = SubType, act_data = Data2
                    },
                    lib_custom_act_data:save_custom_data(RoleId, ActData),
                    Role2 = lib_custom_act:custom_act_send_reward(Role, RewardCfg),
                    lib_log_api:custom_act_reward_log(Role2, Role, Type, SubType, AwardId,RewardList),
                    {ok, Role2}
            end
    end,
    case Result of
        {false, Reason} ->
            {ok, Bin} = pt_331:write(33100, [Reason]),
            lib_server_send:send_to_sid(Sid, Bin),
            {ok, Role};
        {ok, NewRole} ->
            {ok, Bin} = pt_331:write(33105, [?SUCCESS, Type, SubType, AwardId]),
            lib_server_send:send_to_sid(Sid, Bin),
            {ok, NewRole}
    end.



%% ---------------------------------------------------------------------------
%% @doc 处理充值事件
-spec handle_event(Role, Event) -> {ok, NewRole} when
    Role        :: #player_status{},
    Event       :: #event_callback{},
    NewRole     :: #player_status{}.
%% ---------------------------------------------------------------------------
handle_event(Role, #event_callback{type_id = ?EVENT_RECHARGE, data = #callback_recharge_data{gold = Gold}}) ->
    case lib_custom_act_util:get_open_subtype_list(?CUSTOM_ACT_TYPE_SMALL_RECHARGE) of
        [] ->
            {ok, Role};
        OpenActList ->
            NowTime = utime:unixtime(),
            Role0   = act_handle_zero(Role, OpenActList,NowTime),
            NewRole = act_handle_recharge(Role0, OpenActList, Gold, NowTime),
            [get_small_recharge_resign(NewRole, SubType)||#act_info{ key = {_, SubType}}<-OpenActList],
            {ok, NewRole}
    end;
% handle_event(Role, #event_callback{type_id = ?EVENT_LV_UP}) ->
%     NeedLev = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_SMALL_RECHARGE),
%     #player_status{figure = #figure{lv = RoleLev}}=Role,
%     case RoleLev>= NeedLev of
%         true->
%             case lib_custom_act_util:get_open_subtype_list(?CUSTOM_ACT_TYPE_SMALL_RECHARGE) of
%                 [] ->
%                     {ok, Role};
%                 OpenActList ->
%                     NowTime = utime:unixtime(),
%                     NewRole = act_handle_recharge(Role, OpenActList, 0, NowTime),
%                     {ok, NewRole}
%             end;
%         _->
%             {ok,Role}
%     end;
handle_event(Role, #event_callback{type_id = ?EVENT_ZERO_CLOCK}) ->
    NeedLev = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_SMALL_RECHARGE),
    #player_status{figure = #figure{lv = RoleLev}}=Role,
    case RoleLev>= NeedLev of
        true->
            check_delay_fetch_mail(Role),
            case lib_custom_act_util:get_open_subtype_list(?CUSTOM_ACT_TYPE_SMALL_RECHARGE) of
                [] ->
                    {ok, Role};
                OpenActList ->
                    NowTime = utime:unixtime(),
                    NewRole = act_handle_zero(Role, OpenActList,NowTime),
                    [get_small_recharge_resign(NewRole, SubType)||#act_info{ key = {_, SubType}}<-OpenActList],
                    {ok, NewRole}
            end;
        _->
            {ok, Role}
    end;
handle_event(Role, #event_callback{type_id = ?EVENT_LOGIN_CAST}) ->
    NeedLev = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_SMALL_RECHARGE),
    #player_status{figure = #figure{lv = RoleLev}}=Role,
    case RoleLev>= NeedLev of
        true->
            check_delay_fetch_mail(Role),
            case lib_custom_act_util:get_open_subtype_list(?CUSTOM_ACT_TYPE_SMALL_RECHARGE) of
                [] ->
                    {ok, Role};
                OpenActList ->
                    NowTime = utime:unixtime(),
                    NewRole = act_handle_zero(Role, OpenActList,NowTime),
                    {ok, NewRole}
            end;
        _->
            {ok,Role}
    end;
handle_event(Role, _) ->
    {ok, Role}.

%%检测玩家未领取 邮件发送
check_delay_fetch_mail(Status)->
    Now = utime:unixtime(),
    Type = ?CUSTOM_ACT_TYPE_SMALL_RECHARGE,
    SubList = lib_custom_act_util:get_subtype_list(Type),
    check_delay_fetch_mail(Status,Now,Type,SubList).

%%还在开的 只返回常规未领取奖励 已结束的累积奖励一并返还
check_delay_fetch_mail(_Status,_Now,_Type,[])->
    ok;
check_delay_fetch_mail(Status,Now,Type,[H|T])->
    #custom_act_data{
        act_data = Data
    } = lib_custom_act_data:custom_act_data(Type, H),
    case Data of
        #small_recharge{award_info=AwardList} ->
            #player_status{id=RoleID}=Status,
            [Awards,NAwardList] = case lib_custom_act_api:is_open_act(Type,H) of
                true->
                    calc_reback_awards(false,Type,H,Now,AwardList,[],[]);
                _->
                    calc_reback_awards(true,Type,H,Now,AwardList,[],[])
            end,
            #custom_act_cfg{name=Name}=lib_custom_act_util:get_act_cfg_info(Type, H),
            Awards /= [] andalso begin
                Data2 = Data#small_recharge{award_info = NAwardList},
                ActData = #custom_act_data{
                    type = Type, subtype = H, act_data = Data2
                },
                lib_custom_act_data:save_custom_data(RoleID, ActData),
                lib_mail_api:send_sys_mail([RoleID], ?MOD_AC_CUSTOM, utext:get(3310001), utext:get(3310002,[Name]), Awards)
            end,
            check_delay_fetch_mail(Status,Now,Type,T);
        _->
            check_delay_fetch_mail(Status,Now,Type,T)
    end.

calc_reback_awards(_,_,_,_,[],Awards,AwardList)->
    [util:combine_list(Awards,1),AwardList];
calc_reback_awards(IsAll,Type,SubType,Now,[H|T],Awards,AwardList)->
    case H of
        #small_award{award_id=Day,status=?AWARD_CAN_GET,time=Time}->
            case utime:is_same_day(Now,Time) of
                true->
                    calc_reback_awards(IsAll,Type,SubType,Now,T,Awards,[H|AwardList]);
                _->
                    case lib_custom_act_util:get_act_reward_cfg_info(Type, SubType, Day) of
                        #custom_act_reward_cfg{reward = Award}->
                            case IsAll of
                                true->
                                    NewH = H#small_award{status=?AWARD_HAS_GET,time=Now},
                                    calc_reback_awards(IsAll,Type,SubType,Now,T,Award++Awards,[NewH|AwardList]);
                                false when Day=<99->
                                    NewH = H#small_award{status=?AWARD_HAS_GET,time=Now},
                                    calc_reback_awards(IsAll,Type,SubType,Now,T,Award++Awards,[NewH|AwardList]);
                                _->
                                    calc_reback_awards(IsAll,Type,SubType,Now,T,Awards,[H|AwardList])
                            end;
                        _->
                            calc_reback_awards(IsAll,Type,SubType,Now,T,Awards,[H|AwardList])
                    end
            end;
        _->
            calc_reback_awards(IsAll,Type,SubType,Now,T,Awards,[H|AwardList])
    end.

%%0点和登录
%%20210330 一次性解锁
act_handle_zero(Role,[],_Now)->
    Role;
act_handle_zero(Role,[H|T],Now)->
    case H of
        #act_info{stime=STime, etime = ETime, key = {Type, SubType}} when ETime >= Now ->
            Data = #small_recharge{
                refresh = Refresh
            } = small_recharge_data(Role, Type, SubType),
            case utime:is_same_day(Now, Refresh) of
                true -> %%今天刷过
                    act_handle_zero(Role, T, Now);
                false ->
                    MaxDay = utime:day_span(STime,ETime),
                    update_award_zero_status(Role, Data, Now, Type, SubType, MaxDay),
                    ask_reward_status(Role,Type,SubType),
                    act_handle_zero(Role, T, Now)
            end;
        _ ->
            act_handle_zero(Role, T, Now)
    end.

act_handle_recharge(Role, [], _Gold, _Now) ->
    Role;
act_handle_recharge(Role, [ActInfo | OpenActList], Gold, Now) ->
    case ActInfo of
        #act_info{stime=STime,etime = ETime, key = {Type, SubType}} when ETime >= Now ->
            Data = #small_recharge{
                time = Time
            } = small_recharge_data(Role, Type, SubType),
            case utime:is_same_day(Now, Time) of
                true -> %% 这个活动今天的充值任务已达成
                    act_handle_recharge(Role, OpenActList, Gold, Now);
                false ->
                    ToDay = utime:day_span(STime,Now),
                    update_award_status(Role, Data, Now, Gold, Type, SubType,ToDay),
                    ask_reward_status(Role,Type,SubType),
                    act_handle_recharge(Role, OpenActList, Gold, Now)
            end;
        _ ->
            act_handle_recharge(Role, OpenActList, Gold, Now)
    end.

%%解锁下一个
update_award_zero_status(Role, Data, Now, Type, SubType, MaxDay)->
    #player_status{id=RoleID}=Role,
    #small_recharge{
        award_info = AwardList
    } = Data,
    All = lib_custom_act_util:get_act_reward_grade_list(Type, SubType),
    NAwardList = fix_small_awards(Type, SubType,AwardList,All,MaxDay),
    Data1 = Data#small_recharge{
        refresh = Now,award_info = NAwardList
    },
    ActData = #custom_act_data{
        type = Type, subtype = SubType, act_data = Data1,time=Now
    },
    lib_custom_act_data:save_custom_data(RoleID, ActData).

fix_small_awards(_Type,_SubType,AwardList,[],_MaxDay)->
    AwardList;
fix_small_awards(Type, SubType,AwardList,[H|T],MaxDay)->
    case lib_custom_act_util:get_act_reward_cfg_info(Type, SubType, H) of
        #custom_act_reward_cfg{}->
            case lists:keyfind(H,#small_award.award_id,AwardList) of
                false->
                    AwardInfo1 = #small_award{award_id = H},
                    NAwardList = lists:keystore(H,#small_award.award_id,AwardList,AwardInfo1),
                    fix_small_awards(Type, SubType,NAwardList,T,MaxDay);
                _->
                    fix_small_awards(Type, SubType,AwardList,T,MaxDay)
            end;
        _->
            fix_small_awards(Type, SubType,AwardList,T,MaxDay)
    end.

update_award_status(Role, Data, Now, Gold, Type, SubType,ToDay) ->
    #small_recharge{
        award_info = AwardList,
        award_num  = AwardNum
    } = Data,
    AwardId = ToDay,
    RewardCfg = lib_custom_act_util:get_act_reward_cfg_info(Type, SubType, AwardId),
    NeedLev = lib_module:get_open_lv(?MOD_AC_CUSTOM, Type),
    #player_status{id = RoleId, figure = #figure{lv = RoleLev}} = Role,
    if
        NeedLev > RoleLev -> %% 等级不足
            ok;
        not is_record(RewardCfg, custom_act_reward_cfg) ->
            %% 全部完成了，或者配置不对。
            ok;
        true ->
            #custom_act_reward_cfg{condition = Condition} = RewardCfg,
            case lists:keyfind(recharge_gold, 1, Condition) of
                {recharge_gold, NeedGold} ->
                    NeedGold;
                _ ->
                    NeedGold = false
            end,
            DateTime = utime:unixtime({today, Now}),
            NextDateTime = utime:tomorrow(DateTime),
            TodayRecharge = lib_recharge_data:get_my_recharge_between(RoleId, DateTime, NextDateTime),
            %% 是累积充值额
            case Gold >= NeedGold orelse TodayRecharge >= NeedGold of
                true -> %% 达成条件
                    AwardInfo2 = #small_award{
                        award_id = AwardId, status = ?AWARD_CAN_GET
                        ,time = Now,process =  NeedGold
                    },
                    NAwardNum = AwardNum+1,
                    AwardList1 = lists:keystore(AwardId,#small_award.award_id,AwardList,AwardInfo2),

                    AwardList2 = check_day_status(Type,SubType,NAwardNum,Now,AwardList1),
                    Data2 = Data#small_recharge{
                        award_info = AwardList2,
                        time = Now,
                        award_num = NAwardNum
                    },
                    ActData = #custom_act_data{
                        type = Type, subtype = SubType, act_data = Data2,time=Now
                    },
                    lib_custom_act_data:save_custom_data(RoleId, ActData);
                false ->
                    AwardInfo2 = #small_award{
                        award_id = AwardId,process=TodayRecharge
                    },
                    AwardList2 = lists:keystore(AwardId,#small_award.award_id,AwardList,AwardInfo2),
                    Data2 = Data#small_recharge{
                        award_info = AwardList2
                    },
                    ActData = #custom_act_data{
                        type = Type, subtype = SubType, act_data = Data2,time=Now
                    },
                    lib_custom_act_data:save_custom_data(RoleId, ActData)
            end
    end.

check_day_status(Type,SubType,AwardNum,Now,AwardList)->
    check_day_status(Type,SubType,AwardNum,Now,AwardList,AwardList).

check_day_status(_,_,_,_,[],AwardList)->
    AwardList;
check_day_status(Type,SubType,AwardNum,Now,[H|T],AwardList)->
    case H of
        #small_award{award_id=AwardId} when AwardId<100->
            check_day_status(Type,SubType,AwardNum,Now,T,AwardList);
        #small_award{status=CurStatus} when ?AWARD_CAN_GET=<CurStatus,CurStatus=<?AWARD_HAS_GET->
            check_day_status(Type,SubType,AwardNum,Now,T,AwardList);
        #small_award{award_id=AwardId}->
            case lib_custom_act_util:get_act_reward_cfg_info(Type, SubType, AwardId) of
                #custom_act_reward_cfg{condition = Condition}->
                    case lists:keyfind(recharge_days,1,Condition) of
                        {_,NeedDay} when AwardNum>=NeedDay->
                            NewH = H#small_award{status = ?AWARD_CAN_GET,time=Now},
                            NAwardList = lists:keystore(AwardId,#small_award.award_id,AwardList,NewH),
                            check_day_status(Type,SubType,AwardNum,Now,T,NAwardList);
                        _->
                            check_day_status(Type,SubType,AwardNum,Now,T,AwardList)
                    end;
                _->
                    check_day_status(Type,SubType,AwardNum,Now,T,AwardList)
            end;
        _->
            check_day_status(Type,SubType,AwardNum,Now,T,AwardList)
    end.


%% ---------------------------------------------------------------------------
%% @doc 活动派发接口：定制活动开启或者关闭 默认处理
notify_other_module(?CUSTOM_ACT_STATUS_OPEN,ActInfo) ->
    case ActInfo of
        #act_info{key={?CUSTOM_ACT_TYPE_SMALL_RECHARGE,_SubType},trigger_time = T} when T=:=1 ->
             %% 清理活动数据
            lib_custom_act_data:clean_up_data(ActInfo);
        _->
            ok
    end;
notify_other_module(_ActStatus,_ActInfo)->
    ok.
