52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package hero
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
// 新手招募
|
|
type ModelSelect struct {
|
|
modules.MCompModel
|
|
}
|
|
|
|
func (this *ModelSelect) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableHeroSelect
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *ModelSelect) GetDrawSelectData(uid string) (result *pb.DBSelectDraw, err error) {
|
|
result = &pb.DBSelectDraw{}
|
|
if err = this.Get(uid, result); err != nil {
|
|
if mongo.ErrNoDocuments == err { // 创建一条新的数据
|
|
result.Id = primitive.NewObjectID().Hex()
|
|
result.Uid = uid
|
|
|
|
this.Add(uid, result)
|
|
err = nil
|
|
}
|
|
return
|
|
}
|
|
|
|
err = nil
|
|
return result, err
|
|
}
|
|
|
|
func (this *ModelSelect) ChangeHeroSelectData(uid string, value map[string]interface{}) (err error) {
|
|
if len(value) == 0 {
|
|
return nil
|
|
}
|
|
|
|
return this.Change(uid, value)
|
|
}
|