94 lines
2.3 KiB
Go
94 lines
2.3 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"
|
|
UseItemReq = "pack.useitemreq"
|
|
UseItemResp = "pack.useitemresp"
|
|
SellItemReq = "pack.sellitemreq"
|
|
SellItemResp = "pack.sellitemresp"
|
|
)
|
|
|
|
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", code, &pb.QueryUserPackResp{Items: items})
|
|
}()
|
|
if session.GetUserId() == "" {
|
|
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
|
|
}
|
|
|
|
//使用道具
|
|
func (this *Api_Comp) UseItemReq(ctx context.Context, session comm.IUserSession, req *pb.UseItemReq) (err error) {
|
|
var (
|
|
code pb.ErrorCode
|
|
)
|
|
defer func() {
|
|
session.SendMsg(string(this.module.GetType()), UseItemResp, code, &pb.UseItemResp{})
|
|
}()
|
|
if session.GetUserId() == "" {
|
|
code = pb.ErrorCode_NoLogin
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
//出售道具
|
|
func (this *Api_Comp) SellItemReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserPackReq) (err error) {
|
|
var (
|
|
code pb.ErrorCode
|
|
)
|
|
defer func() {
|
|
session.SendMsg(string(this.module.GetType()), SellItemResp, code, &pb.SellItemResp{})
|
|
}()
|
|
if session.GetUserId() == "" {
|
|
code = pb.ErrorCode_NoLogin
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|