64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package items
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
|
|
"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
|
|
grids []*pb.DB_UserItemData
|
|
modifys []*pb.DB_UserItemData
|
|
dels []*pb.DB_UserItemData
|
|
)
|
|
defer func() {
|
|
if code == pb.ErrorCode_Success {
|
|
if len(modifys) > 0 {
|
|
this.module.modelItems.UpdateUserPack(session.GetUserId(), modifys...)
|
|
}
|
|
if len(dels) > 0 {
|
|
this.module.modelItems.DeleteUserPack(session.GetUserId(), dels...)
|
|
}
|
|
}
|
|
}()
|
|
|
|
if items, err = this.module.modelItems.QueryUserPack(session.GetUserId()); err != nil {
|
|
this.module.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(items))
|
|
dels = make([]*pb.DB_UserItemData, 0, len(items))
|
|
grids = make([]*pb.DB_UserItemData, 0, len(items))
|
|
nt = configure.Now().Unix()
|
|
for _, v := range items {
|
|
if v.ETime > 0 && v.ETime < nt { //已经过期
|
|
dels = append(dels, v)
|
|
} else {
|
|
grids = append(grids, v)
|
|
if v.IsNewItem {
|
|
temp := *v
|
|
temp.IsNewItem = false
|
|
modifys = append(modifys, &temp)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "getlist", &pb.ItemsGetlistResp{Grids: items})
|
|
return
|
|
}
|