修正
This commit is contained in:
parent
2292d25d74
commit
6730204aa3
@ -154,8 +154,8 @@ service admin-api {
|
||||
|
||||
type (
|
||||
UserListRequest {
|
||||
Page int64 `json:"page"` // 分页页码
|
||||
PageSize int64 `json:"pageSize"` // 每页大小
|
||||
Page int64 `form:"page"` // 分页页码
|
||||
PageSize int64 `form:"pageSize"` // 每页大小
|
||||
}
|
||||
UserListResponse {
|
||||
List []UserItem `json:"list"`
|
||||
@ -172,8 +172,8 @@ type (
|
||||
UpdatedAt string `json:"updatedAt"` // 更新时间
|
||||
}
|
||||
rechargeRequest {
|
||||
UserId int64 `json:userId`
|
||||
Amount int64 `json:amount`
|
||||
UserId int64 `json:"userId"`
|
||||
Amount int64 `json:"amount"`
|
||||
}
|
||||
)
|
||||
|
||||
@ -184,7 +184,7 @@ type (
|
||||
)
|
||||
service admin-api {
|
||||
@handler getUserList
|
||||
post /user/list (UserListRequest) returns (UserListResponse)
|
||||
get /user/list (UserListRequest) returns (UserListResponse)
|
||||
|
||||
@handler recharge
|
||||
post /user/recharge (rechargeRequest)
|
||||
|
@ -99,7 +99,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
[]rest.Middleware{serverCtx.AuthInterceptor},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/list",
|
||||
Handler: user.GetUserListHandler(serverCtx),
|
||||
},
|
||||
|
@ -111,8 +111,8 @@ type UserItem struct {
|
||||
}
|
||||
|
||||
type UserListRequest struct {
|
||||
Page int64 `json:"page"` // 分页页码
|
||||
PageSize int64 `json:"pageSize"` // 每页大小
|
||||
Page int64 `form:"page"` // 分页页码
|
||||
PageSize int64 `form:"pageSize"` // 每页大小
|
||||
}
|
||||
|
||||
type UserListResponse struct {
|
||||
@ -121,6 +121,6 @@ type UserListResponse struct {
|
||||
}
|
||||
|
||||
type RechargeRequest struct {
|
||||
UserId int64 `json:userId`
|
||||
Amount int64 `json:amount`
|
||||
UserId int64 `json:"userId"`
|
||||
Amount int64 `json:"amount"`
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func (l *AliTopUpNotifyLogic) AliTopUpNotify(in *sentinel.AliTopUpNotifyRequest)
|
||||
UserId: payOrder.UserId,
|
||||
OutTradeNo: payOrder.OutTradeNo,
|
||||
Amount: int64(payOrder.Amount),
|
||||
PaymentMethod: 0,
|
||||
PaymentMethod: 1,
|
||||
})
|
||||
if rechargeWallet != nil {
|
||||
return nil, globalErr
|
||||
|
@ -64,6 +64,7 @@ func (l *RechargeWalletLogic) RechargeWallet(in *user.RechargeWalletRequest) (*u
|
||||
OutTradeNo: in.OutTradeNo,
|
||||
UserId: in.UserId,
|
||||
Amount: float64(in.Amount),
|
||||
PaymentMethod: in.PaymentMethod,
|
||||
}, session)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -33,8 +33,8 @@ func NewRechargeModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option
|
||||
func (m *customRechargeModel) InsertRechargeTrans(ctx context.Context, data *Recharge, session sqlx.Session) (sql.Result, error) {
|
||||
rechargeOutTradeNoKey := fmt.Sprintf("%s%v", cacheRechargeOutTradeNoPrefix, data.OutTradeNo)
|
||||
rechargeTransactionIdKey := fmt.Sprintf("%s%v", cacheRechargeTransactionIdPrefix, data.TransactionId)
|
||||
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?)", m.table, rechargeRowsExpectAutoSet)
|
||||
ret, err := session.ExecCtx(ctx, query, data.UserId, data.TransactionId, data.OutTradeNo, data.Amount, data.PaymentMethod)
|
||||
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?, ?)", m.table, rechargeRowsExpectAutoSet)
|
||||
ret, err := session.ExecCtx(ctx, query, data.UserId, data.TransactionId, data.OutTradeNo, data.Amount, data.PaymentMethod, data.Remark)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -48,8 +48,13 @@ func (m *customWalletsModel) TransCtx(ctx context.Context, fn func(ctx context.C
|
||||
// 更新余额的方法
|
||||
func (m *customWalletsModel) UpdateBalance(session sqlx.Session, ctx context.Context, userId int64, amount float64) error {
|
||||
|
||||
wallet, err := m.FindOneByUserId(ctx, userId)
|
||||
if err != nil {
|
||||
//wallet, err := m.FindOneByUserId(ctx, userId)
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
var wallet Wallets
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `user_id` = ? limit 1", walletsRows, m.table)
|
||||
if err := m.QueryRowNoCacheCtx(ctx, &wallet, query, userId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -73,12 +78,6 @@ func (m *customWalletsModel) UpdateBalance(session sqlx.Session, ctx context.Con
|
||||
if rowsAffected == 0 {
|
||||
return ErrVersionMismatch
|
||||
}
|
||||
|
||||
walletsUserIdKey := fmt.Sprintf("%s%v", cacheWalletsUserIdPrefix, userId)
|
||||
cacheErrors := m.DelCacheCtx(ctx, walletsUserIdKey)
|
||||
if cacheErrors != nil {
|
||||
return cacheErrors
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *customWalletsModel) InsertWalletsTrans(ctx context.Context, wallets *Wallets, session sqlx.Session) (sql.Result, error) {
|
||||
@ -96,7 +95,7 @@ func (m *customWalletsModel) FindWalletsByUserIds(ctx context.Context, userIds [
|
||||
}
|
||||
|
||||
queryBuilder := strings.Builder{}
|
||||
queryBuilder.WriteString(fmt.Sprintf("SELECT user_id, balance FROM %s WHERE user_id IN (", m.table))
|
||||
queryBuilder.WriteString(fmt.Sprintf("SELECT %s FROM %s WHERE user_id IN (", walletsRows, m.table))
|
||||
|
||||
placeholders := make([]string, len(userIds))
|
||||
args := make([]interface{}, len(userIds))
|
||||
@ -110,15 +109,16 @@ func (m *customWalletsModel) FindWalletsByUserIds(ctx context.Context, userIds [
|
||||
|
||||
query := queryBuilder.String()
|
||||
|
||||
var wallets []*Wallets
|
||||
err := m.QueryRowNoCacheCtx(ctx, &wallets, query, args...)
|
||||
var wallets []Wallets
|
||||
err := m.QueryRowsNoCacheCtx(ctx, &wallets, query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
walletMap := make(map[int64]*Wallets)
|
||||
for _, wallet := range wallets {
|
||||
walletMap[wallet.UserId] = wallet
|
||||
walletCopy := wallet // Create a copy to ensure the correct address is used
|
||||
walletMap[wallet.UserId] = &walletCopy
|
||||
}
|
||||
|
||||
return walletMap, nil
|
||||
|
Loading…
Reference in New Issue
Block a user