Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
momo 2023-10-08 18:38:45 +08:00
commit 17dc892c07
11 changed files with 104 additions and 82 deletions

View File

@ -82,14 +82,14 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
mapRsp := make(map[string]interface{}) mapRsp := make(map[string]interface{})
for _, modelInfo := range modelPriceList { for _, modelInfo := range modelPriceList {
var stepPrice gmodel.StepPriceJsonStruct var stepPrice gmodel.StepPriceJsonStruct
//没有设置阶梯价格
if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
continue
}
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil { if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse step price json") return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse step price json")
} }
rangeLen := len(stepPrice.PriceRange)
if rangeLen == 0 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price is not set:%d", modelInfo.Id))
}
*modelInfo.PartList = strings.Trim(*modelInfo.PartList, ",") *modelInfo.PartList = strings.Trim(*modelInfo.PartList, ",")
mapFittingUnit := make(map[string]interface{}) mapFittingUnit := make(map[string]interface{})
if *modelInfo.PartList != "" { if *modelInfo.PartList != "" {

View File

@ -246,6 +246,7 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
ProductId: &req.ProductId, ProductId: &req.ProductId,
TemplateId: &req.TemplateId, TemplateId: &req.TemplateId,
ModelId: &modelInfo.Id, ModelId: &modelInfo.Id,
IsHighlyCustomized: &req.IsHighlyCustomized,
LightId: modelInfo.Light, LightId: modelInfo.Light,
SizeId: &req.SizeId, SizeId: &req.SizeId,
FittingId: &req.FittingId, FittingId: &req.FittingId,

View File

@ -197,7 +197,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
PurchaseQuantity: *cart.PurchaseQuantity, PurchaseQuantity: *cart.PurchaseQuantity,
MinPurchaseQuantity: stepPrice.MinBuyUnitsNum, MinPurchaseQuantity: stepPrice.MinBuyUnitsNum,
StepPurchaseQuantity: stepPurchaseQuantity, StepPurchaseQuantity: stepPurchaseQuantity,
IsHighlyCustomized: *cart.IsHighlyCustomized > 0, IsHighlyCustomized: *cart.IsHighlyCustomized,
IsSelected: cartIsSelected, IsSelected: cartIsSelected,
TemplateTag: templateTag, TemplateTag: templateTag,
Logo: snapShot.Logo, Logo: snapShot.Logo,

View File

@ -8,6 +8,7 @@ import (
type AddToCartReq struct { type AddToCartReq struct {
ProductId int64 `json:"product_id"` //产品id ProductId int64 `json:"product_id"` //产品id
TemplateId int64 `json:"template_id,optional"` //模板id(不可定制的不传) TemplateId int64 `json:"template_id,optional"` //模板id(不可定制的不传)
IsHighlyCustomized int64 `json:"is_highly_customized"` //是否高度定制
SelectColorIndex int64 `json:"select_color_index"` //选择的颜色索引 SelectColorIndex int64 `json:"select_color_index"` //选择的颜色索引
SizeId int64 `json:"size_id"` //尺寸id SizeId int64 `json:"size_id"` //尺寸id
FittingId int64 `json:"fitting_id,optional"` //配件id(没有可以不传) FittingId int64 `json:"fitting_id,optional"` //配件id(没有可以不传)
@ -50,7 +51,7 @@ type CartItem struct {
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量 PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
MinPurchaseQuantity int64 `json:"min_purchase_quantity"` //起购数量 MinPurchaseQuantity int64 `json:"min_purchase_quantity"` //起购数量
StepPurchaseQuantity int64 `json:"step_purchase_quantity"` //购买加或者减少步进量 StepPurchaseQuantity int64 `json:"step_purchase_quantity"` //购买加或者减少步进量
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制 IsHighlyCustomized int64 `json:"is_highly_customized"` //是否高度定制
IsInvalid bool `json:"is_invalid"` //是否无效 IsInvalid bool `json:"is_invalid"` //是否无效
InvalidDescription string `json:"invalid_description"` //无效原因 InvalidDescription string `json:"invalid_description"` //无效原因
IsSelected bool `json:"is_selected"` //是否选中 IsSelected bool `json:"is_selected"` //是否选中

View File

@ -59,15 +59,13 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "failed to parse param taskId !!!!") return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "failed to parse param taskId !!!!")
} }
//重新赋值(很重要) //重新赋值(很重要)
req.TaskId = info.TaskId
wid := info.Wid wid := info.Wid
renderId := info.RenderId renderId := info.RenderId
unityRenderBeginTime := info.RenderBeginTime unityRenderBeginTime := info.RenderBeginTime
//存base64打印测试 //获取连接
/* f, _ := os.Create("b.txt") value, wsConnectOk := mapConnPool.Load(wid)
defer f.Close() if req.Code == 0 { //渲染成功
f.WriteString(req.Image)*/ //上传文件
// 上传文件
var upload = file.Upload{ var upload = file.Upload{
Ctx: l.ctx, Ctx: l.ctx,
MysqlConn: l.svcCtx.MysqlConn, MysqlConn: l.svcCtx.MysqlConn,
@ -75,7 +73,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
} }
uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{
Source: "unity cloud render", Source: "unity cloud render",
FileHash: req.TaskId, FileHash: info.TaskId,
FileData: req.Image, FileData: req.Image,
Metadata: "", Metadata: "",
UploadBucket: 1, UploadBucket: 1,
@ -89,7 +87,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image") return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image")
} }
uploadUnityRenderImageTakesTime := time.Now().UTC().UnixMilli() - unityRenderEndTime uploadUnityRenderImageTakesTime := time.Now().UTC().UnixMilli() - unityRenderEndTime
if value, ok := mapConnPool.Load(wid); ok { if wsConnectOk {
//断言连接 //断言连接
ws, ok := value.(wsConnectItem) ws, ok := value.(wsConnectItem)
if !ok { if !ok {
@ -105,7 +103,21 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
UploadUnityRenderImageTakesTime: fmt.Sprintf("%dms", uploadUnityRenderImageTakesTime), UploadUnityRenderImageTakesTime: fmt.Sprintf("%dms", uploadUnityRenderImageTakesTime),
}, },
}) })
}
logx.Info("渲染回调成功,渲染结果图片为:", uploadRes.ResourceUrl) logx.Info("渲染回调成功,渲染结果图片为:", uploadRes.ResourceUrl)
return resp.SetStatusWithMessage(basic.CodeOK, "success") return resp.SetStatusWithMessage(basic.CodeOK, "success")
}
return resp.SetStatusWithMessage(basic.CodeOK, "successbut websocket connect not found")
}
//渲染失败走下面
if wsConnectOk {
//断言连接
ws, ok := value.(wsConnectItem)
if !ok {
logx.Error("渲染回调断言websocket连接失败")
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "渲染回调断言websocket连接失败")
}
//发送错误信息给前端
ws.renderErrResponse(renderId, info.TemplateTag, info.TaskId, "unity云渲染错误:"+req.Msg, 0, 0, 0, 0, 0, 0, 0)
}
return resp.SetStatusWithMessage(basic.CodeOK, "success")
} }

