fix import cycle

This commit is contained in:
Zhang Minghan 2024-01-03 16:39:06 +08:00
parent 6dae6c448e
commit 24b86e3b4d
4 changed files with 34 additions and 4 deletions

View File

@ -127,5 +127,6 @@ func UpdateRootPassword(db *sql.DB, cache *redis.Client, password string) error
}
cache.Del(context.Background(), fmt.Sprint("nio:user:root"))
return nil
}

31
auth/analysis.go Normal file
View File

@ -0,0 +1,31 @@
package auth
import (
"chat/utils"
"fmt"
"github.com/go-redis/redis/v8"
"time"
)
func getMonth() string {
date := time.Now()
return date.Format("2006-01")
}
func getDay() string {
date := time.Now()
return date.Format("2006-01-02")
}
func getBillingFormat(t string) string {
return fmt.Sprintf("nio:billing-analysis-%s", t)
}
func getMonthBillingFormat(t string) string {
return fmt.Sprintf("nio:billing-analysis-%s", t)
}
func incrBillingRequest(cache *redis.Client, amount int64) {
utils.IncrWithExpire(cache, getBillingFormat(getDay()), amount, time.Hour*24*30*2)
utils.IncrWithExpire(cache, getMonthBillingFormat(getMonth()), amount, time.Hour*24*30*2)
}

View File

@ -1,7 +1,6 @@
package auth
import (
"chat/admin"
"chat/utils"
"database/sql"
"errors"
@ -79,7 +78,7 @@ func (u *User) Pay(db *sql.DB, cache *redis.Client, amount float32) bool {
if useDeeptrain() {
state := Pay(u.Username, amount)
if state {
admin.IncrBillingRequest(cache, int64(amount*100))
incrBillingRequest(cache, int64(amount*100))
}
return state
}

View File

@ -1,7 +1,6 @@
package auth
import (
"chat/admin"
"chat/utils"
"database/sql"
"errors"
@ -106,7 +105,7 @@ func (u *User) UseRedeem(db *sql.DB, cache *redis.Client, code string) (float32,
return 0, fmt.Errorf("failed to use redeem code: %w", err)
}
admin.IncrBillingRequest(cache, int64(redeem.GetQuota()*10))
incrBillingRequest(cache, int64(redeem.GetQuota()*10))
return redeem.GetQuota(), nil
}
}