feat(1.0): 调整模版变量

This commit is contained in:
summer 2025-11-05 16:43:44 +08:00
parent 7eade510a5
commit 4001993e96
4 changed files with 65 additions and 20 deletions

View File

@ -1946,6 +1946,10 @@ const docTemplate = `{
"description": "小程序头像",
"type": "string"
},
"check_status_text": {
"description": "状态文字描述",
"type": "string"
},
"created_at": {
"description": "创建时间",
"type": "string"

View File

@ -1938,6 +1938,10 @@
"description": "小程序头像",
"type": "string"
},
"check_status_text": {
"description": "状态文字描述",
"type": "string"
},
"created_at": {
"description": "创建时间",
"type": "string"

View File

@ -311,6 +311,9 @@ definitions:
avatar:
description: 小程序头像
type: string
check_status_text:
description: 状态文字描述
type: string
created_at:
description: 创建时间
type: string

View File

@ -6,9 +6,11 @@ import (
"mini-chat/internal/code"
"mini-chat/internal/pkg/core"
"mini-chat/internal/pkg/httpclient"
"mini-chat/internal/pkg/timeutil"
"mini-chat/internal/pkg/validation"
"go.uber.org/zap"
"gorm.io/gorm"
)
@ -31,6 +33,7 @@ type listData struct {
CreatedAt string `json:"created_at"` // 创建时间
UpdatedAt string `json:"updated_at"` // 更新时间
MessageTotal int64 `json:"message_total"` // 消息总数
CheckStatusText string `json:"check_status_text"` // 状态文字描述
}
type listResponse struct {
@ -135,8 +138,38 @@ func (h *handler) PageList() core.HandlerFunc {
res.Total = count
res.List = make([]listData, len(resultData))
type checkAppResponse struct {
Code int `json:"code"`
Appid string `json:"appid"`
Status string `json:"status"`
}
checkAppRes := new(checkAppResponse)
for k, v := range resultData {
messageTotalCount, _ := h.readDB.AppMessageLog.WithContext(ctx.RequestContext()).Where(h.readDB.AppMessageLog.AppID.Eq(v.AppID)).Count()
checkStatusText := "未知"
response, err := httpclient.GetHttpClientWithContext(ctx.RequestContext()).R().
SetQueryParams(map[string]string{
"appid": v.AppID,
}).
SetResult(checkAppRes).
Get("https://api.wxapi.work/xcx/checkxcx.php")
if err != nil {
h.logger.Error("请求失败", zap.Error(err))
}
// 检查响应状态码
if response.IsError() {
h.logger.Error(fmt.Sprintf("请求APP验证服务异常(%d)", response.StatusCode()))
}
if checkAppRes.Code == 1 {
checkStatusText = "正常"
} else if checkAppRes.Code == 0 {
checkStatusText = "封禁"
}
res.List[k] = listData{
ID: v.ID,
AppID: v.AppID,
@ -148,6 +181,7 @@ func (h *handler) PageList() core.HandlerFunc {
CreatedAt: timeutil.FriendlyTime(v.CreatedAt),
UpdatedAt: timeutil.FriendlyTime(v.UpdatedAt),
MessageTotal: messageTotalCount,
CheckStatusText: checkStatusText,
}
}