From 3f8fed2dd6cdc3ba383ce890336702bf7d909797 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 12 Sep 2023 17:55:23 +0800 Subject: [PATCH] 11 --- utils/template_switch_info/template_switch.go | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/utils/template_switch_info/template_switch.go b/utils/template_switch_info/template_switch.go index e90c4bfb..3ccf3910 100644 --- a/utils/template_switch_info/template_switch.go +++ b/utils/template_switch_info/template_switch.go @@ -2,7 +2,6 @@ package template_switch_info import ( "encoding/json" - "errors" "github.com/zeromicro/go-zero/core/logx" ) @@ -60,24 +59,8 @@ type MaterialItem struct { } // 获取模板开关信息(目前写死,以后后台做好了功能再更新变动) -func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMaterialImg string) (resp GetTemplateSwitchInfoRsp, err error) { - if templateJsonStr == nil || *templateJsonStr == "" { - return GetTemplateSwitchInfoRsp{ - Id: templateId, - Material: templateMaterialImg, - MaterialData: MaterialData{ - Logo: Logo{ - Material: "/image/logo/aHnT1_rzubdwax_scale.png", - }, - }, - }, nil - } - var templateJsonInfo TemplateSimpleParseInfo - if err = json.Unmarshal([]byte(*templateJsonStr), &templateJsonInfo); err != nil { - logx.Error(err) - return GetTemplateSwitchInfoRsp{}, errors.New("解析模板json获取DIY开关设置失败") - } - mapSwitchInfo := GetTemplateSwitchInfoRsp{ +func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMaterialImg string) GetTemplateSwitchInfoRsp { + returnData := GetTemplateSwitchInfoRsp{ Id: templateId, Material: templateMaterialImg, MaterialData: MaterialData{ @@ -86,6 +69,14 @@ func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMa }, }, } + 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" && !v.Visible { return GetTemplateSwitchInfoRsp{ @@ -96,40 +87,40 @@ func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMa Material: "/image/logo/aHnT1_rzubdwax_scale.png", }, }, - }, nil + } } switch v.Tag { case "Phone": //电话 - mapSwitchInfo.MaterialData.Phone = Phone{ + returnData.MaterialData.Phone = Phone{ IfShow: v.Visible, Text: v.Text, DefaultValue: "000 xxx xxx 1111", } case "Address": //地址 - mapSwitchInfo.MaterialData.Address = Address{ + returnData.MaterialData.Address = Address{ IfShow: v.Visible, Text: v.Text, DefaultValue: "USA", } case "Website": - mapSwitchInfo.MaterialData.Website = Website{ + returnData.MaterialData.Website = Website{ IfShow: v.Visible, Text: v.Text, DefaultValue: "https://www.xxxxxx.com", } case "QRcode": - mapSwitchInfo.MaterialData.QRcode = QRcode{ + returnData.MaterialData.QRcode = QRcode{ IfShow: v.Visible, Text: v.Text, DefaultValue: "qrcode xxxxxxx", } case "Slogan": - mapSwitchInfo.MaterialData.Slogan = Slogan{ + returnData.MaterialData.Slogan = Slogan{ IfShow: v.Visible, Text: v.Text, DefaultValue: "slogan xxxxxxx", } } } - return mapSwitchInfo, nil + return returnData }