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{})
for _, modelInfo := range modelPriceList {
var stepPrice gmodel.StepPriceJsonStruct
//没有设置阶梯价格
if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
continue
}
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
logx.Error(err)
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, ",")
mapFittingUnit := make(map[string]interface{})
if *modelInfo.PartList != "" {

View File

@ -242,17 +242,18 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
snapshotJsonStr := string(snapshotJsonBytes)
now := time.Now().UTC()
err = l.svcCtx.AllModels.FsShoppingCart.Create(l.ctx, &gmodel.FsShoppingCart{
UserId: &userinfo.UserId,
ProductId: &req.ProductId,
TemplateId: &req.TemplateId,
ModelId: &modelInfo.Id,
LightId: modelInfo.Light,
SizeId: &req.SizeId,
FittingId: &req.FittingId,
PurchaseQuantity: &req.PurchaseQuantity,
Snapshot: &snapshotJsonStr,
Ctime: &now,
Utime: &now,
UserId: &userinfo.UserId,
ProductId: &req.ProductId,
TemplateId: &req.TemplateId,
ModelId: &modelInfo.Id,
IsHighlyCustomized: &req.IsHighlyCustomized,
LightId: modelInfo.Light,
SizeId: &req.SizeId,
FittingId: &req.FittingId,
PurchaseQuantity: &req.PurchaseQuantity,
Snapshot: &snapshotJsonStr,
Ctime: &now,
Utime: &now,
})
if err != nil {
logx.Error(err)

View File

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

View File

@ -6,16 +6,17 @@ import (
)
type AddToCartReq struct {
ProductId int64 `json:"product_id"` //产品id
TemplateId int64 `json:"template_id,optional"` //模板id(不可定制的不传)
SelectColorIndex int64 `json:"select_color_index"` //选择的颜色索引
SizeId int64 `json:"size_id"` //尺寸id
FittingId int64 `json:"fitting_id,optional"` //配件id(没有可以不传)
PurchaseQuantity int64 `json:"purchase_quantity"` //购买数量
Logo string `json:"logo,optional"` //logo地址(没有可以不传)
CombineImage string `json:"combine_image,optional"` //合图地址 (没有可以不传)
RenderImage string `json:"render_image,optional"` //渲染结果图 (没有可以不传)
DiyInfo DiyInfo `json:"diy_info,optional"` //用户diy数据可选
ProductId int64 `json:"product_id"` //产品id
TemplateId int64 `json:"template_id,optional"` //模板id(不可定制的不传)
IsHighlyCustomized int64 `json:"is_highly_customized"` //是否高度定制
SelectColorIndex int64 `json:"select_color_index"` //选择的颜色索引
SizeId int64 `json:"size_id"` //尺寸id
FittingId int64 `json:"fitting_id,optional"` //配件id(没有可以不传)
PurchaseQuantity int64 `json:"purchase_quantity"` //购买数量
Logo string `json:"logo,optional"` //logo地址(没有可以不传)
CombineImage string `json:"combine_image,optional"` //合图地址 (没有可以不传)
RenderImage string `json:"render_image,optional"` //渲染结果图 (没有可以不传)
DiyInfo DiyInfo `json:"diy_info,optional"` //用户diy数据可选
}
type DiyInfo struct {
@ -50,7 +51,7 @@ type CartItem struct {
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
MinPurchaseQuantity int64 `json:"min_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"` //是否无效
InvalidDescription string `json:"invalid_description"` //无效原因
IsSelected bool `json:"is_selected"` //是否选中

View File

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

View File

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

View File

@ -6,14 +6,16 @@ import (
)
type RenderNotifyReq struct {
TaskId string `json:"task_id"` //任务id + " " + wid的结合字符串
TaskId string `json:"task_id"`
UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"`
Image string `json:"image"`
Code int `json:"code,optional"`
Msg string `json:"msg,optional"`
}
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
GuestId int64 `json:"guest_id,optional"` //游客id
Data map[string]interface{} `json:"data"` //后端与前端约定好的数据
@ -42,10 +44,10 @@ type File struct {
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
TotalCount int64 `json:"total_count"`
PageCount int64 `json:"page_count"`
CurrentPage int `json:"current_page"`
PerPage int `json:"per_page"`
}
// Set 设置Response的Code和Message值

View File

@ -25,16 +25,17 @@ service shopping-cart {
//加入购物车
type AddToCartReq {
ProductId int64 `json:"product_id"` //产品id
TemplateId int64 `json:"template_id,optional"` //模板id(不可定制的不传)
SelectColorIndex int64 `json:"select_color_index"` //选择的颜色索引
SizeId int64 `json:"size_id"` //尺寸id
FittingId int64 `json:"fitting_id,optional"` //配件id(没有可以不传)
PurchaseQuantity int64 `json:"purchase_quantity"` //购买数量
Logo string `json:"logo,optional"` //logo地址(没有可以不传)
CombineImage string `json:"combine_image,optional"` //合图地址 (没有可以不传)
RenderImage string `json:"render_image,optional"` //渲染结果图 (没有可以不传)
DiyInfo DiyInfo `json:"diy_info,optional"` //用户diy数据可选
ProductId int64 `json:"product_id"` //产品id
TemplateId int64 `json:"template_id,optional"` //模板id(不可定制的不传)
IsHighlyCustomized int64 `json:"is_highly_customized"` //是否高度定制
SelectColorIndex int64 `json:"select_color_index"` //选择的颜色索引
SizeId int64 `json:"size_id"` //尺寸id
FittingId int64 `json:"fitting_id,optional"` //配件id(没有可以不传)
PurchaseQuantity int64 `json:"purchase_quantity"` //购买数量
Logo string `json:"logo,optional"` //logo地址(没有可以不传)
CombineImage string `json:"combine_image,optional"` //合图地址 (没有可以不传)
RenderImage string `json:"render_image,optional"` //渲染结果图 (没有可以不传)
DiyInfo DiyInfo `json:"diy_info,optional"` //用户diy数据可选
}
type DiyInfo {
Phone string `json:"phone,optional"` //电话(可选)
@ -67,7 +68,7 @@ type CartItem {
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
MinPurchaseQuantity int64 `json:"min_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"` //是否无效
InvalidDescription string `json:"invalid_description"` //无效原因
IsSelected bool `json:"is_selected"` //是否选中

View File

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

View File

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

View File

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