You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package user
|
|
|
|
import (
|
|
"dcg/app/user_center/pb"
|
|
"dcg/app/user_center/usercenter"
|
|
"dcg/game/manager"
|
|
pbCommon "dcg/game/pb/common"
|
|
"dcg/game/svc"
|
|
"git.noahlan.cn/northlan/ngs/component"
|
|
"git.noahlan.cn/northlan/ngs/session"
|
|
"github.com/pkg/errors"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
type UserLogic struct {
|
|
component.Base
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewUserIntegral(svcCtx *svc.ServiceContext) *UserLogic {
|
|
return &UserLogic{
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (p *UserLogic) Init() {
|
|
}
|
|
|
|
func (p *UserLogic) Shutdown() {
|
|
}
|
|
|
|
func (p *UserLogic) CMD() string {
|
|
return "user"
|
|
}
|
|
|
|
func (p *UserLogic) Prefix() string {
|
|
return "integral"
|
|
}
|
|
|
|
// Change 更新积分
|
|
func (p *UserLogic) Change(s *session.Session, msg *pbCommon.ChangeUserIntegralReq) error {
|
|
integral, err := p.svcCtx.UserCenterRpc.ChangeIntegral(p.svcCtx.Ctx, &usercenter.ChangeIntegralReq{
|
|
UserId: msg.UserId,
|
|
BattleId: manager.GameManager.DataManager.BattleIdBySession(s),
|
|
Change: msg.Change,
|
|
IntegralType: pb.IntegralType_Battle,
|
|
})
|
|
if err != nil {
|
|
cause := errors.Cause(err)
|
|
gStatus, _ := status.FromError(cause)
|
|
|
|
return s.Response(&pbCommon.ChangeUserIntegralResp{
|
|
Code: int32(gStatus.Code()),
|
|
Msg: gStatus.Message(),
|
|
})
|
|
}
|
|
return s.Response(&pbCommon.ChangeUserIntegralResp{
|
|
Code: 200,
|
|
Msg: "成功",
|
|
UserId: msg.UserId,
|
|
Change: msg.Change,
|
|
Integral: integral.Integral,
|
|
})
|
|
}
|