fusenapi/utils/template_switch_info/template_switch.go
laodaming ed910df0b8 fix
2023-10-27 11:29:39 +08:00

134 lines
3.8 KiB
Go

package template_switch_info
import (
"encoding/json"
"github.com/zeromicro/go-zero/core/logx"
)
type GetTemplateSwitchInfoRsp struct {
Id int64 `json:"id"`
Material string `json:"material"`
SwitchInfo SwitchInfo `json:"switch_info"`
CombineIsVisible bool `json:"combine_is_visible"` //合图总开关是否开启
}
type SwitchInfo struct {
QRcode QRcode `json:"QRcode"`
Website Website `json:"Website"`
Address Address `json:"Address"`
Phone Phone `json:"Phone"`
Slogan Slogan `json:"slogan"`
Logo Logo `json:"Logo"`
}
type QRcode struct {
IfShow bool `json:"if_show"`
UserDisabled bool `json:"user_disabled"`
Text string `json:"text"`
DefaultValue string `json:"default_value"`
}
type Website struct {
IfShow bool `json:"if_show"`
UserDisabled bool `json:"user_disabled"`
Text string `json:"text"`
DefaultValue string `json:"default_value"`
}
type Address struct {
IfShow bool `json:"if_show"`
UserDisabled bool `json:"user_disabled"`
Text string `json:"text"`
DefaultValue string `json:"default_value"`
}
type Slogan struct {
IfShow bool `json:"if_show"`
UserDisabled bool `json:"user_disabled"`
Text string `json:"text"`
DefaultValue string `json:"default_value"`
}
type Phone struct {
IfShow bool `json:"if_show"`
UserDisabled bool `json:"user_disabled"`
Text string `json:"text"`
DefaultValue string `json:"default_value"`
}
type Logo struct {
Material string `json:"material"`
}
// 模板开关信息简单结构
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"`
}
// 获取模板开关信息(目前写死,以后后台做好了功能再更新变动)
func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMaterialImg string) GetTemplateSwitchInfoRsp {
returnData := GetTemplateSwitchInfoRsp{
Id: templateId,
Material: templateMaterialImg,
SwitchInfo: SwitchInfo{
Logo: Logo{
Material: "/image/logo/aHnT1_rzubdwax_scale.png",
},
},
CombineIsVisible: false,
}
defer func() {
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
}()
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
}
for _, v := range templateJsonInfo.MaterialList {
if v.Type == "combine" {
returnData.CombineIsVisible = v.Visible
continue
}
switch v.Tag {
case "Phone": //电话
returnData.SwitchInfo.Phone = Phone{
IfShow: v.Visible,
Text: v.Text,
DefaultValue: "your phone",
}
case "Address": //地址
returnData.SwitchInfo.Address = Address{
IfShow: v.Visible,
Text: v.Text,
DefaultValue: "your address",
}
case "Website":
returnData.SwitchInfo.Website = Website{
IfShow: v.Visible,
Text: v.Text,
DefaultValue: "your website",
}
case "QRcode":
returnData.SwitchInfo.QRcode = QRcode{
IfShow: v.Visible,
Text: v.Text,
DefaultValue: "your qrcode content",
}
case "Slogan":
returnData.SwitchInfo.Slogan = Slogan{
IfShow: v.Visible,
Text: v.Text,
DefaultValue: "your slogan",
}
}
}
return returnData
}