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

-include("server.hrl").
-include("common.hrl").
-include("custom_act.hrl").
-include("errcode.hrl").
-include("def_module.hrl").
-include("figure.hrl").
-include("kv.hrl").
-include("def_fun.hrl").
-include("smashed_egg.hrl").
-include("cloud_buy.hrl").
-include("goods.hrl").
-include("red_envelopes.hrl").
-include("predefine.hrl").
-include("treasure_evaluation.hrl").
-include("lucky_wheel.hrl").
-include("joy_wish.hrl").
-include("def_goods.hrl").

-export([handle/3]).

%% 获取活动列表
handle(Cmd = 33101, Player, _) ->
    ActList  = lib_custom_act_util:get_custom_act_open_list(),
    ActList1 = custom_act_personal:arrange_personal_act(Player, ActList),
    ActList2 = lib_vie_rank:get_delay_show_act(Player, ActList1),
    PackList = lib_custom_act:pack_custom_act_list(ActList2),
    % ?PRINT("PackList~p~n",[PackList]),
    {ok, BinData} = pt_331:write(Cmd, [PackList]),
    lib_server_send:send_to_sid(Player#player_status.sid, BinData);

%% 获取奖励领取状态(通用活动)
handle(_Cmd = 33104, Player, [Type, SubType]) ->
    lib_custom_act:ask_reward_status(Player, Type, SubType);

%% 奖励领取(通用活动)
handle(_Cmd = 33105, Player, [Type, SubType, GradeId]) ->
    lib_custom_act:receive_reward(Player, Type, SubType, GradeId);

%% 某些特殊活动要限制今天总的兑换数量
handle(Cmd = 33106, Player, [Type, SubType, ModId, CounterId]) ->
    ExchangeTime = 0,
    {ok, Bin} = pt_331:write(Cmd, [Type, SubType, ModId, CounterId, ExchangeTime]),
    lib_server_send:send_to_sid(Player#player_status.sid, Bin);

handle(33108, Ps, [Type, SubType, GradeId]) ->
    case lib_custom_act_util:get_custom_act_open_info(Type, SubType) of
        ActInfo when is_record(ActInfo, act_info) ->
            case lib_custom_act_util:get_act_reward_cfg_info(Type, SubType, GradeId) of
                #custom_act_reward_cfg{condition = Condition} = RewardCfg ->
                    case lib_custom_act_check:check_act_condtion([timeout_cost], Condition) of
                        [Cost] ->
                            case lib_custom_act:count_reward_status(Ps, ActInfo, 0, RewardCfg) of
                                ?ACT_REWARD_TIME_OUT ->
                                    RewardList = lib_custom_act_util:count_act_reward(Ps, ActInfo, RewardCfg),
                                    case lib_goods_api:can_give_goods(Ps, RewardList) of
                                        true ->
                                            Mark = lists:concat([Type, "-", SubType, "-", GradeId]),
                                            Produce = #produce{reward = RewardList, remark = Mark, type = custom_act_reward_buy},
                                            case Cost of
                                                [] ->
                                                    NewPs = lib_goods_api:send_reward_with_mail(Ps, Produce, ?MOD_AC_CUSTOM, Type),
                                                    {ok, BinData} = pt_331:write(33108, [?SUCCESS, Type, SubType, GradeId]),
                                                    lib_server_send:send_to_sid(Ps#player_status.sid, BinData),
                                                    {ok, NewPs};
                                                _ ->
                                                    case lib_goods_api:cost_object_list_with_check(Ps, Cost, custom_act_reward_buy, Mark) of
                                                        {true, CostPs,_} ->
                                                            NewPs = lib_goods_api:send_reward_with_mail(CostPs, Produce, ?MOD_AC_CUSTOM, Type),
                                                            {ok, BinData} = pt_331:write(33108, [?SUCCESS, Type, SubType, GradeId]),
                                                            lib_server_send:send_to_sid(Ps#player_status.sid, BinData),
                                                            {ok, NewPs};
                                                        {false, Code, _} ->
                                                            {ok, BinData} = pt_331:write(33108, [Code, Type, SubType, GradeId]),
                                                            lib_server_send:send_to_sid(Ps#player_status.sid, BinData)
                                                    end
                                            end;
                                        _ ->
                                            {ok, BinData} = pt_331:write(33108, [?ERRCODE(err150_no_cell), Type, SubType, GradeId]),
                                            lib_server_send:send_to_sid(Ps#player_status.sid, BinData)
                                    end;
                                _ ->
                                    {ok, BinData} = pt_331:write(33108, [?ERRCODE(err331_cannot_get_back), Type, SubType, GradeId]),
                                    lib_server_send:send_to_sid(Ps#player_status.sid, BinData)
                            end;
                        _ ->
                            {ok, BinData} = pt_331:write(33108, [?ERRCODE(err331_cannot_get_back), Type, SubType, GradeId]),
                            lib_server_send:send_to_sid(Ps#player_status.sid, BinData)
                    end;
                _ ->
                    {ok, BinData} = pt_331:write(33108, [?ERRCODE(err331_cannot_get_back), Type, SubType, GradeId]),
                    lib_server_send:send_to_sid(Ps#player_status.sid, BinData)
            end;
        _ ->
            {ok, BinData} = pt_331:write(33108, [?ERRCODE(err331_act_closed), Type, SubType, GradeId]),
            lib_server_send:send_to_sid(Ps#player_status.sid, BinData)
    end;

handle(33109,Ps,[Mod,SubMod,TmpSubAct])->
    #player_status{id=RoleId}=Ps,
    List0 = data_act_ratio_show:get_award_list(Mod,SubMod,TmpSubAct),
    {Lists,SubAct} = case length(List0)=<0 of
        true->
            {data_act_ratio_show:get_award_list(Mod,SubMod,0),0};
        _->
            {List0,TmpSubAct}
    end,
    Awards = [begin
        #act_draw_ratio{
            name=Name,
            goods_name=GName,
            ratio=Ratio
        } = data_act_ratio_show:get_award_ratio(Mod,SubMod,SubAct,AwardId),
        {AwardId,Name,GName,Ratio}
    end || AwardId<-Lists],
    {ok,Bin} = pt_331:write(33109,[Mod,SubMod,TmpSubAct,Awards]),
    lib_server_send:send_to_uid(RoleId,Bin),
    {ok,Ps};


%% ------------------------- 特惠商城 --------------------------
%% 打开特惠商城
handle(33111, Ps, [_Type, SubType]) ->
    lib_custom_act_do_limit_buy:send_info(Ps, SubType);

%% 众仙云购信息
handle(33112, Ps, [SubType]) ->
    #player_status{
        id = RoleId,
        sid = Sid,
        figure = Figure
    } = Ps,
    #figure{
        lv = Lv
    } = Figure,
    CloudOpenLv = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_CLOUD_BUY),
    case lib_custom_act_util:keyfind_act_condition(?CUSTOM_ACT_TYPE_CLOUD_BUY, SubType, if_kf) of
        {if_kf, IfKf} ->
            case Lv >= CloudOpenLv of
                false ->
                    lib_server_send:send_to_sid(Sid, pt_331, 33112, [?LEVEL_LIMIT, SubType, IfKf, 0, 0, 0, 0, [], 0, 0]);
                true ->
                    case lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_CLOUD_BUY, SubType) of
                        false -> skip;
                            % lib_server_send:send_to_sid(Sid, pt_331, 33112, [?ERRCODE(err331_act_closed), SubType, IfKf, 0, 0, 0, 0, [], 0, 0]);
                        true ->
                            Node = clusters_node:get_node(),
                            % {VipType, VipLv} = lib_vip_api:get_valid_vip_lv(Ps),
                            VipType = 0, VipLv = 0,
                            case IfKf of
                                0 ->
                                    mod_cloud_buy_mgr:get_info(Node, SubType, RoleId, Sid, VipType, VipLv);
                                _ ->
                                    clusters_node:apply_cast(mod_cloud_buy_mgr, get_info, [Node, SubType, RoleId, Sid, VipType, VipLv])
                            end
                    end
            end;
        false ->
            lib_server_send:send_to_sid(Sid, pt_331, 33112, [?MISSING_CONFIG, SubType, 0, 0, 0, 0, 0, [], 0, 0])
    end;

%% 众仙云购-购买
handle(33113, Ps, [SubType, Count, IfAutoBuy]) when Count > 0 ->
    lib_cloud_buy:order(Ps, SubType, Count, IfAutoBuy, 0);

%% 众仙云购-上期中奖名单
handle(33114, Ps, [SubType]) ->
    case lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_CLOUD_BUY, SubType) of
        false -> skip;
        true ->
            Node = clusters_node:get_node(),
            case  lib_custom_act_util:keyfind_act_condition(?CUSTOM_ACT_TYPE_CLOUD_BUY, SubType, if_kf) of
                false -> skip;
                {if_kf, IfKf} ->
                    case IfKf of
                        0 -> mod_cloud_buy_mgr:get_last_lucky_orders(Node, SubType, Ps#player_status.sid);
                        _ -> clusters_node:apply_cast(mod_cloud_buy_mgr, get_last_lucky_orders, [Node, SubType, Ps#player_status.sid])
                    end
            end
    end;

%% 打开完美恋人
handle(33115, Ps, [SubType]) ->
    #player_status{
        id = RoleId,
        sid = Sid,
        figure = Figure
    } = Ps,
    #figure{
        lv = Lv
    } = Figure,
    OpenLv = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_PERFECT_LOVER),
    case Lv >= OpenLv of
        false ->
            lib_server_send:send_to_sid(Sid, pt_331, 33115, [?LEVEL_LIMIT, SubType, 0, "", 0, [], [], [], []]);
        true ->
            case lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_PERFECT_LOVER, SubType) of
                true ->
                    mod_perfect_lover:open_perfect_lover(SubType, RoleId, 0, "");
                false ->
                    lib_server_send:send_to_sid(Sid, pt_331, 33115, [?ERRCODE(err331_act_closed), SubType, 0, "", 0, [], [], [], []])
            end
    end;

%% 完美恋人领取奖励
handle(33116, Ps, [SubType, WeddingType]) ->
    mod_perfect_lover:send_reward(SubType, Ps#player_status.id, WeddingType);

%% 砸蛋配置信息
handle(_Cmd = 33119, Player, []) ->
    #player_status{sid = Sid} = Player,
    lib_smashed_egg:send_cfg(Sid);

%% 砸蛋界面信息
handle(_Cmd = 33120, Player, [Type, SubType]) ->
    #player_status{id = RoleId, figure = #figure{lv = RoleLv}, last_login_time = LastLoginTime} = Player,
    mod_smashed_egg:send_act_info(Type, SubType, RoleId, RoleLv, LastLoginTime);

%% 砸蛋刷新
handle(_Cmd = 33121, Player, [Type, SubType]) ->
    #player_status{id = RoleId, figure = #figure{lv = RoleLv}} = Player,
    case catch mod_smashed_egg:check_refresh_egg(Type, SubType, RoleId, RoleLv) of
        {ok, free} -> %% 免费刷新
            mod_smashed_egg:refresh_egg(Type, SubType, RoleId, RoleLv);
        {ok, CostList} ->
            case lib_goods_api:cost_object_list_with_check(Player, CostList, smashed_egg_refresh, "") of
                {true, NewPlayer,_} ->
                    mod_smashed_egg:refresh_egg(Type, SubType, RoleId, RoleLv);
                {false, ErrorCode, NewPlayer} ->
                    lib_server_send:send_to_uid(RoleId, pt_331, 33100, [ErrorCode])
            end,
            {ok, NewPlayer};
        {false, ErrorCode} ->
            lib_server_send:send_to_uid(RoleId, pt_331, 33100, [ErrorCode]);
        Err ->
            ?ERR("smashed_egg_refresh err:~p", [Err]),
            lib_server_send:send_to_uid(RoleId, pt_331, 33100, [?ERRCODE(system_busy)])
    end;

%% 砸蛋
handle(_Cmd = 33122, Player, [Type, SubType, Index, AutoBuy]) when Index >= 0, Index < 9 ->
    #player_status{id = RoleId, figure = #figure{name = RoleName, lv = RoleLv}, last_login_time = LastLoginTime} = Player,
    SmashedType = ?IF(Index == 0, ?SMASHED_TYPE_ALL, ?SMASHED_TYPE_ONE),
    case catch mod_smashed_egg:check_smashed_egg(Type, SubType, RoleId, RoleLv, SmashedType, Index, LastLoginTime) of
        {ok, free, SmashedEggNum, UseFreeTimes} -> %% 免费砸蛋
            mod_smashed_egg:smashed_egg(Type, SubType, RoleId, RoleName, SmashedType, Index, SmashedEggNum, UseFreeTimes, AutoBuy, []);
        {ok, CostList, SmashedEggNum, UseFreeTimes} -> %% 花钱砸蛋
            Res = case AutoBuy == 1 of
                      true -> %% 自动购买
                          lib_goods_api:cost_objects_with_auto_buy(Player, CostList, smashed_egg, "");
                      false ->
                          case lib_goods_api:cost_object_list_with_check(Player, CostList, smashed_egg, "") of
                              {true, TmpNewPlayer,_} -> {true, TmpNewPlayer, CostList};
                              Other -> Other
                          end
                  end,
            case Res of
                {true, NewPlayer, RealCostList} -> %% 扣钱成功，开始砸蛋
                    mod_smashed_egg:smashed_egg(Type, SubType, RoleId, RoleName, SmashedType, Index, SmashedEggNum, UseFreeTimes, AutoBuy, RealCostList);
                {false, ErrorCode, NewPlayer} ->
                    lib_server_send:send_to_uid(RoleId, pt_331, 33122, [ErrorCode, []])
            end,
            {ok, NewPlayer};
        {false, ErrorCode} ->
            lib_server_send:send_to_uid(RoleId, pt_331, 33122, [ErrorCode, []]);
        Err ->
            ?ERR("smashed_egg err:~p", [Err]),
            lib_server_send:send_to_uid(RoleId, pt_331, 33122, [?ERRCODE(system_busy), []])
    end;

%% 领取累计奖励
handle(_Cmd = 33123, Player, [Type, SubType, Times]) ->
    #player_status{sid = Sid, id = RoleId, figure = #figure{lv = RoleLv}} = Player,
    NowTime = utime:unixtime(),
    case lib_custom_act_util:get_custom_act_open_info(Type, SubType) of
        #act_info{wlv = WorldLv, etime = Etime} = _ActInfo when NowTime < Etime ->
            case data_smashed_egg:get_cumulate_reward(Times, WorldLv) of
                #cumulate_reward_cfg{reward = RewardL} when RewardL =/= [] ->
                    case lib_goods_api:can_give_goods(Player, RewardL) of
                        true ->
                            mod_smashed_egg:receive_cumulate_reward(Type, SubType, RoleId, RoleLv, Times);
                        _ ->
                            lib_server_send:send_to_sid(Sid, pt_331, 33100, [?ERRCODE(err150_no_cell)])
                    end;
                _ ->
                    lib_server_send:send_to_sid(Sid, pt_331, 33100, [?ERRCODE(err331_no_act_reward_cfg)])
            end;
        false ->
            lib_server_send:send_to_sid(Sid, pt_331, 33100, [?ERRCODE(err331_act_closed)])
    end;
%% 查看砸蛋未领取的奖励
handle(_Cmd = 33124, Player, [Type, SubType]) ->
    #player_status{sid = Sid, id = RoleId} = Player,
    NowTime = utime:unixtime(),
    case lib_custom_act_util:get_custom_act_open_info(Type, SubType) of
        #act_info{wlv = _WorldLv, etime = Etime} when NowTime < Etime ->
            mod_smashed_egg:send_reward_info(RoleId, Type, SubType);
        false ->
            lib_server_send:send_to_sid(Sid, pt_331, 33100, [?ERRCODE(err331_act_closed)])
    end;
%% 一键领取砸蛋奖励
handle(_Cmd = 33125, Player, [Type, SubType, GoodsId]) ->
    #player_status{sid = Sid, id = RoleId} = Player,
    NowTime = utime:unixtime(),
    case lib_custom_act_util:get_custom_act_open_info(Type, SubType) of
        #act_info{wlv = _WorldLv, etime = Etime} = _ActInfo when NowTime < Etime ->
            mod_smashed_egg:receive_reward(RoleId, Type, SubType, GoodsId);
        false ->
            lib_server_send:send_to_sid(Sid, pt_331, 33100, [?ERRCODE(err331_act_closed)])
    end;

%% 满减折扣-信息
handle(Cmd = 33126, Player, [SubType]) ->
    Type = ?CUSTOM_ACT_TYPE_DISCOUNT_MALL,
    Info = lib_custom_act_do_discount_mall:get_discount_mall_info(Player, Type, SubType),
    {ok, Bin} = pt_331:write(Cmd, Info),
    lib_server_send:send_to_sid(Player#player_status.sid, Bin),
    ok;
%% 满减折扣-购买记录
handle(Cmd = 33127, Player, [SubType]) ->
    Type = ?CUSTOM_ACT_TYPE_DISCOUNT_MALL,
    Info = lib_custom_act_do_discount_mall:get_discount_mall_log(Player, Type, SubType),
    {ok, Bin} = pt_331:write(Cmd, [SubType, Info]),
    lib_server_send:send_to_sid(Player#player_status.sid, Bin),
    ok;
%% 满减折扣-抽奖
handle(Cmd = 33128, Player, [SubType]) ->
    Type = ?CUSTOM_ACT_TYPE_DISCOUNT_MALL,
    case lib_custom_act_do_discount_mall:discount_mall_lottery(Player, Type, SubType) of
        {false, Err} ->
            {ok, Bin} = pt_331:write(Cmd, [SubType, Err, 0]),
            lib_server_send:send_to_sid(Player#player_status.sid, Bin),
            ok;
        {true, NewPlayer, GoodsId} ->
            {ok, Bin} = pt_331:write(Cmd, [SubType, 1, GoodsId]),
            lib_server_send:send_to_sid(Player#player_status.sid, Bin),
            {true, NewPlayer}
    end;
%% 满减折扣-购买商品 pt_33129_[1,[{2,1},{3,1}],0,0]
handle(Cmd = 33129, Player, [SubType, _BuyList, DiscountId, AbDiscountId]) when _BuyList =/= [] ->
    Type = ?CUSTOM_ACT_TYPE_DISCOUNT_MALL,
    BuyList = lib_goods_util:merge_same_goods(_BuyList),
    case lib_custom_act_do_discount_mall:discount_mall_buy(Player, Type, SubType, BuyList, DiscountId, AbDiscountId) of
        {false, Err} ->
            {ok, Bin} = pt_331:write(Cmd, [Err, SubType]),
            lib_server_send:send_to_sid(Player#player_status.sid, Bin),
            ok;
        {true, NewPlayer} ->
            {ok, Bin} = pt_331:write(Cmd, [1, SubType]),
            lib_server_send:send_to_sid(Player#player_status.sid, Bin),
            {true, NewPlayer}
    end;
%% 满减折扣-抽奖转盘信息
handle(Cmd = 33130, Player, [SubType]) ->
    Type = ?CUSTOM_ACT_TYPE_DISCOUNT_MALL,
    GoodsList = lib_custom_act_do_discount_mall:ask_lottery_candidates(Type, SubType),
    {ok, Bin} = pt_331:write(Cmd, [SubType, GoodsList]),
    lib_server_send:send_to_sid(Player#player_status.sid, Bin),
    ok;

%%彩钻复制机
handle(33131,Player,[SubType])->
    lib_custom_act_loans:get_loans_info(SubType,Player),
    {ok,Player};

%%彩钻复制机-购买
handle(33132,Player,[SubType,Add])->
    NPlayer = lib_custom_act_loans:buy_loans(SubType,Add,Player),
    {ok,NPlayer};

handle(33133,Player,[SubType])->
    NPlayer = lib_custom_act_loans:fetch_loans(SubType,Player),
    {ok,NPlayer};

handle(33134, PS, [RankType, SubType, IsPublic]) ->
    #player_status{id = RoleId} = PS,
    mod_consume_rank_act:update_role_public(RankType, SubType, RoleId, IsPublic);

handle(33135, PS, [RankType, SubType]) ->
    mod_consume_rank_act:send_rank_list(RankType, SubType, PS#player_status.id);

%% 明日之礼：轮次信息
handle(_Cmd = 33136, Player, [SubType]) ->
    custom_act_hope_gift:get_round_data(Player, SubType),
    ok;

%% 明日之礼：领取返还
handle(_Cmd = 33137, Player, [SubType]) ->
    {Result, NewPlayer} =
    custom_act_hope_gift:get_hope_gift_return(Player, SubType),
    {ok, BinData} = pt_331:write(_Cmd, [Result, SubType]),
    lib_server_send:send_to_sid(Player#player_status.sid, BinData),
    {ok, NewPlayer};

%% 明日之礼：抽奖
handle(_Cmd = 33138, Player, [SubType, Num]) ->
    {Result, GotIdList, IsDailyDrawLimit, NewPlayer} =
    custom_act_hope_gift:hope_gift_draw(Player, SubType, Num),
    {ok, BinData} = pt_331:write(_Cmd, [Result, SubType, IsDailyDrawLimit, GotIdList]),
    lib_server_send:send_to_sid(Player#player_status.sid, BinData),
    {ok, NewPlayer};

%% 嗨点信息
handle(_Cmd = 33140, Player, [Type, SubType]) ->
    case lib_custom_act_api:is_open_act(Type, SubType) of
        true ->
            mod_hi_point:act_info(Type, SubType, Player#player_status.id);
        false ->
            lib_server_send:send_to_sid(Player#player_status.sid, pt_331, 33100, [?ERRCODE(err331_act_closed)])
    end;
%% 查询运营活动投资信息
handle(33141, Player, [SubType]) ->
    lib_custom_act_investment:send_invest_act_info(Player, SubType),
    {ok,Player};

%% 购买运营活动投资
handle(33142, Player, [SubType, Grade]) ->
    #player_status{id = RoleId} = Player,
    case lib_custom_act_investment:buy_investment(Player, SubType, Grade) of
        {ok,NewPlayer}->
            Res = ?SUCCESS,
            lib_custom_act_investment:send_invest_act_info(NewPlayer,SubType);
        {false,Res}->
            NewPlayer = Player
    end,
    {ok,Bin} = pt_331:write(33142,[Res,SubType,Grade]),
    lib_server_send:send_to_uid(RoleId,Bin),
    {ok,NewPlayer};

%%领取投资回报
handle(33144,Player,[SubType,Grade,Day])->
    #player_status{id = RoleId} = Player,
    case lib_custom_act_investment:fetch_invest_award(Player, SubType, Grade, Day) of
        {ok,NewPlayer}->
            Res = ?SUCCESS;
        {false,Res}->
            NewPlayer = Player
    end,
    {ok,Bin} = pt_331:write(33144,[Res,SubType,Grade,Day]),
    lib_server_send:send_to_uid(RoleId,Bin),
    {ok,NewPlayer};


%% 连续消费活动
handle(_Cmd = 33143, PS, [SubType]) ->
    lib_custom_act_do_continue_consume:send_info(PS, SubType);

handle(_Cmd = 33145, PS, [SubType]) ->
    custom_act_small_recharge:get_small_recharge_resign(PS, SubType),
    {ok,PS};

handle(_Cmd = 33146, PS, [SubType]) ->
    #player_status{sid=Sid}=PS,
    case custom_act_small_recharge:recharge_resign(PS, SubType) of
        {ok,NewPs}->
            Res = ?SUCCESS;
        {false,Res}->
            NewPs = PS
    end,
    {ok,Bin} = pt_331:write(33146,[Res,SubType]),
    lib_server_send:send_to_sid(Sid,Bin),
    {ok,NewPs};

%% 超值礼包时间戳
handle(_Cmd = 33148, PS, [SubType]) ->
    #player_status{id = RoleId, sid = Sid, overflow_gift = Maps, figure = #figure{lv = Lv}} = PS,
    case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_OVERFLOW_GIFTBAG, SubType) of
        #act_info{stime = STime, etime = Etime} ->
            case maps:get(SubType, Maps, false) of
                LvTime when LvTime >= STime, LvTime =< Etime ->
                    NewMap = Maps;
                _ ->
                    case lib_custom_act_util:keyfind_act_condition(?CUSTOM_ACT_TYPE_OVERFLOW_GIFTBAG, SubType, role_lv) of
                        {role_lv, CfgLv} when Lv >= CfgLv ->
                            NowTime = utime:unixtime(),
                            Sql = io_lib:format(<<"replace into overflow_gift(role_id, sub_type, lv_time) values (~p, ~p, ~p)">>, [RoleId, SubType, NowTime]),
                            db:execute(Sql),
                            LvTime = NowTime,
                            NewMap = maps:put(SubType, NowTime, Maps);
                        _ ->
                            LvTime = 0,
                            NewMap = Maps
                    end
            end,
            lib_server_send:send_to_sid(Sid, pt_331, 33148, [SubType, LvTime]),
            {ok, PS#player_status{overflow_gift = NewMap}};
        _ -> lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed))
    end;
%% 精品特卖时间戳
handle(_Cmd = 33149, PS, [SubType]) ->
    #player_status{id = RoleId, sid = Sid, spec_sell_act = Maps} = PS,
    case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_SPEC_SELL, SubType) of
        #act_info{stime = _STime} ->
            LvTime = maps:get(SubType, Maps, 0),
            lib_server_send:send_to_sid(Sid, pt_331, 33149, [SubType, LvTime]);
        _ -> lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed))
    end;

handle(_Cmd = 33150, Player, []) ->
    case lib_custom_act_util:get_open_subtype_list(?CUSTOM_ACT_TYPE_ACT_CAPSULE_TOYS) of
        [_|_] -> lib_capsule_toys:get_capsule_toys_cfg(Player); %% 有开启中的子类时返回数据
        _ -> ok
    end,
    {ok, Player};

%% 扭蛋寻宝
handle(_Cmd = 33151, Player, [SubType, DrawType]) ->
    #player_status{id = RoleId, sid = Sid} = Player,
    NowTime = utime:unixtime(),
    case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_ACT_CAPSULE_TOYS, SubType) of
        #act_info{
            stime = Stime,
            etime = Etime,
            wlv = Wlv
        } when NowTime >= Stime andalso NowTime =< Etime ->
            case lib_capsule_toys:capsule_toys(Player, SubType, DrawType, Wlv) of
                {true, RewardList, NewPS} ->
                    lib_server_send:send_to_sid(Sid, pt_331, 33151, [SubType, DrawType, RewardList]),
                    {ok, NewPS};
                {false, ErrCode} ->
                    lib_custom_act:send_error_code(RoleId, ErrCode),
                    {ok, Player}
            end;
        _ ->
            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed)),
            {ok, Player}
    end;

%% 烟花配置世界等级
handle(_Cmd = 33152, Player, [SubType]) ->
    #player_status{id = RoleId, sid = Sid} = Player,
    case lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_ACT_CAPSULE_TOYS, SubType) of
        true ->
            case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_ACT_CAPSULE_TOYS, SubType) of
                false -> lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed));
                #act_info{wlv = Wlv} ->
                    lib_server_send:send_to_sid(Sid, pt_331, 33152, [Wlv])
            end;
        false ->
            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed))
    end;

handle(33153,Player,[SubType])->
    #player_status{id = RoleID} = Player,
    lib_custom_act_slices:send_slice_info(RoleID,SubType),
    {ok,Player};

handle(33154,Player,[SubType,Grade])->
    #player_status{id = RoleID} = Player,
    lib_custom_act_slices:fetch_slice_award(RoleID,SubType,Grade),
    {ok,Player};

%% 活动红包可领取tips
handle(_Cmd = 33155, Player, [_SubType]) ->
    #player_status{id = RoleId} = Player,
    case lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_RED_ENVELOPES) of
        true ->
            mod_red_envelopes:send_red_point_info(?ACT_RED_ENVELOPES, 0, RoleId);
        false ->
            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed))
    end;

