From 104a9db7eadc42394f3028e9f0b86f928af5156d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 10:19:37 +0800 Subject: [PATCH 1/5] fix --- server/product/internal/logic/getpricebypidlogic.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index 44bfe67a..ea18202f 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -116,7 +116,12 @@ func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []in end := int64(0) if numKey == 0 { //第一个 begin = *priceInfo.MinBuyNum * (*priceInfo.EachBoxNum) - end = num - 1 + //只有一阶价格 + if lenStepPrice == 1 { + end = -1 + } else { + end = num - 1 + } } else if numKey < lenStepNum-1 { //中间的 nextNum := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum) begin = num From 2b5c8c9cd6107e99a81f9ac11afcfdf37385e2c5 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 10:47:48 +0800 Subject: [PATCH 2/5] fix --- .../internal/logic/getpricebypidlogic.go | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index ea18202f..60d5381f 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -104,6 +104,17 @@ func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []in lenStepNum := len(stepNumSlice) lenStepPrice := len(stepPriceSlice) stepListRsp := make([]types.StepRange, 0, lenStepNum) + //只有一个阶梯价格 + if lenStepPrice == 1 { + stepListRsp = append(stepListRsp, types.StepRange{ + Begin: *priceInfo.MinBuyNum * (*priceInfo.EachBoxNum), + End: -1, + Price: float64(stepPriceSlice[0]) / 100, + }) + return stepListRsp + } + begin := int64(0) + end := int64(0) for numKey, stepNum := range stepNumSlice { //先取最后一个 tmpPrice := float64(stepPriceSlice[lenStepPrice-1]) / 100 @@ -111,23 +122,12 @@ func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []in if numKey < lenStepPrice { tmpPrice = float64(stepPriceSlice[numKey]) / 100 } - num := int64(stepNum) * (*priceInfo.EachBoxNum) - begin := int64(0) - end := int64(0) - if numKey == 0 { //第一个 - begin = *priceInfo.MinBuyNum * (*priceInfo.EachBoxNum) - //只有一阶价格 - if lenStepPrice == 1 { - end = -1 - } else { - end = num - 1 - } - } else if numKey < lenStepNum-1 { //中间的 - nextNum := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum) - begin = num - end = nextNum - 1 - } else { //最后的 - begin = num + begin = int64(stepNum) * (*priceInfo.EachBoxNum) + //不是最后一个 + if numKey < lenStepNum-1 { + nextBegin := int64(stepNumSlice[numKey+1]) * (*priceInfo.EachBoxNum) + end = nextBegin - 1 + } else { end = -1 } stepListRsp = append(stepListRsp, types.StepRange{ From 0208110cbc55202497fe4070208f29ce9efc8785 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 11:34:04 +0800 Subject: [PATCH 3/5] fix --- .../internal/logic/getpricebypidlogic.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index 60d5381f..4848af9b 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -101,6 +101,25 @@ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo // 组装阶梯价格范围 func (l *GetPriceByPidLogic) dealWithStepRange(stepNumSlice, stepPriceSlice []int, priceInfo gmodel.FsProductPrice) []types.StepRange { + //要求写死不影响前端展示 + return []types.StepRange{ + { + Begin: 1000, + End: 2999, + Price: 0.23, + }, + { + Begin: 3000, + End: 4999, + Price: 0.2, + }, + { + Begin: 5000, + End: -1, + Price: 0.1, + }, + } + //下面是正常的 lenStepNum := len(stepNumSlice) lenStepPrice := len(stepPriceSlice) stepListRsp := make([]types.StepRange, 0, lenStepNum) From 3023c7d9dde548a3d2eeb73bb6e6d5503ec90098 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 11:39:57 +0800 Subject: [PATCH 4/5] fix --- server/render/consumer/assemble_render_data.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/render/consumer/assemble_render_data.go b/server/render/consumer/assemble_render_data.go index a3fc6ef0..7306b92f 100644 --- a/server/render/consumer/assemble_render_data.go +++ b/server/render/consumer/assemble_render_data.go @@ -56,6 +56,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { logx.Error("failed to get template info:", err) return err } + combineImage := "" //刀版图 combineHash := hash.JsonHashKey(parseInfo) //区别于云渲染的taskid,这个用获取刀版图缓存 //获取该hash值下有没有对应的资源 resource, err := svcCtx.AllModels.FsResource.FindOneById(ctx, combineHash) @@ -63,7 +64,6 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { logx.Error("failed to get resource :", err) return err } - combineImage := "" //刀版图 //如果不存在,则请求生成刀版图 if errors.Is(err, gorm.ErrRecordNotFound) { combineImage, err = getCombineImage(ctx, svcCtx, parseInfo, combineHash) From bd8200898597e2c5392c943fffddbf7b292143b8 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 10 Aug 2023 12:30:53 +0800 Subject: [PATCH 5/5] fix --- model/gmodel/fs_user_material_logic.go | 5 ++ .../render/consumer/assemble_render_data.go | 76 ++++++++++++++++--- .../internal/logic/ws_render_image_logic.go | 1 + utils/websocket_data/render_data.go | 11 +-- 4 files changed, 77 insertions(+), 16 deletions(-) diff --git a/model/gmodel/fs_user_material_logic.go b/model/gmodel/fs_user_material_logic.go index 134ced4b..98c0bb08 100644 --- a/model/gmodel/fs_user_material_logic.go +++ b/model/gmodel/fs_user_material_logic.go @@ -70,3 +70,8 @@ func (m *FsUserMaterialModel) FindLatestOne(ctx context.Context, userId int64, g err = db.Take(&resp).Error return resp, err } + +func (m *FsUserMaterialModel) FindOneById(ctx context.Context, id int64) (resp *FsUserMaterial, err error) { + err = m.db.WithContext(ctx).Model(&FsUserMaterial{}).Where("id = ?", id).Take(&resp).Error + return resp, err +} diff --git a/server/render/consumer/assemble_render_data.go b/server/render/consumer/assemble_render_data.go index 7306b92f..21609849 100644 --- a/server/render/consumer/assemble_render_data.go +++ b/server/render/consumer/assemble_render_data.go @@ -1,12 +1,14 @@ package consumer import ( + "bytes" "context" "encoding/json" "errors" "fmt" "fusenapi/constants" "fusenapi/initalize" + "fusenapi/model/gmodel" "fusenapi/server/render/internal/svc" "fusenapi/utils/curl" "fusenapi/utils/file" @@ -16,7 +18,6 @@ import ( "gorm.io/gorm" "io/ioutil" "strconv" - "strings" ) // 这里请求的py接口返回数据 @@ -47,7 +48,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { } rabbitmq := initalize.RabbitMqHandle{} //获取模板(产品第一个sku的模板) - templateInfo, err := svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId)) + productTemplate, err := svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId)) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { logx.Error("template info is not found") @@ -66,7 +67,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { } //如果不存在,则请求生成刀版图 if errors.Is(err, gorm.ErrRecordNotFound) { - combineImage, err = getCombineImage(ctx, svcCtx, parseInfo, combineHash) + combineImage, err = getCombineImage(ctx, svcCtx, parseInfo, productTemplate, combineHash) if err != nil { return err } @@ -74,10 +75,10 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { combineImage = *resource.ResourceUrl } //获取渲染设置信息 - element, err := svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(ctx, *templateInfo.ModelId) + element, err := svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(ctx, *productTemplate.ModelId) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - logx.Error("element info is not found,model_id = ?", *templateInfo.ModelId) + logx.Error("element info is not found,model_id = ?", *productTemplate.ModelId) return nil } logx.Error("failed to get element list,", err) @@ -132,7 +133,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { "light": *element.Light, "refletion": refletion, "scale": *element.Scale, - "sku_id": *templateInfo.ProductId, + "sku_id": parseInfo.RenderData.ProductId, "tid": *element.Title, "rotation": *element.Rotation, "filePath": "", //todo 文件路径,针对千人千面 @@ -160,14 +161,67 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { } // 获取刀版图 -func getCombineImage(ctx context.Context, svcCtx *svc.ServiceContext, parseInfo websocket_data.AssembleRenderData, combineHash string) (image string, err error) { - // todo 获取sku对应用来合成刀版图的json数据 - +func getCombineImage(ctx context.Context, svcCtx *svc.ServiceContext, parseInfo websocket_data.AssembleRenderData, productTemplate *gmodel.FsProductTemplateV2, combineHash string) (image string, err error) { + if productTemplate.TemplateInfo == nil || *productTemplate.TemplateInfo == "" { + logx.Error("product template info`template_info is empty") + return "", errors.New("product template info`template_info is empty") + } + //反序列化替换其中一些参数 + var combineInfo map[string]interface{} + if err = json.Unmarshal([]byte(*productTemplate.TemplateInfo), &combineInfo); err != nil { + logx.Error("failed to parse json:template_info:", err) + return "", err + } + //需要替换的参数 + replaceData := map[string]interface{}{ + "logo_url": parseInfo.RenderData.Logo, + "website": "", + "slogan": "", + "address": "", + "phone": "", + "colors": []string{}, + "template_tagid": []string{}, + "is_crop": false, + "shape": "", + "ratio": 0, + "line": "", + "other": "", + "other1": "", + } + //获取用户素材信息 + if parseInfo.RenderData.UserMaterialId > 0 { + userMaterial, err := svcCtx.AllModels.FsUserMaterial.FindOneById(ctx, parseInfo.RenderData.UserMaterialId) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error("user material not exists:", parseInfo.RenderData.UserMaterialId) + return "", errors.New("user material not exists") + } + logx.Error("err failed to get user material info") + } + if userMaterial.Metadata != nil && *userMaterial.Metadata != "" { + //解析元数据 + var materialMetaData map[string]interface{} + if err = json.Unmarshal([]byte(*userMaterial.Metadata), &materialMetaData); err != nil { + logx.Error("failed to parse user material`matadata: ", err) + return "", err + } + //赋值 + replaceData["colors"] = materialMetaData["colors"] + replaceData["logo_url"] = materialMetaData["logo_url"] + replaceData["shape"] = materialMetaData["shape"] + replaceData["is_crop"] = materialMetaData["is_crop"] + replaceData["ratio"] = materialMetaData["ratio"] + replaceData["line"] = materialMetaData["line"] + replaceData["other"] = materialMetaData["other"] + replaceData["other1"] = materialMetaData["other1"] + } + } + combineInfo["param_data"] = replaceData + postData, _ := json.Marshal(combineInfo) url := "http://192.168.1.7:45678/LogoCombine" header := make(map[string]string) header["content-type"] = "application/json" - postData := "" // todo 请求数据要查出来 - httpRsp, err := curl.ApiCall(url, "POST", header, strings.NewReader(postData), 20) + httpRsp, err := curl.ApiCall(url, "POST", header, bytes.NewReader(postData), 20) if err != nil { logx.Error("failed to combine logo:", err) return "", err diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 65eee011..6e6f74ae 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -59,6 +59,7 @@ func (w *wsConnectItem) renderImage(data []byte) { renderImageData.RenderData.Logo = "https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/f5ccd11365099fa47a6316b1cd639f6dd6064dcd2d37c8d2fcd0a322160b33cc" } else { renderImageData.RenderData.Logo = *userMaterial.ResourceUrl + renderImageData.RenderData.UserMaterialId = userMaterial.Id } //用户id赋值 renderImageData.RenderData.UserId = w.userId diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 928d1005..8bde5dbe 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -12,11 +12,12 @@ type RenderImageReqMsg struct { RenderData RenderData `json:"render_data"` } type RenderData struct { - TemplateTagId int64 `json:"template_tag_id"` //模板标签id - ProductId int64 `json:"product_id"` //产品id - Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) - UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) - GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) + TemplateTagId int64 `json:"template_tag_id"` //模板标签id + ProductId int64 `json:"product_id"` //产品id + UserMaterialId int64 `json:"user_material_id"` //用户素材id + Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) + UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) + GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) } // websocket发送渲染完的数据