%% ---------------------------------------------------------------------------
%% @doc pp_guild.erl

%% @author  hjh
%% @email  hejiahua@163.com
%% @since  2016-12-15
%% @deprecated 公会协议处理
%% ---------------------------------------------------------------------------
-module(pp_guild).
-export([handle/3]).

-include("server.hrl").
-include("common.hrl").
-include("guild.hrl").
-include("errcode.hrl").
-include("role.hrl").
-include("daily.hrl").
-include("scene.hrl").
-include("def_event.hrl").
-include("rec_event.hrl").
-include("figure.hrl").
-include("team.hrl").
-include("goods.hrl").
-include("def_goods.hrl").
-include("sql_guild.hrl").
-include("def_module.hrl").
-include("def_daily.hrl").
-include("def_fun.hrl").
-include("predefine.hrl").

%% 公会列表界面
handle(40001, Status, [GuildName, Filter, PageSize, PageNo]) ->
    #player_status{id=RoleID}=Status,
    mod_guild:search_guild_list(RoleID, GuildName, Filter, PageSize, PageNo),
    {ok,Status};

%% 申请加入公会
handle(40002, Status, [GuildId]) ->
    #player_status{
        id = RoleID,
        figure = #figure{lv = Lv},
        sid = Sid, guild = GuildStatus
    } = Status,
    #status_guild{id = MyGuildId, leave_time=LeaveTime} = GuildStatus,
    NeedLv = data_guild:get(apply_join_guild_lv),
    NeedLeaveTime = data_guild:get(leave_again_apply),
    AcCheck = lib_mutex_check:check_apply_guild(Status),
    Utime = utime:unixtime(),
    if
        MyGuildId > 0 -> lib_guild:send_error_code(Sid, ?ERRCODE(err400_on_guild_not_to_apply));
        Lv < NeedLv -> lib_guild:send_error_code(Sid, ?ERRCODE(err400_not_enough_lv_to_apply_join_guild));
        LeaveTime>0 andalso LeaveTime + NeedLeaveTime > Utime -> lib_guild:send_error_code(Sid, ?ERRCODE(err400_leave_again_apply));
        AcCheck =/= true ->
            {false, Err} = AcCheck,
            lib_guild:send_error_code(Sid, Err);
        true ->
            RoleInfoMap = lib_guild:make_role_map(Status),
            mod_guild:apply_join_guild(RoleID, RoleInfoMap, GuildId)
    end,
    {ok,Status};

%% 批量申请
handle(40003, Status, _) ->
    #player_status{
        id = RoleID, figure = #figure{lv = Lv},
        sid = Sid, guild = GuildStatus
    } = Status,
    #status_guild{id = GuildId, leave_time=LeaveTime} = GuildStatus,
    NeedLv = data_guild:get(apply_join_guild_lv),
    NeedLeaveTime = data_guild:get(leave_again_apply),
    AcCheck = lib_mutex_check:check_apply_guild(Status),
    Utime = utime:unixtime(),
    if
        GuildId > 0 -> lib_guild:send_error_code(Sid, ?ERRCODE(err400_on_guild_not_to_apply));
        Lv < NeedLv -> lib_guild:send_error_code(Sid, ?ERRCODE(err400_not_enough_lv_to_apply_join_guild));
        LeaveTime>0 andalso LeaveTime + NeedLeaveTime > Utime -> lib_guild:send_error_code(Sid, ?ERRCODE(err400_leave_again_apply));
        AcCheck =/= true ->
            {false, Err} = AcCheck,
            lib_guild:send_error_code(Sid, Err);
        true ->
            RoleInfoMap = lib_guild:make_role_map(Status),
            mod_guild:apply_join_guild_multi(RoleID, RoleInfoMap)
    end,
    {ok,Status};

%% 创建公会
handle(40004, Status, [OpTy,GuildName,Flag]) ->
    {ok, NStatus} = lib_guild:create_guild(Status, OpTy, GuildName,Flag),
    {ok, NStatus};