%% 活动红包列表
handle(_Cmd = 33156, Player, [_SubType]) ->
    #player_status{id = RoleId} = Player,
    case lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_RED_ENVELOPES) of
        true ->
            mod_red_envelopes:send_red_envelopes_list(?ACT_RED_ENVELOPES, 0, RoleId);
        false ->
            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed))
    end;

%% 使用红包道具发送红包
handle(_Cmd = 33157, Player, [_SubType, GoodsId, GoodsTypeId, _SplitNum]) ->
    #player_status{sid = Sid, id = RoleId} = Player,
    IsActOpen = lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_RED_ENVELOPES),
    TmpCfg = data_red_envelopes:get_goods_cfg(GoodsTypeId),
    Cfg = ?IF(is_record(TmpCfg, red_envelopes_goods_cfg), TmpCfg, #red_envelopes_goods_cfg{}),
    HasTimes = lib_red_envelopes:check_red_envelopes_times(?GOODS_RED_ENVELOPES, ?MOD_RED_ENVELOPES_ACT_GOODS, RoleId, GoodsTypeId),
    if
        is_record(TmpCfg, red_envelopes_goods_cfg) == false -> ErrCode = ?ERRCODE(missing_config);
        IsActOpen == false -> ErrCode = ?ERRCODE(err331_act_closed);
        Cfg#red_envelopes_goods_cfg.ownership_type =/= ?ACT_RED_ENVELOPES -> ErrCode = ?ERRCODE(err_config);
        HasTimes == false -> ErrCode = ?ERRCODE(err339_daily_times_no_enough);
        true ->
            GoodsStatus = lib_goods_do:get_goods_status(),
            GoodsNum = 1,
            #red_envelopes_goods_cfg{money = Money, min_num = SplitNum } = Cfg,
            case lib_goods_check:check_use_goods(Player, GoodsId, GoodsTypeId, GoodsNum, GoodsStatus) of
                {fail, ErrCode} -> skip;
                {ok, GoodsInfo} -> %% 物品
                    [NewStatus, _] = goods_del:delete_one(GoodsInfo, [GoodsStatus, GoodsNum]),
                    lib_goods_do:set_goods_status(NewStatus),
                    %% 日志
                    lib_log_api:log_throw(send_goods_red_envelopes, RoleId, GoodsId, GoodsTypeId, GoodsNum, 0, 0),
                    lib_goods_api:notify_client_num(RoleId, [GoodsInfo#goods{num = GoodsInfo#goods.num - GoodsNum}]),
                    ErrCode = ?SUCCESS,
                    MoneyList = lib_red_envelopes:get_rand_money_list(Money, SplitNum, ?FULL_MONEY_TYPE),
                    Args = [?RED_ENVELOPES_TYPE_GOODS, ?ACT_RED_ENVELOPES, 0, RoleId,
                        ?HAS_SEND, Money, MoneyList, SplitNum, GoodsTypeId, 0, "", []],
                    mod_red_envelopes:add_red_envelopes(Args),
                    lib_daily:increment(RoleId, ?MOD_RED_ENVELOPES, ?MOD_RED_ENVELOPES_ACT_GOODS, GoodsTypeId);
                _ -> ErrCode = ?FAIL
            end
    end,
    case is_integer(ErrCode) of
        true ->
            {ok, BinData1} = pt_331:write(33157, [ErrCode]),
            lib_server_send:send_to_sid(Sid, BinData1);
        _ -> skip
    end;

%% 打开红包
%%handle(33158, Player, [_SubType, RedEnvelopesId]) ->
%%    #player_status{id = RoleId} = Player,
%%    case lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_RED_ENVELOPES) of
%%        true ->
%%            mod_red_envelopes:open_red_envelopes(?ACT_RED_ENVELOPES, 0, RoleId, RedEnvelopesId);
%%        false ->
%%            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed))
%%    end;

