88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
package entertainment
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"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) queryPlayers(uIds []string) (result []*pb.DBXXLData, err error) {
|
|
result = make([]*pb.DBXXLData, 0)
|
|
if _, err = this.Gets(uIds, &result); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *modelComp) getEntertainmList(uid string) (result *pb.DBXXLData, err error) {
|
|
|
|
result = &pb.DBXXLData{
|
|
Reward: map[int32]int32{},
|
|
Card: map[string]int32{},
|
|
Skill: map[int32]int32{},
|
|
}
|
|
|
|
err = this.Get(uid, result)
|
|
|
|
if mongo.ErrNoDocuments == err { // 没有数据直接创建新的数据
|
|
result.Id = primitive.NewObjectID().Hex()
|
|
result.Uid = uid
|
|
result.Reward = make(map[int32]int32)
|
|
result.Card = make(map[string]int32)
|
|
_, endSeasonTime := utils.GetMonthStartEnd()
|
|
result.Etime = endSeasonTime
|
|
|
|
// 初始化默认获得类型为1的卡片
|
|
for _, v := range this.module.configure.GetInitGameConsumeHero() {
|
|
result.Card[v] = 1
|
|
}
|
|
// 默认技能
|
|
for _, v := range this.module.configure.GetInitGameConsumeSkill() {
|
|
result.Skill[v] = 1
|
|
}
|
|
if user, e := this.module.ModuleUser.GetUser(uid); e == nil {
|
|
// 查询一次 写基本信息
|
|
result.Uinfo = &pb.BaseUserInfo{
|
|
Uid: uid,
|
|
Sid: user.Sid,
|
|
Name: user.Name,
|
|
Gender: user.Gender,
|
|
Skin: user.CurSkin,
|
|
Aframe: user.Curaframe,
|
|
Title: user.Curtitle,
|
|
Lv: user.Lv,
|
|
}
|
|
}
|
|
err = this.Add(uid, result)
|
|
}
|
|
return result, err
|
|
}
|
|
|
|
func (this *modelComp) modifyEntertainmList(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|