上传埋点校验查询接口跨服使用优化
This commit is contained in:
parent
559b96b287
commit
12315a53c7
@ -8,6 +8,7 @@ import (
|
||||
"go_dreamfactory/lego/sys/redis"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
@ -62,21 +63,48 @@ func (this *modelBuried) userlock(uid string) (result *redis.RedisMutex, err err
|
||||
}
|
||||
|
||||
//更新埋点数据到db中
|
||||
// func (this *modelBuried) getburiedModel(uid string) (model *buriedModel, err error) {
|
||||
// var m *db.DBModel
|
||||
// if db.IsCross() {
|
||||
// if m, err = this.module.GetDBModelByUid(uid, this.TableName); err != nil {
|
||||
// return
|
||||
// }
|
||||
// model = &buriedModel{module: this.module, model: m}
|
||||
// } else {
|
||||
// model = &buriedModel{module: this.module, model: this.DBModel}
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
func (this *modelBuried) getburiedModel(uid string) (model *buriedModel, err error) {
|
||||
var m *db.DBModel
|
||||
if db.IsCross() {
|
||||
if m, err = this.module.GetDBModelByUid(uid, this.TableName); err != nil {
|
||||
return
|
||||
}
|
||||
model = &buriedModel{module: this.module, model: m}
|
||||
} else {
|
||||
model = &buriedModel{module: this.module, model: this.DBModel}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// //埋点专属模型 会封装特殊的数据转换接口
|
||||
// type buriedModel struct {
|
||||
// module *Buried
|
||||
// model *db.DBModel
|
||||
// }
|
||||
//埋点专属模型 会封装特殊的数据转换接口
|
||||
type buriedModel struct {
|
||||
module *Buried
|
||||
model *db.DBModel
|
||||
}
|
||||
|
||||
//获取用户全部的埋点数据
|
||||
func (this *buriedModel) getUserBurieds(uid string) (results *pb.DBBuried, err error) {
|
||||
results = &pb.DBBuried{}
|
||||
if err = this.model.Get(uid, results); err != nil && err != mgo.MongodbNil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
if err == mgo.MongodbNil {
|
||||
err = nil
|
||||
results = &pb.DBBuried{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
Uid: uid,
|
||||
Items: make(map[int32]*pb.DBBuriedItem),
|
||||
}
|
||||
err = this.model.Add(uid, results)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//更新用户数据
|
||||
func (this *buriedModel) updateUserBurieds(uid string, data *pb.DBBuried) (err error) {
|
||||
err = this.model.Change(uid, map[string]interface{}{
|
||||
"items": data.Items,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@ -72,10 +72,13 @@ func (this *Buried) ActiveCondition(uid string, condiIds ...int32) (err error) {
|
||||
var (
|
||||
conf *cfg.GameBuriedCondiData
|
||||
bdatas *pb.DBBuried
|
||||
model *buriedModel
|
||||
chanage bool
|
||||
)
|
||||
|
||||
if bdatas, err = this.modelBuried.getUserBurieds(uid); err != nil {
|
||||
if model, err = this.modelBuried.getburiedModel(uid); err != nil {
|
||||
return
|
||||
}
|
||||
if bdatas, err = model.getUserBurieds(uid); err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range condiIds {
|
||||
@ -110,7 +113,7 @@ func (this *Buried) ActiveCondition(uid string, condiIds ...int32) (err error) {
|
||||
}
|
||||
}
|
||||
if chanage {
|
||||
err = this.modelBuried.updateUserBurieds(uid, bdatas)
|
||||
err = model.updateUserBurieds(uid, bdatas)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user