%% 幸运鉴宝
handle(33159, Player, []) ->
    {ok, Bin} = lib_treasure_evaluation:get_te_all_cfg(),
    lib_server_send:send_to_sid(Player#player_status.sid, Bin);

%% 打开幸运鉴宝
handle(33160, Ps, [SubType]) ->
    #player_status{
        id = RoleId,
        figure    = Figure,
        te_status = TEStatus
    } = Ps,
    #figure{
        lv = Lv
    } = Figure,
    OpenLv = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_TREASURE_EVALUATION),
    case Lv >= OpenLv of
        true ->
            NowTime = utime:unixtime(),
            case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_TREASURE_EVALUATION, SubType) of
                #act_info{stime = Stime, etime = Etime} when NowTime >= Stime, NowTime < Etime ->
                    Code = ?SUCCESS,
                    LuckyNumMax = lib_daily:get_count_limit(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_TREASURE_EVALUATION,1),
                    {main_reward_id, MainRewardId} = lib_custom_act_util:keyfind_act_condition(?CUSTOM_ACT_TYPE_TREASURE_EVALUATION, SubType, main_reward_id),
                    BigRewardConIdList = data_treasure_evaluation:get_all_big_reward_id_list(MainRewardId),
                    {ChooseBigRewardId, LuckyNum, NewTEStatus} = lib_treasure_evaluation:get_te_lucky_choose_num(RoleId, SubType, Stime, Etime, TEStatus),
                    case length(BigRewardConIdList) of
                        1 ->
                            [BigRewardId|_] = BigRewardConIdList;
                        _ ->
                            BigRewardId = ChooseBigRewardId
                    end,
                    NewPs = Ps#player_status{te_status = NewTEStatus},
                    {ok, Bin} = pt_331:write(33160, [Code, SubType, BigRewardId, LuckyNum, LuckyNumMax]);
                _ ->
                    Code = ?ERRCODE(err331_act_closed),
                    NewPs = Ps,
                    {ok, Bin} = pt_331:write(33160, [Code, SubType, 0, 0, 0])
            end;
        false ->
            Code = ?LEVEL_LIMIT,
            NewPs = Ps,
            {ok, Bin} = pt_331:write(33160, [Code, SubType, 0, 0, 0])
    end,
    lib_server_send:send_to_uid(RoleId, Bin),
    {ok, NewPs};

