修改stat接口返回值

This commit is contained in:
CaIon 2023-08-25 00:40:11 +08:00
parent 8f2119e410
commit 3b0f1ae978
5 changed files with 54 additions and 25 deletions

View File

@ -118,14 +118,15 @@ func GetLogsStat(c *gin.Context) {
tokenName := c.Query("token_name") tokenName := c.Query("token_name")
username := c.Query("username") username := c.Query("username")
modelName := c.Query("model_name") modelName := c.Query("model_name")
quotaNum := model.SumUsedQuota(logType, startTimestamp, endTimestamp, modelName, username, tokenName) stat := model.SumUsedQuota(logType, startTimestamp, endTimestamp, modelName, username, tokenName)
//tokenNum := model.SumUsedToken(logType, startTimestamp, endTimestamp, modelName, username, "") //tokenNum := model.SumUsedToken(logType, startTimestamp, endTimestamp, modelName, username, "")
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"success": true, "success": true,
"message": "", "message": "",
"data": gin.H{ "data": gin.H{
"quota": quotaNum, "quota": stat.Quota,
//"token": tokenNum, "rpm": stat.Rpm,
"tpm": stat.Tpm,
}, },
}) })
} }
@ -143,7 +144,9 @@ func GetLogsSelfStat(c *gin.Context) {
"success": true, "success": true,
"message": "", "message": "",
"data": gin.H{ "data": gin.H{
"quota": quotaNum, "quota": quotaNum.Quota,
"rpm": quotaNum.Rpm,
"tpm": quotaNum.Tpm,
//"token": tokenNum, //"token": tokenNum,
}, },
}) })

View File

