go_dreamfactory/modules/entertainment/api_match.go
2023-11-21 16:07:51 +08:00

74 lines
2.0 KiB
Go

package entertainment
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
//参数校验
func (this *apiComp) MatchCheck(session comm.IUserSession, req *pb.EntertainMatchReq) (errdata *pb.ErrorData) {
if req.Idcard == "" {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
}
return
}
func (this *apiComp) Match(session comm.IUserSession, req *pb.EntertainMatchReq) (errdata *pb.ErrorData) {
var (
user *pb.DBUser
err error
conf *cfg.GameConsumeHeroData
)
user, err = this.module.ModuleUser.GetUser(session.GetUserId())
if err != nil {
return
}
if conf, err = this.module.configure.GetGameConsumeHero(req.Idcard); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
if conf.Type != 1 { // 校验数量够不够
if list, err := this.module.model.getEntertainmList(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
} else {
if list.Card[req.Idcard] <= 0 { // 需要购买
if errdata = this.module.ConsumeRes(session, conf.Consume, true); errdata != nil {
return
}
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), comm.GMResDelType, "EntertainMatchReq", conf.Consume)
})
list.Card[req.Idcard] += 1
this.module.model.modifyEntertainmList(session.GetUserId(), map[string]interface{}{
"card": list.Card,
})
}
}
}
this.module.match.MatchReq(&pb.DBXXLMatch{
Userinfo: comm.GetUserBaseInfo(user),
Cardid: req.Idcard,
Consumeexp: user.Consumeexp,
})
session.SendMsg(string(this.module.GetType()), "match", &pb.EntertainMatchResp{
Maych: true,
})
return
}