%% 开始幸运鉴宝
handle(33161, Ps, [SubType, Type]) ->
    #player_status{
        id = RoleId,
        figure    = Figure,
        te_status = TEStatus
    } = Ps,
    #figure{
        name = _Name,
        lv = Lv,
        career = Career
    } = Figure,
    OpenLv = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_TREASURE_EVALUATION),
    case Lv >= OpenLv of
        false ->
            Code = ?LEVEL_LIMIT,
            NewChooseBigRewardId = 0,
            NewLuckyNum = 0,
            RewardIdList = [],
            NewPs = Ps;
        true ->
            NowTime = utime:unixtime(),
            case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_TREASURE_EVALUATION, SubType) of
                #act_info{stime = Stime, etime = Etime} when NowTime >= Stime, NowTime < Etime ->
                    case lib_goods_api:get_cell_num(Ps) > 0 of
                        false ->
                            Code = ?ERRCODE(err401_bag_cell_not_enough),
                            NewChooseBigRewardId = 0,
                            NewLuckyNum = 0,
                            RewardIdList = [],
                            NewPs = Ps;
                        true ->
                            {ChooseBigRewardId, OldLuckyNum, NewTEStatus} = lib_treasure_evaluation:get_te_lucky_choose_num(RoleId, SubType, Stime, Etime, TEStatus),
                            TempPs = Ps#player_status{te_status = NewTEStatus},
                            {main_reward_id, MainRewardId} = lib_custom_act_util:keyfind_act_condition(?CUSTOM_ACT_TYPE_TREASURE_EVALUATION, SubType, main_reward_id),
                            BigRewardConIdList = data_treasure_evaluation:get_all_big_reward_id_list(MainRewardId),
                            case length(BigRewardConIdList) of
                                1 ->
                                    NotChangeId = true,
                                    [BigRewardId|_] = BigRewardConIdList;
                                _ ->
                                    NotChangeId = false,
                                    BigRewardId = ChooseBigRewardId
                            end,
                            case BigRewardId of
                                0 ->
                                    Code = ?ERRCODE(err331_te_not_choose_big),
                                    NewChooseBigRewardId = 0,
                                    NewLuckyNum = 0,
                                    RewardIdList = [],
                                    NewPs = TempPs;
                                _ ->
                                    case Type of
                                        1 ->
                                            CostList = ?TeCostListOnce,
                                            Times = 1;
                                        _ ->
                                            CostList = ?TeCostListTen,
                                            Times = 10
                                    end,
                                    LuckyNumMax = lib_daily:get_count_limit(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_TREASURE_EVALUATION,1),
                                    RewardWeightList1 = data_treasure_evaluation:get_te_weight_list(MainRewardId),
                                    #te_main_reward_con{
                                        reward_type = RewardType1,
                                        goods_list = TBigGoodsList,
                                        weight = BigWeight
                                    } = data_treasure_evaluation:get_te_main_reward_con(MainRewardId, BigRewardId),
                                    BigGoodsList = lib_treasure_evaluation:get_reward_list(RewardType1, Career, TBigGoodsList),
                                    RewardWeightList = [{BigWeight, BigRewardId}|RewardWeightList1],
                                    F = fun(_No, {RewardIdList1, RewardList1, LuckNum1}) ->
                                        case LuckNum1 >= LuckyNumMax of
                                            true ->
                                                [RewardTuple|_] = BigGoodsList,
                                                {[BigRewardId|RewardIdList1], [RewardTuple|RewardList1], 0};
                                            false ->
                                                RewardConId = urand:rand_with_weight(RewardWeightList),
                                                case RewardConId =:= BigRewardId of
                                                    true ->
                                                        NewLuckNum2 = 0,
                                                        [RewardTuple | _] = BigGoodsList;
                                                    false ->
                                                        NewLuckNum2 = LuckNum1 + ?AddLuckNum,
                                                        RewardWeightCon = data_treasure_evaluation:get_te_weight_con(MainRewardId, RewardConId),
                                                        #te_reward_weight_con{
                                                            reward_type = RewardType2,
                                                            goods_list = TGoodsList
                                                        } = RewardWeightCon,
                                                        GoodsList = lib_treasure_evaluation:get_reward_list(RewardType2, Career, TGoodsList),
                                                        [RewardTuple | _] = GoodsList
                                                end,
                                                {[RewardConId|RewardIdList1], [RewardTuple|RewardList1], NewLuckNum2}
                                        end
                                    end,
                                    {RewardIdList, RewardList, NewLuckyNum} = lists:foldl(F, {[], [], OldLuckyNum}, lists:seq(1, Times)),
                                    case lib_goods_api:can_give_goods(TempPs, RewardList) of
                                        true ->
                                            case lib_goods_api:cost_objects_with_auto_buy(TempPs, CostList, treasure_evaluation, "") of
                                                {true, NewPs1, _} ->
                                                    Code = ?SUCCESS,
                                                    F1 = fun(RewardConId, NewChooseBigRewardId1) ->
                                                        case RewardConId =:= BigRewardId of
                                                            true ->
                                                                [{_GoodsType, BigGoodsTypeId, _BigGoodsNum} | _] = BigGoodsList,
                                                                _GoodsColor = data_goods:get_goods_color(BigGoodsTypeId),
                                                                % lib_chat:send_TV({all}, ?MOD_AC_CUSTOM, 10, [Name, RoleId, GoodsColor, BigGoodsTypeId, BigGoodsNum]),
                                                                0;
                                                            false ->
                                                                NewChooseBigRewardId1
                                                        end
                                                    end,
                                                    TNewChooseBigRewardId = lists:foldl(F1, ChooseBigRewardId, RewardIdList),
                                                    NewChooseBigRewardId = ?IF(NotChangeId, BigRewardId, TNewChooseBigRewardId),
                                                    NewPs2 = lib_goods_api:send_reward(NewPs1, RewardList, treasure_evaluation, 0),
                                                    NewPs = lib_treasure_evaluation:set_lucky_num(NewPs2, NewChooseBigRewardId, NewLuckyNum, SubType),
                                                    SCostList = util:term_to_string(CostList),
                                                    SRewardList = util:term_to_string(RewardList),
                                                    lib_log_api:log_treasure_evaluation(RoleId, Type, OldLuckyNum, NewLuckyNum, SCostList, SRewardList);
                                                {false, Code, NewPs} ->
                                                    NewChooseBigRewardId = 0
                                            end;
                                        _ ->
                                            Code = ?ERRCODE(err150_no_cell),
                                            NewChooseBigRewardId = 0,
                                            NewPs = TempPs
                                    end
                            end
                    end;
                _ ->
                    Code = ?ERRCODE(err331_act_closed),
                    NewChooseBigRewardId = 0,
                    NewLuckyNum = 0,
                    RewardIdList = [],
                    NewPs = Ps
            end
    end,
    {ok, Bin} = pt_331:write(33161, [Code, SubType, Type, NewChooseBigRewardId, NewLuckyNum, RewardIdList]),
    lib_server_send:send_to_uid(RoleId, Bin),
    {ok, NewPs};

%% 打开收集活动
handle(33162, _Ps, [_SubType]) ->
    ok;

%% 提交收集活动
handle(33163, _Ps, [_SubType, _PutType]) ->
    ok;

%% 打开充值消费活动
handle(33164, Ps, [SubType]) ->
    lib_custom_act_do_recharge_consume:send_info(Ps, SubType);

%% 打开幸运转盘活动
handle(33165, Ps, [_SubType]) ->
    % #player_status{
    %     id     = RoleId,
    %     figure = Figure
    % } = Ps,
    % #figure{
    %     lv = Lv
    % } = Figure,
    % OpenLv = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_LUCKY_WHEEL),
    % case Lv >= OpenLv of
    %     false ->
    %         {ok, Bin} = pt_331:write(33165, [?LEVEL_LIMIT, SubType, []]),
    %         lib_server_send:send_to_uid(RoleId, Bin);
    %     true ->
    %         case lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_LUCKY_WHEEL, SubType) of
    %             false ->
    %                 {ok, Bin} = pt_331:write(33165, [?ERRCODE(err331_act_closed), SubType, []]),
    %                 lib_server_send:send_to_uid(RoleId, Bin);
    %             true ->
    %                 mod_lucky_wheel:open_lucky_wheel(SubType, RoleId)
    %         end
    % end;
    {ok, Ps};
