From afd644f558fc77bf12106bb33c82b978548c2f2b Mon Sep 17 00:00:00 2001 From: Rogee Date: Mon, 12 May 2025 21:39:31 +0800 Subject: [PATCH] feat: add user balance --- backend/app/http/posts.go | 6 ++++++ backend/app/http/users.go | 2 ++ frontend/wechat/src/views/UserProfile.vue | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/app/http/posts.go b/backend/app/http/posts.go index 2e20ca6..66d473f 100644 --- a/backend/app/http/posts.go +++ b/backend/app/http/posts.go @@ -293,6 +293,12 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPI return &wechat.JSAPIPayParams{ AppId: "balance", }, nil + } else { + payPrice = payPrice - user.Balance + err = models.Users.SetBalance(ctx.Context(), user.ID, 0) + if err != nil { + return nil, errors.Wrap(err, "余额支付失败") + } } prePayResp, err := ctl.wepay.V3TransactionJsapi(ctx.Context(), func(bm *wepay.BodyMap) { diff --git a/backend/app/http/users.go b/backend/app/http/users.go index 7c22ec3..5c56e11 100644 --- a/backend/app/http/users.go +++ b/backend/app/http/users.go @@ -18,6 +18,7 @@ type UserInfo struct { CreatedAt time.Time `json:"created_at,omitempty"` Username string `json:"username,omitempty"` Avatar string `json:"avatar,omitempty"` + Balance int64 `json:"balance,omitempty"` } // @Router /users/profile [get] @@ -28,6 +29,7 @@ func (ctl *users) Profile(ctx fiber.Ctx, user *model.Users) (*UserInfo, error) { CreatedAt: user.CreatedAt, Username: user.Username, Avatar: *user.Avatar, + Balance: user.Balance, }, nil } diff --git a/frontend/wechat/src/views/UserProfile.vue b/frontend/wechat/src/views/UserProfile.vue index f32b909..c00c399 100644 --- a/frontend/wechat/src/views/UserProfile.vue +++ b/frontend/wechat/src/views/UserProfile.vue @@ -44,11 +44,12 @@ const menuGroups = [

{{ userInfo.username }}

用户编号: {{ userInfo.id }} + 账户余额: {{ (userInfo.balance / 100).toFixed(2) }}
-