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"
)
@ -21,16 +23,17 @@ type listRequest struct {
}
type listData struct {
ID int32 `json:"id"` // 小程序编号
AppID string `json:"app_id"` // 小程序ID
AppSecret string `json:"app_secret"` // 小程序密钥
Name string `json:"name"` // 小程序名称
Description string `json:"description"` // 小程序描述
Avatar string `json:"avatar"` // 小程序头像
TemplateID string `json:"template_id"` // 模版ID
CreatedAt string `json:"created_at"` // 创建时间
UpdatedAt string `json:"updated_at"` // 更新时间
MessageTotal int64 `json:"message_total"` // 消息总数
ID int32 `json:"id"` // 小程序编号
AppID string `json:"app_id"` // 小程序ID
AppSecret string `json:"app_secret"` // 小程序密钥
Name string `json:"name"` // 小程序名称
Description string `json:"description"` // 小程序描述
Avatar string `json:"avatar"` // 小程序头像
TemplateID string `json:"template_id"` // 模版ID
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,19 +138,50 @@ 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,
AppSecret: v.AppSecret,
Name: v.Name,
Description: v.Description,
Avatar: v.Avatar,
TemplateID: v.TemplateID,
CreatedAt: timeutil.FriendlyTime(v.CreatedAt),
UpdatedAt: timeutil.FriendlyTime(v.UpdatedAt),
MessageTotal: messageTotalCount,
ID: v.ID,
AppID: v.AppID,
AppSecret: v.AppSecret,
Name: v.Name,
Description: v.Description,
Avatar: v.Avatar,
TemplateID: v.TemplateID,
CreatedAt: timeutil.FriendlyTime(v.CreatedAt),
UpdatedAt: timeutil.FriendlyTime(v.UpdatedAt),
MessageTotal: messageTotalCount,
CheckStatusText: checkStatusText,
}
}