%% 获取公会信息界面-基础信息
handle(40005, Status, []) ->
    #player_status{
        id = RoleID,
        guild = #status_guild{id = GuildId}
    } = Status,
    case GuildId == 0 of
        true -> skip;
        false ->
            mod_guild:send_guild_info(RoleID, GuildId, 0)
    end;

%% 获取公会信息界面-成员列表
handle(40006, Player, [PageSize, PageNo]) ->
    #player_status{id = RoleID, guild = #status_guild{id = GuildId}} = Player,
    case GuildId == 0 of
        true -> skip;
        false -> mod_guild:send_guild_member_short_info(RoleID, GuildId, PageSize, PageNo, 0, 0, 0, 0)
    end;

%% 主动退出公会
handle(40007, #player_status{sid = Sid} = Player, []) ->
    #player_status{id = RoleID, guild = #status_guild{id = GuildId}} = Player,
    case GuildId == 0 of
        true -> skip;
        false ->
            case lib_mutex_check:check_quit_guild(Player) of
                {false, ErrorCode} -> lib_server_send:send_to_sid(Sid, pt_400, 40007, [ErrorCode]);
                true -> mod_guild:quit_guild(RoleID)
            end
    end;

%% 申请列表
handle(40008, Player, []) ->
    #player_status{id = RoleId, guild = #status_guild{id = GuildId}} = Player,
    case GuildId == 0 of
        true -> skip;
        false -> mod_guild:send_guild_apply_list(RoleId, GuildId)
    end;

%% 审批加入公会的玩家
handle(40009, Player, [ApplyRoleId, Type]) ->
    #player_status{id = RoleId} = Player,
    case lib_role:get_role_show(ApplyRoleId) of
        [] -> skip;
        RoleShow ->
            ApplyRoleInfoMap = lib_guild:make_role_map(RoleShow),
            mod_guild:approve_guild_apply(RoleId, ApplyRoleId, ApplyRoleInfoMap, Type)
    end;

%% 审批设置界面
handle(40010, Player, []) ->
    #player_status{id = RoleId, guild = #status_guild{id = GuildId}} = Player,
    case GuildId == 0 of
        true -> skip;
        false -> mod_guild:send_approve_setting_view(RoleId, GuildId)
    end;

%% 设置审批
handle(40011, Player, [ApproveType, AutoApproveLv, AutoApprovePower]) ->
    #player_status{id = RoleId, guild = #status_guild{id = GuildId}} = Player,
    IsArrpoveTypeRight = lists:member(ApproveType, [?APPROVE_TYPE_AUTO, ?APPROVE_TYPE_MANUAL]),
    if
        IsArrpoveTypeRight == false -> ErrorCode = ?ERRCODE(err400_approve_type_error);
        GuildId =< 0 -> ErrorCode = ?ERRCODE(err400_not_on_guild_to_modify_approve);
        AutoApproveLv < 0 orelse AutoApproveLv > ?MAX_SMALLINT -> ErrorCode = ?ERRCODE(err400_auto_approve_lv_error);
        AutoApprovePower < 0 orelse AutoApprovePower > ?MAX_INT -> ErrorCode = ?ERRCODE(err400_auto_approve_power_error);
        true ->
            ErrorCode = nothing,
            mod_guild:setting_approve(RoleId, ApproveType, AutoApproveLv, AutoApprovePower)
    end,
    case ErrorCode == nothing of
        true -> skip;
        false ->
            {ok, BinData} = pt_400:write(40011, [ErrorCode]),
            lib_server_send:send_to_sid(Player#player_status.sid, BinData)
    end;

%% 编辑公告
handle(40012, Player, [Announce, Type]) ->
    #player_status{id = RoleId, guild = #status_guild{id = GuildId}} = Player,
    {AMin, AMax} = data_guild:get(announce_len),
    CheckLength = util:check_length(Announce, AMin, AMax),
    CheckKeyWord = lib_word:check_keyword(Announce),
    if
        GuildId =< 0 -> ErrorCode = ?ERRCODE(err400_not_on_guild_to_modify_announce);
        CheckLength == false -> ErrorCode = ?ERRCODE(err400_tenet_len);
        CheckKeyWord -> ErrorCode = ?ERRCODE(err400_announce_sensitive);
        true ->
            ErrorCode = nothing,
            mod_guild:modify_announce(RoleId, Announce, Type)
    end,
    case ErrorCode == nothing of
        true -> skip;
        false ->
            {ok, BinData} = pt_400:write(40012, [ErrorCode, 0]),
            lib_server_send:send_to_sid(Player#player_status.sid, BinData)
    end;

%% 任命职位
handle(40013, Player, [AppointeeId, Position]) ->
    #player_status{sid = Sid, id = RoleId, guild = #status_guild{id = GuildId}} = Player,
    case GuildId == 0 of
        false when RoleId /= AppointeeId->
            case lib_mutex_check:check_appoint_position(Position) of
                {false, ErrorCode} -> lib_server_send:send_to_sid(Sid, pt_400, 40000, [ErrorCode]);
                true ->  mod_guild:appoint_position(RoleId, AppointeeId, Position)
            end;
        _->
            skip
    end;

%% 踢出公会
handle(40014, #player_status{sid = Sid} = Player, [LeaveId]) ->
    #player_status{id = RoleId, guild = #status_guild{id = GuildId}} = Player,
    case GuildId == 0 of
        true -> skip;
        false ->
            case lib_mutex_check:check_kick_out_guild(Player, LeaveId) of
                {false, ErrorCode} -> lib_server_send:send_to_sid(Sid, pt_400, 40014, [ErrorCode, LeaveId]);
                true -> mod_guild:kick_out_guild(RoleId, LeaveId)
            end
    end;

%% 玩家的公会信息
handle(40015, Player, []) ->
    lib_guild:send_info(Player);

%% 全部同意/拒绝入会
handle(40016, Player, [Type]) when Type == 1 orelse Type == 2 ->
    #player_status{id = RoleId, guild = #status_guild{id = GuildId}} = Player,
    case GuildId =/= 0 of
        true ->
            case Type == 1 of
                true ->
                    mod_guild:approve_all_guild_apply_on_this_guild(RoleId);
                false ->
                    mod_guild:clean_all_guild_apply_on_this_guild(RoleId)
            end;
        false -> skip
    end;

%% 申请代理团长
%% 20200520 不再设置代理团长 符合条件直接成为成为团长
handle(40018, Player, [ApplyPosition]) when ApplyPosition=:=?POS_CHIEF ->
    #player_status{id = RoleId, sid = Sid, guild = GuildStatus} = Player,
    #status_guild{id = GuildId, position = Position} = GuildStatus,
    if
        GuildId =< 0 ->
            lib_guild:send_error_code(Sid, ?ERRCODE(err400_no_guild));
        ApplyPosition =:= Position ->
            lib_guild:send_error_code(Sid, ?ERRCODE(err400_apply_same_position));
        Position =:= ?POS_CHIEF ->
            lib_guild:send_error_code(Sid, ?ERRCODE(err400_chief_cannot_apply));
        true ->
            mod_guild:apply_guild_position(RoleId, ApplyPosition, GuildId)
    end;

%% 申请帮派职位
handle(40018, Player, [ApplyPosition]) ->
    #player_status{id = RoleId, sid = Sid, guild = GuildStatus} = Player,
    #status_guild{id = GuildId, position = Position} = GuildStatus,
    IsPosition = lists:member(ApplyPosition, ?BE_APPOINT_POS_LIST),
    if
        GuildId =< 0 ->
            lib_guild:send_error_code(Sid, ?ERRCODE(err400_no_guild));
        ApplyPosition =:= Position ->
            lib_guild:send_error_code(Sid, ?ERRCODE(err400_apply_same_position));
        Position =:= ?POS_CHIEF ->
            lib_guild:send_error_code(Sid, ?ERRCODE(err400_chief_cannot_apply));
        not IsPosition ->
            lib_guild:send_error_code(Sid, ?ERRCODE(err400_position_not_exist));
        true ->
            mod_guild:apply_guild_position(RoleId, ApplyPosition, GuildId)
    end;

%% 公告编辑界面
handle(40019, Player, []) ->
    #player_status{sid = Sid, guild = #status_guild{id = GuildId}} = Player,
    case GuildId =/= 0 of
        true ->
            mod_guild:send_announce_view_info(Sid, GuildId);
        false -> skip
    end;

%% 旗帜使用情况
handle(40020, Player, []) ->
    #player_status{id=RoleID} = Player,
    mod_guild:search_guild_flag_list(RoleID),
    {ok,Player};

%% 玩家拥有的权限列表
handle(40021, Player, []) ->
    #player_status{id = RoleId, guild = #status_guild{id = GuildId}} = Player,
    case GuildId == 0 of
        true -> skip;
        false -> mod_guild:send_role_permission_list(RoleId)
    end;

%% 职位管理界面
handle(40022, Player, [PageSize, PageNo]) ->
    #player_status{id = RoleId, guild = #status_guild{id = GuildId} } = Player,
    case GuildId == 0 of
        true -> skip;
        false -> mod_guild:cast_to_guild({'send_position_manage_view',RoleId, GuildId, PageSize, PageNo})
    end;

%% 取职位管理界面-职位数量
handle(40023, Player, []) ->
    #player_status{id = RoleId, guild = #status_guild{id = GuildId} } = Player,
    case GuildId == 0 of
        true -> skip;
        false -> mod_guild:cast_to_guild({'send_position_num_list',RoleId, GuildId})
    end;

% %% 批量任命职位
% handle(40024, Player, [Position, AppointeeIdList]) ->
%     #player_status{id = RoleId, guild = #status_guild{id = GuildId}, sid = Sid} = Player,
%     case GuildId == 0 of
%         true -> skip;
%         false ->
%             case lib_mutex_check:check_appoint_position(Position) of
%                 {false, ErrorCode} -> lib_server_send:send_to_sid(Sid, pt_400, 40000, [ErrorCode]);
%                 true ->
%                     NewAppointeeIdList = util:ulist(AppointeeIdList),
%                     mod_guild:cast_to_guild({'bulk_appoint_position', RoleId, Position, NewAppointeeIdList})
%             end
%     end;

%% 公会改名
handle(40025, Player, [OpTy, GuildName,Flag]) ->
    #player_status{id = RoleId, guild = #status_guild{id = GuildId} } = Player,
    case GuildId == 0 of
        true -> skip;
        false -> mod_guild:check_rename_guild(GuildId, RoleId, OpTy,GuildName, Flag)
    end;

% %% 公会解散
% handle(40026, Player, []) ->
%     #player_status{id = RoleId, sid = Sid, guild = #status_guild{id = GuildId} } = Player,
%     case GuildId == 0 of
%         true -> skip;
%         false ->
%             case lib_mutex_check:check_disband_guild(GuildId) of
%                 true -> mod_guild:do_disband_guild(GuildId, RoleId);
%                 {false, ErrorCode} ->
%                     lib_server_send:send_to_sid(Sid, pt_400, 40026, [ErrorCode])
%             end
%     end;

%% 商店界面
handle(40027, Status, []) ->
    #player_status{
        guild = #status_guild{id = GuildId}
    } = Status,
    case GuildId == 0 of
        true ->
            skip;
        false ->
            lib_guild_shop_mod:get_cargos(Status)
    end,
    {ok,Status};

%% 购买商品
handle(40028, Status, [Id,Num]) ->
    #player_status{
        guild = #status_guild{id = GuildId}
    } = Status,
    case GuildId == 0 of
        true ->
            {ok,Status};
        false ->
            NStatus = lib_guild_shop_mod:buy_goods(Status,Id, Num),
            {ok,NStatus}
    end;

%%发起合并
handle(40031, Status, [Target]) ->
    #player_status{
        id = RoleID,
        guild = #status_guild{id = GuildId,position = Position}
    } = Status,
    case GuildId == 0 of
        true ->
            skip;
        _->
            case Position =:= ?POS_CHIEF of
                true->
                    mod_guild:cast_to_guild({'apply_guild_merge',RoleID,GuildId,Target});
                _->
                    skip
            end
    end,
    {ok,Status};

%%查看自己收到的合并请求
handle(40032,Status,[])->
    #player_status{
        id = RoleId,
        guild = #status_guild{id = GuildId,position = Position}
    } = Status,
    case GuildId == 0 of
        true ->
            skip;
        _->
            case Position =:= ?POS_CHIEF of
                true->
                    mod_guild:cast_to_guild({'get_merge_apply',RoleId,GuildId});
                _->
                    skip
            end
    end,
    {ok,Status};

