package pack import ( "context" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "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 items []*pb.DB_UserItemData nt int64 tempgrids []*pb.DB_UserItemData grids []*pb.DB_UserItemData modifys []*pb.DB_UserItemData dels []string ) defer func() { session.SendMsg(string(this.module.GetType()), GetlistResp, code, &pb.GetlistResp{Grids: grids}) if code == pb.ErrorCode_Success { go func() { //异步处理修改数据 this.module.cache_comp.Pack_UpdateUserPack(session.GetUserId(), modifys...) this.module.cache_comp.Pack_DeleteUserPack(session.GetUserId(), dels...) }() } }() if code = this.Getlist_Check(ctx, session, req); code != pb.ErrorCode_Success { return } if items, err = this.module.cache_comp.Pack_QueryUserPack(session.GetUserId()); err != nil { log.Errorf("QueryUserPackReq err:%v", err) code = pb.ErrorCode_CacheReadError return } else { tempgrids = this.module.configure_comp.GetPackItemByType(items, req.IType) modifys = make([]*pb.DB_UserItemData, 0, len(tempgrids)) dels = make([]string, 0, len(tempgrids)) grids = make([]*pb.DB_UserItemData, 0, len(grids)) nt = time.Now().Unix() for _, v := range tempgrids { if v.ETime > 0 && v.ETime < nt { //已经过期 dels = append(dels, v.GridId) } else { grids = append(grids, v) if v.IsNewItem { v.IsNewItem = false modifys = append(modifys, v) } } } } return }