mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-18 04:37:27 +00:00
Add plan-level quota reset periods and display/reset cadence in admin/UI Enforce natural reset alignment with background reset task and cleanup job Make subscription pre-consume/refund idempotent with request-scoped records and retries Use database time for consistent resets across multi-instance deployments Harden payment callbacks with locking and idempotent order completion Record subscription purchases in topup history and billing logs Optimize subscription queries and add critical composite indexes
23 lines
570 B
Go
23 lines
570 B
Go
package model
|
|
|
|
import "github.com/QuantumNous/new-api/common"
|
|
|
|
// GetDBTimestamp returns a UNIX timestamp from database time.
|
|
// Falls back to application time on error.
|
|
func GetDBTimestamp() int64 {
|
|
var ts int64
|
|
var err error
|
|
switch {
|
|
case common.UsingPostgreSQL:
|
|
err = DB.Raw("SELECT EXTRACT(EPOCH FROM NOW())").Scan(&ts).Error
|
|
case common.UsingSQLite:
|
|
err = DB.Raw("SELECT strftime('%s','now')").Scan(&ts).Error
|
|
default:
|
|
err = DB.Raw("SELECT UNIX_TIMESTAMP()").Scan(&ts).Error
|
|
}
|
|
if err != nil || ts <= 0 {
|
|
return common.GetTimestamp()
|
|
}
|
|
return ts
|
|
}
|