%%回复申请
handle(40033,Status,[OpTy,Target])->
    #player_status{
        id = RoleId,
        sid = Sid,
        guild = #status_guild{id = GuildId,position = Position}
    } = Status,
    case GuildId == 0 of
        true ->
            skip;
        _->
            case Position =:= ?POS_CHIEF of
                true->
                    case lib_mutex_check:check_merge_guild() of
                        {false, ErrorCode} ->
                            lib_server_send:send_to_sid(Sid, pt_400, 40033, [ErrorCode,0,0,0]);
                        _->
                            mod_guild:cast_to_guild({'reply_merge_apply',RoleId,GuildId,OpTy,Target})
                    end;
                _->
                    skip
            end
    end,
    {ok,Status};

%取消申请
handle(40034,Status,[])->
    #player_status{
        id = RoleID,
        guild = #status_guild{id = GuildId,position = Position}
    } = Status,
    case GuildId == 0 of
        true ->
            skip;
        _->
            case Position =:= ?POS_CHIEF of
                true->
                    mod_guild:cast_to_guild({'cancle_guild_merge',RoleID,GuildId});
                _->
                    skip
            end
    end,
    {ok,Status};

%%拼单界面
handle(40035,Status,[])->
    #player_status{
        guild = #status_guild{id = GuildId}
    } = Status,
    NStatus = case GuildId =< 0 of
        true ->
            Status;
        _->
            lib_guild_order_mod:get_pane_orders(Status)
    end,
    {ok,NStatus};