%% 进行幸运转盘
handle(33166, Ps, [_SubType]) ->
    % #player_status{
    %     id     = RoleId,
    %     figure = Figure
    % } = Ps,
    % #figure{
    %     name = Name,
    %     lv = Lv
    % } = Figure,
    % OpenLv = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_LUCKY_WHEEL),
    % case Lv >= OpenLv of
    %     false ->
    %         Code = ?LEVEL_LIMIT,
    %         LuckyRollId = 0,
    %         NewPs = Ps;
    %     true ->
    %         case lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_LUCKY_WHEEL, SubType) of
    %             false ->
    %                 Code = ?ERRCODE(err331_act_closed),
    %                 LuckyRollId = 0,
    %                 NewPs = Ps;
    %             true ->
    %                 %% 至少获得两种物品，所以至少要有两个格子
    %                 case lib_goods_api:get_cell_num(Ps) >= 2 of
    %                     false ->
    %                         Code = ?ERRCODE(err401_bag_cell_not_enough),
    %                         LuckyRollId = 0,
    %                         NewPs = Ps;
    %                     true ->
    %                         {need_goods, CostList} = lib_custom_act_util:keyfind_act_condition(?CUSTOM_ACT_TYPE_LUCKY_WHEEL, SubType, need_goods),
    %                         case lib_goods_api:cost_objects_with_auto_buy(Ps, CostList, lucky_wheel, "") of
    %                             {false, Code, NewPs} ->
    %                                 LuckyRollId = 0;
    %                             {true, NewPs1, _RealCostList} ->
    %                                 Code = ?SUCCESS,
    %                                 NotRollIdList = mod_lucky_wheel:get_not_roll_id_list(SubType, RoleId),
    %                                 RollWeightList1 = data_lucky_wheel:get_lw_weight_list(),
    %                                 RollWeightList = [{Weight, RollId}||{Weight, RollId} <- RollWeightList1, lists:member(RollId, NotRollIdList) =:= false],
    %                                 LuckyRollId = urand:rand_with_weight(RollWeightList),
    %                                 #lucky_wheel_reward_con{
    %                                     reward_list = LuckyRewardList,
    %                                     single_limit = SingleLimit,
    %                                     all_limit = AllLimit,
    %                                     if_chat = IfChat
    %                                 } = data_lucky_wheel:get_lucky_wheel_reward_con(LuckyRollId),
    %                                 {other_reward, OtherRewardList} = lib_custom_act_util:keyfind_act_condition(?CUSTOM_ACT_TYPE_LUCKY_WHEEL, SubType, other_reward),
    %                                 RewardList = LuckyRewardList ++ OtherRewardList,
    %                                 NewPs = lib_goods_api:send_reward(NewPs1, RewardList, lucky_wheel, 0),
    %                                 Args = [SubType, RoleId, Name, LuckyRollId, SingleLimit, AllLimit],
    %                                 mod_lucky_wheel:add_limit_times(Args),
    %                                 case IfChat of
    %                                     0 ->
    %                                         skip;
    %                                     _ ->
    %                                         [{_GoodsType, GoodsTypeId, GoodsNum}|_] = LuckyRewardList,
    %                                         lib_chat:send_TV({all}, ?MOD_AC_CUSTOM, 23, [Name, GoodsTypeId, GoodsNum])
    %                                 end,
    %                                 lib_log_api:log_lucky_wheel_do(RoleId, LuckyRollId, RewardList)
    %                         end
    %                 end
    %         end
    % end,
    % {ok, Bin} = pt_331:write(33166, [Code, SubType, LuckyRollId]),
    % lib_server_send:send_to_uid(RoleId, Bin),
    % {ok, NewPs};
    {ok, Ps};
%% 选择幸运鉴宝大奖
handle(33167, Ps, [SubType, BigRewardId]) ->
    #player_status{
        id        = RoleId,
        figure    = Figure,
        te_status = TEStatus
    } = Ps,
    #figure{
        lv = Lv
    } = Figure,
    OpenLv = lib_module:get_open_lv(?MOD_AC_CUSTOM, ?CUSTOM_ACT_TYPE_TREASURE_EVALUATION),
    case Lv >= OpenLv of
        false ->
            Code = ?LEVEL_LIMIT,
            NewPs = Ps;
        true ->
            NowTime = utime:unixtime(),
            case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_TREASURE_EVALUATION, SubType) of
                #act_info{stime = Stime, etime = Etime} when NowTime >= Stime, NowTime < Etime ->
                    {main_reward_id, MainRewardId} = lib_custom_act_util:keyfind_act_condition(?CUSTOM_ACT_TYPE_TREASURE_EVALUATION, SubType, main_reward_id),
                    BigRewardConIdList = data_treasure_evaluation:get_all_big_reward_id_list(MainRewardId),
                    IfBigId = lists:member(BigRewardId, BigRewardConIdList),
                    if
                        length(BigRewardConIdList) =:= 1 ->
                            Code = ?ERRCODE(err331_te_cant_choose_big),
                            NewPs = Ps;
                        IfBigId =:= false ->
                            Code = ?ERRCODE(err331_te_big_id_wrong),
                            NewPs = Ps;
                        true ->
                            {ChooseBigRewardId, _LuckyNum, NewTEStatus1} = lib_treasure_evaluation:get_te_lucky_choose_num(RoleId, SubType, Stime, Etime, TEStatus),
                            if
                                ChooseBigRewardId =/= 0 ->
                                    Code = ?ERRCODE(err331_te_not_choose_again),
                                    NewPs = Ps;
                                true ->
                                    Code = ?SUCCESS,
                                    #te_status{
                                        te_list = TEList
                                    } = NewTEStatus1,
                                    case lists:keyfind(SubType, #te_info.sub_type, TEList) of
                                        false ->
                                            NewTEInfo = #te_info{
                                                sub_type = SubType,
                                                choose_big_reward_id = BigRewardId
                                            };
                                        TEInfo ->
                                            NewTEInfo = TEInfo#te_info{
                                                choose_big_reward_id = BigRewardId
                                            }
                                    end,
                                    lib_treasure_evaluation:sql_treasure_evaluation(RoleId, NewTEInfo),
                                    NewTEList = lists:keystore(SubType, #te_info.sub_type, TEList, NewTEInfo),
                                    NewTEStatus = NewTEStatus1#te_status{
                                        te_list = NewTEList
                                    },
                                    NewPs = Ps#player_status{
                                        te_status = NewTEStatus
                                    }
                            end
                    end;
                _ ->
                    Code = ?ERRCODE(err331_act_closed),
                    NewPs = Ps
            end
    end,
    {ok, Bin} = pt_331:write(33167, [Code, SubType, BigRewardId]),
    lib_server_send:send_to_uid(RoleId, Bin),
    {ok, NewPs};

handle(33168,Player,[OpTy])->
    #player_status{id=RoleID}=Player,
    case lib_lucky_bag:vie_lucky_bag(OpTy,Player) of
        {false,LTime,Res}->
            {ErrorCodeInt, ErrorCodeArgs} = util:parse_error_code(Res),
            NewPs = Player,Grade=0;
        {ok,LTime,Grade,NewPs}->
            Res = ?SUCCESS,
            {ErrorCodeInt, ErrorCodeArgs} = util:parse_error_code(Res)
    end,
    {ok,Bin} = pt_331:write(33168,[ErrorCodeInt,ErrorCodeArgs,OpTy,Grade,LTime]),
    lib_server_send:send_to_uid(RoleID,Bin),
    {ok,NewPs};

handle(33169,Status,[BaseType,SubType])->
    lib_vie_rank:get_vie_ranks(BaseType,SubType,Status),
    {ok,Status};

