88 lines
2.0 KiB
Go
88 lines
2.0 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// 公会申请
|
|
|
|
func (this *apiComp) ApplyCheck(session comm.IUserSession, req *pb.SociatyApplyReq) (code pb.ErrorCode) {
|
|
if req.SociatyId == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Apply(session comm.IUserSession, req *pb.SociatyApplyReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.ApplyCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
// 全局配置
|
|
ggd := this.module.configure.GetGlobalConf()
|
|
if ggd == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
uid := session.GetUserId()
|
|
|
|
sociaty := this.module.modelSociaty.getSociaty(req.SociatyId)
|
|
if sociaty.Id == "" {
|
|
code = pb.ErrorCode_SociatyNoFound
|
|
this.module.Errorf("sociatyId: %s no found", req.SociatyId)
|
|
return
|
|
}
|
|
|
|
// 是否达到入会等级
|
|
user, err := this.module.ModuleUser.GetRemoteUser(uid)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if user == nil {
|
|
code = pb.ErrorCode_UserSessionNobeing
|
|
return
|
|
}
|
|
|
|
if user.Lv < sociaty.ApplyLv {
|
|
code = pb.ErrorCode_SociatyAppyLvNoEnough
|
|
return
|
|
}
|
|
|
|
// 是否公会成员
|
|
if this.module.modelSociaty.isMember(uid, sociaty) {
|
|
code = pb.ErrorCode_SociatyBelongTo
|
|
return
|
|
}
|
|
|
|
// 是否已申请
|
|
if this.module.modelSociaty.isApplied(uid, sociaty) {
|
|
code = pb.ErrorCode_SociatyApplied
|
|
return
|
|
}
|
|
|
|
//判断申请人数是否超出最大允许申请数
|
|
if len(sociaty.ApplyRecord) >= int(ggd.GuildAcceptApplyMax) {
|
|
code = pb.ErrorCode_SociatyApplyMax
|
|
return
|
|
}
|
|
|
|
// 申请
|
|
if err := this.module.modelSociaty.apply(uid, sociaty); err != nil {
|
|
code = pb.ErrorCode_SociatyApply
|
|
this.module.Errorf("公会申请失败 sociatyId:%s err:%v", req.SociatyId, err)
|
|
return
|
|
}
|
|
rsp := &pb.SociatyApplyResp{
|
|
Uid: uid,
|
|
ScoiatyId: req.SociatyId,
|
|
}
|
|
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeApply, rsp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
return
|
|
}
|