go_dreamfactory/modules/sociaty/api_cross_apply.go
2022-11-14 15:55:50 +08:00

95 lines
2.2 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
}
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
}
// userex
// userEx, err := this.module.ModuleUser.GetRemoteUserExpand(uid)
// if err != nil {
// this.module.Errorf("GetRemoteUserExpand uid: err:%v", uid, err)
// code = pb.ErrorCode_UserSessionNobeing
// return
// }
// if utils.IsInCDHour(userEx.SociatyCd) {
// code = pb.ErrorCode_SociatyCDLimit
// 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(this.module.globalConf.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
}