1、新增自定义用户私人价格2、优化api服务鉴权缓存3、新增管理员端对公充值
This commit is contained in:
@@ -18,6 +18,7 @@ type (
|
||||
usersModel
|
||||
UpdateUserTrans(ctx context.Context, user *Users, session sqlx.Session) (sql.Result, error)
|
||||
FindOneTrans(ctx context.Context, userId int64, session sqlx.Session) (*Users, error)
|
||||
FindUserPageList(ctx context.Context, page, pageSize int64) ([]Users, int64, error)
|
||||
}
|
||||
|
||||
customUsersModel struct {
|
||||
@@ -76,3 +77,23 @@ func (m *defaultUsersModel) FindOneTrans(ctx context.Context, userId int64, sess
|
||||
// 返回查询结果
|
||||
return &user, nil
|
||||
}
|
||||
func (m *customUsersModel) FindUserPageList(ctx context.Context, page, pageSize int64) ([]Users, int64, error) {
|
||||
offset := (page - 1) * pageSize
|
||||
var users []Users
|
||||
|
||||
query := fmt.Sprintf("SELECT * FROM %s ORDER BY created_at DESC LIMIT ?,?", m.table)
|
||||
err := m.QueryRowsNoCacheCtx(ctx, &users, query, offset, pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 查询总数量
|
||||
var total int64
|
||||
countQuery := fmt.Sprintf("SELECT COUNT(*) FROM %s", m.table)
|
||||
err = m.QueryRowNoCacheCtx(ctx, &total, countQuery)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return users, total, nil
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ WalletsModel = (*customWalletsModel)(nil)
|
||||
@@ -19,6 +20,7 @@ type (
|
||||
InsertWalletsTrans(ctx context.Context, wallets *Wallets, session sqlx.Session) (sql.Result, error)
|
||||
UpdateBalance(session sqlx.Session, ctx context.Context, userId int64, amount float64) error
|
||||
TransCtx(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error
|
||||
FindWalletsByUserIds(ctx context.Context, userIds []int64) (map[int64]*Wallets, error)
|
||||
}
|
||||
|
||||
customWalletsModel struct {
|
||||
@@ -88,3 +90,36 @@ func (m *customWalletsModel) InsertWalletsTrans(ctx context.Context, wallets *Wa
|
||||
|
||||
return ret, err
|
||||
}
|
||||
func (m *customWalletsModel) FindWalletsByUserIds(ctx context.Context, userIds []int64) (map[int64]*Wallets, error) {
|
||||
if len(userIds) == 0 {
|
||||
return make(map[int64]*Wallets), nil
|
||||
}
|
||||
|
||||
queryBuilder := strings.Builder{}
|
||||
queryBuilder.WriteString(fmt.Sprintf("SELECT user_id, balance FROM %s WHERE user_id IN (", m.table))
|
||||
|
||||
placeholders := make([]string, len(userIds))
|
||||
args := make([]interface{}, len(userIds))
|
||||
for i, userId := range userIds {
|
||||
placeholders[i] = "?"
|
||||
args[i] = userId
|
||||
}
|
||||
|
||||
queryBuilder.WriteString(strings.Join(placeholders, ","))
|
||||
queryBuilder.WriteString(")")
|
||||
|
||||
query := queryBuilder.String()
|
||||
|
||||
var wallets []*Wallets
|
||||
err := m.QueryRowNoCacheCtx(ctx, &wallets, query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
walletMap := make(map[int64]*Wallets)
|
||||
for _, wallet := range wallets {
|
||||
walletMap[wallet.UserId] = wallet
|
||||
}
|
||||
|
||||
return walletMap, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user