公会名不重复校验

This commit is contained in:
wh_zcy 2022-11-07 11:50:26 +08:00
parent ed6dbbe7f8
commit 4f5e027f64
3 changed files with 29 additions and 4 deletions

View File

@ -58,6 +58,16 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.SociatyCreateReq)
return return
} }
// 验证公会名是否重复
if ok, err := this.module.modelSociaty.isNameExist(req.Name); ok {
if err != nil {
code = pb.ErrorCode_DBError
} else {
code = pb.ErrorCode_SociatyNameExist
}
return
}
//检查钻石 //检查钻石
ggd := this.module.modelSociaty.moduleSociaty.configure.GetGlobalConf() ggd := this.module.modelSociaty.moduleSociaty.configure.GetGlobalConf()
if ggd == nil { if ggd == nil {

View File

@ -32,7 +32,7 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.SociatyReceiveRe
sociatyTask := this.module.modelSociaty.getUserTaskList(uid, sociaty.Id) sociatyTask := this.module.modelSociaty.getUserTaskList(uid, sociaty.Id)
for _, v := range sociatyTask.TaskList { for _, v := range sociatyTask.TaskList {
if v.TaskId == req.TaskId { if v.TaskId == req.TaskId {
if v.Status == 1 { if v.Status == 1 {//已领取
code = pb.ErrorCode_SociatyRewardReceived code = pb.ErrorCode_SociatyRewardReceived
return return
} }

View File

@ -2,7 +2,6 @@ package sociaty
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
@ -15,6 +14,8 @@ import (
"sort" "sort"
"time" "time"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
@ -70,6 +71,20 @@ func (this *ModelSociaty) create(sociaty *pb.DBSociaty) error {
return this.AddList("", sociaty.Id, sociaty) return this.AddList("", sociaty.Id, sociaty)
} }
// 公会名是否存在
func (this *ModelSociaty) isNameExist(name string) (bool, error) {
var sociaties []*pb.DBSociaty
if err := this.GetList("", &sociaties); err != nil {
return false, err
}
for _, s := range sociaties {
if s.Name == name {
return true, nil
}
}
return false, nil
}
// 公会列表 // 公会列表
func (this *ModelSociaty) list(uid string, filter pb.SociatyListFilter) (list []*pb.DBSociaty) { func (this *ModelSociaty) list(uid string, filter pb.SociatyListFilter) (list []*pb.DBSociaty) {
user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(uid) user, err := this.moduleSociaty.ModuleUser.GetRemoteUser(uid)
@ -656,7 +671,7 @@ func (this *ModelSociaty) IsSign(uid string, sociaty *pb.DBSociaty) bool {
// 获取玩家任务列表 // 获取玩家任务列表
func (this *ModelSociaty) getUserTaskList(uid, sociatyId string) (sociatyTask *pb.DBSociatyTask) { func (this *ModelSociaty) getUserTaskList(uid, sociatyId string) (sociatyTask *pb.DBSociatyTask) {
sociatyTask = &pb.DBSociatyTask{} sociatyTask = &pb.DBSociatyTask{}
this.moduleSociaty.modelSociatyTask.GetListObj(sociatyId, uid, sociatyTask) this.GetListObj(sociatyId, uid, sociatyTask)
return return
} }