61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package addrecharge
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"sync"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type ModelRecharge struct {
|
|
modules.MCompModel
|
|
module *AddRecharge
|
|
lock sync.RWMutex
|
|
open bool
|
|
}
|
|
|
|
func (this *ModelRecharge) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.TableName = comm.TablekRecharge
|
|
this.module = module.(*AddRecharge)
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
// 获取用户全部的埋点数据
|
|
func (this *ModelRecharge) getUserDTasks(uid string) (results *pb.DBAddRecharge, err error) {
|
|
results = &pb.DBAddRecharge{}
|
|
if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
results = &pb.DBAddRecharge{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: uid,
|
|
Record: make(map[int32]bool),
|
|
}
|
|
err = this.Add(uid, results)
|
|
}
|
|
return
|
|
}
|
|
func (this *ModelRecharge) setopen() {
|
|
this.lock.Lock()
|
|
defer this.lock.Unlock()
|
|
this.open = true
|
|
}
|
|
|
|
func (this *ModelRecharge) getopen() bool {
|
|
this.lock.RLock()
|
|
defer this.lock.RUnlock()
|
|
return this.open
|
|
}
|