go_dreamfactory/modules/integral/model_integral.go
2023-12-06 11:47:17 +08:00

49 lines
1.2 KiB
Go

package integral
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 modelIntegral struct {
modules.MCompModel
module *Integral
}
func (this *modelIntegral) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = string(comm.TableIntegral)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Integral)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
func (this *modelIntegral) modifyIntegralDataByObjId(uid string, data map[string]interface{}) error {
return this.Change(uid, data)
}
// 获取列表信息
func (this *modelIntegral) getIntegralList(uid string) (result *pb.DBIntegralBoss, err error) {
result = &pb.DBIntegralBoss{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Buff: map[int32]int32{},
Score: map[int32]int32{},
}
if err = this.Get(uid, result); err != nil {
return
}
err = nil
return result, err
}