go_dreamfactory/modules/sociaty/api_cross_dismiss.go
2022-10-31 18:27:07 +08:00

69 lines
1.8 KiB
Go

package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
// 公会解散
func (this *apiComp) DismissCheck(session comm.IUserSession, req *pb.SociatyDismissReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) Dismiss(session comm.IUserSession, req *pb.SociatyDismissReq) (code pb.ErrorCode, data proto.Message) {
uid := session.GetUserId()
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
}
for _, m := range sociaty.Members {
//清除成员任务
if err := this.module.modelSociatyTask.deleTask(sociaty.Id, m.Uid); err != nil {
this.module.Errorf("删除玩家 uid:%s 公会 sociatyId:%s err:%v", m.Uid, sociaty.Id, err)
}
//清除玩家sociatyId
update := map[string]interface{}{
"sociatyId": "", //公会ID置空
}
if err := this.module.ModuleUser.ChangeRemoteUserExpand(m.Uid, update); err != nil {
code = pb.ErrorCode_DBError
this.module.Errorf("更新玩家公会ID err:%v", err)
return
}
//清除公会日志
if err := this.module.modelSociatyLog.logDelete(sociaty.Id); err != nil {
this.module.Errorf("删除公会日志 sociatyId:%s err:%v", sociaty.Id, err)
}
}
// 删除公会
if err := this.module.modelSociaty.dismiss(sociaty); err != nil {
code = pb.ErrorCode_SociatyDismiss
this.module.Errorf("sociatyId: %s dismiss err:%v", sociaty.Id, err)
return
}
rsp := &pb.SociatyDismissResp{
Uid: session.GetUserId(),
SociatyId: sociaty.Id,
}
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeDismiss, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}