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.
103 lines
2.5 KiB
103 lines
2.5 KiB
package biz
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
|
|
"matchmaking-system/internal/biz/structure"
|
|
"matchmaking-system/internal/pkg/flags"
|
|
|
|
models "matchmaking-system/internal/pkg/model"
|
|
)
|
|
|
|
// UserSecondOrder
|
|
// @Description:
|
|
type UserSecondOrder struct {
|
|
ud UserSecondOrderRepo
|
|
|
|
log *log.Helper
|
|
}
|
|
|
|
// UserSecondOrderRepo
|
|
// @Description: 订单操作(订单列表|下单)
|
|
type UserSecondOrderRepo interface {
|
|
CheckToken(ctx context.Context) (int, error)
|
|
GetBotSecondTradeList(pageSize, pageCount, userId, status int64) ([]*models.BotContractSecTrade, int64, error)
|
|
CreateSecondBotContractTrade(ctx context.Context, userId int64, order structure.ContractOrder) (string, error)
|
|
}
|
|
|
|
// NewUserSecondOrderRepo
|
|
//
|
|
// @Description:
|
|
// @param uo
|
|
// @param logger
|
|
// @return *UserSecondOrder
|
|
func NewUserSecondOrderRepo(uo UserSecondOrderRepo, logger log.Logger) *UserSecondOrder {
|
|
return &UserSecondOrder{ud: uo, log: log.NewHelper(logger)}
|
|
}
|
|
|
|
// GetUserIdByToken
|
|
//
|
|
// @Description: 通过token获取用户Id
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @return int64
|
|
// @return bool
|
|
// @return error
|
|
func (uo *UserSecondOrder) 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
|
|
}
|
|
|
|
// SecondTradeList
|
|
//
|
|
// @Description: 订单列表查询
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param pageSize
|
|
// @param pageCount
|
|
// @param status
|
|
// @param state
|
|
// @return []*models.BotContractTrade
|
|
// @return int64
|
|
// @return error
|
|
func (uo *UserSecondOrder) SecondTradeList(ctx context.Context, pageSize, pageCount, status int64) ([]*models.BotContractSecTrade, int64, error) {
|
|
userId, token, err := uo.GetUserIdByToken(ctx)
|
|
if userId == 0 || err != nil || !token {
|
|
return nil, 0, flags.ErrTokenMessage
|
|
}
|
|
|
|
contractList, totalCount, err := uo.ud.GetBotSecondTradeList(pageSize, pageCount-1, userId, status)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
return contractList, totalCount, nil
|
|
}
|
|
|
|
// SecondOrder
|
|
//
|
|
// @Description: 下单
|
|
// @receiver uo
|
|
// @param ctx
|
|
// @param order
|
|
// @return string
|
|
// @return error
|
|
func (uo *UserSecondOrder) SecondOrder(ctx context.Context, order structure.ContractOrder) (string, error) {
|
|
userId, token, err := uo.GetUserIdByToken(ctx)
|
|
if !token || err != nil || userId == 0 {
|
|
return flags.SetNull, flags.ErrTokenMessage
|
|
}
|
|
|
|
orderId, err := uo.ud.CreateSecondBotContractTrade(ctx, userId, order)
|
|
if err != nil {
|
|
return flags.SetNull, err
|
|
}
|
|
|
|
return orderId, nil
|
|
}
|
|
|