From c638d3bbcef582ec1ceeb61527d8da39e6265779 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 10 Oct 2023 18:34:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=85=AC=E4=BC=9A=E5=BC=B9?= =?UTF-8?q?=E5=8A=BE=E4=BB=A3=E7=A0=81=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/sociaty/api_cross_mine.go | 46 ++++++++++++++++--------------- modules/sociaty/model_sociaty.go | 27 ++++++------------ 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/modules/sociaty/api_cross_mine.go b/modules/sociaty/api_cross_mine.go index f00602ddd..1135589e5 100644 --- a/modules/sociaty/api_cross_mine.go +++ b/modules/sociaty/api_cross_mine.go @@ -4,6 +4,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" "go_dreamfactory/utils" ) @@ -74,32 +75,33 @@ func (this *apiComp) Mine(session comm.IUserSession, req *pb.SociatyMineReq) (er } } - // 获取会长 - master := this.module.modelSociaty.getMasterInfo(sociaty) - if master != nil { - // 会长弹劾判断 - if err := this.module.modelSociaty.extendJob(master.Uid, sociaty); err == nil { - // 获取新的会长 - master = this.module.modelSociaty.getMasterInfo(sociaty) - } else { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_DBError, - Title: pb.ErrorCode_DBError.ToString(), - Message: err.Error(), + if sociaty.AccuseTime > 0 { + // 获取会长 + master := this.module.modelSociaty.getMasterInfo(sociaty) + if master != nil { + if master.Uid == session.GetUserId() { //自己是会长 + sociaty.AccuseTime = 0 + update := map[string]interface{}{ + "accuseTime": 0, + } + this.module.modelSociaty.updateSociaty(sociaty.Id, update) + } else { + now := configure.Now().Unix() + if now > sociaty.AccuseTime { // 重新选择会长 + if err := this.module.modelSociaty.extendJob(master.Uid, sociaty); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + rsp.Master = master + } } - - this.module.Error("会长弹劾", - log.Field{Key: "uid", Value: uid}, - log.Field{Key: "sociatyId", Value: sociaty.Id}, - log.Field{Key: "master", Value: master.Uid}, - log.Field{Key: "err", Value: err.Error()}, - ) } } - rsp.Sociaty = sociaty - rsp.Master = master - session.SendMsg(string(this.module.GetType()), SociatySubTypeMine, rsp) return } diff --git a/modules/sociaty/model_sociaty.go b/modules/sociaty/model_sociaty.go index 4db46c971..9e8a8ce1c 100644 --- a/modules/sociaty/model_sociaty.go +++ b/modules/sociaty/model_sociaty.go @@ -656,25 +656,16 @@ func (this *ModelSociaty) accuse(sociaty *pb.DBSociaty) error { // 会长在截至时间前进入公会终止弹劾,否则进行新会长选举 // srcMasterId 原会长ID func (this *ModelSociaty) extendJob(srcMasterId string, sociaty *pb.DBSociaty) error { - if sociaty.AccuseTime != 0 { - //会长在截至时间前进入公会终止弹劾 - now := configure.Now().Unix() - if now < sociaty.AccuseTime { - update := map[string]interface{}{ - "accuseTime": 0, - } - return this.updateSociaty(sociaty.Id, update) - } else { - //选举新会长 - if err := this.electNewMaster(srcMasterId, sociaty); err != nil { - return err - } - //会长降为普通成员 - if err := this.settingJob(srcMasterId, pb.SociatyJob_MEMBER, sociaty); err != nil { - return err - } - } + + //选举新会长 + if err := this.electNewMaster(srcMasterId, sociaty); err != nil { + return err } + //会长降为普通成员 + if err := this.settingJob(srcMasterId, pb.SociatyJob_MEMBER, sociaty); err != nil { + return err + } + return nil }