feat: add user balance

This commit is contained in:
Rogee
2025-05-12 21:39:31 +08:00
parent 006e6220bd
commit afd644f558
3 changed files with 10 additions and 1 deletions

View File

@@ -293,6 +293,12 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPI
return &wechat.JSAPIPayParams{ return &wechat.JSAPIPayParams{
AppId: "balance", AppId: "balance",
}, nil }, 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) { prePayResp, err := ctl.wepay.V3TransactionJsapi(ctx.Context(), func(bm *wepay.BodyMap) {

View File

@@ -18,6 +18,7 @@ type UserInfo struct {
CreatedAt time.Time `json:"created_at,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
Username string `json:"username,omitempty"` Username string `json:"username,omitempty"`
Avatar string `json:"avatar,omitempty"` Avatar string `json:"avatar,omitempty"`
Balance int64 `json:"balance,omitempty"`
} }
// @Router /users/profile [get] // @Router /users/profile [get]
@@ -28,6 +29,7 @@ func (ctl *users) Profile(ctx fiber.Ctx, user *model.Users) (*UserInfo, error) {
CreatedAt: user.CreatedAt, CreatedAt: user.CreatedAt,
Username: user.Username, Username: user.Username,
Avatar: *user.Avatar, Avatar: *user.Avatar,
Balance: user.Balance,
}, nil }, nil
} }

View File

@@ -44,11 +44,12 @@ const menuGroups = [
<div> <div>
<h3 class="text-xl font-medium">{{ userInfo.username }}</h3> <h3 class="text-xl font-medium">{{ userInfo.username }}</h3>
<span class="text-gray-500">用户编号: {{ userInfo.id }}</span> <span class="text-gray-500">用户编号: {{ userInfo.id }}</span>
<span class="text-gray-500">账户余额: {{ (userInfo.balance / 100).toFixed(2) }}</span>
</div> </div>
</div> </div>
</div> </div>
<div class="menus space-y-4 mt-4 px-4"> <div class="menus space-y-4 mt-4 px-4 hidden">
<div v-for="(group, groupIndex) in menuGroups" :key="groupIndex" class="bg-white rounded-lg overflow-hidden"> <div v-for="(group, groupIndex) in menuGroups" :key="groupIndex" class="bg-white rounded-lg overflow-hidden">
<div class="px-4 py-2 text-sm text-gray-500">{{ group.title }}</div> <div class="px-4 py-2 text-sm text-gray-500">{{ group.title }}</div>
<div class="divide-y divide-gray-100"> <div class="divide-y divide-gray-100">