mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 05:41:37 +00:00
Improve subscription payment safety and data integrity by handling user/URL lookup failures, fixing Stripe subscription mode, persisting quota reset fields, and correcting subscription delta accounting and DB timestamp casting. Refine the UI with stricter custom duration validation, accurate currency rounding, conditional Epay labeling, rollback on preference update failure, and shared subscription formatting helpers plus clearer component naming.
23 lines
578 B
Go
23 lines
578 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())::bigint").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
|
|
}
|