%%0选中可拼单1出发
handle(40036,Status,[OpTy,OrderId])->
    #player_status{
        id = RoleID
    } = Status,
    case lib_guild_order_mod:change_order_state(OpTy,OrderId,Status) of
        {ok,NStatus}->
            lib_guild_order_mod:get_pane_orders(NStatus),
            Res = ?SUCCESS;
        {false,Res}->
            NStatus = Status
    end,
    {ok,Bin} = pt_400:write(40036,[Res,OpTy,OrderId]),
    lib_server_send:send_to_uid(RoleID,Bin),
    {ok,NStatus};

handle(40037,Status,[OrderId,IRid])->
    #player_status{
        id = RoleID
    } = Status,
    case IRid /= RoleID of
        true->
            case lib_guild_order_mod:invite_guild_member(OrderId,IRid,Status) of
                {ok,NStatus}->
                    Res = ?SUCCESS;
                {false,Res}->
                    NStatus = Status
            end,
            {ok,Bin} = pt_400:write(40037,[Res,OrderId,IRid]),
            lib_server_send:send_to_uid(RoleID,Bin),
            {ok,NStatus};
        _->
            {ok,Status}
    end;

handle(40039,Status,[OrderId, TRid]) ->
    #player_status{
        id=RoleID,
        guild = #status_guild{id = GuildId}
    } = Status,
    case RoleID /= TRid of
        true when GuildId>0->
            lib_player:apply_cast(TRid, ?APPLY_CAST_SAVE, lib_guild_order_mod, reply_guild_order, [GuildId,RoleID, OrderId]);
        _->
            skip
    end,
    {ok,Status};

