58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package pay
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
///每日礼包
|
|
type modelPayUserComp struct {
|
|
modules.MCompModel
|
|
module *Pay
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *modelPayUserComp) 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.TablePayUser
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
//查询用户重置数据
|
|
func (this *modelPayUserComp) queryUserPay(uId string) (result *pb.DBUserPay, err error) {
|
|
result = &pb.DBUserPay{
|
|
Uid: uId,
|
|
Record: make(map[string]int32),
|
|
}
|
|
if err = this.Get(uId, result); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorf("err:%v", err)
|
|
}
|
|
if err == mgo.MongodbNil {
|
|
|
|
err = nil
|
|
}
|
|
return
|
|
}
|
|
|
|
//添加用户订单数据
|
|
func (this *modelPayUserComp) updateUserPay(info *pb.DBUserPay) (err error) {
|
|
if err = this.Change(info.Uid, map[string]interface{}{
|
|
"record": info.Record,
|
|
}); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
return
|
|
}
|