@ -14,6 +14,12 @@ import (
) )
func UpdateMidjourneyTask() { func UpdateMidjourneyTask() {
//revocer
defer func() {
if err := recover(); err != nil {
log.Printf("UpdateMidjourneyTask: %v", err)
}
}()
imageModel := "midjourney" imageModel := "midjourney"
for { for {
time.Sleep(time.Duration(15) * time.Second) time.Sleep(time.Duration(15) * time.Second)

View File

@ -24,21 +24,28 @@ type AmountRequest struct {
TopUpCode string `json:"top_up_code"` TopUpCode string `json:"top_up_code"`
} }
//var client, _ = epay.NewClientWithUrl(&epay.Config{
// PartnerID: "1096",
// Key: "n08V9LpE8JffA3NPP893689u8p39NV9J",
//}, "https://api.lempay.org")
var client, _ = epay.NewClientWithUrl(&epay.Config{ var client, _ = epay.NewClientWithUrl(&epay.Config{
PartnerID: "1096", PartnerID: "1064",
Key: "n08V9LpE8JffA3NPP893689u8p39NV9J", Key: "nqrrZ5RjR86mKP8rKkyrOY5Pg8NmYfKR",
}, "https://api.lempay.org") }, "https://pay.yunjuw.cn")
func GetAmount(id int, count float64, topUpCode string) float64 { func GetAmount(id int, count float64, topUpCode string) float64 {
amount := count * 1.5 amount := count * 1.5
if topUpCode != "" { if topUpCode != "" {
if topUpCode == "nekoapi" { if topUpCode == "nekoapi" {
if id == 89 { if id == 89 {
amount = count * 1 amount = count * 0.8
} else if id == 98 || id == 105 || id == 107 { } else if id == 105 || id == 107 {
amount = count * 1.2 amount = count * 1.2
} else if id == 1 { } else if id == 1 {
amount = count * 1 amount = count * 1
} else if id == 98 {
amount = count * 1.1
} }
} }
} }
@ -61,15 +68,15 @@ func RequestEpay(c *gin.Context) {
} }
} }
if req.PaymentMethod == "zfb" { if req.PaymentMethod == "zfb" {
if amount > 400 { if amount > 2000 {
c.JSON(200, gin.H{"message": "支付宝最大充值400元", "data": amount, "count": 400}) c.JSON(200, gin.H{"message": "支付宝最大充值2000元", "data": amount, "count": 2000})
return return
} }
req.PaymentMethod = "alipay" req.PaymentMethod = "alipay"
} }
if req.PaymentMethod == "wx" { if req.PaymentMethod == "wx" {
if amount > 600 { if amount > 2000 {
c.JSON(200, gin.H{"message": "微信最大充值600元", "data": amount, "count": 600}) c.JSON(200, gin.H{"message": "微信最大充值2000元", "data": amount, "count": 2000})
return return
} }
req.PaymentMethod = "wxpay" req.PaymentMethod = "wxpay"
@ -78,11 +85,18 @@ func RequestEpay(c *gin.Context) {
returnUrl, _ := url.Parse("https://nekoapi.com/log") returnUrl, _ := url.Parse("https://nekoapi.com/log")
notifyUrl, _ := url.Parse("https://nekoapi.com/api/user/epay/notify") notifyUrl, _ := url.Parse("https://nekoapi.com/api/user/epay/notify")
tradeNo := strconv.FormatInt(time.Now().Unix(), 10) tradeNo := strconv.FormatInt(time.Now().Unix(), 10)
payMoney := amount
//if payMoney < 400 {
// payMoney = amount * 0.99
// if amount-payMoney > 2 {
// payMoney = amount - 2
// }
//}
uri, params, err := client.Purchase(&epay.PurchaseArgs{ uri, params, err := client.Purchase(&epay.PurchaseArgs{
Type: epay.PurchaseType(req.PaymentMethod), Type: epay.PurchaseType(req.PaymentMethod),
ServiceTradeNo: "A" + tradeNo, ServiceTradeNo: "A" + tradeNo,
Name: "B" + tradeNo, Name: "B" + tradeNo,
Money: strconv.FormatFloat(amount*0.99, 'f', 2, 64), Money: strconv.FormatFloat(payMoney, 'f', 2, 64),
Device: epay.PC, Device: epay.PC,
NotifyUrl: notifyUrl, NotifyUrl: notifyUrl,
ReturnUrl: returnUrl, ReturnUrl: returnUrl,
@ -163,10 +177,10 @@ func RequestAmount(c *gin.Context) {
c.JSON(200, gin.H{"message": "最小充值10刀", "data": GetAmount(id, 10, req.TopUpCode), "count": 10}) c.JSON(200, gin.H{"message": "最小充值10刀", "data": GetAmount(id, 10, req.TopUpCode), "count": 10})
return return
} }
if req.Amount > 400 { //if req.Amount > 1500 {
c.JSON(200, gin.H{"message": "最大充值400刀", "data": GetAmount(id, 400, req.TopUpCode), "count": 400}) // c.JSON(200, gin.H{"message": "最大充值1000刀", "data": GetAmount(id, 1000, req.TopUpCode), "count": 1500})
return // return
} //}
} }
c.JSON(200, gin.H{"message": "success", "data": GetAmount(id, float64(req.Amount), req.TopUpCode)}) c.JSON(200, gin.H{"message": "success", "data": GetAmount(id, float64(req.Amount), req.TopUpCode)})

View File

@ -133,8 +133,14 @@ func SearchUserLogs(userId int, keyword string) (logs []*Log, err error) {
return logs, err return logs, err
} }
func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string) (quota int) { type Stat struct {
tx := DB.Table("logs").Select("sum(quota)") Quota int `json:"quota"`
Rpm int `json:"rpm"`
Tpm int `json:"tpm"`
}
func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string) (stat Stat) {
tx := DB.Table("logs").Select("sum(quota) quota, count(*) rpm, sum(prompt_tokens) + sum(completion_tokens) tpm")
if username != "" { if username != "" {
tx = tx.Where("username = ?", username) tx = tx.Where("username = ?", username)
} }
@ -150,8 +156,8 @@ func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelNa
if modelName != "" { if modelName != "" {
tx = tx.Where("model_name = ?", modelName) tx = tx.Where("model_name = ?", modelName)
} }
tx.Where("type = ?", LogTypeConsume).Scan(&quota) tx.Where("type = ?", LogTypeConsume).Scan(&stat)
return quota return stat
} }
func SumUsedToken(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string) (token int) { func SumUsedToken(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string) (token int) {

View File

@ -184,7 +184,7 @@ const TopUp = () => {
<Grid.Column> <Grid.Column>
<Form> <Form>
<Form.Input <Form.Input
placeholder='充值金额最低10,最高400' placeholder='充值金额最低10,最高1000'
name='redemptionCount' name='redemptionCount'
type={'number'} type={'number'}
value={topUpCount} value={topUpCount}
@ -207,14 +207,14 @@ const TopUp = () => {
onlineTopUp('zfb') onlineTopUp('zfb')
} }
}> }>
支付宝最大400元 支付宝最大2000元
</Button> </Button>
<Button color='green' onClick={ <Button color='green' onClick={
async () => { async () => {
onlineTopUp('wx') onlineTopUp('wx')
} }
}> }>
微信最大600元 微信最大2000元
</Button> </Button>
</Form> </Form>
</Grid.Column> </Grid.Column>