From 4d0081b19cfe04d0f8c5b09b3ab7fd8b0dcb2e0b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 6 Sep 2023 10:48:45 +0800 Subject: [PATCH] 11 --- .../internal/logic/gettemplatebypidlogic.go | 32 +-------- .../internal/logic/datatransferlogic.go | 12 ++-- .../internal/logic/ws_render_image.go | 15 ++++ utils/template_switch_info/template_switch.go | 71 +++++++++++++++++++ 4 files changed, 95 insertions(+), 35 deletions(-) create mode 100644 utils/template_switch_info/template_switch.go diff --git a/server/product/internal/logic/gettemplatebypidlogic.go b/server/product/internal/logic/gettemplatebypidlogic.go index cc0c3226..7764fcc7 100644 --- a/server/product/internal/logic/gettemplatebypidlogic.go +++ b/server/product/internal/logic/gettemplatebypidlogic.go @@ -7,6 +7,7 @@ import ( "fusenapi/constants" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/template_switch_info" "gorm.io/gorm" "strings" @@ -111,36 +112,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, }*/ modelInfo := modelList[modelIndex] mapKey := fmt.Sprintf("_%d", *modelInfo.SizeId) - rsp[mapKey] = map[string]interface{}{ - "id": templateInfo.Id, - "material": *templateInfo.MaterialImg, - //写死的数据 - "material_data": map[string]interface{}{ - "QRcode": map[string]interface{}{ - "if_show": true, - "text": "qrcode", - "default_value": "default qrcode", - }, - "Website": map[string]interface{}{ - "if_show": true, - "text": "website", - "default_value": "default website", - }, - "Address": map[string]interface{}{ - "if_show": true, - "text": "address", - "default_value": "default address", - }, - "Phone": map[string]interface{}{ - "if_show": true, - "text": "phone", - "default_value": "17557283679", - }, - "Logo": map[string]interface{}{ - "material": "/image/logo/aHnT1_rzubdwax_scale.png", - }, - }, - } + rsp[mapKey] = template_switch_info.GetTemplateSwitchInfo(templateInfo.Id, *templateInfo.MaterialImg) } return resp.SetStatusWithMessage(basic.CodeOK, "success", rsp) } diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 4494a663..f3959dfe 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -80,7 +80,7 @@ var ( //渲染任务缓冲队列长度 renderChanLen = 500 //是否开启debug - openDebug = false + openDebug = true //允许跨域的origin mapAllowOrigin = map[string]struct{}{ "https://www.fusen.3718.cn": struct{}{}, @@ -118,11 +118,13 @@ type wsConnectItem struct { func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) { origin := r.Header.Get("Origin") //判断是不是允许的跨域 - upgrader.CheckOrigin = func(r *http.Request) bool { - if _, ok := mapAllowOrigin[origin]; !ok { - return false + if !openDebug { + upgrader.CheckOrigin = func(r *http.Request) bool { + if _, ok := mapAllowOrigin[origin]; !ok { + return false + } + return true } - return true } //把子协议携带的token设置到标准token头信息中 token := r.Header.Get("Sec-Websocket-Protocol") diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 8c6846f8..f4d581cf 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -11,6 +11,7 @@ import ( "fusenapi/service/repositories" "fusenapi/utils/curl" "fusenapi/utils/hash" + "fusenapi/utils/template_switch_info" "fusenapi/utils/websocket_data" "github.com/zeromicro/go-zero/core/logx" "gorm.io/gorm" @@ -135,6 +136,20 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("failed to get element ,", err) return } + //获取模板开关信息并且对于没有默认值的给赋值默认值 + templateSwitchInfo := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, *productTemplate.MaterialImg) + if renderImageData.RenderData.Website == "" { + renderImageData.RenderData.Website = templateSwitchInfo.MaterialData.Website.DefaultValue + } + if renderImageData.RenderData.Phone == "" { + renderImageData.RenderData.Phone = templateSwitchInfo.MaterialData.Phone.DefaultValue + } + if renderImageData.RenderData.Address == "" { + renderImageData.RenderData.Address = templateSwitchInfo.MaterialData.Address.DefaultValue + } + if renderImageData.RenderData.Qrcode == "" { + renderImageData.RenderData.Qrcode = templateSwitchInfo.MaterialData.QRcode.DefaultValue + } //获取刀版图 combineReq := repositories.LogoCombineReq{ UserId: renderImageData.RenderData.UserId, diff --git a/utils/template_switch_info/template_switch.go b/utils/template_switch_info/template_switch.go new file mode 100644 index 00000000..c262baa6 --- /dev/null +++ b/utils/template_switch_info/template_switch.go @@ -0,0 +1,71 @@ +package template_switch_info + +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"` +} + +// 获取模板开关信息(目前写死,以后后台做好了功能再更新变动) +func GetTemplateSwitchInfo(templateId int64, templateMaterialImg string) GetTemplateSwitchInfoRsp { + return 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", + }, + }, + } + +}