51 lines
1.3 KiB
Go
Executable File
51 lines
1.3 KiB
Go
Executable File
package common
|
||
|
||
import (
|
||
"bindbox-game/internal/pkg/core"
|
||
)
|
||
|
||
type ConfigResponse struct {
|
||
SubscribeTemplates map[string]string `json:"subscribe_templates"`
|
||
ContactServiceQRCode string `json:"contact_service_qrcode"` // 客服二维码
|
||
}
|
||
|
||
// GetPublicConfig 获取公开配置(包含订阅模板ID)
|
||
// @Summary 获取公开配置
|
||
// @Description 获取小程序前端需要用到的公开配置,如订阅消息模板ID
|
||
// @Tags 公共
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Success 200 {object} ConfigResponse
|
||
// @Router /api/app/config/public [get]
|
||
func (h *handler) GetPublicConfig() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
// 查询配置
|
||
var subscribeTemplateID string
|
||
var serviceQRCode string
|
||
|
||
configs, err := h.readDB.SystemConfigs.WithContext(ctx.RequestContext()).
|
||
Where(h.readDB.SystemConfigs.ConfigKey.In("wechat.lottery_result_template_id", "contact.service_qrcode")).
|
||
Find()
|
||
|
||
if err == nil {
|
||
for _, cfg := range configs {
|
||
switch cfg.ConfigKey {
|
||
case "wechat.lottery_result_template_id":
|
||
subscribeTemplateID = cfg.ConfigValue
|
||
case "contact.service_qrcode":
|
||
serviceQRCode = cfg.ConfigValue
|
||
}
|
||
}
|
||
}
|
||
|
||
rsp := ConfigResponse{
|
||
SubscribeTemplates: map[string]string{
|
||
"lottery_result": subscribeTemplateID,
|
||
},
|
||
ContactServiceQRCode: serviceQRCode,
|
||
}
|
||
|
||
ctx.Payload(rsp)
|
||
}
|
||
}
|