feat: add charge
This commit is contained in:
@@ -174,13 +174,13 @@ func (svc *Service) TenantHasUser(ctx context.Context, userID, tenantID int64) (
|
||||
log.Debug(stmt.DebugSql())
|
||||
|
||||
var result struct {
|
||||
cnt int64
|
||||
Cnt int64
|
||||
}
|
||||
if err := stmt.QueryContext(ctx, db.FromContext(ctx, svc.db), &result); err != nil {
|
||||
return false, errors.Wrap(err, "failed to query user-tenant relation")
|
||||
}
|
||||
|
||||
return result.cnt > 0, nil
|
||||
return result.Cnt > 0, nil
|
||||
}
|
||||
|
||||
// CreateTenantUser
|
||||
@@ -268,7 +268,7 @@ func (svc *Service) GenerateChargeCode(ctx context.Context, tenantID, chargeAmou
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to encode charge code")
|
||||
}
|
||||
log.Infof("generate charge code: %s", code)
|
||||
log.Infof("generate charge code: %s, info: %+v", code, []int64{tenantID, chargeAmount, timestamp})
|
||||
|
||||
return code, nil
|
||||
}
|
||||
@@ -379,3 +379,20 @@ func (svc *Service) Charge(ctx context.Context, claim *jwt.Claims, code string)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTenantUserBalance
|
||||
func (svc *Service) GetTenantUserBalance(ctx context.Context, tenantID, userID int64) (int64, error) {
|
||||
log := svc.log.WithField("method", "GetTenantUserBalance")
|
||||
|
||||
tbl := table.UsersTenants
|
||||
stmt := tbl.SELECT(tbl.Balance.AS("balance")).WHERE(tbl.TenantID.EQ(Int64(tenantID)).AND(tbl.UserID.EQ(Int64(userID))))
|
||||
log.Debug(stmt.DebugSql())
|
||||
|
||||
var result struct {
|
||||
Balance int64
|
||||
}
|
||||
if err := stmt.QueryContext(ctx, db.FromContext(ctx, svc.db), &result); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to query user balance")
|
||||
}
|
||||
return result.Balance, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user