63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package items
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"time"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) GetlistCheck(session comm.IUserSession, req *pb.ItemsGetlistReq) (code pb.ErrorCode) {
|
|
|
|
return
|
|
}
|
|
|
|
///获取用户道具
|
|
func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ItemsGetlistReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
err error
|
|
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()), "getlist", &pb.ItemsGetlistResp{Grids: grids})
|
|
if code == pb.ErrorCode_Success {
|
|
go func() { //异步处理修改数据
|
|
this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...)
|
|
this.module.modelItems.Pack_DeleteUserPack(session.GetUserId(), dels...)
|
|
}()
|
|
}
|
|
}()
|
|
|
|
if items, err = this.module.modelItems.Pack_QueryUserPack(session.GetUserId()); err != nil {
|
|
log.Errorf("QueryUserPackReq err:%v", err)
|
|
code = pb.ErrorCode_CacheReadError
|
|
return
|
|
} else {
|
|
tempgrids = this.module.configure.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
|
|
}
|