114 lines
3.1 KiB
Go
114 lines
3.1 KiB
Go
package template_switch_info
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetTemplateSwitchInfoRsp struct {
|
|
Id int64 `json:"id"`
|
|
Material string `json:"material"`
|
|
MaterialData MaterialData `json:"material_data"`
|
|
}
|
|
type MaterialData struct {
|
|
QRcode QRcode `json:"QRcode"`
|
|
Website Website `json:"Website"`
|
|
Address Address `json:"Address"`
|
|
Phone Phone `json:"Phone"`
|
|
Logo Logo `json:"Logo"`
|
|
}
|
|
type QRcode struct {
|
|
IfShow bool `json:"if_show"`
|
|
Text string `json:"text"`
|
|
DefaultValue string `json:"default_value"`
|
|
}
|
|
type Website struct {
|
|
IfShow bool `json:"if_show"`
|
|
Text string `json:"text"`
|
|
DefaultValue string `json:"default_value"`
|
|
}
|
|
type Address struct {
|
|
IfShow bool `json:"if_show"`
|
|
Text string `json:"text"`
|
|
DefaultValue string `json:"default_value"`
|
|
}
|
|
type Phone struct {
|
|
IfShow bool `json:"if_show"`
|
|
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) (resp GetTemplateSwitchInfoRsp, err error) {
|
|
if templateJsonStr == nil || *templateJsonStr == "" {
|
|
return GetTemplateSwitchInfoRsp{}, nil
|
|
}
|
|
var templateJsonInfo TemplateSimpleParseInfo
|
|
if err = json.Unmarshal([]byte(*templateJsonStr), &templateJsonInfo); err != nil {
|
|
logx.Error(err)
|
|
return GetTemplateSwitchInfoRsp{}, errors.New("解析模板json获取DIY开关设置失败")
|
|
}
|
|
mapSwitchInfo := GetTemplateSwitchInfoRsp{
|
|
Id: templateId,
|
|
Material: templateMaterialImg,
|
|
MaterialData: MaterialData{
|
|
Logo: Logo{
|
|
Material: "/image/logo/aHnT1_rzubdwax_scale.png",
|
|
},
|
|
},
|
|
}
|
|
for _, v := range templateJsonInfo.MaterialList {
|
|
if v.Type == "combine" && !v.Visible {
|
|
return GetTemplateSwitchInfoRsp{
|
|
MaterialData: MaterialData{
|
|
Logo: Logo{
|
|
Material: "/image/logo/aHnT1_rzubdwax_scale.png",
|
|
},
|
|
},
|
|
}, nil
|
|
}
|
|
switch v.Tag {
|
|
case "Phone": //电话
|
|
mapSwitchInfo.MaterialData.Phone = Phone{
|
|
IfShow: v.Visible,
|
|
Text: v.Text,
|
|
DefaultValue: "xxx xxx xxx xxxx",
|
|
}
|
|
case "Address": //地址
|
|
mapSwitchInfo.MaterialData.Address = Address{
|
|
IfShow: v.Visible,
|
|
Text: v.Text,
|
|
DefaultValue: "USA",
|
|
}
|
|
case "Website":
|
|
mapSwitchInfo.MaterialData.Website = Website{
|
|
IfShow: v.Visible,
|
|
Text: v.Text,
|
|
DefaultValue: "https://www.xxxxxx.com",
|
|
}
|
|
case "QRcode":
|
|
mapSwitchInfo.MaterialData.QRcode = QRcode{
|
|
IfShow: v.Visible,
|
|
Text: v.Text,
|
|
DefaultValue: "xxxxxxx",
|
|
}
|
|
}
|
|
}
|
|
return mapSwitchInfo, nil
|
|
}
|