go_dreamfactory/modules/sociaty/api_cross_challengefinish.go
2023-01-14 18:47:14 +08:00

60 lines
1.7 KiB
Go

package sociaty
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
// 结束挑战
func (this *apiComp) ChallengefinishCheck(session comm.IUserSession, req *pb.SociatyBChallengeFinishReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) Challengefinish(session comm.IUserSession, req *pb.SociatyBChallengeFinishReq) (code pb.ErrorCode, data proto.Message) {
if code = this.ChallengefinishCheck(session, req); code != pb.ErrorCode_Success {
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
}
userEx, err := this.module.ModuleUser.GetUserExpand(uid)
if err != nil {
this.module.Error("GetRemoteUserExpand",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "err", Value: err.Error()},
)
code = pb.ErrorCode_UserSessionNobeing
return
}
this.module.modelSociatyBoss.challengefinish(sociaty, uid, req.Report)
//扣除挑战券
userEx.SociatyTicket -= 1
updateEx := map[string]interface{}{
"sociatyTicket": userEx.SociatyTicket,
}
if err := this.module.ModuleUser.ChangeUserExpand(uid, updateEx); err != nil {
this.module.Error("更新扣除挑战券失败",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "err", Value: err.Error()})
}
rsp := &pb.SociatyBChallengeFinishResp{
Integral: this.module.modelSociatyBoss.transIntegral(req.Report.Harm),
}
if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeChallengefinish, rsp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}