fix
This commit is contained in:
parent
00be036e59
commit
ac11753274
|
@ -105,14 +105,13 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, fmt.Sprintf("failed to parse json product template info(may be old data):%d", templateInfo.Id))
|
||||
}
|
||||
//后台隐藏/显示信息(现在下面是写死了)
|
||||
/*var switchInfo interface{}
|
||||
if templateInfo.SwitchInfo != nil && *templateInfo.SwitchInfo != "" {
|
||||
_ = json.Unmarshal([]byte(*templateInfo.SwitchInfo), &switchInfo)
|
||||
}*/
|
||||
modelInfo := modelList[modelIndex]
|
||||
mapKey := fmt.Sprintf("_%d", *modelInfo.SizeId)
|
||||
rsp[mapKey] = template_switch_info.GetTemplateSwitchInfo(templateInfo.Id, *templateInfo.MaterialImg)
|
||||
switchInfo, err := template_switch_info.GetTemplateSwitchInfo(templateInfo.Id, templateInfo.TemplateInfo, *templateInfo.MaterialImg)
|
||||
if err != nil {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
}
|
||||
rsp[mapKey] = switchInfo
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", rsp)
|
||||
}
|
||||
|
|
|
@ -153,7 +153,12 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
|||
return
|
||||
}
|
||||
//获取模板开关信息并且对于没有默认值的给赋值默认值
|
||||
templateSwitchInfo := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, *productTemplate.MaterialImg)
|
||||
templateSwitchInfo, err := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, productTemplate.TemplateInfo, *productTemplate.MaterialImg)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
|
||||
return
|
||||
}
|
||||
if renderImageData.RenderData.Website == "" {
|
||||
renderImageData.RenderData.Website = templateSwitchInfo.MaterialData.Website.DefaultValue
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
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"`
|
||||
|
@ -36,36 +42,72 @@ 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, templateMaterialImg string) GetTemplateSwitchInfoRsp {
|
||||
return GetTemplateSwitchInfoRsp{
|
||||
func GetTemplateSwitchInfo(templateId int64, templateInfo *string, templateMaterialImg string) (resp GetTemplateSwitchInfoRsp, err error) {
|
||||
if templateInfo == nil || *templateInfo == "" {
|
||||
return GetTemplateSwitchInfoRsp{}, nil
|
||||
}
|
||||
var templateJsonInfo TemplateSimpleParseInfo
|
||||
if err = json.Unmarshal([]byte(*templateInfo), &templateJsonInfo); err != nil {
|
||||
logx.Error(err)
|
||||
return GetTemplateSwitchInfoRsp{}, errors.New("解析模板json获取DIY开关设置失败")
|
||||
}
|
||||
mapSwitchInfo := GetTemplateSwitchInfoRsp{
|
||||
Id: templateId,
|
||||
Material: templateMaterialImg,
|
||||
MaterialData: MaterialData{
|
||||
QRcode: QRcode{
|
||||
IfShow: true,
|
||||
Text: "qrcode",
|
||||
DefaultValue: "default qrcode",
|
||||
},
|
||||
Website: Website{
|
||||
IfShow: true,
|
||||
Text: "website",
|
||||
DefaultValue: "default website",
|
||||
},
|
||||
Address: Address{
|
||||
IfShow: true,
|
||||
Text: "address",
|
||||
DefaultValue: "default address",
|
||||
},
|
||||
Phone: Phone{
|
||||
IfShow: true,
|
||||
Text: "phone",
|
||||
DefaultValue: "17557283679",
|
||||
},
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user