58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package pack
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/cache"
|
|
|
|
"github.com/liwei1dao/lego/core"
|
|
"github.com/liwei1dao/lego/sys/log"
|
|
)
|
|
|
|
const (
|
|
QueryUserPackReq = "pack.queryuserpackreq"
|
|
QueryUserPackResp = "pack.queryuserpackresp"
|
|
)
|
|
|
|
type Api_Comp struct {
|
|
modules.MComp_GateComp
|
|
module *Pack
|
|
}
|
|
|
|
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.MComp_GateComp.Init(service, module, comp, options)
|
|
this.module = module.(*Pack)
|
|
return
|
|
}
|
|
|
|
///查询用户背包数据
|
|
func (this *Api_Comp) QueryUserPackReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserPackReq) (err error) {
|
|
var (
|
|
code pb.ErrorCode
|
|
pack *pb.DB_UserPackData
|
|
items []*pb.ItemAmount
|
|
)
|
|
defer func() {
|
|
session.SendMsg("pack", "queryuserpackresp", &pb.QueryUserPackResp{Code: code, Items: items})
|
|
}()
|
|
if session.GetUserId() == 0 {
|
|
code = pb.ErrorCode_NoLogin
|
|
return
|
|
}
|
|
if pack, err = cache.Defsys.QueryUserPack(session.GetUserId()); err != nil {
|
|
log.Errorf("QueryUserPackReq err:%v", err)
|
|
code = pb.ErrorCode_CacheReadError
|
|
return
|
|
} else {
|
|
items = make([]*pb.ItemAmount, 0, len(pack.Pack))
|
|
for _, v := range pack.Pack {
|
|
if v.Itype == req.IType {
|
|
items = append(items, &pb.ItemAmount{IsNew: v.IsNew, ItemId: v.ItemId, Amount: v.Amount})
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|