refactor: 优化交易类型判断逻辑,使用switch语句增强可读性
This commit is contained in:
@@ -45,10 +45,11 @@ func (s *wallet) GetWallet(ctx context.Context, userID int64) (*user_dto.WalletR
|
||||
for _, o := range orders {
|
||||
var txType string
|
||||
var title string
|
||||
if o.Type == consts.OrderTypeContentPurchase {
|
||||
switch o.Type {
|
||||
case consts.OrderTypeContentPurchase:
|
||||
txType = "expense"
|
||||
title = "购买内容"
|
||||
} else if o.Type == consts.OrderTypeRecharge {
|
||||
case consts.OrderTypeRecharge:
|
||||
txType = "income"
|
||||
title = "钱包充值"
|
||||
}
|
||||
@@ -68,7 +69,11 @@ func (s *wallet) GetWallet(ctx context.Context, userID int64) (*user_dto.WalletR
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *wallet) Recharge(ctx context.Context, userID int64, form *user_dto.RechargeForm) (*user_dto.RechargeResponse, error) {
|
||||
func (s *wallet) Recharge(
|
||||
ctx context.Context,
|
||||
userID int64,
|
||||
form *user_dto.RechargeForm,
|
||||
) (*user_dto.RechargeResponse, error) {
|
||||
amount := int64(form.Amount * 100)
|
||||
if amount <= 0 {
|
||||
return nil, errorx.ErrBadRequest.WithMsg("金额无效")
|
||||
|
||||
Reference in New Issue
Block a user