fusenapi/utils/template_switch_info/template_switch.go

134 lines
3.8 KiB
Go
Raw Normal View History

2023-09-06 02:48:45 +00:00
package template_switch_info
2023-09-11 04:17:07 +00:00
import (
"encoding/json"
"github.com/zeromicro/go-zero/core/logx"
)
2023-09-06 02:48:45 +00:00
type GetTemplateSwitchInfoRsp struct {
2023-10-27 03:28:09 +00:00
Id int64 `json:"id"`
Material string `json:"material"`
2023-10-27 03:29:39 +00:00
SwitchInfo SwitchInfo `json:"switch_info"`
2023-10-27 03:28:09 +00:00
CombineIsVisible bool `json:"combine_is_visible"` //合图总开关是否开启
2023-09-06 02:48:45 +00:00
}
2023-10-27 03:28:09 +00:00
type SwitchInfo struct {
2023-09-06 02:48:45 +00:00
QRcode QRcode `json:"QRcode"`
Website Website `json:"Website"`
Address Address `json:"Address"`
Phone Phone `json:"Phone"`
2023-09-11 07:15:38 +00:00
Slogan Slogan `json:"slogan"`
2023-09-06 02:48:45 +00:00
Logo Logo `json:"Logo"`
}
type QRcode struct {
IfShow bool `json:"if_show"`
2023-10-27 03:02:50 +00:00
UserDisabled bool `json:"user_disabled"`
2023-09-06 02:48:45 +00:00
Text string `json:"text"`
DefaultValue string `json:"default_value"`
}
type Website struct {
IfShow bool `json:"if_show"`
2023-10-27 03:02:50 +00:00
UserDisabled bool `json:"user_disabled"`
2023-09-06 02:48:45 +00:00
Text string `json:"text"`
DefaultValue string `json:"default_value"`
}
type Address struct {
IfShow bool `json:"if_show"`
2023-10-27 03:02:50 +00:00
UserDisabled bool `json:"user_disabled"`
2023-09-06 02:48:45 +00:00
Text string `json:"text"`
DefaultValue string `json:"default_value"`
}
2023-09-11 07:15:38 +00:00
type Slogan struct {
IfShow bool `json:"if_show"`
2023-10-27 03:02:50 +00:00
UserDisabled bool `json:"user_disabled"`
2023-09-11 07:15:38 +00:00
Text string `json:"text"`
DefaultValue string `json:"default_value"`
}
2023-09-06 02:48:45 +00:00
type Phone struct {
IfShow bool `json:"if_show"`
2023-10-27 03:02:50 +00:00
UserDisabled bool `json:"user_disabled"`
2023-09-06 02:48:45 +00:00
Text string `json:"text"`
DefaultValue string `json:"default_value"`
}
type Logo struct {
Material string `json:"material"`
}
2023-09-11 04:17:07 +00:00
// 模板开关信息简单结构
type TemplateSimpleParseInfo struct {
MaterialList []MaterialItem `json:"materialList"`
}
type MaterialItem struct {
Type string `json:"type"`
Tag string `json:"tag"`
Visible bool `json:"visible"`
Text string `json:"text"`
}
2023-09-06 02:48:45 +00:00
// 获取模板开关信息(目前写死,以后后台做好了功能再更新变动)
2023-09-12 09:55:23 +00:00
func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMaterialImg string) GetTemplateSwitchInfoRsp {
returnData := GetTemplateSwitchInfoRsp{
2023-09-06 02:48:45 +00:00
Id: templateId,
Material: templateMaterialImg,
2023-10-27 03:28:09 +00:00
SwitchInfo: SwitchInfo{
2023-09-06 02:48:45 +00:00
Logo: Logo{
Material: "/image/logo/aHnT1_rzubdwax_scale.png",
},
},
2023-09-27 02:16:40 +00:00
CombineIsVisible: false,
2023-09-06 02:48:45 +00:00
}
2023-10-27 03:24:41 +00:00
defer func() {
2023-10-27 03:28:09 +00:00
returnData.SwitchInfo.QRcode.UserDisabled = true
returnData.SwitchInfo.Website.UserDisabled = true
returnData.SwitchInfo.Address.UserDisabled = true
returnData.SwitchInfo.Phone.UserDisabled = true
returnData.SwitchInfo.Slogan.UserDisabled = true
2023-10-27 03:24:41 +00:00
}()
2023-09-12 09:55:23 +00:00
if templateJsonStr == nil || *templateJsonStr == "" {
return returnData
}
var templateJsonInfo TemplateSimpleParseInfo
if err := json.Unmarshal([]byte(*templateJsonStr), &templateJsonInfo); err != nil {
logx.Error("解析模板json获取DIY开关设置失败", err)
return returnData
}
2023-09-11 04:17:07 +00:00
for _, v := range templateJsonInfo.MaterialList {
2023-09-27 02:16:40 +00:00
if v.Type == "combine" {
2023-10-27 03:24:41 +00:00
returnData.CombineIsVisible = v.Visible
continue
2023-09-11 04:17:07 +00:00
}
switch v.Tag {
case "Phone": //电话
2023-10-27 03:28:09 +00:00
returnData.SwitchInfo.Phone = Phone{
2023-09-11 04:17:07 +00:00
IfShow: v.Visible,
Text: v.Text,
2023-10-27 02:42:52 +00:00
DefaultValue: "your phone",
2023-09-11 04:17:07 +00:00
}
case "Address": //地址
2023-10-27 03:28:09 +00:00
returnData.SwitchInfo.Address = Address{
2023-09-11 04:17:07 +00:00
IfShow: v.Visible,
Text: v.Text,
2023-10-27 02:42:52 +00:00
DefaultValue: "your address",
2023-09-11 04:17:07 +00:00
}
case "Website":
2023-10-27 03:28:09 +00:00
returnData.SwitchInfo.Website = Website{
2023-09-11 04:17:07 +00:00
IfShow: v.Visible,
Text: v.Text,
2023-10-27 02:42:52 +00:00
DefaultValue: "your website",
2023-09-11 04:17:07 +00:00
}
case "QRcode":
2023-10-27 03:28:09 +00:00
returnData.SwitchInfo.QRcode = QRcode{
2023-09-11 04:17:07 +00:00
IfShow: v.Visible,
Text: v.Text,
2023-10-27 02:42:52 +00:00
DefaultValue: "your qrcode content",
2023-09-11 07:15:38 +00:00
}
case "Slogan":
2023-10-27 03:28:09 +00:00
returnData.SwitchInfo.Slogan = Slogan{
2023-09-11 07:15:38 +00:00
IfShow: v.Visible,
Text: v.Text,
2023-10-27 02:42:52 +00:00
DefaultValue: "your slogan",
2023-09-11 04:17:07 +00:00
}
}
}
2023-09-12 09:55:23 +00:00
return returnData
2023-09-06 02:48:45 +00:00
}