You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.5 KiB
71 lines
1.5 KiB
2 months ago
|
package biz
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/go-kratos/kratos/v2/log"
|
||
|
"matchmaking-system/internal/pkg/flags"
|
||
|
)
|
||
|
|
||
|
// UserOrder
|
||
|
// @Description:
|
||
|
type UserBackend struct {
|
||
|
ud UserBackendRepo
|
||
|
|
||
|
log *log.Helper
|
||
|
}
|
||
|
|
||
|
// UserBackendRepo
|
||
|
// @Description:
|
||
|
type UserBackendRepo interface {
|
||
|
// 检查用户(Token|UserID)
|
||
|
CheckToken(ctx context.Context) (int, error)
|
||
|
UpdateBotUsersByIsReal(ctx context.Context, userId int64) error
|
||
|
}
|
||
|
|
||
|
// NewUserBackendRepo
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param logger
|
||
|
// @return *UserOrder
|
||
|
func NewUserBackendRepo(uo UserBackendRepo, logger log.Logger) *UserBackend {
|
||
|
return &UserBackend{ud: uo, log: log.NewHelper(logger)}
|
||
|
}
|
||
|
|
||
|
// GetUserIdByToken
|
||
|
//
|
||
|
// @Description: 通过token获取用户Id
|
||
|
// @receiver uo
|
||
|
// @param ctx
|
||
|
// @return int64
|
||
|
// @return error
|
||
|
func (uo *UserBackend) GetUserIdByToken(ctx context.Context) (int64, bool, error) {
|
||
|
userId, err := uo.ud.CheckToken(ctx)
|
||
|
if err != nil {
|
||
|
return 0, false, flags.ErrTokenMessage
|
||
|
}
|
||
|
|
||
|
return int64(userId), true, nil
|
||
|
}
|
||
|
|
||
|
// SharePreTrade 新股申购交易下单-开盘服务(美股|印尼股|马股|泰股|印度股|新加坡股|港股|英股)
|
||
|
//
|
||
|
// @Description:
|
||
|
// @receiver uo
|
||
|
// @param ctx
|
||
|
// @param id
|
||
|
// @param code
|
||
|
// @param stock
|
||
|
// @return error
|
||
|
func (uo *UserBackend) UpdateBotUsersByIsReal(ctx context.Context) error {
|
||
|
userId, token, err := uo.GetUserIdByToken(ctx)
|
||
|
if userId == 0 || err != nil || !token {
|
||
|
return flags.ErrTokenMessage
|
||
|
}
|
||
|
|
||
|
if err = uo.ud.UpdateBotUsersByIsReal(ctx, userId); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|