View File

@ -137,6 +137,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
return return
} }
//没传分辨率 //没传分辨率
//renderImageData.RenderData.Resolution = "512"
if renderImageData.RenderData.Resolution == "" { if renderImageData.RenderData.Resolution == "" {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入合图分辨率", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入合图分辨率", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
return return
@ -372,6 +373,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
Wid: w.uniqueId, Wid: w.uniqueId,
RenderId: info.RenderId, RenderId: info.RenderId,
RenderBeginTime: time.Now().UTC().UnixMilli(), RenderBeginTime: time.Now().UTC().UnixMilli(),
TemplateTag: info.RenderData.TemplateTag,
} }
temIdBytes, _ := json.Marshal(temId) temIdBytes, _ := json.Marshal(temId)
sendData := map[string]interface{}{ sendData := map[string]interface{}{

View File

@ -6,14 +6,16 @@ import (
) )
type RenderNotifyReq struct { type RenderNotifyReq struct {
TaskId string `json:"task_id"` //任务id + " " + wid的结合字符串 TaskId string `json:"task_id"`
UserId int64 `json:"user_id"` UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"` GuestId int64 `json:"guest_id"`
Image string `json:"image"` Image string `json:"image"`
Code int `json:"code,optional"`
Msg string `json:"msg,optional"`
} }
type CommonNotifyReq struct { type CommonNotifyReq struct {
Wid string `json:"wid,optional"` //websocket连接标识 Wid string `json:"wid,optional"` //websocket连接标识(找ws连接优先级高于user_id和guestid)
UserId int64 `json:"user_id,optional"` //用户id UserId int64 `json:"user_id,optional"` //用户id
GuestId int64 `json:"guest_id,optional"` //游客id GuestId int64 `json:"guest_id,optional"` //游客id
Data map[string]interface{} `json:"data"` //后端与前端约定好的数据 Data map[string]interface{} `json:"data"` //后端与前端约定好的数据
@ -42,10 +44,10 @@ type File struct {
} }
type Meta struct { type Meta struct {
TotalCount int64 `json:"totalCount"` TotalCount int64 `json:"total_count"`
PageCount int64 `json:"pageCount"` PageCount int64 `json:"page_count"`
CurrentPage int `json:"currentPage"` CurrentPage int `json:"current_page"`
PerPage int `json:"perPage"` PerPage int `json:"per_page"`
} }
// Set 设置Response的Code和Message值 // Set 设置Response的Code和Message值

View File

@ -27,6 +27,7 @@ service shopping-cart {
type AddToCartReq { type AddToCartReq {
ProductId int64 `json:"product_id"` //产品id ProductId int64 `json:"product_id"` //产品id
TemplateId int64 `json:"template_id,optional"` //模板id(不可定制的不传) TemplateId int64 `json:"template_id,optional"` //模板id(不可定制的不传)
IsHighlyCustomized int64 `json:"is_highly_customized"` //是否高度定制
SelectColorIndex int64 `json:"select_color_index"` //选择的颜色索引 SelectColorIndex int64 `json:"select_color_index"` //选择的颜色索引
SizeId int64 `json:"size_id"` //尺寸id SizeId int64 `json:"size_id"` //尺寸id
FittingId int64 `json:"fitting_id,optional"` //配件id(没有可以不传) FittingId int64 `json:"fitting_id,optional"` //配件id(没有可以不传)
@ -67,7 +68,7 @@ type CartItem {
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量 PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
MinPurchaseQuantity int64 `json:"min_purchase_quantity"` //起购数量 MinPurchaseQuantity int64 `json:"min_purchase_quantity"` //起购数量
StepPurchaseQuantity int64 `json:"step_purchase_quantity"` //购买加或者减少步进量 StepPurchaseQuantity int64 `json:"step_purchase_quantity"` //购买加或者减少步进量
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制 IsHighlyCustomized int64 `json:"is_highly_customized"` //是否高度定制
IsInvalid bool `json:"is_invalid"` //是否无效 IsInvalid bool `json:"is_invalid"` //是否无效
InvalidDescription string `json:"invalid_description"` //无效原因 InvalidDescription string `json:"invalid_description"` //无效原因
IsSelected bool `json:"is_selected"` //是否选中 IsSelected bool `json:"is_selected"` //是否选中

View File

@ -26,6 +26,8 @@ type RenderNotifyReq {
UserId int64 `json:"user_id"` UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"` GuestId int64 `json:"guest_id"`
Image string `json:"image"` Image string `json:"image"`
Code int `json:"code,optional"`
Msg string `json:"msg,optional"`
} }
//通用回调接口 //通用回调接口
type CommonNotifyReq { type CommonNotifyReq {

View File

@ -4,7 +4,7 @@ import "strings"
// 通过url解析资源id // 通过url解析资源id
func GetS3ResourceIdFormUrl(s3Url string) string { func GetS3ResourceIdFormUrl(s3Url string) string {
if !strings.Contains(s3Url, "http") { if !strings.Contains(s3Url, "storage.fusenpack.com") {
return "" return ""
} }
s := strings.Split(s3Url, "/") s := strings.Split(s3Url, "/")

View File

@ -74,4 +74,5 @@ type ToUnityIdStruct struct {
Wid string `json:"wid"` Wid string `json:"wid"`
RenderId string `json:"render_id"` RenderId string `json:"render_id"`
RenderBeginTime int64 `json:"render_begin_time"` RenderBeginTime int64 `json:"render_begin_time"`
TemplateTag string `json:"template_tag"`
} }