89 lines
2.1 KiB
Go
89 lines
2.1 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) (code pb.ErrorCode) {
|
|
if req.Atn != nil && req.Atn.N <= 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Buy(session comm.IUserSession, req *pb.SociatyBuyReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
if code = this.BuyCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
ggd := this.module.ModuleTools.GetGlobalConf()
|
|
if ggd == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
uid := session.GetUserId()
|
|
sociaty := this.module.modelSociaty.getUserSociaty(uid)
|
|
if sociaty == nil {
|
|
code = pb.ErrorCode_SociatyNoFound
|
|
this.module.Error("当前玩家所在的公会未找到", log.Field{Key: "uid", Value: uid})
|
|
return
|
|
}
|
|
|
|
//校验钻石
|
|
imodule, err := this.module.service.GetModule(comm.ModuleUser)
|
|
if err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
|
|
iuser, ok := imodule.(comm.IUser)
|
|
if !ok {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
|
|
atn := []*cfg.Gameatn{
|
|
{A: req.Atn.A,
|
|
T: req.Atn.T,
|
|
N: req.Atn.N},
|
|
}
|
|
if code = this.module.CheckRes(session, atn); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
ex, err := iuser.GetUserExpand(uid)
|
|
if err != nil {
|
|
code = pb.ErrorCode_UserSessionNobeing
|
|
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 code = this.module.DispenseRes(session, atn, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
rsp := &pb.SociatyBuyResp{
|
|
Uid: uid,
|
|
}
|
|
|
|
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeBuy, rsp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
return
|
|
}
|