103 lines
2.5 KiB
Go
103 lines
2.5 KiB
Go
package sociaty
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
func (this *apiComp) BuyCheck(session comm.IUserSession, req *pb.SociatyBuyReq) (errdata *pb.ErrorData) {
|
|
if req.Atn != nil && req.Atn.N <= 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Buy(session comm.IUserSession, req *pb.SociatyBuyReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.BuyCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
ggd := this.module.ModuleTools.GetGlobalConf()
|
|
if ggd == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
uid := session.GetUserId()
|
|
sociaty := this.module.modelSociaty.getUserSociaty(uid)
|
|
if sociaty == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
}
|
|
this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid})
|
|
return
|
|
}
|
|
|
|
//校验钻石
|
|
imodule, err := this.module.service.GetModule(comm.ModuleUser)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ExternalModule,
|
|
Title: pb.ErrorCode_ExternalModule.ToString(),
|
|
Message: comm.NewExternalModuleErr("user", "").Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
iuser, ok := imodule.(comm.IUser)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
atn := []*cfg.Gameatn{
|
|
{A: req.Atn.A,
|
|
T: req.Atn.T,
|
|
N: req.Atn.N},
|
|
}
|
|
if errdata = this.module.CheckRes(session, atn); errdata != nil {
|
|
return
|
|
}
|
|
|
|
ex, err := iuser.GetUserExpand(uid)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_UserSessionNobeing,
|
|
Title: pb.ErrorCode_UserSessionNobeing.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
//挑战券数量计算
|
|
ex.SociatyTicket += req.BuyNum
|
|
|
|
//更新购买次数
|
|
updateEx := map[string]interface{}{
|
|
"sociatyTicket": ex.SociatyTicket, //挑战券数量
|
|
"sociatyTicketBuyNum": ex.SociatyTicketBuyNum + 1, //购买次数
|
|
}
|
|
if err := iuser.ChangeUserExpand(uid, updateEx); err != nil {
|
|
this.module.Error("更新userexpand错误", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err})
|
|
}
|
|
|
|
//扣除资源
|
|
if errdata = this.module.DispenseRes(session, atn, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
rsp := &pb.SociatyBuyResp{
|
|
Uid: uid,
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), SociatySubTypeBuy, rsp)
|
|
return
|
|
}
|