go_dreamfactory/modules/caravan/model_troll.go
2023-04-24 20:35:03 +08:00

66 lines
1.7 KiB
Go

package caravan
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelCaravan struct {
modules.MCompModel
module *Caravan
}
func (this *modelCaravan) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = string(comm.TableTroll)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Caravan)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
func (this *modelCaravan) getTrollList(uid string) (result *pb.DBTrollTrain, err error) {
result = &pb.DBTrollTrain{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Items: map[int32]int32{},
Price: map[int32]int32{},
GridNum: 0,
TarinPos: 1,
RangeId: 0,
Buy: 0,
Sell: 0,
NpcLv: 0,
NpcReward: map[int32]int32{},
TotalEarn: 0,
SellCount: 0,
RefreshTime: configure.Now().Unix(),
AiCount: 0,
Shop: map[int32]int32{},
Ctime: configure.Now().Unix(),
Circle: 0,
SurpriseID: map[int32]int32{},
ResetTime: configure.Now().Unix(),
}
if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err {
// 创建一条数据
err = this.Add(uid, result)
return
}
err = nil
return result, err
}
func (this *modelCaravan) modifyTrollDataByObjId(uid string, data map[string]interface{}) error {
return this.Change(uid, data)
}