上传商城api接口代码

This commit is contained in:
liwei1dao 2022-07-04 19:09:13 +08:00
parent 813568cb63
commit ccfe0dfc02
6 changed files with 88 additions and 50 deletions

View File

@ -19,15 +19,17 @@ func (this *apiComp) GetlistCheck(session comm.IUserSession, req *pb.ShopGetList
///获取用户商品列表 ///获取用户商品列表
func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq) (code pb.ErrorCode, data proto.Message) { func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
err error err error
filed string filed string
shopconf *cfg.Game_shopData shopconf *cfg.Game_shopData
shopData *pb.DBShop shopData *pb.DBShop
sdata *pb.UserShopData udata *pb.DBUser
items []*cfg.Game_shopitemData sdata *pb.UserShopData
goods []*pb.ShopItem items []*cfg.Game_shopitemData
tdata time.Duration ushoputem map[int32]*pb.DBShopItem
ltime time.Duration goods []*pb.ShopItem
tdata time.Duration
ltime time.Duration
) )
defer func() { defer func() {
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
@ -42,7 +44,14 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return
} }
if udata = this.module.ModuleUser.GetUser(session.GetUserId()); udata == nil {
code = pb.ErrorCode_SystemError
return
}
if ushoputem, err = this.module.modelShopItems.QueryUserShopData(session.GetUserId()); err != nil {
code = pb.ErrorCode_SystemError
return
}
switch req.SType { switch req.SType {
case pb.ShopType_GoldShop: case pb.ShopType_GoldShop:
sdata = shopData.GoldShop sdata = shopData.GoldShop
@ -91,13 +100,13 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq)
var _items []*cfg.Game_shopitemData var _items []*cfg.Game_shopitemData
for _, v := range shopconf.Shopitem { for _, v := range shopconf.Shopitem {
if _items, err = this.module.configure.GetShopItemsConfigureByGroups(v); err != nil { if _items, err = this.module.configure.GetShopItemsConfigureByGroups(v, udata); err != nil {
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return
} }
items = append(items, randomGoods(_items)) items = append(items, randomGoods(_items))
} }
goods = transGoods(items) goods = transGoods(items, ushoputem)
sdata.LastRefreshTime = time.Now().Unix() sdata.LastRefreshTime = time.Now().Unix()
sdata.Items = make([]int32, len(items)) sdata.Items = make([]int32, len(items))
for i, v := range items { for i, v := range items {
@ -108,13 +117,13 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq)
if tdata > ltime { //达到刷新时间 可以刷新商品列表 if tdata > ltime { //达到刷新时间 可以刷新商品列表
var _items []*cfg.Game_shopitemData var _items []*cfg.Game_shopitemData
for _, v := range shopconf.Shopitem { for _, v := range shopconf.Shopitem {
if _items, err = this.module.configure.GetShopItemsConfigureByGroups(v); err != nil { if _items, err = this.module.configure.GetShopItemsConfigureByGroups(v, udata); err != nil {
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return
} }
items = append(items, randomGoods(_items)) items = append(items, randomGoods(_items))
} }
goods = transGoods(items) goods = transGoods(items, ushoputem)
sdata.LastRefreshTime = time.Now().Unix() sdata.LastRefreshTime = time.Now().Unix()
sdata.Items = make([]int32, len(items)) sdata.Items = make([]int32, len(items))
for i, v := range items { for i, v := range items {
@ -126,7 +135,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq)
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return
} }
goods = transGoods(items) goods = transGoods(items, ushoputem)
} }
} else { } else {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError

View File

@ -5,6 +5,7 @@ import (
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
) )
@ -65,7 +66,7 @@ func (this *configureComp) GetShopItemsConfigure(key int32) (result *cfg.Game_sh
} }
//读取商品组 //读取商品组
func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32) (result []*cfg.Game_shopitemData, err error) { func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32, user *pb.DBUser) (result []*cfg.Game_shopitemData, err error) {
result = make([]*cfg.Game_shopitemData, 0, 10) result = make([]*cfg.Game_shopitemData, 0, 10)
var ( var (
v interface{} v interface{}
@ -78,7 +79,10 @@ func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32) (result
} else { } else {
table = v.(*cfg.Game_shopitem) table = v.(*cfg.Game_shopitem)
for _, v := range table.GetDataMap() { for _, v := range table.GetDataMap() {
if v.Id == groupid { if v.Id == groupid &&
user.Lv >= v.Lvmin &&
user.Lv <= v.Lvmax &&
v.Vip >= v.Vip {
result = append(result, item) result = append(result, item)
} }
} }

View File

@ -30,13 +30,19 @@ func randomGoods(goods []*cfg.Game_shopitemData) (result *cfg.Game_shopitemData)
} }
//转换商品对象 //转换商品对象
func transGoods(goods []*cfg.Game_shopitemData) (result []*pb.ShopItem) { func transGoods(goods []*cfg.Game_shopitemData, ushoputem map[int32]*pb.DBShopItem) (result []*pb.ShopItem) {
result = make([]*pb.ShopItem, len(goods)) result = make([]*pb.ShopItem, len(goods))
ok := false
uitem := &pb.DBShopItem{}
for i, v := range goods { for i, v := range goods {
if uitem, ok = ushoputem[v.Key]; !ok {
uitem = &pb.DBShopItem{}
}
result[i] = &pb.ShopItem{ result[i] = &pb.ShopItem{
GoodsId: v.Key, GoodsId: v.Key,
Sale: int32(v.Sale), Sale: int32(v.Sale),
} }
result[i].LeftBuyNum = v.Buyminnum - uitem.BuyNum
result[i].Items = make([]*pb.Resource, len(v.Iteminfo)) result[i].Items = make([]*pb.Resource, len(v.Iteminfo))
for i1, v1 := range v.Iteminfo { for i1, v1 := range v.Iteminfo {
result[i].Items[i1] = &pb.Resource{ result[i].Items[i1] = &pb.Resource{

View File

@ -3,6 +3,7 @@ package shop
import ( import (
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
@ -30,9 +31,16 @@ func (this *modelShopItemsComp) Init(service core.IService, module core.IModule,
} }
//查询用户装备数据 //查询用户装备数据
func (this *modelShopItemsComp) QueryUserShopData(uId string) (data []*pb.DBShopItem, err error) { func (this *modelShopItemsComp) QueryUserShopData(uId string) (result map[int32]*pb.DBShopItem, err error) {
data = make([]*pb.DBShopItem, 0) result = make(map[int32]*pb.DBShopItem)
err = this.GetList(uId, &data) data := make([]*pb.DBShopItem, 0)
if err = this.GetList(uId, &data); err != nil && err != mgo.MongodbNil {
return
}
err = nil
for _, v := range data {
result[v.GoodsId] = v
}
return return
} }

View File

@ -15,7 +15,8 @@ message ShopItem {
int32 GoodsId = 1; //Id int32 GoodsId = 1; //Id
repeated Resource Items = 2; // repeated Resource Items = 2; //
repeated Resource Consume = 3; // repeated Resource Consume = 3; //
int32 Sale = 4; // int32 Sale = 4; //
int32 LeftBuyNum = 5; //
} }
// //

View File

@ -90,10 +90,11 @@ type ShopItem struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
GoodsId int32 `protobuf:"varint,1,opt,name=GoodsId,proto3" json:"GoodsId"` //商品Id GoodsId int32 `protobuf:"varint,1,opt,name=GoodsId,proto3" json:"GoodsId"` //商品Id
Items []*Resource `protobuf:"bytes,2,rep,name=Items,proto3" json:"Items"` //货物 Items []*Resource `protobuf:"bytes,2,rep,name=Items,proto3" json:"Items"` //货物
Consume []*Resource `protobuf:"bytes,3,rep,name=Consume,proto3" json:"Consume"` //消耗 Consume []*Resource `protobuf:"bytes,3,rep,name=Consume,proto3" json:"Consume"` //消耗
Sale int32 `protobuf:"varint,4,opt,name=Sale,proto3" json:"Sale"` //打折 Sale int32 `protobuf:"varint,4,opt,name=Sale,proto3" json:"Sale"` //打折
LeftBuyNum int32 `protobuf:"varint,5,opt,name=LeftBuyNum,proto3" json:"LeftBuyNum"` //还可购买次数
} }
func (x *ShopItem) Reset() { func (x *ShopItem) Reset() {
@ -156,6 +157,13 @@ func (x *ShopItem) GetSale() int32 {
return 0 return 0
} }
func (x *ShopItem) GetLeftBuyNum() int32 {
if x != nil {
return x.LeftBuyNum
}
return 0
}
//获取装备列表请求 //获取装备列表请求
type ShopGetListReq struct { type ShopGetListReq struct {
state protoimpl.MessageState state protoimpl.MessageState
@ -368,30 +376,32 @@ var file_shop_shop_msg_proto_rawDesc = []byte{
0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x52, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x52,
0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, 0x6f,
0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e,
0x74, 0x22, 0x7e, 0x0a, 0x08, 0x53, 0x68, 0x6f, 0x70, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x18, 0x0a, 0x74, 0x22, 0x9e, 0x01, 0x0a, 0x08, 0x53, 0x68, 0x6f, 0x70, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x18,
0x07, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x0a, 0x07, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
0x47, 0x6f, 0x6f, 0x64, 0x73, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x07, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x05, 0x49, 0x74, 0x65, 0x6d,
0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72,
0x65, 0x52, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x23, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x73, 0x63, 0x65, 0x52, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x23, 0x0a, 0x07, 0x43, 0x6f, 0x6e,
0x75, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x73, 0x75, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x52, 0x65, 0x73,
0x75, 0x72, 0x63, 0x65, 0x52, 0x07, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x07, 0x43, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x12, 0x12,
0x04, 0x53, 0x61, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x53, 0x61, 0x6c, 0x0a, 0x04, 0x53, 0x61, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x53, 0x61,
0x65, 0x22, 0x5b, 0x0a, 0x0e, 0x53, 0x68, 0x6f, 0x70, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x6c, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x4c, 0x65, 0x66, 0x74, 0x42, 0x75, 0x79, 0x4e, 0x75, 0x6d,
0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x05, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x4c, 0x65, 0x66, 0x74, 0x42, 0x75, 0x79, 0x4e,
0x28, 0x0e, 0x32, 0x09, 0x2e, 0x53, 0x68, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x52, 0x05, 0x73, 0x75, 0x6d, 0x22, 0x5b, 0x0a, 0x0e, 0x53, 0x68, 0x6f, 0x70, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x73,
0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x0f, 0x49, 0x73, 0x4d, 0x61, 0x6e, 0x75, 0x61, 0x6c, 0x74, 0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x05, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20,
0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x49, 0x01, 0x28, 0x0e, 0x32, 0x09, 0x2e, 0x53, 0x68, 0x6f, 0x70, 0x54, 0x79, 0x70, 0x65, 0x52, 0x05,
0x73, 0x4d, 0x61, 0x6e, 0x75, 0x61, 0x6c, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x22, 0x32, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x0f, 0x49, 0x73, 0x4d, 0x61, 0x6e, 0x75, 0x61,
0x0a, 0x0f, 0x53, 0x68, 0x6f, 0x70, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x6c, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f,
0x70, 0x12, 0x1f, 0x0a, 0x05, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x49, 0x73, 0x4d, 0x61, 0x6e, 0x75, 0x61, 0x6c, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x22,
0x32, 0x09, 0x2e, 0x53, 0x68, 0x6f, 0x70, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x05, 0x47, 0x6f, 0x6f, 0x32, 0x0a, 0x0f, 0x53, 0x68, 0x6f, 0x70, 0x47, 0x65, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65,
0x64, 0x73, 0x22, 0x26, 0x0a, 0x0a, 0x53, 0x68, 0x6f, 0x70, 0x42, 0x75, 0x79, 0x52, 0x65, 0x71, 0x73, 0x70, 0x12, 0x1f, 0x0a, 0x05, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28,
0x12, 0x18, 0x0a, 0x07, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x53, 0x68, 0x6f, 0x70, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x05, 0x47, 0x6f,
0x05, 0x52, 0x07, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x49, 0x64, 0x22, 0x25, 0x0a, 0x0b, 0x53, 0x68, 0x6f, 0x64, 0x73, 0x22, 0x26, 0x0a, 0x0a, 0x53, 0x68, 0x6f, 0x70, 0x42, 0x75, 0x79, 0x52, 0x65,
0x6f, 0x70, 0x42, 0x75, 0x79, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x73, 0x53, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
0x75, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x49, 0x73, 0x53, 0x75, 0x63, 0x28, 0x05, 0x52, 0x07, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x49, 0x64, 0x22, 0x25, 0x0a, 0x0b, 0x53,
0x63, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x68, 0x6f, 0x70, 0x42, 0x75, 0x79, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x73,
0x33, 0x53, 0x75, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x49, 0x73, 0x53, 0x75,
0x63, 0x63, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
} }
var ( var (