handle(40041,Status,[OrderId])->
    #player_status{
        id = RoleID
    } = Status,
    case lib_guild_order_mod:thanks_teams(OrderId,Status) of
        {ok,NStatus}->
            Res = ?SUCCESS;
        {false,Res}->
            NStatus = Status
    end,
    {ok,Bin} = pt_400:write(40041,[Res]),
    lib_server_send:send_to_uid(RoleID,Bin),
    {ok,NStatus};

handle(40066,Status,[])->
    #player_status{
        id = RoleID
    } = Status,
    case lib_guild_order_mod:refresh_orders(Status) of
        {ok,NStatus}->
            lib_guild_order_mod:get_pane_orders(NStatus),
            Res = ?SUCCESS;
        {false,Res}->
            NStatus = Status
    end,
    {ok,Bin} = pt_400:write(40066,[Res]),
    lib_server_send:send_to_uid(RoleID,Bin),
    {ok,NStatus};


%% 进入社团驻地
handle(40044, Status, _) ->
    #player_status{id = RoleID, scene = Scene, figure = #figure{lv = Lv}, guild = GuildStatus} = Status,
    #status_guild{id = GuildId, name = GName} = GuildStatus,
    CheckList = [
        {check_guilded,GuildId},
        {check_repeate_enter,Scene},
        {check_enter_lv,Lv},
        {check_transferable,Status}
    ],
    case util:check_lists(lib_guild_tribe_mod,CheckList) of
        true->
            mod_guild_tribe_mgr:enter_scene(RoleID, GuildId, GName,Lv);
        {false,ErrCode}->
            {ok,Bin} = pt_400:write(40044,[ErrCode]),
            lib_server_send:send_to_uid(RoleID,Bin)
    end,
    {ok,Status};

