mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 21:10:18 +09:00
fix import cycle
This commit is contained in:
parent
6dae6c448e
commit
24b86e3b4d
@ -127,5 +127,6 @@ func UpdateRootPassword(db *sql.DB, cache *redis.Client, password string) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
cache.Del(context.Background(), fmt.Sprint("nio:user:root"))
|
cache.Del(context.Background(), fmt.Sprint("nio:user:root"))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
31
auth/analysis.go
Normal file
31
auth/analysis.go
Normal 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)
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"chat/admin"
|
|
||||||
"chat/utils"
|
"chat/utils"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
@ -79,7 +78,7 @@ func (u *User) Pay(db *sql.DB, cache *redis.Client, amount float32) bool {
|
|||||||
if useDeeptrain() {
|
if useDeeptrain() {
|
||||||
state := Pay(u.Username, amount)
|
state := Pay(u.Username, amount)
|
||||||
if state {
|
if state {
|
||||||
admin.IncrBillingRequest(cache, int64(amount*100))
|
incrBillingRequest(cache, int64(amount*100))
|
||||||
}
|
}
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"chat/admin"
|
|
||||||
"chat/utils"
|
"chat/utils"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"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)
|
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
|
return redeem.GetQuota(), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user