61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package items
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"time"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) Getlist_Check(session comm.IUserSession, req *pb.Items_Getlist_Req) (result map[string]interface{}, code comm.ErrorCode) {
|
|
result = map[string]interface{}{"ce": 123}
|
|
return
|
|
}
|
|
|
|
///获取用户道具
|
|
func (this *apiComp) Getlist(session comm.IUserSession, agrs map[string]interface{}, req *pb.Items_Getlist_Req) (code pb.ErrorCode) {
|
|
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()), GetlistResp, &pb.Items_Getlist_Resp{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
|
|
}
|