From caf2f753a5b3d1455925d38c118a12b4133485bb Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 22 Sep 2023 11:36:10 +0800 Subject: [PATCH] fix --- .../internal/logic/addtocartlogic.go | 27 +++++++++++++++++++ .../internal/svc/servicecontext.go | 10 ++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/server/shopping-cart/internal/logic/addtocartlogic.go b/server/shopping-cart/internal/logic/addtocartlogic.go index 1d6ef135..b6f4e21c 100644 --- a/server/shopping-cart/internal/logic/addtocartlogic.go +++ b/server/shopping-cart/internal/logic/addtocartlogic.go @@ -10,6 +10,8 @@ import ( "fusenapi/server/shopping-cart/internal/types" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/file" + "fusenapi/utils/hash" "gorm.io/gorm" "time" @@ -51,6 +53,31 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI if cartCount >= 100 { return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "sorry,the count of your carts can`t greater than 100") } + if req.RenderImage != "" { + //上传base64文件 + // 上传文件 + var upload = file.Upload{ + Ctx: l.ctx, + MysqlConn: l.svcCtx.MysqlConn, + AwsSession: l.svcCtx.AwsSession, + } + uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ + Source: "webGl render image", + FileHash: hash.JsonHashKey(req.RenderImage), + FileData: req.RenderImage, + Metadata: "", + UploadBucket: 1, + ApiType: 2, + UserId: userinfo.UserId, + GuestId: userinfo.GuestId, + FileByte: nil, + }) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload webGl render image") + } + req.RenderImage = uploadRes.ResourceUrl + } //获取产品是否存在 productInfo, err := l.svcCtx.AllModels.FsProduct.FindOne(l.ctx, req.ProductId) if err != nil { diff --git a/server/shopping-cart/internal/svc/servicecontext.go b/server/shopping-cart/internal/svc/servicecontext.go index f2b1f557..835b70da 100644 --- a/server/shopping-cart/internal/svc/servicecontext.go +++ b/server/shopping-cart/internal/svc/servicecontext.go @@ -16,6 +16,7 @@ type ServiceContext struct { AllModels *gmodel.AllModelsGen RabbitMq *initalize.RabbitMqHandle Repositories *initalize.Repositories + AwsSession *session.Session } func NewServiceContext(c config.Config) *ServiceContext { @@ -24,10 +25,11 @@ func NewServiceContext(c config.Config) *ServiceContext { Credentials: credentials.NewStaticCredentials(c.AWS.S3.Credentials.AccessKeyID, c.AWS.S3.Credentials.Secret, c.AWS.S3.Credentials.Token), } return &ServiceContext{ - Config: c, - MysqlConn: conn, - AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), - RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), + Config: c, + MysqlConn: conn, + AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), + RabbitMq: initalize.InitRabbitMq(c.SourceRabbitMq, nil), + AwsSession: session.Must(session.NewSession(&config)), Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{ GormDB: conn, BLMServiceUrl: &c.BLMService.Url,