修改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")
username := c.Query("username")
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, "")
c.JSON(200, gin.H{
"success": true,
"message": "",
"data": gin.H{
"quota": quotaNum,
//"token": tokenNum,
"quota": stat.Quota,
"rpm": stat.Rpm,
"tpm": stat.Tpm,
},
})
}
@ -143,7 +144,9 @@ func GetLogsSelfStat(c *gin.Context) {
"success": true,
"message": "",
"data": gin.H{
"quota": quotaNum,
"quota": quotaNum.Quota,
"rpm": quotaNum.Rpm,
"tpm": quotaNum.Tpm,
//"token": tokenNum,
},
})

View File

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

View File

@ -24,21 +24,28 @@ type AmountRequest struct {
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{
PartnerID: "1096",
Key: "n08V9LpE8JffA3NPP893689u8p39NV9J",
}, "https://api.lempay.org")
PartnerID: "1064",
Key: "nqrrZ5RjR86mKP8rKkyrOY5Pg8NmYfKR",
}, "https://pay.yunjuw.cn")
func GetAmount(id int, count float64, topUpCode string) float64 {
amount := count * 1.5
if topUpCode != "" {
if topUpCode == "nekoapi" {
if id == 89 {
amount = count * 1
} else if id == 98 || id == 105 || id == 107 {
amount = count * 0.8
} else if id == 105 || id == 107 {
amount = count * 1.2
} else if id == 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 amount > 400 {
c.JSON(200, gin.H{"message": "支付宝最大充值400元", "data": amount, "count": 400})
if amount > 2000 {
c.JSON(200, gin.H{"message": "支付宝最大充值2000元", "data": amount, "count": 2000})
return
}
req.PaymentMethod = "alipay"
}
if req.PaymentMethod == "wx" {
if amount > 600 {
c.JSON(200, gin.H{"message": "微信最大充值600元", "data": amount, "count": 600})
if amount > 2000 {
c.JSON(200, gin.H{"message": "微信最大充值2000元", "data": amount, "count": 2000})
return
}
req.PaymentMethod = "wxpay"
@ -78,11 +85,18 @@ func RequestEpay(c *gin.Context) {
returnUrl, _ := url.Parse("https://nekoapi.com/log")
notifyUrl, _ := url.Parse("https://nekoapi.com/api/user/epay/notify")
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{
Type: epay.PurchaseType(req.PaymentMethod),
ServiceTradeNo: "A" + tradeNo,
Name: "B" + tradeNo,
Money: strconv.FormatFloat(amount*0.99, 'f', 2, 64),
Money: strconv.FormatFloat(payMoney, 'f', 2, 64),
Device: epay.PC,
NotifyUrl: notifyUrl,
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})
return
}
if req.Amount > 400 {
c.JSON(200, gin.H{"message": "最大充值400刀", "data": GetAmount(id, 400, req.TopUpCode), "count": 400})
return
}
//if req.Amount > 1500 {
// c.JSON(200, gin.H{"message": "最大充值1000刀", "data": GetAmount(id, 1000, req.TopUpCode), "count": 1500})
// return
//}
}
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
}
func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string) (quota int) {
tx := DB.Table("logs").Select("sum(quota)")
type Stat struct {
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 != "" {
tx = tx.Where("username = ?", username)
}
@ -150,8 +156,8 @@ func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelNa
if modelName != "" {
tx = tx.Where("model_name = ?", modelName)
}
tx.Where("type = ?", LogTypeConsume).Scan(&quota)
return quota
tx.Where("type = ?", LogTypeConsume).Scan(&stat)
return stat
}
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>
<Form>
<Form.Input
placeholder='充值金额最低10,最高400'
placeholder='充值金额最低10,最高1000'
name='redemptionCount'
type={'number'}
value={topUpCount}
@ -207,14 +207,14 @@ const TopUp = () => {
onlineTopUp('zfb')
}
}>
支付宝最大400元
支付宝最大2000元
</Button>
<Button color='green' onClick={
async () => {
onlineTopUp('wx')
}
}>
微信最大600元
微信最大2000元
</Button>
</Form>
</Grid.Column>