95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package items
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) SellinbulkCheck(session comm.IUserSession, req *pb.ItemsSellinbulkReq) (errdata *pb.ErrorData) {
|
|
if req.Grids == nil || req.Amount == nil || len(req.Grids) != len(req.Amount) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//批量出售
|
|
func (this *apiComp) Sellinbulk(session comm.IUserSession, req *pb.ItemsSellinbulkReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
items []*pb.DB_UserItemData
|
|
cids []string
|
|
itemcf []*cfg.GameItemData
|
|
issucc []bool
|
|
sale []*cfg.Gameatn
|
|
)
|
|
if errdata = this.SellinbulkCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if items, err = this.module.modelItems.QueryUserPackByGridIds(session.GetUserId(), req.Grids); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
cids = make([]string, len(items))
|
|
for i, v := range items {
|
|
cids[i] = v.ItemId
|
|
}
|
|
if itemcf, err = this.module.configure.GetItemConfigures(cids); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigurationException,
|
|
Title: pb.ErrorCode_ConfigurationException.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
issucc = make([]bool, len(items))
|
|
for i, v := range itemcf {
|
|
issucc[i] = true
|
|
if v.Sale == nil || len(v.Sale) == 0 {
|
|
issucc[i] = false
|
|
this.module.Errorf("Sellinbulk Sale is nill id:%s", v.Id)
|
|
continue
|
|
}
|
|
if req.Amount[i] > items[i].Amount {
|
|
issucc[i] = false
|
|
this.module.Errorf("Sellinbulk over all amount:[%d:%d]", req.Amount[i], items[i].Amount)
|
|
continue
|
|
}
|
|
sale = make([]*cfg.Gameatn, len(v.Sale))
|
|
for i, v := range v.Sale {
|
|
temp := *v
|
|
sale[i] = &temp
|
|
sale[i].N = v.N * int32(req.Amount[i])
|
|
}
|
|
items[i].Amount = items[i].Amount - req.Amount[i]
|
|
}
|
|
|
|
if errdata = this.module.DispenseRes(session, sale, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if err = this.module.modelItems.UpdateUserPack(session.GetUserId(), items...); err != nil {
|
|
this.module.Errorln(err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
this.module.itemsChangePush(session, items)
|
|
session.SendMsg(string(this.module.GetType()), "sellitem", &pb.ItemsSellinbulkResp{Grids: req.Grids, Amount: req.Amount, Issucc: issucc})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), "ItemsSellinbulkReq", sale)
|
|
})
|
|
return
|
|
}
|