84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
package entertainment
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
"go_dreamfactory/utils"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelComp struct {
|
|
modules.MCompModel
|
|
module *Entertainment
|
|
}
|
|
|
|
func (this *modelComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableEntertainm
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Entertainment)
|
|
// 通过uid创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelComp) getEntertainmList(uid string) (result *pb.DBXXLData, err error) {
|
|
var (
|
|
dbModel *db.DBModel
|
|
)
|
|
result = &pb.DBXXLData{
|
|
|
|
Reward: map[int32]int32{},
|
|
Card: map[string]int32{},
|
|
}
|
|
if db.IsCross() {
|
|
if tag, _, b := utils.UIdSplit(uid); b {
|
|
if conn, err := db.ServerDBConn(tag); err == nil {
|
|
dbModel = db.NewDBModel(comm.TableEntertainm, conn)
|
|
|
|
}
|
|
}
|
|
}
|
|
if dbModel == nil {
|
|
err = this.Get(uid, result)
|
|
} else {
|
|
err = dbModel.Get(uid, result)
|
|
}
|
|
|
|
if err != nil {
|
|
if redis.RedisNil != err { // 没有数据直接创建新的数据
|
|
result.Id = primitive.NewObjectID().Hex()
|
|
result.Uid = uid
|
|
result.Reward = make(map[int32]int32)
|
|
result.Card = make(map[string]int32, 0)
|
|
}
|
|
}
|
|
err = nil
|
|
return result, err
|
|
}
|
|
|
|
func (this *modelComp) modifyEntertainmList(uid string, data map[string]interface{}) error {
|
|
var (
|
|
err error
|
|
)
|
|
if db.IsCross() {
|
|
if tag, _, b := utils.UIdSplit(uid); b {
|
|
if conn, err := db.ServerDBConn(tag); err == nil {
|
|
dbModel := db.NewDBModel(comm.TableEntertainm, conn)
|
|
err = dbModel.Change(uid, data)
|
|
}
|
|
}
|
|
} else {
|
|
err = this.Change(uid, data)
|
|
}
|
|
return err
|
|
}
|