77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package activity
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelhdData struct {
|
|
modules.MCompModel
|
|
module *Activity
|
|
}
|
|
|
|
func (this *modelhdData) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableHdData)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Activity)
|
|
// uid 创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
// 获取所有活动数据
|
|
func (this *modelhdData) getHdAlldata(uid string) (result []*pb.DBActivityData, err error) {
|
|
result = make([]*pb.DBActivityData, 0)
|
|
if err = this.GetList(uid, &result); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 通过活动唯一ID 获取活动数据
|
|
func (this *modelhdData) getHddataByOid(uid string, oid string) (result *pb.DBActivityData, err error) {
|
|
result = &pb.DBActivityData{
|
|
Id: "",
|
|
Uid: uid,
|
|
Hdoid: oid,
|
|
Gotarr: map[int32]int32{},
|
|
Lasttime: 0,
|
|
Val: 0,
|
|
}
|
|
key := fmt.Sprintf("%s-%s", uid, oid)
|
|
if err = this.GetListObj(uid, key, result); err == mongo.ErrNoDocuments {
|
|
result.Id = key
|
|
result.Uid = uid
|
|
result.Hdoid = oid
|
|
result.Lasttime = configure.Now().Unix()
|
|
this.AddList(uid, result.Id, result)
|
|
err = nil
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 新增一条活动数据
|
|
func (this *modelhdData) InsertHddata(uid string, data *pb.DBActivityData) (err error) {
|
|
if err = this.AddList(uid, data.Id, data); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *modelhdData) ModifyActivityList(uid string, oid string, data map[string]interface{}) error {
|
|
return this.ChangeList(uid, oid, data)
|
|
}
|