%% 弹珠活动请求抽奖
handle(33179 = Cmd, Player, [SubType]) ->
    {ErrCode, Time, Key, NewPlayer} = custom_act_pellet:pellet_draw_request(Player, SubType),
    {ok, BinData} = pt_331:write(Cmd, [ErrCode, Time, Key]),
    lib_server_send:send_to_sid(Player#player_status.sid, BinData),
    case ErrCode =:= ?SUCCESS of
        true  ->
            {ok, NewPlayer};
        false ->
            ignore
    end;

%% 查询弹珠活动状态
handle(33180 = Cmd, Player, []) ->
    {Round, CurrCount, AwardStatusList} =
    custom_act_pellet:pellet_query_count_status(Player),
    {ok, BinData} = pt_331:write(Cmd, [Round, CurrCount, AwardStatusList]),
    lib_server_send:send_to_sid(Player#player_status.sid, BinData),
    ok;

%% 弹珠活动领取当前轮次次数奖励
handle(33181 = Cmd, Player, [Count]) ->
    {ErrCode, AwardId, NewPlayer} = custom_act_pellet:pellet_get_award(Player, Count),
    {ok, BinData} = pt_331:write(Cmd, [ErrCode, AwardId]),
    lib_server_send:send_to_sid(Player#player_status.sid, BinData),
    case ErrCode =:= ?SUCCESS of
        true  ->
            {ok, NewPlayer};
        false ->
            ignore
    end;

%% 查询活动某档次的状态信息（主要推送用，33104较重）
handle(33182, Player, [Type, SubType, _GradeId]) ->
    %% 由于之前已经存在的活动太多差异化处理，
    %% 这里暂时不做通用的请求的实现，直接转向33104请求的处理
    %% 33182仅在有需要的地方由服务端主动推送给前端
    handle(33104, Player, [Type, SubType]);

%% 弹珠抽奖日志查询
handle(33183, #player_status{sid = RoleSid}, [PageSize, PageNum]) ->
    custom_act_pellet_mgr:query_award_record(RoleSid, PageSize, PageNum),
    ok;

%% 抽奖结果提交
handle(33184 = Cmd, Player, [DrawResult, Sign]) ->
    {ErrCode, AwardId, NewPlayer} = custom_act_pellet:submit_draw_result(Player, DrawResult, Sign),
    {ok, BinData} = pt_331:write(Cmd, [ErrCode, AwardId]),
    lib_server_send:send_to_sid(Player#player_status.sid, BinData),
    case ErrCode =:= ?SUCCESS of
        true  ->
            {ok, NewPlayer};
        false ->
            ignore
    end;

%% 查询单个0元礼包
handle(33185, Player, [Type = ?CUSTOM_ACT_TYPE_FREE_GIFT, SubType]) ->
    zero_gift:send_personal_act_info(Player, Type, SubType);

%% 0元礼包购买
handle(33186, Player = #player_status{sid = Sid}, [Type, SubType, Grade]) ->
    {Reason, Time, Status, NewPlayer} =
    case zero_gift:personal_act_award(Player, Type, SubType, Grade) of
        {false, Rea} ->
            {Rea, 0, 0, Player};
        {ok, Player2, Status2, Time2} ->
            {?SUCCESS, Time2, Status2, Player2}
    end,
    {ok, BinData1} = pt_331:write(33186, [Reason, Type, SubType, Grade, Time, Status]),
    lib_server_send:send_to_sid(Sid, BinData1),
    {ok, NewPlayer};

%% 秒杀-打开秒杀界面
handle(33187, Player, [SubType]) ->
    Type = ?CUSTOM_ACT_TYPE_SECKILL,
    case lib_custom_act_api:is_open_act(Type, SubType) of
        true  ->
            seckill_center:ask_seckill_info(SubType, Player#player_status.sid, Player#player_status.id, Player#player_status.figure#figure.lv);
        false ->
            ignore
    end;

%% 秒杀-打开秒杀界面-各场次数据
handle(33188, Player, [SubType, Round]) ->
    Type = ?CUSTOM_ACT_TYPE_SECKILL,
    case lib_custom_act_api:is_open_act(Type, SubType) of
        true  ->
            seckill_center:ask_seckill_round_info(SubType, Player#player_status.sid, Player#player_status.id, Player#player_status.figure#figure.lv, Round);
        false ->
            ignore
    end;
%% 秒杀-购买记录
handle(33189, Player, [SubType]) ->
    Type = ?CUSTOM_ACT_TYPE_SECKILL,
    case lib_custom_act_api:is_open_act(Type, SubType) of
        true  ->
            seckill_center:ask_seckill_log(Player#player_status.sid);
        false ->
            ignore
    end;

%% 秒杀-抢购
handle(33191, Player, [SubType, GradeId]) ->
    case custom_act_seckill:buy_seckill(Player, SubType, GradeId) of
        {false, Error} ->
            {ok, Bin} = pt_331:write(33191, [GradeId, Error, 0]),
            lib_server_send:send_to_sid(Player#player_status.sid, Bin);
        _ ->
            ok
    end;
%% 秒杀-订阅
handle(33192, Player, [Status]) ->
    seckill_local:subscribe_seckill(Player#player_status.id, Status);

%% 预开启活动
handle(33195, Ps, []) ->
    #player_status{sid = Sid} = Ps,
    ActList = lib_custom_act_util:get_custom_act_will_open_list(),
    PackList = lib_custom_act:pack_custom_act_will_open_list(ActList),
    % ?PRINT("PackList~p~n",[PackList]),
    {ok, BinData} = pt_331:write(33195, [PackList]),
    lib_server_send:send_to_sid(Sid, BinData);

%% 打开祈愿主界面
handle(33196, Ps, []) ->
    lib_supplication:send_info(Ps);

%% 领取任务奖励
handle(33197, Ps, [GetTaskId]) ->
    lib_supplication:receive_reward(Ps, GetTaskId);

%% 更换奖励
handle(33198, Ps, [RewardIds]) ->
    lib_supplication:change_select_reward(Ps, RewardIds);

%% 祈愿
handle(33199, Ps, []) ->
    lib_supplication:supplication(Ps);

%% 打开重复充值领奖界面
handle(33201, PS, [SubType]) ->
    lib_custom_act_do_repeat_recharge_reward:send_info(PS, SubType);

%% 幸运轮盘信息查询
handle(33202, PS, [SubType, TurnType]) ->
    lib_lucky_turntable:send_act_info(PS, SubType, TurnType);

%% 幸运轮盘-转盘
handle(33203, PS, [SubType, TurnType, Skip]) ->
    lib_lucky_turntable:turn_table(PS, SubType, TurnType, Skip);

%% 祈愿任务状态
handle(33204, PS, []) ->
    lib_supplication:send_task_status(PS);

%% 每日目标界面
handle(33205, PS, [SubType]) ->
    lib_custom_act_do_daily_target:send_info(PS, SubType);

%% 成长积分-获取界面信息
handle(33206, PS, [SubType]) ->
    ActType = ?CUSTOM_ACT_TYPE_GROWTH_SCORE,
    case lib_custom_act_util:get_custom_act_open_info(ActType, SubType) of
        #act_info{} -> %% 活动开启中
            RwParam = lib_custom_act:make_rwparam(PS),
            mod_growth_score:act_info(PS#player_status.id, RwParam, SubType);
        _ ->
            lib_server_send:send_to_sid(PS#player_status.sid, pt_331, 33100, [?ERRCODE(err331_act_closed)])
    end;

%% 成长积分-领取奖励
handle(33207, PS, [SubType, RewardId]) ->
    #player_status{sid = Sid, id = RoleId, figure = #figure{lv = Lv}} = PS,
    ActType = ?CUSTOM_ACT_TYPE_GROWTH_SCORE,
    NeedLv =  lib_custom_act_util:get_act_open_lv(ActType, SubType),
    if
        Lv >= NeedLv ->
            case lib_custom_act_util:get_custom_act_open_info(ActType, SubType) of
                #act_info{} -> %% 活动开启中
                    RwParam = lib_custom_act:make_rwparam(PS),
                    mod_growth_score:recieve_reward(RoleId, RwParam, SubType, RewardId);
                _ ->
                    lib_server_send:send_to_sid(Sid, pt_331, 33100, [?ERRCODE(err331_act_closed)])
            end;
        true ->
            lib_server_send:send_to_sid(Sid, pt_331, 33100, [?ERRCODE(lv_limit)])
    end;

%% 欢乐许愿
handle(_Cmd = 33208, Player, [SubType, DrawType, BuyType]) ->
    #player_status{id = RoleId, sid = Sid} = Player,
    NowTime = utime:unixtime(),
    case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_JOY_WISH, SubType) of
        #act_info{
            stime = Stime,
            etime = Etime,
            wlv = Wlv
        } when NowTime >= Stime andalso NowTime =< Etime ->
            case lib_joy_wish_act:wish(Player, ?CUSTOM_ACT_TYPE_JOY_WISH, SubType, DrawType, Wlv, BuyType) of
                {true, RewardList, NewPS} ->
                    lib_server_send:send_to_sid(Sid, pt_332, 33208, [SubType, DrawType, RewardList]),
                    lib_draw_record:send_draw_reward_record_local(NewPS, ?CUSTOM_ACT_TYPE_JOY_WISH, SubType),
                    {ok, NewPS};
                {false, ErrCode} ->
                    lib_custom_act:send_error_code(RoleId, ErrCode),
                    {ok, Player}
            end;
        _ ->
            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed)),
            {ok, Player}
    end;

%% 欢乐许愿配置世界等级
handle(_Cmd = 33209, Player, [SubType]) ->
    #player_status{id = RoleId, sid = Sid} = Player,
    case lib_custom_act_api:is_open_act(?CUSTOM_ACT_TYPE_JOY_WISH, SubType) of
        true ->
            case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_JOY_WISH, SubType) of
                false -> lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed));
                #act_info{wlv = Wlv} ->
                    #player_status{joy_wish = #joy_wish{wish_times = JoyWishMaps}} = Player,
                    WishTimes = maps:get({?CUSTOM_ACT_TYPE_JOY_WISH, SubType}, JoyWishMaps, 0),
                    lib_server_send:send_to_sid(Sid, pt_332, 33209, [Wlv, WishTimes])
            end;
        false ->
            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed))
    end;

%% 本服定制活动 抽奖记录
handle(_Cmd = 33210, Player, [Type, SubType]) ->
    #player_status{id = RoleId} = Player,
    case lib_custom_act_api:is_open_act(Type, SubType) of
        true ->
            lib_draw_record:send_draw_reward_record_local(Player, Type, SubType);
        false ->
            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed))
    end;

%% 跨服定制活动 抽奖记录
handle(_Cmd = 33211, Player, [Type, SubType]) ->
    #player_status{id = RoleId} = Player,
    case lib_custom_act_api:is_open_act(Type, SubType) of
        true ->
            lib_draw_record:send_draw_reward_record_kf(Player, Type, SubType);
        false ->
            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed))
    end;

%% VIP特惠获取礼包价格信息
handle(_Cmd = 33212, Player, [SubType, Grade]) ->
    #player_status{id = RoleId, sid = Sid} = Player,
    NowTime = utime:unixtime(),
    case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_VIP_BAG_ONSALE, SubType) of
        #act_info{
            stime = Stime,
            etime = Etime
        } when NowTime >= Stime andalso NowTime =< Etime ->
            case lib_vip_bag_onsale:get_reward_price_info(Player, ?CUSTOM_ACT_TYPE_VIP_BAG_ONSALE, SubType, Grade) of
                {NormalPrice, Price, Percent} ->
                    lib_server_send:send_to_sid(Sid, pt_332, 33212, [SubType, Grade, NormalPrice, Price, Percent]),
                    % ?DEBUG("SubType:~p, Grade:~p, NormalPrice:~p, Price:~p, Percent:~p", [SubType, Grade, NormalPrice, Price, Percent]),
                    {ok, Player};
                {false,ErrCode} ->
                    lib_custom_act:send_error_code(RoleId, ErrCode),
                    {ok, Player}
            end;
        _ ->
            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed)),
            % ?DEBUG("ErrorCode:~p",[33212]),
            {ok, Player}
    end;

%% VIP特惠获取优惠价格
handle(_Cmd = 33213, Player, [SubType, Grade]) ->
    #player_status{id = RoleId, sid = Sid} = Player,
    NowTime = utime:unixtime(),
    case lib_custom_act_util:get_custom_act_open_info(?CUSTOM_ACT_TYPE_VIP_BAG_ONSALE, SubType) of
        #act_info{
            stime = Stime,
            etime = Etime
        } when NowTime >= Stime andalso NowTime =< Etime ->
            case lib_vip_bag_onsale:do_get_onsale_price(Player, ?CUSTOM_ACT_TYPE_VIP_BAG_ONSALE, SubType, Grade) of
                {Price, Percent, NewPS} ->
                    lib_server_send:send_to_sid(Sid, pt_332, 33213, [SubType, Grade, Price, Percent]),
                    % ?DEBUG("SubType:~p, Grade:~p, Price:~p, Percent:~p", [SubType, Grade, Price, Percent]),
                    {ok, NewPS};
                {false,ErrCode} ->
                    lib_custom_act:send_error_code(RoleId, ErrCode),
                    {ok, Player}
            end;
        _ ->
            lib_custom_act:send_error_code(RoleId, ?ERRCODE(err331_act_closed)),
            {ok, Player}
    end;

%% 幸运翻牌界面
handle(_Cmd = 33214, Player, [SubType]) ->
    lib_lucky_flop:send_info(Player, SubType);

%% 幸运翻牌选择奖励
handle(_Cmd = 33215, Player, [SubType, SelectList]) ->
    lib_lucky_flop:select_reward(Player, SubType, SelectList);

%% 幸运翻牌抽奖
handle(_Cmd = 33216, Player, [SubType]) ->
    lib_lucky_flop:draw(Player, SubType);

%% 幸运翻牌领取累计奖励
handle(_Cmd = 33217, Player, [SubType, Times]) ->
    lib_lucky_flop:recieve_reward(Player, SubType, Times);

%% 幸运翻牌重置奖励
handle(_Cmd = 33218, Player, [SubType]) ->
    lib_lucky_flop:reset_reward(Player, SubType);

