topfans/backend/services/statisticService/client/user_rpc_client.go
2026-06-09 00:37:42 +08:00

43 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package client
import (
"context"
pbCommon "github.com/topfans/backend/pkg/proto/common"
pbUser "github.com/topfans/backend/pkg/proto/user"
)
// UserServiceClient 封装 userService 的 Dubbo 调用
type UserServiceClient struct {
userSocial pbUser.UserSocialService
}
// NewUserServiceClient 构造
func NewUserServiceClient(svc pbUser.UserSocialService) *UserServiceClient {
return &UserServiceClient{userSocial: svc}
}
// GetCrystalBalance 调 userService.GetFanProfile 取 crystal_balance
// userService 没单独 GetCrystalBalanceFanProfile 含此字段)
// 注意: StatusCode_STATUS_OK == 200不是 0之前用 resp.Base.Code != 0
// 检查等价于"任何成功响应都被当作错误",导致永远返回 0
func (c *UserServiceClient) GetCrystalBalance(ctx context.Context, userID, starID int64) (int64, error) {
resp, err := c.userSocial.GetFanProfile(ctx, &pbUser.GetFanProfileRequest{
UserId: userID,
StarId: starID,
})
if err != nil {
return 0, err
}
if resp == nil || resp.Base == nil {
return 0, nil
}
if resp.Base.Code != pbCommon.StatusCode_STATUS_OK {
return 0, nil
}
if resp.Profile == nil {
return 0, nil
}
return resp.Profile.CrystalBalance, nil
}