diff --git a/api/core/types/config.go b/api/core/types/config.go index 1ead005..cf039f2 100644 --- a/api/core/types/config.go +++ b/api/core/types/config.go @@ -132,19 +132,20 @@ type ModelAPIConfig struct { } type SystemConfig struct { - Title string `json:"title"` - AdminTitle string `json:"admin_title"` - Models []string `json:"models"` - UserInitCalls int `json:"user_init_calls"` // 新用户注册默认总送多少次调用 - InitImgCalls int `json:"init_img_calls"` - VipMonthCalls int `json:"vip_month_calls"` // 会员每个赠送的调用次数 - EnabledRegister bool `json:"enabled_register"` - EnabledMsg bool `json:"enabled_msg"` // 启用短信验证码服务 - EnabledDraw bool `json:"enabled_draw"` // 启动 AI 绘画功能 - RewardImg string `json:"reward_img"` // 众筹收款二维码地址 - EnabledFunction bool `json:"enabled_function"` // 启用 API 函数功能 - EnabledReward bool `json:"enabled_reward"` // 启用众筹功能 - EnabledAlipay bool `json:"enabled_alipay"` // 是否启用支付宝支付通道 - OrderPayTimeout int `json:"order_pay_timeout"` //订单支付超时时间 - DefaultModels []string `json:"default_models"` // 默认开通的 AI 模型 + Title string `json:"title"` + AdminTitle string `json:"admin_title"` + Models []string `json:"models"` + UserInitCalls int `json:"user_init_calls"` // 新用户注册默认总送多少次调用 + InitImgCalls int `json:"init_img_calls"` + VipMonthCalls int `json:"vip_month_calls"` // 会员每个赠送的调用次数 + EnabledRegister bool `json:"enabled_register"` + EnabledMsg bool `json:"enabled_msg"` // 启用短信验证码服务 + EnabledDraw bool `json:"enabled_draw"` // 启动 AI 绘画功能 + RewardImg string `json:"reward_img"` // 众筹收款二维码地址 + EnabledFunction bool `json:"enabled_function"` // 启用 API 函数功能 + EnabledReward bool `json:"enabled_reward"` // 启用众筹功能 + EnabledAlipay bool `json:"enabled_alipay"` // 是否启用支付宝支付通道 + OrderPayTimeout int `json:"order_pay_timeout"` //订单支付超时时间 + DefaultModels []string `json:"default_models"` // 默认开通的 AI 模型 + OrderPayInfoText string `json:"order_pay_info_text"` // 订单支付页面说明文字 } diff --git a/api/handler/admin/dashboard_handler.go b/api/handler/admin/dashboard_handler.go index 9052304..7b5cc9b 100644 --- a/api/handler/admin/dashboard_handler.go +++ b/api/handler/admin/dashboard_handler.go @@ -2,6 +2,7 @@ package admin import ( "chatplus/core" + "chatplus/core/types" "chatplus/handler" "chatplus/store/model" "chatplus/utils/resp" @@ -22,10 +23,10 @@ func NewDashboardHandler(app *core.AppServer, db *gorm.DB) *DashboardHandler { } type statsVo struct { - Users int64 `json:"users"` - Chats int64 `json:"chats"` - Tokens int64 `json:"tokens"` - Rewards float64 `json:"rewards"` + Users int64 `json:"users"` + Chats int64 `json:"chats"` + Tokens int `json:"tokens"` + Income float64 `json:"income"` } func (h *DashboardHandler) Stats(c *gin.Context) { @@ -47,17 +48,24 @@ func (h *DashboardHandler) Stats(c *gin.Context) { } // tokens took stats - var tokenCount int64 - res = h.db.Model(&model.HistoryMessage{}).Select("sum(tokens) as total").Where("created_at > ?", zeroTime).Scan(&tokenCount) - if res.Error == nil { - stats.Tokens = tokenCount + var historyMessages []model.HistoryMessage + res = h.db.Where("created_at > ?", zeroTime).Find(&historyMessages) + for _, item := range historyMessages { + stats.Tokens += item.Tokens } - // reward revenue - var amount float64 - res = h.db.Model(&model.Reward{}).Select("sum(amount) as total").Where("created_at > ?", zeroTime).Scan(&amount) - if res.Error == nil { - stats.Rewards = amount + // 众筹收入 + var rewards []model.Reward + res = h.db.Where("created_at > ?", zeroTime).Find(&rewards) + for _, item := range rewards { + stats.Income += item.Amount + } + + // 订单收入 + var orders []model.Order + res = h.db.Where("status = ?", types.OrderPaidSuccess).Where("created_at > ?", zeroTime).Find(&orders) + for _, item := range orders { + stats.Income += item.Amount } resp.SUCCESS(c, stats) } diff --git a/api/handler/chatimpl/baidu_handler.go b/api/handler/chatimpl/baidu_handler.go index 1ca49e5..f20756b 100644 --- a/api/handler/chatimpl/baidu_handler.go +++ b/api/handler/chatimpl/baidu_handler.go @@ -84,6 +84,11 @@ func (h *ChatHandler) sendBaiduMessage( content = line[5:] } + // 处理代码换行 + if len(content) == 0 { + content = "\n" + } + var resp baiduResp err := utils.JsonDecode(content, &resp) if err != nil { diff --git a/api/handler/chatimpl/chatglm_handler.go b/api/handler/chatimpl/chatglm_handler.go index 3f680ca..0efa47a 100644 --- a/api/handler/chatimpl/chatglm_handler.go +++ b/api/handler/chatimpl/chatglm_handler.go @@ -71,6 +71,10 @@ func (h *ChatHandler) sendChatGLMMessage( if strings.HasPrefix(line, "data:") { content = line[5:] } + // 处理代码换行 + if len(content) == 0 { + content = "\n" + } switch event { case "add": if len(contents) == 0 { diff --git a/api/handler/chatimpl/xunfei_handler.go b/api/handler/chatimpl/xunfei_handler.go index 8169aeb..02d0c48 100644 --- a/api/handler/chatimpl/xunfei_handler.go +++ b/api/handler/chatimpl/xunfei_handler.go @@ -138,6 +138,10 @@ func (h *ChatHandler) sendXunFeiMessage( } content = result.Payload.Choices.Text[0].Content + // 处理代码换行 + if len(content) == 0 { + content = "\n" + } contents = append(contents, content) // 第一个结果 if result.Payload.Choices.Status == 0 { diff --git a/web/src/components/ChatReply.vue b/web/src/components/ChatReply.vue index 7c8b6bf..b9f4369 100644 --- a/web/src/components/ChatReply.vue +++ b/web/src/components/ChatReply.vue @@ -31,11 +31,11 @@