优化支付退款钱包链路

This commit is contained in:
yml
2026-06-03 21:47:04 +08:00
parent 04193ae687
commit c80d3f960e
26 changed files with 1342 additions and 504 deletions
@@ -81,6 +81,25 @@ func (h *Handler) Recharge(c *gin.Context) {
response.OK(c, account)
}
func (h *Handler) Withdraw(c *gin.Context) {
userID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
var req WithdrawRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "提现金额不正确")
return
}
account, err := h.service.Withdraw(userID, req)
if err != nil {
writeWalletError(c, err)
return
}
response.OK(c, account)
}
func (h *Handler) AdminLedger(c *gin.Context) {
query, ok := parseAdminLedgerQuery(c)
if !ok {
@@ -136,6 +155,10 @@ func writeWalletError(c *gin.Context, err error) {
response.BadRequest(c, "充值金额不正确")
case errors.Is(err, ErrInsufficientBalance):
response.Error(c, 409, "insufficient_balance", "钱包余额不足")
case errors.Is(err, ErrRechargeDisabled):
response.Error(c, 410, "wallet_recharge_disabled", "钱包充值已关闭")
case errors.Is(err, ErrFeaturePending):
response.Error(c, 501, "feature_pending", "提现功能待开发")
default:
response.ServiceUnavailable(c, "钱包服务暂时不可用")
}