添加支付宝和微信充值功能,重构交易处理逻辑,优化资源创建与支付链接生成
This commit is contained in:
46
web/services/user.go
Normal file
46
web/services/user.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
q "platform/web/queries"
|
||||
)
|
||||
|
||||
var User = &userService{}
|
||||
|
||||
type userService struct{}
|
||||
|
||||
func (s *userService) RechargeConfirm(ctx context.Context, tradeNo string, verified *TransactionVerifyResult) error {
|
||||
|
||||
err := q.Q.Transaction(func(tx *q.Query) error {
|
||||
|
||||
// 更新交易状态
|
||||
result, err := Transaction.CompleteTransaction(ctx, tx, &TransactionCompleteData{
|
||||
TradeNo: tradeNo,
|
||||
TransactionVerifyResult: *verified,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新用户余额
|
||||
user, err := tx.User.
|
||||
Where(tx.User.ID.Eq(result.Trade.UserID)).Take()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.User.
|
||||
Where(tx.User.ID.Eq(user.ID)).
|
||||
Update(tx.User.Balance, user.Balance+result.Trade.Amount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user