fix:修复上传
This commit is contained in:
@@ -80,14 +80,14 @@ func (l *UserOrderCancelLogic) UserOrderCancel(req *types.UserOrderCancelReq, us
|
||||
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||
// 修改订单信息
|
||||
orderModelTS := gmodel.NewFsOrderModel(tx)
|
||||
err = orderModelTS.Update(ctx, orderInfo)
|
||||
err = orderModelTS.RBUpdate(ctx, orderInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 新增退款记录
|
||||
var isRefund int64 = 0
|
||||
refundReasonModelTS := gmodel.NewFsRefundReasonModel(tx)
|
||||
refundReasonModelTS.CreateOrUpdate(ctx, &gmodel.FsRefundReason{
|
||||
refundReasonModelTS.RBCreateOrUpdate(ctx, &gmodel.FsRefundReason{
|
||||
IsRefund: &isRefund,
|
||||
RefundReasonId: &req.RefundReasonId,
|
||||
RefundReason: &req.RefundReason,
|
||||
|
||||
@@ -116,7 +116,7 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte
|
||||
var fspay *gmodel.FsPay
|
||||
newFsPayModel := gmodel.NewFsPayModel(connGorm)
|
||||
if *orderInfo.Status == int64(constants.STATUS_NEW_NOT_PAY) {
|
||||
fspay, err = newFsPayModel.GetListByOrderNumberStage(ctx, *orderInfo.Sn, 1)
|
||||
fspay, err = newFsPayModel.RBGetListByOrderNumberStage(ctx, *orderInfo.Sn, 1)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
@@ -124,7 +124,7 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte
|
||||
}
|
||||
payStage = 1
|
||||
} else {
|
||||
fspay, err = newFsPayModel.GetListByOrderNumberStage(ctx, *orderInfo.Sn, 2)
|
||||
fspay, err = newFsPayModel.RBGetListByOrderNumberStage(ctx, *orderInfo.Sn, 2)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
@@ -146,7 +146,7 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte
|
||||
}
|
||||
|
||||
// 订单信息--修改
|
||||
err = gmodel.NewFsOrderModel(connGorm).Update(ctx, orderInfo)
|
||||
err = gmodel.NewFsOrderModel(connGorm).RBUpdate(ctx, orderInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte
|
||||
fspay.OrderSource = &orderSource
|
||||
fspay.PayStatus = &payStatus
|
||||
|
||||
_, err = newFsPayModel.CreateOrUpdate(ctx, fspay)
|
||||
_, err = newFsPayModel.RBCreateOrUpdate(ctx, fspay)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge)
|
||||
err = l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error {
|
||||
// 查询支付记录
|
||||
payModelT := gmodel.NewFsPayModel(connGorm)
|
||||
payModelTRSB := payModelT.RowSelectBuilder(nil)
|
||||
payModelTRSB := payModelT.BuilderTrans(nil)
|
||||
payModelTRSB1 := payModelTRSB.Where("trade_no = ?", chargeRefunded.PaymentIntent.ID).Where("pay_status = ?", constants.PAYSTATUS_SUCCESS).Where("is_refund = ?", 0)
|
||||
payInfo, err := payModelT.FindOneByQuery(ctx, payModelTRSB1, nil)
|
||||
if err != nil {
|
||||
@@ -165,7 +165,7 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge)
|
||||
}
|
||||
// 更新支付记录
|
||||
*payInfo.IsRefund = 1
|
||||
_, err = payModelT.CreateOrUpdate(ctx, payInfo)
|
||||
_, err = payModelT.RBCreateOrUpdate(ctx, payInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -175,7 +175,7 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge)
|
||||
if count == 0 {
|
||||
// 退款完成更新订单状态
|
||||
orderModelT := gmodel.NewFsOrderModel(connGorm)
|
||||
orderModelTRSB := orderModelT.RowSelectBuilder(nil).Where("sn =?", payInfo.OrderNumber)
|
||||
orderModelTRSB := orderModelT.BuilderTrans(nil).Where("sn =?", payInfo.OrderNumber)
|
||||
orderInfoRel, err := orderModelT.FindOneByQuery(ctx, orderModelTRSB, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -192,13 +192,14 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge)
|
||||
|
||||
// 记录退款原因
|
||||
refundReasonModelT := gmodel.NewFsRefundReasonModel(connGorm)
|
||||
refundReasonModelTRSB := refundReasonModelT.RowSelectBuilder(nil).Where("order_id =?", orderInfoRel.Id)
|
||||
refundReasonInfo, err := refundReasonModelT.FindOneByQuery(ctx, refundReasonModelTRSB, nil)
|
||||
refundReasonModelTRSB := refundReasonModelT.BuilderTrans(nil)
|
||||
refundReasonModelTRSB1 := refundReasonModelTRSB.Where("order_id =?", orderInfoRel.Id)
|
||||
refundReasonInfo, err := refundReasonModelT.FindOneByQuery(ctx, refundReasonModelTRSB1, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*refundReasonInfo.IsRefund = 1
|
||||
_, err = refundReasonModelT.CreateOrUpdate(ctx, refundReasonInfo)
|
||||
_, err = refundReasonModelT.RBCreateOrUpdate(ctx, refundReasonInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -304,15 +305,16 @@ func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.
|
||||
*payInfo.CardNo = card
|
||||
*payInfo.Brand = brand
|
||||
*payInfo.TradeNo = paymentIntent.ID
|
||||
_, err = payModelT.CreateOrUpdate(ctx, payInfo)
|
||||
_, err = payModelT.RBCreateOrUpdate(ctx, payInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新设计数据
|
||||
productDesignModelT := gmodel.NewFsProductDesignModel(connGorm)
|
||||
productDesignModelTRSB := productDesignModelT.BuilderTrans(ctx, nil)
|
||||
var isPay int64 = 1
|
||||
err = productDesignModelT.UpdateByIds(ctx, designIds, &gmodel.FsProductDesign{IsPay: &isPay})
|
||||
err = productDesignModelT.RBUpdateByIds(productDesignModelTRSB, designIds, &gmodel.FsProductDesign{IsPay: &isPay})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -331,7 +333,8 @@ func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.
|
||||
|
||||
// 删除购物车
|
||||
cartModelT := gmodel.NewFsCartModel(connGorm)
|
||||
err = cartModelT.DeleteCartsByIds(ctx, cartIds)
|
||||
cartModelTRSB := cartModelT.BuilderTrans(ctx, nil)
|
||||
err = cartModelT.RBDeleteCartsByIds(cartModelTRSB, cartIds)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -353,7 +356,7 @@ func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.
|
||||
orderInfo.Ptime = &nowTime
|
||||
orderInfo.PayedAmount = &orderPayedAmount
|
||||
orderModelT := gmodel.NewFsOrderModel(connGorm)
|
||||
err = orderModelT.Update(ctx, orderInfo)
|
||||
err = orderModelT.RBUpdate(ctx, orderInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func UploadLogoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewUploadLogoLogic(r.Context(), svcCtx)
|
||||
l := logic.NewUploadLogoLogic(r, svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
@@ -66,8 +66,10 @@ func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, useri
|
||||
|
||||
ctx := l.ctx
|
||||
err := l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error {
|
||||
resourceModelTS := gmodel.NewFsResourceModel(l.svcCtx.MysqlConn)
|
||||
resourceInfo, err := resourceModelTS.FindOneById(ctx, req.ResourceId)
|
||||
resourceModelTS := gmodel.NewFsResourceModel(connGorm)
|
||||
transBuilder := resourceModelTS.BuilderTrans(nil)
|
||||
transBuilderFind := transBuilder.Where("resource_id =?", req.ResourceId)
|
||||
resourceInfo, err := resourceModelTS.FindOneByQuery(ctx, transBuilderFind, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -84,9 +86,9 @@ func (l *UploadCallbackLogic) UploadCallback(req *types.UploadCallbackReq, useri
|
||||
fsResource.BucketName = bucketName
|
||||
fsResource.Version = &version
|
||||
if resourceInfo.ResourceId == "" {
|
||||
_, err = resourceModelTS.Create(ctx, fsResource)
|
||||
_, err = resourceModelTS.BuilderCreate(ctx, transBuilder, fsResource)
|
||||
} else {
|
||||
_, err = resourceModelTS.Update(ctx, fsResource)
|
||||
_, err = resourceModelTS.BuilderUpdate(ctx, transBuilder, fsResource)
|
||||
}
|
||||
return err
|
||||
})
|
||||
|
||||
@@ -6,7 +6,10 @@ import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/curl"
|
||||
"fusenapi/utils/file"
|
||||
"fusenapi/utils/hash"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -22,13 +25,15 @@ type UploadLogoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
r *http.Request
|
||||
}
|
||||
|
||||
func NewUploadLogoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogoLogic {
|
||||
func NewUploadLogoLogic(r *http.Request, svcCtx *svc.ServiceContext) *UploadLogoLogic {
|
||||
return &UploadLogoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
Logger: logx.WithContext(r.Context()),
|
||||
ctx: r.Context(),
|
||||
svcCtx: svcCtx,
|
||||
r: r,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +66,43 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||
userId = userinfo.UserId
|
||||
}
|
||||
|
||||
//设置内存大小
|
||||
l.r.ParseMultipartForm(32 << 20)
|
||||
|
||||
fileObject, _, err := l.r.FormFile("file")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,no files")
|
||||
}
|
||||
|
||||
// 读取数据流
|
||||
ioData, err := io.ReadAll(fileObject)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeFileUploadErr, "file upload err,no files")
|
||||
}
|
||||
|
||||
// 上传文件
|
||||
var upload = file.Upload{
|
||||
Ctx: l.ctx,
|
||||
MysqlConn: l.svcCtx.MysqlConn,
|
||||
AwsSession: l.svcCtx.AwsSession,
|
||||
}
|
||||
var resourceId string = hash.JsonHashKey(req.FileKey)
|
||||
uploadRes, err := upload.UploadFileByByte(&file.UploadBaseReq{
|
||||
FileHash: resourceId,
|
||||
FileByte: ioData,
|
||||
UploadBucket: 1,
|
||||
ApiType: 2,
|
||||
UserId: userId,
|
||||
GuestId: guestId,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeFileUploadErr, "upload file failed")
|
||||
}
|
||||
|
||||
var logoWidth int64
|
||||
var logoHeight int64
|
||||
// 查看sku是否存在
|
||||
@@ -82,17 +124,14 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||
logoHeight = 200
|
||||
}
|
||||
var resultStr string
|
||||
var err error
|
||||
|
||||
var postMap = make(map[string]interface{}, 1)
|
||||
postMap["logo_url"] = req.ResourceUrl
|
||||
postMap["logo_url"] = uploadRes.ResourceUrl
|
||||
postMapB, _ := json.Marshal(postMap)
|
||||
|
||||
//result, err := http.Post(l.svcCtx.Config.BLMService.ImageProcess.Url, "application/json", strings.NewReader(string(postMapB)))
|
||||
|
||||
var headerData = make(map[string]string, 1)
|
||||
headerData["Content-Type"] = "application/json"
|
||||
result, err := curl.ApiCall(l.svcCtx.Config.BLMService.ImageProcess.Url, "POST", headerData, strings.NewReader(string(postMapB)), 20)
|
||||
result, err := curl.ApiCall(l.svcCtx.Config.BLMService.ImageProcess.Url, "POST", headerData, strings.NewReader(string(postMapB)), time.Second*20)
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
@@ -118,8 +157,8 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
|
||||
Module: &module,
|
||||
UserId: &userId,
|
||||
GuestId: &guestId,
|
||||
ResourceId: &req.ResourceId,
|
||||
ResourceUrl: &req.ResourceUrl,
|
||||
ResourceId: &uploadRes.ResourceId,
|
||||
ResourceUrl: &uploadRes.ResourceUrl,
|
||||
Metadata: &resultStr,
|
||||
CreateAt: &nowTime,
|
||||
})
|
||||
|
||||
@@ -16,11 +16,10 @@ type UploadFileBaseReq struct {
|
||||
}
|
||||
|
||||
type UploadLogoReq struct {
|
||||
ResourceId string `form:"resource_id"` // 资源ID
|
||||
ResourceUrl string `form:"resource_url"` // 资源URL
|
||||
IsRemoveBg int64 `form:"is_remove_bg,optional"` // 是否要去掉背景
|
||||
Proportion int64 `form:"proportion,default=60"` // 贴图在模型面板上的比例
|
||||
SkuId int64 `form:"sku_id,default=0"` // 模板ID
|
||||
FileKey string `form:"file_key"` // 上传logo唯一标识信息
|
||||
IsRemoveBg int64 `form:"is_remove_bg,optional"` // 是否要去掉背景
|
||||
Proportion int64 `form:"proportion,default=60"` // 贴图在模型面板上的比例
|
||||
SkuId int64 `form:"sku_id,default=0"` // 模板ID
|
||||
}
|
||||
|
||||
type UploadFileBackendReq struct {
|
||||
|
||||
Reference in New Issue
Block a user