73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
package shop
|
|
|
|
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 modelShopItemsComp struct {
|
|
modules.MCompModel
|
|
module *Shop
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *modelShopItemsComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableShopitems
|
|
this.MCompModel.Init(service, module, comp, opt)
|
|
this.module = module.(*Shop)
|
|
//创建uid索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}, {Key: "goodsid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
//查询用户装备数据
|
|
func (this *modelShopItemsComp) QueryUserShopData(uId string) (result map[int32]*pb.DBShopItem, err error) {
|
|
result = make(map[int32]*pb.DBShopItem)
|
|
data := make([]*pb.DBShopItem, 0)
|
|
if err = this.GetList(uId, &data); err != nil && err != mgo.MongodbNil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
err = nil
|
|
for _, v := range data {
|
|
result[v.GoodsId] = v
|
|
}
|
|
return
|
|
}
|
|
|
|
//查询用户装备数据
|
|
func (this *modelShopItemsComp) QueryUserShopDataByGoodId(uId string, goodId int32) (result *pb.DBShopItem, ok bool) {
|
|
var (
|
|
err error
|
|
data []*pb.DBShopItem
|
|
)
|
|
data = make([]*pb.DBShopItem, 0)
|
|
if err = this.GetList(uId, &data); err != nil {
|
|
this.module.Errorf("err%v", err)
|
|
return
|
|
}
|
|
for _, v := range data {
|
|
if v.GoodsId == goodId {
|
|
result = v
|
|
ok = true
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//添加用户的商品购买记录
|
|
func (this *modelShopItemsComp) AddUserShopItemData(data *pb.DBShopItem) (err error) {
|
|
err = this.AddList(data.Uid, data.Id, data)
|
|
return
|
|
}
|