chore: stabilize lint and verify builds

This commit is contained in:
2026-02-06 11:51:32 +08:00
parent edede17880
commit 1782f64417
114 changed files with 3032 additions and 1345 deletions

View File

@@ -3,17 +3,15 @@ package services
import (
"context"
"errors"
"strings"
"time"
"quyun/v2/app/errorx"
user_dto "quyun/v2/app/http/v1/dto"
"quyun/v2/database/fields"
"quyun/v2/database/models"
"quyun/v2/pkg/consts"
"github.com/google/uuid"
"go.ipao.vip/gen/field"
"go.ipao.vip/gen/types"
"gorm.io/gorm"
)
@@ -27,6 +25,7 @@ func (s *wallet) GetWallet(ctx context.Context, tenantID, userID int64) (*user_d
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errorx.ErrRecordNotFound
}
return nil, errorx.ErrDatabaseError.WithCause(err)
}
@@ -84,37 +83,18 @@ func (s *wallet) Recharge(
userID int64,
form *user_dto.RechargeForm,
) (*user_dto.RechargeResponse, error) {
amount := int64(form.Amount * 100)
if amount <= 0 {
return nil, errorx.ErrBadRequest.WithMsg("金额无效")
code := strings.TrimSpace(form.Code)
if code == "" {
return nil, errorx.ErrBadRequest.WithMsg("充值码不能为空")
}
// Create Recharge Order
order := &models.Order{
TenantID: 0, // Platform / System
UserID: userID,
Type: consts.OrderTypeRecharge,
Status: consts.OrderStatusCreated,
Currency: consts.CurrencyCNY,
AmountOriginal: amount,
AmountPaid: amount,
IdempotencyKey: uuid.NewString(),
Snapshot: types.NewJSONType(fields.OrdersSnapshot{}),
}
if err := models.OrderQuery.WithContext(ctx).Create(order); err != nil {
return nil, errorx.ErrDatabaseError.WithCause(err)
}
// MOCK: Automatically pay for recharge order to close the loop
// In production, this would be a callback from payment gateway
if err := Order.ProcessExternalPayment(ctx, tenantID, order.ID, "mock_auto_pay"); err != nil {
resp, err := Recharge.Redeem(ctx, tenantID, userID, code)
if err != nil {
return nil, err
}
// Mock Pay Params
return &user_dto.RechargeResponse{
PayParams: "mock_paid_success",
OrderID: order.ID,
OrderID: resp.OrderID,
Amount: resp.Amount,
}, nil
}