65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package pack
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/cache"
|
|
"time"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *Api_Comp) Getlist_Check(ctx context.Context, session comm.IUserSession, req *pb.GetlistReq) (code pb.ErrorCode) {
|
|
if !session.IsLogin() {
|
|
code = pb.ErrorCode_NoLogin
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///获取用户道具
|
|
func (this *Api_Comp) Getlist(ctx context.Context, session comm.IUserSession, req *pb.GetlistReq) (err error) {
|
|
var (
|
|
code pb.ErrorCode
|
|
pack *pb.DB_UserPackData
|
|
nt int64
|
|
tempgrids []*pb.DB_GridData
|
|
grids []*pb.DB_GridData
|
|
modifys []*pb.DB_GridData
|
|
)
|
|
defer func() {
|
|
session.SendMsg(string(this.module.GetType()), GetlistResp, code, &pb.GetlistResp{Grids: grids})
|
|
if code == pb.ErrorCode_Success {
|
|
go func() { //异步处理修改数据
|
|
cache.Defsys.Pack_UpdateGridToUserPack(session.GetUserId(), modifys...)
|
|
}()
|
|
}
|
|
}()
|
|
if code = this.Getlist_Check(ctx, session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if pack, err = cache.Defsys.Pack_QueryUserPack(session.GetUserId()); err != nil {
|
|
log.Errorf("QueryUserPackReq err:%v", err)
|
|
code = pb.ErrorCode_CacheReadError
|
|
return
|
|
} else {
|
|
tempgrids = this.module.configure_comp.GetPackItemByType(pack, req.IType)
|
|
modifys = make([]*pb.DB_GridData, 0, len(tempgrids))
|
|
grids = make([]*pb.DB_GridData, 0, len(grids))
|
|
nt = time.Now().Unix()
|
|
for _, v := range tempgrids {
|
|
if v.ETime > 0 && v.ETime < nt { //已经过期
|
|
modifys = append(modifys, &pb.DB_GridData{GridId: v.GridId, IsEmpty: true})
|
|
} else {
|
|
grids = append(grids, v)
|
|
if v.IsNewItem {
|
|
v.IsNewItem = false
|
|
modifys = append(modifys, v)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|