70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package activity
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelHdList struct {
|
|
modules.MCompModel
|
|
module *Activity
|
|
}
|
|
|
|
func (this *modelHdList) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableHdInfo)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Activity)
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "hdid", Value: bsonx.Int32(1)}},
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
func (this *modelHdList) getHdInfo() (result []*pb.DBHuodong, err error) {
|
|
|
|
if _data, err := this.DBModel.DB.Find(comm.TableHdInfo, bson.M{}); err == nil {
|
|
for _data.Next(context.TODO()) {
|
|
temp := &pb.DBHuodong{}
|
|
if err = _data.Decode(temp); err != nil {
|
|
this.module.Errorln(err)
|
|
|
|
} else {
|
|
result = append(result, temp)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 通过活动ID查找
|
|
func (this *modelHdList) getHdInfoByHdId(hid int32) (result *pb.DBHuodong, err error) {
|
|
|
|
_data := this.DBModel.DB.FindOne(comm.TableHdInfo, bson.M{"hdid": hid})
|
|
|
|
result = &pb.DBHuodong{}
|
|
if err = _data.Decode(result); err != nil {
|
|
this.module.Errorln(err)
|
|
|
|
}
|
|
return
|
|
}
|
|
|
|
// 不需要修改 此接口不调用
|
|
func (this *modelHdList) modifyHdInfo(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|
|
func (this *modelHdList) addHdInfo(hd *pb.DBHuodong) error {
|
|
if _, err := this.DB.InsertOne(core.SqlTable("hdinfo"), hd); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|