go_dreamfactory/modules/uigame/model_puzzle.go

56 lines
1.4 KiB
Go

package uigame
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo"
"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 modelPuzzle struct {
modules.MCompModel
module *UiGame
}
func (this *modelPuzzle) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = string(comm.TableGamePuzzle)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*UiGame)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
func (this *modelPuzzle) getPuzzleList(uid string, hid string) (result *pb.DBPuzzleData, err error) {
result = &pb.DBPuzzleData{}
if err = this.Get(uid, result); err != nil {
if mgo.MongodbNil == err {
result = &pb.DBPuzzleData{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Hdoid: hid,
Gotarr: map[int32]int32{},
Puzzle: map[int32]int32{},
Lasttime: 0,
Val: 0,
}
err = nil
this.module.modelPuzzle.Add(uid, result)
}
return
}
err = nil
return result, err
}
func (this *modelPuzzle) modifyPuzzleListByObjId(uid string, data map[string]interface{}) error {
return this.Change(uid, data)
}