From 6730204aa372ab9f31d0c74872051470a2e18df3 Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Mon, 21 Oct 2024 17:07:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/admin.api | 10 ++++---- apps/admin/internal/handler/routes.go | 2 +- apps/admin/internal/types/types.go | 8 +++---- .../logic/topup/alitopupnotifylogic.go | 2 +- .../walletservice/rechargewalletlogic.go | 1 + apps/user/internal/model/rechargemodel.go | 4 ++-- apps/user/internal/model/walletsmodel.go | 24 +++++++++---------- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/apps/admin/admin.api b/apps/admin/admin.api index 89435e7..d7f0dd0 100644 --- a/apps/admin/admin.api +++ b/apps/admin/admin.api @@ -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) diff --git a/apps/admin/internal/handler/routes.go b/apps/admin/internal/handler/routes.go index bb730dc..de3061b 100644 --- a/apps/admin/internal/handler/routes.go +++ b/apps/admin/internal/handler/routes.go @@ -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), }, diff --git a/apps/admin/internal/types/types.go b/apps/admin/internal/types/types.go index 4532cb0..5083a32 100644 --- a/apps/admin/internal/types/types.go +++ b/apps/admin/internal/types/types.go @@ -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"` } diff --git a/apps/sentinel/internal/logic/topup/alitopupnotifylogic.go b/apps/sentinel/internal/logic/topup/alitopupnotifylogic.go index 0cd6d01..0f446b2 100644 --- a/apps/sentinel/internal/logic/topup/alitopupnotifylogic.go +++ b/apps/sentinel/internal/logic/topup/alitopupnotifylogic.go @@ -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 diff --git a/apps/user/internal/logic/walletservice/rechargewalletlogic.go b/apps/user/internal/logic/walletservice/rechargewalletlogic.go index 03b6c85..fea9b34 100644 --- a/apps/user/internal/logic/walletservice/rechargewalletlogic.go +++ b/apps/user/internal/logic/walletservice/rechargewalletlogic.go @@ -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 diff --git a/apps/user/internal/model/rechargemodel.go b/apps/user/internal/model/rechargemodel.go index 6fb54c2..c32b35e 100644 --- a/apps/user/internal/model/rechargemodel.go +++ b/apps/user/internal/model/rechargemodel.go @@ -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 } diff --git a/apps/user/internal/model/walletsmodel.go b/apps/user/internal/model/walletsmodel.go index 4a5bff2..89ecb57 100644 --- a/apps/user/internal/model/walletsmodel.go +++ b/apps/user/internal/model/walletsmodel.go @@ -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