63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// 公会转让
|
|
func (this *apiComp) AssignCheck(session comm.IUserSession, req *pb.SociatyAssignReq) (code pb.ErrorCode) {
|
|
if req.TargetId == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Assign(session comm.IUserSession, req *pb.SociatyAssignReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.AssignCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
uid := session.GetUserId()
|
|
if uid == req.TargetId {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
this.module.Errorf("不能转让给自己 uid:%s", uid)
|
|
return
|
|
}
|
|
|
|
sociaty := this.module.modelSociaty.getUserSociaty(uid)
|
|
if sociaty.Id == "" {
|
|
code = pb.ErrorCode_SociatyNoFound
|
|
this.module.Errorf("uid:%s not in sociaty", uid)
|
|
return
|
|
}
|
|
|
|
if !this.module.modelSociaty.isRight(uid, sociaty, pb.SociatyJob_PRESIDENT) {
|
|
code = pb.ErrorCode_SociatyNoRight
|
|
return
|
|
}
|
|
|
|
if err := this.module.modelSociaty.assign(uid, req.TargetId, sociaty); err != nil {
|
|
code = pb.ErrorCode_SociatyAssign
|
|
this.module.Errorf("转让失败:%v", err)
|
|
return
|
|
}
|
|
|
|
if err := this.module.modelSociatyLog.addLog(Log_Job, sociaty.Id,
|
|
uid, req.TargetId, pb.SociatyJob_PRESIDENT.String()); err != nil {
|
|
this.module.Errorf("转让日志 err:%v", err)
|
|
}
|
|
|
|
rsp := &pb.SociatyAssignResp{
|
|
TargetId: req.TargetId,
|
|
SociatyId: sociaty.Id,
|
|
}
|
|
|
|
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeAssign, rsp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
return
|
|
}
|