%% 查询招财猫活动开放列表
handle(33219, Player, _) ->
    lucky_cat:send_lucky_cat_cfg(Player);

%% 查询单个招财猫活动信息
handle(33220, Player, [Type, SubType]) ->
    lucky_cat:send_lucky_cat_act_info(Player, Type, SubType);

%% 招财猫招财
handle(33221, Player, [Type, SubType]) ->
    #player_status{sid = Sid} = Player,
    case lucky_cat:lucky_cat_draw(Player, Type, SubType) of
        {ok, NewPlayer, NewTimes, Sort, Mult} ->
            Res = ?SUCCESS;
        {false,Res}->
            NewPlayer = Player,
            NewTimes  = 0,
            Sort      = 0,
            Mult      = 0
    end,
    {ok, BinData} = pt_332:write(33221, [Res,Type, SubType,NewTimes,Sort,Mult]),
    lib_server_send:send_to_sid(Sid, BinData),
    {ok, NewPlayer};

%% 招财猫招财记录
handle(33222, _Player = #player_status{sid = Sid}, [Type, SubType]) ->
    mod_custom_act_log:cast({send_lucky_cat_log, Type, SubType, Sid}),
    {ok,_Player};

%% 查询单个子类开服团购活动信息
handle(33223, #player_status{sid = Sid}, [SubType]) ->
    ActGradeList = group_buy_api:query_act_grade_list(SubType),
    {ok, BinData} = pt_332:write(33223, [SubType, ActGradeList]),
    lib_server_send:send_to_sid(Sid, BinData),
    ok;

%% 查询全员动员数据
handle(33225, Player, [SubType]) ->
    custom_act_mobilize:send_mobilize_task_info(Player, SubType),
    {ok,Player};

%% 任务完成 领取
handle(33226, Player = #player_status{sid = Sid}, [SubType, TaskTypeId, TaskId]) ->
    {
        Reason, NewPlayer
    } = case custom_act_mobilize:receive_mobilize_task_award(Player, SubType, TaskTypeId, TaskId) of
        {false, Rea} ->
            {Rea, Player};
        {ok, Player2} ->
            {?SUCCESS, Player2}
    end,
    {ok, BinData} = pt_332:write(33226, [SubType, Reason]),
    lib_server_send:send_to_sid(Sid, BinData),
    {ok, NewPlayer};

%% 每日奖励 领取
handle(33227,Player,[SubType, StartDay, EndDay])->      %% todo
    #player_status{sid = Sid} = Player,
    {
        Reason, NewPlayer
    } = case custom_act_mobilize:receive_mobilize_day_award(Player, SubType, StartDay, EndDay) of
        {false, Rea} ->
            {Rea, Player};
        {ok, Player2} ->
            {?SUCCESS, Player2}
    end,
    {ok, BinData} = pt_332:write(33227, [SubType, Reason]),
    lib_server_send:send_to_sid(Sid, BinData),
    {ok, NewPlayer};

%% 超级富豪信息
handle(33228, Player, [SubType]) ->
    #player_status{id = RoleId, sid = Sid} = Player,
    custom_act_mono_poly:role_monopoly_info(RoleId, Sid, SubType),
    ok;

%% 超级富豪操作
handle(33229, Player, [SubType, DiceType]) ->
    custom_act_mono_poly:dice_action(Player, SubType, DiceType);

%% 超级富豪补签
handle(33230, Player, [SubType]) ->
    custom_act_mono_poly:dice_reissue(Player, SubType);

%% 超级富豪 领取圈数奖励
handle(33231, Player, [SubType, Round]) ->
    custom_act_mono_poly:get_round_reward(Player, SubType, Round);

%% 万物宝典信息
handle(33232, Player, [SubType]) ->
    custom_act_contract:contract_info(Player, SubType);

%% 万物宝典任务信息
handle(33233, Player, [SubType]) ->
    custom_act_contract:contract_task_info(Player, SubType);

%% 万物宝典 积分奖励领取 1单日|2单周
handle(33234, Player, [SubType, Type, TaskId]) ->
    custom_act_contract:contract_score_reward(Player, SubType, Type, TaskId);

%% 万物宝典 等级奖励领取 1特定等级|2所有等级
handle(33236, Player, [SubType, Type, Lv]) ->
    custom_act_contract:contract_lv_reward(Player, SubType, Type, Lv);

%% 万物宝典 购买尊享宝典
%% Discount 0不使用折扣卡|1使用折扣卡  Type 0普通尊享|1王牌尊享
handle(33237, Player, [SubType, Discount, Type]) ->
    custom_act_contract:buy_ace_contract(Player, SubType, Discount, Type);

%% 幻魔宝典信息
handle(33238, Player, [SubType]) ->
    custom_act_phantom:phantom_info(Player, SubType);

%% 幻魔宝典 等级奖励领取 1特定等级|2所有等级
handle(33239, Player, [SubType, Type, Lv]) ->
    custom_act_phantom:phantom_lv_reward(Player, SubType, Type, Lv);

%% 幻魔宝典 购买王牌宝典
handle(33240, Player, [SubType]) ->
    custom_act_phantom:buy_ace_phantom(Player, SubType);

%% 幻魔宝典 奖励信息
handle(33241, Player, [SubType]) ->
    custom_act_phantom:phantom_reward_info(Player, SubType);

%% 幻魔宝典 任务信息
handle(33242, Player, [SubType]) ->
    custom_act_phantom:phantom_task_info(Player, SubType);

%% 幸运轮盘-记录展示
handle(33243, Player, [SubType, TurnType]) ->
    #player_status{id = RoleId} = Player,
    mod_lucky_turntable:send_records(RoleId, SubType, TurnType);

%% 刮刮卡-刮卡信息
handle(33244, Player, [SubType]) ->
    scratch_card:get_scratch_card_info(Player, SubType);

%% 刮刮卡-刮卡
handle(33245, Player, [SubType, Option, Pos]) ->
    scratch_card:scratch_card(Player, SubType, Option, Pos);

%% 刮刮卡-抽奖信息
handle(33246, Player, [SubType]) ->
	scratch_card:get_draw_info(Player, SubType);

%% 刮刮卡-抽奖
handle(33247, Player, [SubType]) ->
    scratch_card:score_draw(Player, SubType);

%% 刮刮卡-刷新卡片
handle(33248, Player, [SubType]) ->
    scratch_card:refresh_scratch_card(Player, SubType);

%% 刮刮卡-推送刮卡大奖传闻
handle(33249, Player, [SubType]) ->
    scratch_card:send_scratch_tv(Player, SubType);

%% 惊喜红包-基础信息
handle(33250, Player, [SubType]) ->
    surprise_red_packet:send_red_packet_info(Player, ?CUSTOM_ACT_TYPE_SUP_RED_PACKET, SubType);

%% 惊喜红包-抽取奖励
handle(33251, Player, [SubType]) ->
    surprise_red_packet:draw_red_packet(Player, SubType);

%% 惊喜红包-领取奖励
handle(33252, Player, [SubType]) ->
    surprise_red_packet:receive_red_packet(Player, SubType);

%% 惊喜红包-全服记录
handle(33253, #player_status{sid = Sid} = _Player, [SubType]) ->
    mod_custom_act_log:cast({send_red_packet_log, ?CUSTOM_ACT_TYPE_SUP_RED_PACKET, SubType, Sid}),
    ok;

%% 惊喜红包-领取宝箱奖励
handle(33254, Player, [SubType]) ->
	surprise_red_packet:receive_box(Player, SubType);

%% 塔罗牌
handle(33255, Player, [SubType]) ->
    custom_act_tarot:get_tarot_info(Player, SubType);

%% 翻塔罗牌
handle(33256, Player, [SubType, PosId]) ->
    custom_act_tarot:get_tarot_reward(Player, SubType, PosId);

%% 重置塔罗牌
handle(33257, Player, [SubType]) ->
    custom_act_tarot:refresh_tarot_info(Player, SubType);

%% 塔罗牌日志
handle(33258, Player, [SubType]) ->
    custom_act_tarot:get_tarot_log(Player, SubType);

%% 阶段奖励-商城商品信息
handle(33260, Player, [SubType]) ->
    phase_exchange:send_phase_exchange_goods(Player, SubType);

%% 阶段奖励-商品兑换
handle(33261, Player, [SubType, Phase, GradeId, ExchangeTimes]) ->
    phase_exchange:exchange_goods(Player, SubType, Phase, GradeId, ExchangeTimes);

%% 阶段奖励-查询/领取阶段开启奖励
handle(33262, Player, [SubType, Phase, Option]) ->
    phase_exchange:open_phase_reward(Player, SubType, Phase, Option);

%% 冒险征程-任务信息
handle(33263, Player, [SubType]) ->
    custom_act_adventure:adventure_task_info(Player#player_status.id, SubType);

%% 冒险征程-觅宝
handle(33264, Player, [SubType, LotteryType]) ->
    custom_act_adventure:lottery(Player, SubType, LotteryType);

%% 冒险征程-嗨点信息
handle(33265, Player, [SubType]) ->
    custom_act_adventure:send_task_info(Player, SubType);

%% 黑白棋-总奖池信息
handle(33266, Player, [SubType]) ->
    case custom_act_reversi:get_pool_info(Player, SubType) of
        {false, ErrCode} ->
            Sid = Player#player_status.sid,
            lib_server_send:send_to_sid(Sid, pt_332, 33266, [ErrCode, SubType, 0, 0, 0, []]);
        _ -> skip
    end;

%% 黑白棋-抽奖
handle(33267, Player, [SubType]) ->
    case custom_act_reversi:lottery(Player, SubType) of
        {true, NewPlayer} -> {true, NewPlayer};
        {false, ErrCode} ->
            Sid = Player#player_status.sid,
            lib_server_send:send_to_sid(Sid, pt_332, 33267, [ErrCode, SubType, 0, 0, []])
    end;

%% 黑白棋-奖池信息
handle(33268, Player, [SubType]) ->
    case custom_act_reversi:get_lottery_info(Player, SubType) of
        {false, ErrCode} ->
            Sid = Player#player_status.sid,
            lib_server_send:send_to_sid(Sid, pt_332, 33268, [ErrCode, SubType, []]);
        _ -> skip
    end;

%% 黑白棋-小奖池信息
handle(33269, Player, [SubType]) ->
    case custom_act_reversi:get_display_info(Player, SubType) of
        {false, ErrCode} ->
            Sid = Player#player_status.sid,
            lib_server_send:send_to_sid(Sid, pt_332, 33269, [ErrCode, SubType, 0, util:term_to_string([]), util:term_to_string([]), []]);
        _ -> skip
    end;

%% 黑白棋-刷新奖池
handle(33270, Player, [SubType, IsChoose]) ->
    case custom_act_reversi:refresh_pool(Player, SubType, IsChoose) of
        {true, NewPlayer} -> {true, NewPlayer};
        {false, ErrCode} ->
            Sid = Player#player_status.sid,
            lib_server_send:send_to_sid(Sid, pt_332, 33270, [ErrCode, SubType, 0, []])
    end;

%% 眼疾手快拼图-基础信息
handle(33271, Player, [SubType]) ->
    puzzle:puzzle_base_info(Player, SubType);

%% 眼疾手快拼图-拼图信息/开始拼图
handle(33272, Player, [SubType, Option]) ->
    case Option of
        1 -> puzzle:puzzle_card_info(Player, SubType);
        2 -> puzzle:start_puzzle(Player, SubType);
        _ -> ok
    end;

%% 眼疾手快拼图-替换图片
handle(33273, Player, [SubType, ChangeList]) ->
    puzzle:change_card(Player, SubType, ChangeList);

%% 眼疾手快拼图-奖励信息
handle(33278, Player, [SubType]) ->
    puzzle:reward_info(Player, SubType);

%% 查询单个作战
handle(33275, Player, [SubType]) ->
    custom_act_days_plan:send_days_plan_info(Player, SubType);

%% 作战任务完成
handle(33276, Player, [SubType, Day, TaskType, TaskId]) ->
    #player_status{sid = Sid}=Player,
    {
        Reason, NewPlayer
    } = case custom_act_days_plan:days_plan_task_award(Player, SubType, Day, TaskType, TaskId) of
        {false, Rea} ->
            {Rea, Player};
        {ok, Player2} ->
            {?SUCCESS, Player2}
    end,
    {ok, BinData} = pt_332:write(33276, [SubType, Reason]),
    lib_server_send:send_to_sid(Sid, BinData),
    {ok, NewPlayer};

%% 作战物资购买
handle(33277, Player, [ SubType, Day]) ->
    #player_status{sid = Sid}=Player,
    {
        Reason, NewPlayer, BuyTimes, AwardList
    } = case custom_act_days_plan:days_plan_task_buy(Player, SubType, Day) of
        {false, Rea} ->
            {Rea, Player, 0, []};
        {ok, Player2, BuyTimes2, AwardList2} ->
            {?SUCCESS, Player2, BuyTimes2, AwardList2}
    end,
    Data = [SubType, Reason, Day, BuyTimes, AwardList],
    {ok, BinData} = pt_332:write(33277, Data),
    lib_server_send:send_to_sid(Sid, BinData),
    {ok, NewPlayer};

%% 抽奖树-基本信息
handle(33280, Player, [SubType]) ->
    case custom_act_tree_lottery:get_base_info(SubType) of
        Info = [_|_] ->
            {ok, BinData} = pt_332:write(33280, Info),
            lib_server_send:send_to_sid(Player#player_status.sid, BinData);
        _ ->
            ok
    end,
    ok;

%% 抽奖树-抽奖-单抽/10连
handle(33281, Player, [SubType, Kind]) ->
    case custom_act_tree_lottery:lottery(Player, SubType, Kind) of
        {ok, NewPlayer, GoodsList} ->
            {ok, BinData} = pt_332:write(33281, [1, SubType, Kind, GoodsList]),
            lib_server_send:send_to_sid(Player#player_status.sid, BinData),
            handle(33280, NewPlayer, [SubType]),
            {ok, NewPlayer};
        {false, Error} ->
            {ok, BinData} = pt_332:write(33281, [Error, SubType, Kind, []]),
            lib_server_send:send_to_sid(Player#player_status.sid, BinData),
            ok
    end;

%% 领取积分奖励
handle(33282, Player, [SubType]) ->
    case custom_act_tree_lottery:get_score_reward(Player, SubType) of
        {ok, NewPlayer} ->
            {ok, BinData} = pt_332:write(33282, [1, SubType]),
            lib_server_send:send_to_sid(Player#player_status.sid, BinData),
            handle(33280, NewPlayer, [SubType]),
            {ok, NewPlayer};
        {false, Error} ->
            {ok, BinData} = pt_332:write(33281, [Error, SubType]),
            lib_server_send:send_to_sid(Player#player_status.sid, BinData),
            ok
    end;

%% 通行证-活动信息
handle(33283, Player, [ActType, SubType]) ->
    if
        ActType == ?CUSTOM_ACT_TYPE_PERMIT_LOGIN -> permit_login:permit_info(Player, SubType);
        ActType == ?CUSTOM_ACT_TYPE_PERMIT_ACTIVE -> permit_active:permit_info(Player, SubType);
        true -> skip
    end,
    {ok, Player};

%% 活跃通行证-奖励领取
handle(33284, Player, [SubType]) ->
    case permit_active:receive_reward(Player, SubType) of
        {ok, NewPlayer} -> skip;
        _ -> NewPlayer = Player
    end,
    {ok, NewPlayer};

%% 通行证-购买王牌宝典
handle(33285, Player, [ActType, SubType]) ->
    Result =
        if
            ActType == ?CUSTOM_ACT_TYPE_PERMIT_LOGIN -> permit_login:buy_ace_permit(Player, SubType);
            ActType == ?CUSTOM_ACT_TYPE_PERMIT_ACTIVE -> permit_active:buy_ace_permit(Player, SubType);
            true -> skip
        end,
    case Result of
        {ok, NewPlayer} -> {ok, NewPlayer};
        _ -> {ok, Player}
    end;

%% 通行证-奖励信息
handle(33286, Player, [ActType, SubType]) ->
    if
        ActType == ?CUSTOM_ACT_TYPE_PERMIT_LOGIN -> permit_login:reward_info(Player, SubType);
        ActType == ?CUSTOM_ACT_TYPE_PERMIT_ACTIVE -> permit_active:reward_info(Player, SubType);
        true -> skip
    end,
    {ok, Player};

%% 登录通行证-奖励领取
handle(33287, Player, [SubType, GradeId]) ->
    case permit_login:receive_reward(Player, GradeId, SubType) of
        {ok, NewPlayer} when is_record(NewPlayer, player_status) -> {ok, NewPlayer};
        _ -> {ok, Player}
    end;

%% 登录通行证-补签
handle(33288, Player, [SubType, GradeId]) ->
    case permit_login:register_login(Player, GradeId, SubType) of
        {ok, NewPlayer} when is_record(NewPlayer, player_status) -> {ok, NewPlayer};
        {false, Errcode} ->
            {ok, BinData} = pt_332:write(33288, [Errcode, SubType, GradeId, 0]),
            lib_server_send:send_to_sid(Player#player_status.sid, BinData),
            {ok, Player}
    end;

%% 万物宝典-购买等级
handle(33290, Player, [StartLv, EndLv, SubType]) ->
    custom_act_contract:buy_contract_lv(Player, StartLv, EndLv, SubType);

%% 合成机-提问&反馈判断
handle(33292, Player, [SubType, ChatType, Id, RoleId1]) ->
    #player_status{id = RoleId2, sid = Sid} = Player,
    if ChatType == 0 andalso RoleId1 =/= RoleId2 ->
            lib_server_send:send_to_sid(Sid, pt_332, 33292, [?FAIL, SubType, ChatType, Id, RoleId1]);
        ChatType == 1 andalso RoleId1 == RoleId2 ->
            lib_server_send:send_to_sid(Sid, pt_332, 33292, [?ERRCODE(err331_cannot_answer_yourself), SubType, ChatType, Id, RoleId1]);
        true ->
            custom_act_printer_draw:check_formula(SubType, RoleId1, RoleId2, ChatType, Id)
    end,
    ok;

%% 合成机-收藏
handle(33293, Player, [SubType, Type, Id]) ->
    printer_draw:collect(Player#player_status.id, SubType, Type, Id);

%% 合成机-查看收藏
handle(33294, Player, [SubType]) ->
    custom_act_printer_draw:my_collect(Player, SubType);

%% 合成机-合成
handle(33295, Player, [SubType, GoodsList]) ->
    custom_act_printer_draw:composite(Player, SubType, GoodsList);

%% 合成机-获取配方
handle(33296, Player, [SubType]) ->
    custom_act_printer_draw:get_formula(Player, SubType);

%% 合成机-查看发明家
handle(33297, Player, [SubType]) ->
    printer_draw:get_achieve(Player#player_status.id, SubType);

%% 合成机-询问cd
handle(33299, Player, [SubType]) ->
    printer_draw:get_chat_cd(Player#player_status.id, SubType);

%% 自选扭蛋-奖励信息
handle(33600, Player, [SubType]) ->
    select_capsule_egg:capsule_egg_info(Player, SubType);

%% 自选扭蛋-选择/取消奖励
handle(33601, Player, [SubType, Option, RewardId]) ->
    case Option of
        1 ->
            select_capsule_egg:select_capsule_egg(Player, SubType, RewardId);
        2 ->
            select_capsule_egg:cancel_capsule_egg(Player, SubType, RewardId);
        _ ->
            {ok, Player}
    end;

%% 自选扭蛋-重置奖励
handle(33602, Player, [SubType]) ->
    select_capsule_egg:reset_reward(Player, SubType);

%% 自选扭蛋-抽取奖励
handle(33604, Player, [SubType, SelectList]) ->
    select_capsule_egg:quick_select_capsule_egg(Player, SubType, SelectList);

%% 自选扭蛋-抽取奖励
handle(33603, Player, [SubType]) ->
    select_capsule_egg:draw_reward(Player, SubType);

%% 自选扭蛋-确认奖励
handle(33605, Player, [SubType]) ->
    select_capsule_egg:ensure_reward(Player, SubType);

%% 获取定制活动通用红点礼包信息
handle(_Cmd = 33611, Player, [Type, SubType]) ->
    lib_custom_act:ask_act_red_gift_status(Player, Type, SubType);

%% 领取通用红点礼包奖励
handle(_Cmd = 33612, Player, [Type, SubType, GradeId]) ->
    lib_custom_act:receive_red_gift_reward(Player, Type, SubType, GradeId);

%% 一键领取奖励
handle(Cmd = 33613, Player, [Type, SubType]) ->
    case lib_custom_act_dispatcher:auto_receive_reward(Player, Type, SubType) of
        {false, Error} ->
            {ok, Bin} = pt_336:write(Cmd, [Type, SubType, Error]),
            lib_server_send:send_to_sid(Player#player_status.sid, Bin),
            ok;
        {true, NewPlayer} ->
            {ok, Bin} = pt_336:write(Cmd, [Type, SubType, 1]),
            lib_server_send:send_to_sid(Player#player_status.sid, Bin),
            lib_custom_act:ask_reward_status(NewPlayer, Type, SubType),
            {true, NewPlayer};
        _ ->
            ok
    end;

handle(_Cmd, _Player, _Data) ->
    {error, "pp_custom_act no match~n"}.