%%离开驻地
handle(40045,Status,_)->
    #player_status{
        id = RoleId,
        guild = GuildStatus,
        scene = Scene,
        old_scene_info = OldSceneInfo
    } = Status,
    #status_guild{id = GuildId} = GuildStatus,
    InScene = lib_guild_api:check_in_guild_scene(Scene),
    case  InScene of
        false->
            {ok,Bin} = pt_400:write(40045,[?ERRCODE(err400_not_in_tribe)]),
            lib_server_send:send_to_uid(RoleId,Bin);
        _ ->
            mod_guild_tribe_mgr:exit_scene(RoleId,GuildId,OldSceneInfo)
    end,
    {ok,Status};

%% 获取公会协助信息
handle(40046, Status, []) ->
    #player_status{id = RoleId, guild = StatusGuild} = Status,
    case StatusGuild#status_guild.support_id > 0 of
        true when StatusGuild#status_guild.is_support_asker > 0 -> SupportStatus = 1;
        true -> SupportStatus = 2;
        _ -> SupportStatus = 0
    end,
    mod_guild_support:apply_cast(lib_guild_support_mod, get_support_list, [RoleId, StatusGuild#status_guild.id, StatusGuild#status_guild.support_id, SupportStatus]),
    {ok, Status};

%% 获取感谢礼包发放玩家的具体信息
handle(40049, Status, [_GoodId]) ->
    % guild_thank:get_thank_roles_info(Status, GoodId),
	{ok, Status};

%% 玩家点击感谢
handle(40050, Status, [Type, SupportId, ChatMsg]) ->
    case Type == 1 orelse Type == 2 of
        true ->
            guild_thank:thank_member(Status, Type, SupportId, ChatMsg);
        _ ->
            ignore
    end,
	{ok, Status};

%% 发送协助请求
handle(40051, Status, [Module, SubModule, GameValue1, GameValue2]) ->
    SupportCfgId = lib_guild_support_mod:get_support_cfg_id_by_module(Module, SubModule),
    case SupportCfgId > 0 of
        true ->
            %% 禁止发包,由功能内部发起 - 社团采集,社团跑环,社团拼单协助
            case lists:member(Module, [?MOD_GUILD_COLLECT, ?MOD_GUILD_RUN_ASSIST, ?MOD_GUILD]) of
                true -> ignore;
                _ -> lib_guild_support_mod:ask_for_support(Status, Module, SubModule, {GameValue1, GameValue2})
            end;
        _ ->
            {ok, Bin} = pt_400:write(40051, [?ERRCODE(err400_support_input_err), 0, 0, 0]),
            lib_server_send:send_to_sid(Status#player_status.sid, Bin)
    end,
    {ok, Status};

%% 前往协助
handle(40052, Status, [SupportId]) ->
    lib_guild_support_mod:reply_support(Status, SupportId),
    {ok, Status};

%% 取消协助
handle(40053, Status, []) ->
    NewStatus = lib_guild_support_mod:cancel_support(Status),
    {ok, NewStatus};

%% 感谢红包信息列表
handle(40068, Status, []) ->
    guild_thank:get_thank_packet_info(Status),
    {ok, Status};

%% 接收红包信息列表
handle(40069, Status, []) ->
    guild_thank:get_log_info(Status),
    {ok, Status};

%% 领取协助奖励
handle(40070, Status, [Type, SupportId]) ->
    case Type == 1 orelse Type == 2 of
        true -> guild_thank:receive_reward(Status, Type, SupportId);
        _ -> ignore
    end,
    {ok, Status};

handle(40057,Status,[])->
    #player_status{id=RoleID}=Status,
    mod_guild_tribe_mgr:get_fire_state(RoleID),
    {ok,Status};

handle(40058,Status,[])->
    #player_status{id=RoleID,guild=#status_guild{id=GuildID}}=Status,
    GuildID>0 andalso mod_guild_tribe_mgr:get_pane_data(GuildID,RoleID),
    {ok,Status};

% handle(40060,Status,[])->
%     #player_status{id=RoleID,guild=#status_guild{id=GuildID}}=Status,
%     GuildID>0 andalso mod_guild_tribe_mgr:change_dance(GuildID,RoleID),
%     {ok,Status};

handle(40063,Status,[])->
    #player_status{id=RoleID,guild=#status_guild{id=GuildID}}=Status,
    GuildID>0 andalso mod_guild_tribe_mgr:get_guild_tribe_num(GuildID,RoleID),
    {ok,Status};

handle(40064, Status, [Module]) ->
    #player_status{id = RoleId, sid = Sid, scene = SceneId, guild = #status_guild{id = GuildId}, figure = #figure{name = RoleName}} = Status,
    IsGuildScene = lib_guild:is_guild_scene(SceneId),
    CallTime = erlang:get(guild_call),
    Now = utime:unixtime(),
    CallTime1 = ?IF(CallTime == undefined, 0, CallTime),
    LastTime = Now - CallTime1,
    if
        LastTime >= 10 ->
            if GuildId =/= 0 ->
                if
                    Module == ?MOD_GUILD_BOSS andalso IsGuildScene ->
                        lib_chat:send_TV({guild, GuildId}, Module, 8, [RoleName, RoleId]),
                        lib_server_send:send_to_sid(Sid, pt_400, 40064, [?SUCCESS, Module]),
                        erlang:put(guild_call, Now);
                    Module == 4007 andalso IsGuildScene ->
                        lib_chat:send_TV({guild, GuildId}, 400, 14, [RoleName, RoleId]),
                        lib_server_send:send_to_sid(Sid, pt_400, 40064, [?SUCCESS, Module]),
                        erlang:put(guild_call, Now);
                    Module == ?MOD_GUILD_COLLECT andalso IsGuildScene ->
                        lib_chat:send_TV({guild, GuildId}, Module, 4, [RoleName, RoleId]),
                        lib_server_send:send_to_sid(Sid, pt_400, 40064, [?SUCCESS, RoleId]),
                        erlang:put(guild_call, Now);
                    Module == ?MOD_CAMP_WAR ->
                        camp_war_api:camp_war_tv(Status),
                        erlang:put(guild_call, Now);
                    true ->
                        lib_server_send:send_to_sid(Sid, pt_400, 40064, [?FAIL, Module])
                end;
                true ->
                    lib_server_send:send_to_sid(Sid, pt_400, 40064, [?ERRCODE(err400_not_in_guild), Module])
            end;
        true ->
            lib_server_send:send_to_sid(Sid, pt_400, 40064, [?ERRCODE(err400_guild_call_frequent), Module])
    end,
    ok;

%% 查询历史创建社团数量
handle(40071, Status, [])->
    GuildNum = lib_guild_mod:get_history_guild_num(),
    lib_server_send:send_to_uid(Status#player_status.id, pt_400, 40071, [GuildNum]),
    {ok, Status};

handle(_Cmd, _Player, _Data) ->
    {error, atom_to_list(?MODULE) ++ " no match"}.
