package sys import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" ) type ModelSys struct { modules.MCompModel moduleSys *ModuleSys service core.IService } func (this *ModelSys) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.TableName = comm.TableOpenCond err = this.MCompModel.Init(service, module, comp, options) this.moduleSys = module.(*ModuleSys) this.service = service return } func (this *ModelSys) validCond(uid string, condData *cfg.GameOpencondData) string { for _, conf := range condData.Main { switch conf.Key { case 1: //等级 if conf.Param == 1 { // 等级为1 直接过 continue } iuser := this.moduleSys.ModuleUser user := iuser.GetUser(uid) if user == nil { return "" } if user.Lv < conf.Param { return "" } case 2: //关卡ID // 查询主线进度 if levels := this.moduleSys.mainline.InquireMainLinePassLevel(uid); len(levels) > 0 { if _, ok := levels[conf.Param]; !ok { return "" } } else { return "" } case 3: //世界任务ID d := this.moduleSys.wtask.InquireCompletes(uid) ok := false for _, taskId := range d { if taskId == conf.Param { ok = true } } if !ok { return "" } case 4: module, err := this.service.GetModule(comm.ModuleFriend) if err != nil { this.moduleSys.Debugln(err) return "" } if v, ok := module.(comm.IFriend); ok { if v.GetFriendCount(uid) < conf.Param { return "" } } case 5: if !this.moduleSys.pagoda.CheckCompletePagoda(uid) { return "" } case 6: // 查询工会等级 if s := this.moduleSys.sociaty.GetSociaty(uid); s != nil { if s.Lv < conf.Param { return "" } } } } return condData.Id } func (this *ModelSys) GetOpenCondList(uid string) (result *pb.DBOpenCond, err error) { result = &pb.DBOpenCond{} if err = this.Get(uid, result); err != nil { if mongo.ErrNoDocuments == err { // 创建一条新的数据 result = &pb.DBOpenCond{ Id: primitive.NewObjectID().Hex(), Uid: uid, Cond: map[string]int32{}, } this.Add(uid, result) err = nil } } return result, err } // 修改OpenCond 数据 func (this *ModelSys) ChangeOpenCondData(uid string, value map[string]interface{}) (err error) { if len(value) == 0 { return nil } return this.Change(uid, value) }