go_dreamfactory/modules/pay/model.go
2023-11-21 17:13:53 +08:00

58 lines
1.5 KiB
Go

package pay
import (
"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 modelComp struct {
modules.MCompModel
module *Pay
}
//组件初始化接口
func (this *modelComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Pay)
this.TableName = comm.TablePay
//创建uid索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
//查询用户重置数据
func (this *modelComp) getmodel(oid string) (order *pb.DBPayOrder, err error) {
order = &pb.DBPayOrder{}
if err = this.DBModel.DB.FindOne(core.SqlTable(this.TableName), bson.M{"_id": oid}).Decode(order); err != nil {
this.module.Errorln(err)
}
return
}
//添加用户订单数据
func (this *modelComp) create(order *pb.DBPayOrder) (err error) {
if _, err = this.DBModel.DB.InsertOne(core.SqlTable(this.TableName), order); err != nil {
this.module.Errorln(err)
}
return
}
//添加用户订单数据
func (this *modelComp) updateState(oid string, state pb.DBPayOrderState) (err error) {
if _, err = this.DBModel.DB.UpdateOne(core.SqlTable(this.TableName), bson.M{"_id": oid}, bson.M{
"$set": bson.M{"state": state},
}); err != nil {
this.module.Errorln(err)
}
return
}