From a2b7bfb253d9b8bf86f3bada32b202a423c4e25c Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 22 Sep 2023 15:52:32 +0800 Subject: [PATCH 1/9] fix --- .../internal/logic/ws_render_image.go | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index ebd066d0..7f5f0cfb 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -49,7 +49,7 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { return case w.extendRenderProperty.renderChan <- renderImageData: //发入到缓冲队列 return - case <- time.After(time.Millisecond * 50)://超过50毫秒丢弃 + case <-time.After(time.Millisecond * 50): //超过50毫秒丢弃 w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染队列溢出,请稍后再发", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return } @@ -70,7 +70,9 @@ func (w *wsConnectItem) consumeRenderImageData() { case <-w.closeChan: //已关闭 return case data := <-w.extendRenderProperty.renderChan: //消费数据 + logx.Info("准备执行任务。。。。。") limitChan <- struct{}{} + logx.Info("执行任务中。。。。。") go func(d websocket_data.RenderImageReqMsg) { defer func() { if err := recover(); err != nil { @@ -179,17 +181,11 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe Index: renderImageData.RenderData.TemplateTagColor.SelectedColorIndex, }, } - res := &repositories.LogoCombineRes{} - if w.userId == 127{ - u := "https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/1c4549bea75f9247f8aee5f7f6f3909a551cef97dc7acb0d01568b8bad042a01" - res.ResourceUrl = &u - }else{ - res, err = w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) - if err != nil { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "合成刀版图失败:"+err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) - logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err) - return - } + res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) + if err != nil { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "合成刀版图失败:"+err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) + logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err) + return } combineImage := "" //刀版图 if res != nil && res.ResourceUrl != nil { From 7e400ed761ee99e9d9f92a07010f028b39ecbfb0 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 22 Sep 2023 16:27:17 +0800 Subject: [PATCH 2/9] =?UTF-8?q?fix:=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_order_logic.go | 2 +- .../pay/internal/logic/stripewebhooklogic.go | 140 ++-------- server/pay/internal/svc/servicecontext.go | 8 +- service/repositories/order.go | 242 ++++++++++++++++-- utils/order/order.go | 35 ++- utils/pay/pay.go | 18 +- utils/pay/stripe.go | 6 +- 7 files changed, 303 insertions(+), 148 deletions(-) diff --git a/model/gmodel/fs_order_logic.go b/model/gmodel/fs_order_logic.go index 6fa62a1a..503231af 100644 --- a/model/gmodel/fs_order_logic.go +++ b/model/gmodel/fs_order_logic.go @@ -40,7 +40,7 @@ type PayInfo struct { Metadata map[string]interface{} `json:"metadata"` // 额外参数 PayAmount AmountInfo `json:"pay_amount"` // 金额明细 PayMethod string `json:"pay_method"` // 交易方式 - PayTime **time.Time `json:"pay_time"` // 支付时间 + PayTime *time.Time `json:"pay_time"` // 支付时间 Status PayStatus `json:"status"` // 当前状态 StatusLink []PayStatus `json:"status_link"` // 状态链路 TradeNo string `json:"trade_no"` // 支付交易号 diff --git a/server/pay/internal/logic/stripewebhooklogic.go b/server/pay/internal/logic/stripewebhooklogic.go index c13ab7c5..f08a0df1 100644 --- a/server/pay/internal/logic/stripewebhooklogic.go +++ b/server/pay/internal/logic/stripewebhooklogic.go @@ -3,8 +3,10 @@ package logic import ( "encoding/json" "errors" + "fmt" "fusenapi/constants" "fusenapi/model/gmodel" + "fusenapi/service/repositories" "fusenapi/utils/auth" "fusenapi/utils/basic" "time" @@ -52,7 +54,7 @@ func (l *StripeWebhookLogic) StripeWebhook(req *types.StripeWebhookReq, userinfo event := stripe.Event{} if err := json.Unmarshal(req.Payload, &event); err != nil { - logc.Errorf(l.ctx, "StripeWebhookLogic StripeWebhook Unmarshal err:", err) + logc.Errorf(l.ctx, "StripeWebhookLogic StripeWebhook Unmarshal err:%v", err) return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail") } @@ -106,7 +108,7 @@ func (l *StripeWebhookLogic) StripeWebhook(req *types.StripeWebhookReq, userinfo logx.Errorf("err:%+v,desc:%s", err, "pay notify Unmarshal fail event.Type payment_intent.succeeded") return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type payment_intent.succeeded") } - err = l.HandlePaymentIntentSucceeded(&paymentIntent) + err = l.HandlePaymentIntentSucceeded(&paymentIntent, event.ID) if err != nil { logx.Errorf("err:%+v,desc:%s", err, "pay notify handle payment_intent.succeeded") return resp.SetStatusWithMessage(basic.CodePaybackNotOk, "pay notify handle payment_intent.succeeded") @@ -230,119 +232,27 @@ func (l *StripeWebhookLogic) handlePaymentSessionCompleted(sessionId string, tra } // 付款成功 -func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.PaymentIntent) error { - orderSn, ok := paymentIntent.Metadata["order_sn"] - if !ok || orderSn == "" { - return errors.New("order_sn not found") +func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.PaymentIntent, eventId string) error { + // 支付成功 + if paymentIntent.Status == "succeeded" { + model, ok := paymentIntent.Metadata["model"] + if !ok { + err := errors.New("model is empty") + logc.Errorf(l.ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", eventId, err) + return err + } + switch model { + case "product_order": + res, err := l.svcCtx.Repositories.NewOrder.PaymentSuccessful(l.ctx, &repositories.PaymentSuccessfulReq{ + EventId: eventId, + PaymentMethod: 1, + PaymentIntent: paymentIntent, + }) + if err != nil { + return err + } + fmt.Println(res) + } } return nil - // 查询订单 - - // 支付成功 - // if paymentIntent.Status == "succeeded" { - // var card string - // var brand string - // if paymentIntent.LatestCharge.PaymentMethodDetails != nil { - // if paymentIntent.LatestCharge.PaymentMethodDetails.Card != nil { - // if paymentIntent.LatestCharge.PaymentMethodDetails.Card.Last4 != "" { - // card = paymentIntent.LatestCharge.PaymentMethodDetails.Card.Last4 - // } - // if paymentIntent.LatestCharge.PaymentMethodDetails.Card.Brand != "" { - // brand = string(paymentIntent.LatestCharge.PaymentMethodDetails.Card.Brand) - // } - // } - // } - - // ctx := l.ctx - // err = l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error { - // // 更新支付信息 - // payModelT := gmodel.NewFsPayModel(connGorm) - // *payInfo.PayStatus = 1 - // *payInfo.PayTime = nowTime - // *payInfo.CardNo = card - // *payInfo.Brand = brand - // *payInfo.TradeNo = paymentIntent.ID - // _, 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.RBUpdateByIds(productDesignModelTRSB, designIds, &gmodel.FsProductDesign{IsPay: &isPay}) - // if err != nil { - // return err - // } - - // var orderInfo = &gmodel.FsOrder{} - // var orderStatus int64 - // var orderIsPartPay int64 - // var orderPayedAmount int64 - // var orderIsPayCompleted int64 - // // 支付记录是首款 - // if *payInfo.PayStage == int64(constants.PAYSTAGE_DEPOSIT) { - // orderStatus = int64(constants.STATUS_NEW_PART_PAY) - // orderIsPartPay = 1 - // orderInfo.IsPartPay = &orderIsPartPay - // orderPayedAmount = paymentIntent.Amount - - // // 删除购物车 - // cartModelT := gmodel.NewFsCartModel(connGorm) - // cartModelTRSB := cartModelT.BuilderTrans(ctx, nil) - // err = cartModelT.RBDeleteCartsByIds(cartModelTRSB, cartIds) - // if err != nil { - // return err - // } - // } - - // // 支付记录是尾款 - // if *payInfo.PayStage == int64(constants.PAYSTAGE_REMAINING) { - // if *fsOrderRelInfo.Status < int64(constants.STATUS_NEW_PAY_COMPLETED) { - // orderStatus = int64(constants.STATUS_NEW_PAY_COMPLETED) - // } - // orderIsPayCompleted = 1 - // orderInfo.IsPayCompleted = &orderIsPayCompleted - // orderPayedAmount = *fsOrderRelInfo.PayedAmount + paymentIntent.Amount - // } - - // // 更新订单信息 - // orderInfo.Id = fsOrderRelInfo.Id - // orderInfo.Status = &orderStatus - // orderInfo.Ptime = &nowTime - // orderInfo.PayedAmount = &orderPayedAmount - // orderModelT := gmodel.NewFsOrderModel(connGorm) - // err = orderModelT.RBUpdate(ctx, orderInfo) - // if err != nil { - // return err - // } - // return err - // }) - // if err != nil { - // return err - // } - - //千人千面的处理 - // $renderServer = (new RenderService()); - // $renderServer->thousandsFacesV2($order->id); - // //清除用户最新的设计 - // $cache = \Yii::$app->cache; - // $cache->delete(CacheConfigHelper::LAST_DESIGN . $order->user_id); - // //缓存最新订单编号 - // $cache->set(CacheConfigHelper::USER_ORDERNO . $order->user_id, $order->sn); - - // //查询用户邮箱信息 - // $user = \api\models\User::find()->where(['id' => $order->user_id])->one(); - // $redisData = [ - // 'key' => 'receipt_download', - // 'param' => [ - // 'email' => $user->email, - // 'order_id' => $order->id, - // 'pay_id' => $pay->id, - // 'type' => 1,//付款成功为1 - // ] - // ]; - // Email::timely($redisData); - } diff --git a/server/pay/internal/svc/servicecontext.go b/server/pay/internal/svc/servicecontext.go index 9eca2703..4b437fd9 100644 --- a/server/pay/internal/svc/servicecontext.go +++ b/server/pay/internal/svc/servicecontext.go @@ -18,8 +18,9 @@ type ServiceContext struct { Config config.Config SharedState *shared.SharedState - MysqlConn *gorm.DB - AllModels *gmodel.AllModelsGen + MysqlConn *gorm.DB + AllModels *gmodel.AllModelsGen + Repositories *initalize.Repositories } func NewServiceContext(c config.Config) *ServiceContext { @@ -31,6 +32,9 @@ func NewServiceContext(c config.Config) *ServiceContext { MysqlConn: conn, SharedState: nil, AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)), + Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{ + GormDB: conn, + }), } } diff --git a/service/repositories/order.go b/service/repositories/order.go index a54045bf..e9aa19d8 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -15,6 +15,8 @@ import ( "time" "github.com/aws/aws-sdk-go/aws/session" + "github.com/stripe/stripe-go/v74" + "github.com/zeromicro/go-zero/core/logc" "github.com/zeromicro/go-zero/core/logx" "gorm.io/gorm" ) @@ -40,6 +42,16 @@ type ( List(ctx context.Context, in *ListReq) (res *ListRes, err error) // 详情 Detail(ctx context.Context, in *DetailReq) (res *DetailRes, err error) + // 支付成功 + PaymentSuccessful(ctx context.Context, in *PaymentSuccessfulReq) (res *PaymentSuccessfulRes, err error) + } + + PayInfo struct { + PayMethod int64 `json:"pay_method"` // 交易方式 + PayTime time.Time `json:"pay_time"` // 支付时间 + Status gmodel.PayStatus `json:"status"` // 当前状态 + StatusLink []gmodel.PayStatus `json:"status_link"` // 状态链路 + TradeNo string `json:"trade_no"` // 支付交易号 } OrderAddress struct { @@ -63,6 +75,16 @@ type ( Amount int64 `json:"amount"` // 金额 Label string `json:"label"` // 标签 } + + /* 支付成功 */ + PaymentSuccessfulReq struct { + EventId string + PaymentMethod int64 + PaymentIntent *stripe.PaymentIntent + } + PaymentSuccessfulRes struct{} + /* 支付成功 */ + /* 预支付--定金 */ CreatePrePaymentByDepositReq struct { StripeKey string `json:"stripe_key"` @@ -139,6 +161,175 @@ type ( /* 列表 */ ) +// 支付成功 +func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccessfulReq) (res *PaymentSuccessfulRes, err error) { + var orderSn string + var payStage string + var ok bool + var card string + var brand string + var country string + var currency string + var tradeSn string + var payAmount int64 + var payTitle string + var payTime time.Time + if in.PaymentIntent != nil { + paymentIntent := in.PaymentIntent + orderSn, ok = paymentIntent.Metadata["order_sn"] + if !ok || orderSn == "" { + err = errors.New("order_sn is empty") + logc.Errorf(ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", in.EventId, err) + return &PaymentSuccessfulRes{}, err + } + payStage, ok = paymentIntent.Metadata["pay_stage"] + if !ok || payStage == "" { + err = errors.New("pay_stage is empty") + logc.Errorf(ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", in.EventId, err) + return &PaymentSuccessfulRes{}, err + } + country, ok = paymentIntent.Metadata["country"] + if !ok || country == "" { + err = errors.New("country is empty") + logc.Errorf(ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", in.EventId, err) + return &PaymentSuccessfulRes{}, err + } + if paymentIntent.LatestCharge.PaymentMethodDetails != nil { + if paymentIntent.LatestCharge.PaymentMethodDetails.Card != nil { + if paymentIntent.LatestCharge.PaymentMethodDetails.Card.Last4 != "" { + card = paymentIntent.LatestCharge.PaymentMethodDetails.Card.Last4 + } + if paymentIntent.LatestCharge.PaymentMethodDetails.Card.Brand != "" { + brand = string(paymentIntent.LatestCharge.PaymentMethodDetails.Card.Brand) + } + } + } + if paymentIntent.Currency != "" { + currency = string(paymentIntent.Currency) + } + tradeSn = paymentIntent.ID + payAmount = paymentIntent.Amount + payTitle = paymentIntent.Description + payTime = time.Unix(paymentIntent.Created, 0) + } + err = d.MysqlConn.WithContext(ctx).Transaction(func(tx *gorm.DB) error { + var orderInfo gmodel.FsOrder + result := tx.Where("is_del = ?", 0).Where("order_sn = ?", orderSn).Take(&orderInfo) + err = result.Error + if err != nil { + logx.Errorf("PaymentSuccessful failed order Take, eventId:%s,err: %v", in.EventId, err) + return err + } + ress, err := d.OrderDetailHandler(ctx, &orderInfo, 0) + if err != nil { + logx.Errorf("PaymentSuccessful failed DetailOrderDetailHandler,eventId:%s, err: %v", in.EventId, err) + return err + } + var ntime = time.Now().UTC() + if (payStage == "deposit" && *orderInfo.PayStatus == int64(constants.ORDERPAYSTATUSUNPAIDDEPOSIT)) || (payStage == "remaining_balance" && *orderInfo.PayStatus == int64(constants.ORDERPAYSTATUSPAIDDEPOSIT)) { + var payStatus = int64(constants.PAYSTATUSPAID) + var payStageInt int64 + var orderPayStatusCode constants.OrderPayStatusCode + // 订单状态--当前 + var status gmodel.OrderStatus + var statusLink []gmodel.OrderStatus + var uOrderDetail = make(map[string]interface{}) + var payInfo PayInfo + payInfo.PayMethod = in.PaymentMethod + payInfo.PayTime = payTime + payInfo.TradeNo = tradeSn + + if payStage == "deposit" { + payStageInt = 1 + orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDEPOSIT + status = gmodel.OrderStatus{ + Ctime: &ntime, + Utime: &ntime, + StatusCode: constants.ORDERSTATUSDIRECTMAILORDERED, + StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSDIRECTMAILORDERED], + } + statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{ + Utime: &ntime, + StatusCode: constants.ORDERSTATUSDIRECTMAILORDERED, + StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSDIRECTMAILORDERED], + }) + payInfo.Status = gmodel.PayStatus{ + StatusCode: int64(constants.PAYSTATUSPAID), + StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSPAID], + } + payInfo.StatusLink = append(ress.OrderDetail.OrderAmount.Deposit.StatusLink, payInfo.Status) + uOrderDetail["order_amount"] = struct { + Deposit PayInfo `json:"deposit"` + }{ + Deposit: payInfo, + } + } + if payStage == "remaining_balance" { + payStageInt = 2 + orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDREMAINING + status = gmodel.OrderStatus{ + Ctime: &ntime, + Utime: &ntime, + StatusCode: constants.ORDERSTATUSCLOUDSTOREORDERED, + StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSCLOUDSTOREORDERED], + } + statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{ + Utime: &ntime, + StatusCode: constants.ORDERSTATUSCLOUDSTOREORDERED, + StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSCLOUDSTOREORDERED], + }) + payInfo.StatusLink = append(ress.OrderDetail.OrderAmount.RemainingBalance.StatusLink, payInfo.Status) + uOrderDetail["order_amount"] = struct { + RemainingBalance PayInfo `json:"remaining_balance"` + }{ + RemainingBalance: payInfo, + } + } + + // 新增交易信息 + tx.Create(&gmodel.FsOrderTrade{ + UserId: orderInfo.UserId, + OrderSn: &orderSn, + OrderSource: orderInfo.OrderSource, + TradeSn: &tradeSn, + PayAmount: &payAmount, + PayStatus: &payStatus, + PaymentMethod: &in.PaymentMethod, + PayStage: &payStageInt, + CardSn: &card, + CardBrand: &brand, + Country: &country, + Currency: ¤cy, + Ctime: &ntime, + Utime: &ntime, + PayTitle: &payTitle, + }) + // 更新订单信息 + var sql string = fmt.Sprintf(", `utime` = '%s'", ntime) + uOrderDetail["pay_status"] = orderPayStatusCode + uOrderDetail["order_info"] = struct { + Utime *time.Time `json:"utime"` + Status gmodel.OrderStatus `json:"status"` + StatusLink []gmodel.OrderStatus `json:"status_link"` + }{ + Utime: &ntime, + Status: status, + StatusLink: statusLink, + } + if len(uOrderDetail) > 0 { + err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, orderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", orderInfo.Id) + if err != nil { + logx.Errorf("PaymentSuccessful failed MetadataOrderPATCH,eventId:%s, err: %v", in.EventId, err) + return err + } + } + + } + return nil + }) + return &PaymentSuccessfulRes{}, nil +} + // 预支付--尾款 func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *CreatePrePaymentByBalanceReq) (res *CreatePrePaymentByBalanceRes, err error) { var errorCode basic.StatusResponse @@ -172,7 +363,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create }, err } - ress, err := d.OrderDetailHandler(ctx, &order) + ress, err := d.OrderDetailHandler(ctx, &order, 1) if err != nil { logx.Errorf("create prePayment balance failed DetailOrderDetailHandler, err: %v", err) errorCode = *basic.CodeServiceErr @@ -185,8 +376,13 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create payConfig := &pay.Config{} payConfig.Stripe.PayType = "intent" payConfig.Stripe.Key = in.StripeKey + var metadata = make(map[string]string, 2) + metadata["model"] = "product_order" + metadata["order_sn"] = in.OrderSn + metadata["pay_stage"] = "remaining_balance" + metadata["country"] = in.Country var generatePrepaymentReq = &pay.GeneratePrepaymentReq{ - OrderSn: in.OrderSn, + Metadata: metadata, ProductName: "支付尾款后期统一调整", Amount: amount, Currency: "usd", @@ -270,7 +466,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create }, err } - ress, err := d.OrderDetailHandler(ctx, &order) + ress, err := d.OrderDetailHandler(ctx, &order, 0) if err != nil { logx.Errorf("create prePayment deposit failed DetailOrderDetailHandler, err: %v", err) errorCode = *basic.CodeServiceErr @@ -342,8 +538,13 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create payConfig := &pay.Config{} payConfig.Stripe.PayType = "intent" payConfig.Stripe.Key = in.StripeKey + var metadata = make(map[string]string, 2) + metadata["model"] = "product_order" + metadata["order_sn"] = in.OrderSn + metadata["pay_stage"] = "deposit" + metadata["country"] = in.Country var generatePrepaymentReq = &pay.GeneratePrepaymentReq{ - OrderSn: in.OrderSn, + Metadata: metadata, ProductName: "支付首款", Amount: amount, Currency: "usd", @@ -417,7 +618,7 @@ func (d *defaultOrder) List(ctx context.Context, in *ListReq) (res *ListRes, err return nil, result.Error } for _, order := range orderList { - ress, err := d.OrderDetailHandler(ctx, &order) + ress, err := d.OrderDetailHandler(ctx, &order, 1) if err != nil { return nil, err } @@ -474,7 +675,7 @@ func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRe }, err } - ress, err := d.OrderDetailHandler(ctx, &order) + ress, err := d.OrderDetailHandler(ctx, &order, 1) if err != nil { logx.Errorf("order detail failed, err: %v", err) errorCode = *basic.CodeServiceErr @@ -718,6 +919,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe StatusCode: int64(constants.PAYSTATUSUNPAID), StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSUNPAID], }, + StatusLink: make([]gmodel.PayStatus, 0), PayAmount: order.GetAmountInfo(order.GetAmountInfoReq{ ExchangeRate: in.ExchangeRate, Initiate: depositInt, @@ -734,6 +936,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe StatusCode: int64(constants.PAYSTATUSUNPAID), StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSUNPAID], }, + StatusLink: make([]gmodel.PayStatus, 0), PayAmount: order.GetAmountInfo(order.GetAmountInfoReq{ ExchangeRate: in.ExchangeRate, Initiate: remainingBalanceInt, @@ -817,7 +1020,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe } // 详情处理 -func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel.FsOrder) (res *DetailRes, err error) { +func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel.FsOrder, original int64) (res *DetailRes, err error) { var orderDetail gmodel.OrderDetail err = json.Unmarshal(*orderInfo.Metadata, &orderDetail) @@ -826,18 +1029,21 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel return nil, err } orderDetailOriginal := orderDetail - for orderProductKey, orderProduct := range orderDetail.OrderProduct { - orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice) - orderDetail.OrderProduct[orderProductKey].ItemPrice = order.GetAmountInfoFormat(&orderProduct.ItemPrice) - orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot = nil - orderDetail.OrderProduct[orderProductKey].ProductSnapshot = nil + if original == 1 { + for orderProductKey, orderProduct := range orderDetail.OrderProduct { + orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice) + orderDetail.OrderProduct[orderProductKey].ItemPrice = order.GetAmountInfoFormat(&orderProduct.ItemPrice) + orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot = nil + orderDetail.OrderProduct[orderProductKey].ProductSnapshot = nil + } + orderDetail.OrderInfo.StatusLink = order.GetOrderStatusLinkUser(orderDetail.OrderInfo.DeliveryMethod, orderDetail.OrderInfo.StatusLink) + orderDetail.OrderAmount.Deposit.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Deposit.PayAmount) + orderDetail.OrderAmount.RemainingBalance.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.RemainingBalance.PayAmount) + orderDetail.OrderAmount.Subtotal = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Subtotal) + orderDetail.OrderAmount.Total = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Total) + orderDetail.PayTimeout = time.Duration(orderDetail.OrderInfo.Ctime.Add(orderDetail.PayTimeout).UTC().Unix() - time.Now().UTC().Unix()) + } - orderDetail.OrderInfo.StatusLink = order.GetOrderStatusLinkUser(orderDetail.OrderInfo.DeliveryMethod, orderDetail.OrderInfo.StatusLink) - orderDetail.OrderAmount.Deposit.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Deposit.PayAmount) - orderDetail.OrderAmount.RemainingBalance.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.RemainingBalance.PayAmount) - orderDetail.OrderAmount.Subtotal = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Subtotal) - orderDetail.OrderAmount.Total = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Total) - orderDetail.PayTimeout = time.Duration(orderDetail.OrderInfo.Ctime.Add(orderDetail.PayTimeout).UTC().Unix() - time.Now().UTC().Unix()) return &DetailRes{ OrderDetail: orderDetail, diff --git a/utils/order/order.go b/utils/order/order.go index 60c25905..61b49a16 100644 --- a/utils/order/order.go +++ b/utils/order/order.go @@ -120,7 +120,7 @@ func GenerateOrderNumber() string { return orderNumber } -// 初始化订单状态 +// 初始化订单状态--链路 func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time, expectedTime time.Time) []gmodel.OrderStatus { var list []gmodel.OrderStatus @@ -142,6 +142,39 @@ func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time, expectedTim return list } +// 更新订单状态--链路 +func UpdateOrderStatusLink(statusLink []gmodel.OrderStatus, status gmodel.OrderStatus) []gmodel.OrderStatus { + var list []gmodel.OrderStatus + for _, v := range statusLink { + if v.StatusCode == status.StatusCode { + item := v + if status.StatusTitle != "" { + item.StatusTitle = status.StatusTitle + } + if status.StatusCode != 0 { + item.StatusCode = status.StatusCode + } + if status.Utime != nil { + item.Utime = status.Utime + } + if status.Metadata != nil { + item.Metadata = status.Metadata + } + if status.ExpectedTime != nil { + item.ExpectedTime = status.ExpectedTime + } + if status.Children != nil || len(status.Children) > 0 { + item.Children = status.Children + } + + list = append(list, item) + } else { + list = append(list, v) + } + } + return list +} + // 获取订单状态 func GetOrderStatusLinkUser(deliveryMethod int64, statusLink []gmodel.OrderStatus) []gmodel.OrderStatus { var list []gmodel.OrderStatus diff --git a/utils/pay/pay.go b/utils/pay/pay.go index 12c7998f..9d602318 100644 --- a/utils/pay/pay.go +++ b/utils/pay/pay.go @@ -29,15 +29,15 @@ type Pay interface { } type GeneratePrepaymentReq struct { - OrderSn string `json:"order_sn"` // 订单编号 - Amount int64 `json:"amount"` // 支付金额 - Currency string `json:"currency"` // 支付货币 - ProductName string `json:"product_name"` // 商品名称 - ProductDescription string `json:"product_description"` // 商品描述 - ProductImages []*string `json:"product_imageso"` // 商品照片 - Quantity int64 `json:"quantity"` //数量 - SuccessURL string `json:"success_url"` // 支付成功回调 - CancelURL string `json:"cancel_url"` // 支付取消回调 + Metadata map[string]string `json:"metadata"` // 元数据 + Amount int64 `json:"amount"` // 支付金额 + Currency string `json:"currency"` // 支付货币 + ProductName string `json:"product_name"` // 商品名称 + ProductDescription string `json:"product_description"` // 商品描述 + ProductImages []*string `json:"product_imageso"` // 商品照片 + Quantity int64 `json:"quantity"` //数量 + SuccessURL string `json:"success_url"` // 支付成功回调 + CancelURL string `json:"cancel_url"` // 支付取消回调 } type GeneratePrepaymentRes struct { diff --git a/utils/pay/stripe.go b/utils/pay/stripe.go index 43cf28d3..ba709cbb 100644 --- a/utils/pay/stripe.go +++ b/utils/pay/stripe.go @@ -50,7 +50,7 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge case "session": // session 方式 params := &stripe.CheckoutSessionParams{ - PaymentIntentData: &stripe.CheckoutSessionPaymentIntentDataParams{Metadata: map[string]string{"order_sn": req.OrderSn}}, + PaymentIntentData: &stripe.CheckoutSessionPaymentIntentDataParams{Metadata: req.Metadata}, // Params: stripe.Params{Metadata: map[string]string{"order_id": "1111111111111"}}, PaymentMethodTypes: stripe.StringSlice([]string{ "card", @@ -79,7 +79,6 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge case "intent": // 密钥方式 params := &stripe.PaymentIntentParams{ - Params: stripe.Params{Metadata: map[string]string{"order_sn": req.OrderSn}}, Amount: stripe.Int64(req.Amount), Currency: stripe.String(string(req.Currency)), PaymentMethodTypes: stripe.StringSlice([]string{ @@ -87,6 +86,9 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge // "ideal", }), } + for key, item := range req.Metadata { + params.AddMetadata(key, item) + } resPaymentintent, err := paymentintent.New(params) if err != nil { return nil, err From 2054b9ec977d6653d620240352ac01a2dc1a7e19 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 22 Sep 2023 17:04:01 +0800 Subject: [PATCH 3/9] fix --- .../internal/logic/getcartslogic.go | 23 ++++++------------- server/shopping-cart/internal/types/types.go | 2 +- server_api/shopping-cart.api | 2 +- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/server/shopping-cart/internal/logic/getcartslogic.go b/server/shopping-cart/internal/logic/getcartslogic.go index 67e67138..45e5fa9e 100644 --- a/server/shopping-cart/internal/logic/getcartslogic.go +++ b/server/shopping-cart/internal/logic/getcartslogic.go @@ -41,32 +41,23 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo if !userinfo.IsUser() { return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in") } - if req.CurrentPage <= 0 { - req.CurrentPage = constants.DEFAULT_PAGE - } + currentPage := constants.DEFAULT_PAGE limit := 300 + if len(req.CartIds) > limit { + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "err param:request cart item is too much") + } //获取用户购物车列表 carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{ + Ids: req.CartIds, UserId: userinfo.UserId, Sort: "id DESC", - Page: req.CurrentPage, + Page: currentPage, Limit: limit, }) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to get your shopping carts") } - if len(carts) == 0 { - return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCartsRsp{ - Meta: types.Meta{ - TotalCount: total, - PageCount: int64(math.Ceil(float64(total) / float64(limit))), - CurrentPage: req.CurrentPage, - PerPage: limit, - }, - CartList: nil, - }) - } var ( mapSize = make(map[int64]gmodel.FsProductSize) mapModel = make(map[int64]gmodel.FsProductModel3d) @@ -201,7 +192,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo Meta: types.Meta{ TotalCount: total, PageCount: int64(math.Ceil(float64(total) / float64(limit))), - CurrentPage: req.CurrentPage, + CurrentPage: currentPage, PerPage: limit, }, CartList: list, diff --git a/server/shopping-cart/internal/types/types.go b/server/shopping-cart/internal/types/types.go index b30ae342..ccda464c 100644 --- a/server/shopping-cart/internal/types/types.go +++ b/server/shopping-cart/internal/types/types.go @@ -30,7 +30,7 @@ type DeleteCartReq struct { } type GetCartsReq struct { - CurrentPage int `form:"current_page"` //当前页 + CartIds []int64 `json:"cart_id,optional"` //购物车ids可选 } type GetCartsRsp struct { diff --git a/server_api/shopping-cart.api b/server_api/shopping-cart.api index 5b73ac76..86314683 100644 --- a/server_api/shopping-cart.api +++ b/server_api/shopping-cart.api @@ -49,7 +49,7 @@ type DeleteCartReq { //获取购物车列表 type GetCartsReq { - CurrentPage int `form:"current_page"` //当前页 + CartIds []int64 `json:"cart_id,optional"` //购物车ids可选 } type GetCartsRsp { Meta Meta `json:"meta"` //分页信息 From c34811df833c4b8c67a864b1fd86855b769ffeb9 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 22 Sep 2023 17:21:40 +0800 Subject: [PATCH 4/9] fix --- server/shopping-cart/internal/logic/getcartslogic.go | 9 +++++---- server/shopping-cart/internal/types/types.go | 2 +- server_api/shopping-cart.api | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/shopping-cart/internal/logic/getcartslogic.go b/server/shopping-cart/internal/logic/getcartslogic.go index 45e5fa9e..1f798027 100644 --- a/server/shopping-cart/internal/logic/getcartslogic.go +++ b/server/shopping-cart/internal/logic/getcartslogic.go @@ -43,12 +43,13 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo } currentPage := constants.DEFAULT_PAGE limit := 300 - if len(req.CartIds) > limit { - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "err param:request cart item is too much") - } //获取用户购物车列表 + var cartIds []int64 + if req.CartId > 0 { + cartIds = append(cartIds, req.CartId) + } carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{ - Ids: req.CartIds, + Ids: cartIds, UserId: userinfo.UserId, Sort: "id DESC", Page: currentPage, diff --git a/server/shopping-cart/internal/types/types.go b/server/shopping-cart/internal/types/types.go index ccda464c..366f7858 100644 --- a/server/shopping-cart/internal/types/types.go +++ b/server/shopping-cart/internal/types/types.go @@ -30,7 +30,7 @@ type DeleteCartReq struct { } type GetCartsReq struct { - CartIds []int64 `json:"cart_id,optional"` //购物车ids可选 + CartId int64 `form:"cart_id,optional"` //购物车ids可选 } type GetCartsRsp struct { diff --git a/server_api/shopping-cart.api b/server_api/shopping-cart.api index 86314683..89019534 100644 --- a/server_api/shopping-cart.api +++ b/server_api/shopping-cart.api @@ -49,7 +49,7 @@ type DeleteCartReq { //获取购物车列表 type GetCartsReq { - CartIds []int64 `json:"cart_id,optional"` //购物车ids可选 + CartId int64 `form:"cart_id,optional"` //购物车ids可选 } type GetCartsRsp { Meta Meta `json:"meta"` //分页信息 From 656d5038fe5f53d1f004cc9b7fb58ae86f4cc92e Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 22 Sep 2023 17:32:23 +0800 Subject: [PATCH 5/9] =?UTF-8?q?fix:=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_order_logic.go | 6 +++++- service/repositories/order.go | 8 ++++++-- utils/order/order.go | 9 +++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/model/gmodel/fs_order_logic.go b/model/gmodel/fs_order_logic.go index 503231af..a6fdb2b2 100644 --- a/model/gmodel/fs_order_logic.go +++ b/model/gmodel/fs_order_logic.go @@ -97,7 +97,7 @@ type OrderStatus struct { type OrderProduct struct { TotalPrice AmountInfo `json:"amount"` // 商品总价 ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间 - PurchaseQuantity int64 `json:"purchase_quantity"` // 购买数量 + PurchaseQuantity PurchaseQuantity `json:"purchase_quantity"` // 购买数量 ProductID int64 `json:"product_id"` // 商品ID ProductName string `json:"product_name"` // 商品名称 ItemPrice AmountInfo `json:"product_price"` // 商品单价 @@ -112,6 +112,10 @@ type OrderProduct struct { StepNum []int `json:"step_num"` // 阶梯数量 IsHighlyCustomized int64 `json:"is_highly_customized"` } +type PurchaseQuantity struct { + Current interface{} `json:"current"` + Initiate interface{} `json:"initiate"` +} type OrderProductSizeInfo struct { SizeID int64 `json:"size_id"` diff --git a/service/repositories/order.go b/service/repositories/order.go index e9aa19d8..57364a00 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -863,7 +863,10 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe OriginalCurrency: in.OriginalCurrency, }), ExpectedDeliveryTime: &in.ExpectedDeliveryTime, - PurchaseQuantity: *shoppingCart.PurchaseQuantity, + PurchaseQuantity: gmodel.PurchaseQuantity{ + Current: *shoppingCart.PurchaseQuantity, + Initiate: *shoppingCart.PurchaseQuantity, + }, ProductID: *shoppingCart.ProductId, ProductCover: *shoppingCart.ShoppingCartProduct.Cover, ProductCoverMetadata: productCoverMetadata, @@ -1032,7 +1035,8 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel if original == 1 { for orderProductKey, orderProduct := range orderDetail.OrderProduct { orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice) - orderDetail.OrderProduct[orderProductKey].ItemPrice = order.GetAmountInfoFormat(&orderProduct.ItemPrice) + orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice) + orderDetail.OrderProduct[orderProductKey].PurchaseQuantity = order.GetPurchaseQuantity(&orderProduct.PurchaseQuantity) orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot = nil orderDetail.OrderProduct[orderProductKey].ProductSnapshot = nil } diff --git a/utils/order/order.go b/utils/order/order.go index 61b49a16..583e41d4 100644 --- a/utils/order/order.go +++ b/utils/order/order.go @@ -5,6 +5,7 @@ import ( "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/format" + "strconv" "time" ) @@ -112,6 +113,14 @@ func GetAmountInfoFormat(req *gmodel.AmountInfo) gmodel.AmountInfo { } } +// 处理商品数量 +func GetPurchaseQuantity(req *gmodel.PurchaseQuantity) gmodel.PurchaseQuantity { + return gmodel.PurchaseQuantity{ + Initiate: strconv.FormatInt(req.Initiate.(int64), 10), + Current: strconv.FormatInt(req.Current.(int64), 10), + } +} + // 生成订单编号 func GenerateOrderNumber() string { t := time.Now() From 287ee4db37b0440b35e5dde2835fff8378457f95 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Fri, 22 Sep 2023 17:39:20 +0800 Subject: [PATCH 6/9] =?UTF-8?q?fix:=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/order/order.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/order/order.go b/utils/order/order.go index 583e41d4..5337531b 100644 --- a/utils/order/order.go +++ b/utils/order/order.go @@ -116,8 +116,8 @@ func GetAmountInfoFormat(req *gmodel.AmountInfo) gmodel.AmountInfo { // 处理商品数量 func GetPurchaseQuantity(req *gmodel.PurchaseQuantity) gmodel.PurchaseQuantity { return gmodel.PurchaseQuantity{ - Initiate: strconv.FormatInt(req.Initiate.(int64), 10), - Current: strconv.FormatInt(req.Current.(int64), 10), + Initiate: strconv.FormatInt(int64(req.Initiate.(float64)), 10), + Current: strconv.FormatInt(int64(req.Current.(float64)), 10), } } From a7f21da8da4f8356f9f43087e28587ff68203533 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 25 Sep 2023 11:16:55 +0800 Subject: [PATCH 7/9] fix --- model/gmodel/fs_address_gen.go | 32 +++++++------- model/gmodel/fs_address_logic.go | 28 ++++++------- model/gmodel/fs_change_code_gen.go | 15 +++---- model/gmodel/fs_product_gen.go | 1 + model/gmodel/fs_product_model3d_gen.go | 42 ++++++++++--------- .../internal/logic/getfittingbypidlogic.go | 2 +- .../internal/logic/calculatecartpricelogic.go | 2 +- .../internal/logic/getcartslogic.go | 2 +- service/repositories/order.go | 2 +- 9 files changed, 67 insertions(+), 59 deletions(-) diff --git a/model/gmodel/fs_address_gen.go b/model/gmodel/fs_address_gen.go index 17988dd6..b6085c7d 100644 --- a/model/gmodel/fs_address_gen.go +++ b/model/gmodel/fs_address_gen.go @@ -2,24 +2,28 @@ package gmodel import ( "gorm.io/gorm" + "time" ) // fs_address 用户地址表 type FsAddress struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // - UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID - Name *string `gorm:"default:'';" json:"name"` // 地址名称 - FirstName *string `gorm:"default:'';" json:"first_name"` // FirstName - LastName *string `gorm:"default:'';" json:"last_name"` // LastName - Mobile *string `gorm:"default:'';" json:"mobile"` // 手机号码 - Street *string `gorm:"default:'';" json:"street"` // 街道 - Suite *string `gorm:"default:'';" json:"suite"` // 房号 - City *string `gorm:"default:'';" json:"city"` // 城市 - State *string `gorm:"default:'';" json:"state"` // - Country *string `gorm:"default:'';" json:"country"` // - ZipCode *string `gorm:"default:'';" json:"zip_code"` // - Status *int64 `gorm:"default:0;" json:"status"` // 1正常 0异常 - IsDefault *int64 `gorm:"index;default:0;" json:"is_default"` // 1默认地址,0非默认地址 + AddressId int64 `gorm:"primary_key;default:0;auto_increment;" json:"address_id"` // + UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID + AddressName *string `gorm:"default:'';" json:"address_name"` // + FirstName *string `gorm:"default:'';" json:"first_name"` // FirstName + LastName *string `gorm:"default:'';" json:"last_name"` // LastName + Mobile *string `gorm:"default:'';" json:"mobile"` // 手机号码 + Street *string `gorm:"default:'';" json:"street"` // 街道 + Suite *string `gorm:"default:'';" json:"suite"` // 房号 + City *string `gorm:"default:'';" json:"city"` // 城市 + State *string `gorm:"default:'';" json:"state"` // + Country *string `gorm:"default:'';" json:"country"` // + ZipCode *string `gorm:"default:'';" json:"zip_code"` // + Status *int64 `gorm:"default:0;" json:"status"` // 1正常 0异常 + IsDefault *int64 `gorm:"index;default:0;" json:"is_default"` // 1默认地址,0非默认地址 + Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // 创建时间 + Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // 更新时间 + Ltime *time.Time `gorm:"index;default:'0000-00-00 00:00:00';" json:"ltime"` // 上次被使用的时间 } type FsAddressModel struct { db *gorm.DB diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index c346c507..08b747f2 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -24,19 +24,19 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res err = a.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { // now := time.Now().UTC().Unix() result = &FsAddress{ - UserId: address.UserId, - Name: address.Name, - FirstName: address.FirstName, - LastName: address.LastName, - Mobile: address.Mobile, - Street: address.Street, - Suite: address.Suite, - City: address.City, - State: address.State, - Country: address.Country, - ZipCode: address.ZipCode, - Status: address.Status, - IsDefault: address.IsDefault, + UserId: address.UserId, + AddressName: address.AddressName, + FirstName: address.FirstName, + LastName: address.LastName, + Mobile: address.Mobile, + Street: address.Street, + Suite: address.Suite, + City: address.City, + State: address.State, + Country: address.Country, + ZipCode: address.ZipCode, + Status: address.Status, + IsDefault: address.IsDefault, } return tx.Create(result).Error @@ -57,7 +57,7 @@ func (a *FsAddressModel) UpdateAddAddress(ctx context.Context, address *FsAddres return err } } - return tx.Model(&FsAddress{}).Where("id = ? and user_id = ?", address.Id, address.UserId).Omit("id", "user_id").Updates(address).Error + return tx.Model(&FsAddress{}).Where("id = ? and user_id = ?", address.AddressId, address.UserId).Omit("id", "user_id").Updates(address).Error }) return err } diff --git a/model/gmodel/fs_change_code_gen.go b/model/gmodel/fs_change_code_gen.go index 780107b5..e11f8524 100644 --- a/model/gmodel/fs_change_code_gen.go +++ b/model/gmodel/fs_change_code_gen.go @@ -2,17 +2,18 @@ package gmodel import ( "gorm.io/gorm" + "time" ) // fs_change_code 忘记密码code表 type FsChangeCode struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id - Email *string `gorm:"default:'';" json:"email"` // - Code *string `gorm:"default:'';" json:"code"` // - CreatedAt *int64 `gorm:"default:0;" json:"created_at"` // 创建时间 - IsUse *int64 `gorm:"default:0;" json:"is_use"` // 是否使用 1已使用 0未使用 - Metadata *[]byte `gorm:"default:'';" json:"metadata"` // - Module *string `gorm:"default:'logo';" json:"module"` // + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id + Email *string `gorm:"default:'';" json:"email"` // + Code *string `gorm:"default:'';" json:"code"` // + Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // + IsUse *int64 `gorm:"default:0;" json:"is_use"` // 是否使用 1已使用 0未使用 + Metadata *[]byte `gorm:"default:'';" json:"metadata"` // + Module *string `gorm:"default:'logo';" json:"module"` // } type FsChangeCodeModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_gen.go b/model/gmodel/fs_product_gen.go index 52b458ba..c9010248 100644 --- a/model/gmodel/fs_product_gen.go +++ b/model/gmodel/fs_product_gen.go @@ -36,6 +36,7 @@ type FsProduct struct { RecommendProductSort *string `gorm:"default:'';" json:"recommend_product_sort"` // SceneIds *string `gorm:"default:'';" json:"scene_ids"` // IsCustomization *int64 `gorm:"default:0;" json:"is_customization"` // 是否可定制 + Unit *string `gorm:"default:'';" json:"unit"` // } type FsProductModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_model3d_gen.go b/model/gmodel/fs_product_model3d_gen.go index 51b4e511..527e4b4d 100644 --- a/model/gmodel/fs_product_model3d_gen.go +++ b/model/gmodel/fs_product_model3d_gen.go @@ -2,30 +2,32 @@ package gmodel import ( "gorm.io/gorm" + "time" ) // fs_product_model3d 产品模型表 type FsProductModel3d struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // - ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID - Tag *int64 `gorm:"default:1;" json:"tag"` // 类别(1:模型,2:配件,3:场景) - Title *string `gorm:"default:'';" json:"title"` // 标题 - Name *string `gorm:"default:'';" json:"name"` // 详情页展示名称 - ModelInfo *string `gorm:"default:'';" json:"model_info"` // 模型详情 - MaterialId *int64 `gorm:"default:0;" json:"material_id"` // 材质ID - SizeId *int64 `gorm:"default:0;" json:"size_id"` // 尺寸ID - Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 - Light *int64 `gorm:"default:0;" json:"light"` // 灯光组 - LightList *string `gorm:"default:'';" json:"light_list"` // 灯光备选项 - PartId *int64 `gorm:"default:0;" json:"part_id"` // 配件选项id(配件就是模型的id) - PartList *string `gorm:"default:'';" json:"part_list"` // - Status *int64 `gorm:"default:0;" json:"status"` // 状态位 显示 删除 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 - OptionTemplate *int64 `gorm:"default:0;" json:"option_template"` // 配件绑定的公共模板 - Price *int64 `gorm:"default:0;" json:"price"` // 仅配件用,配件的价格, 单位:美分 - Sku *string `gorm:"default:'';" json:"sku"` // sku - IsHot *int64 `gorm:"default:0;" json:"is_hot"` // 是否热门 - IsCloudRender *int64 `gorm:"default:0;" json:"is_cloud_render"` // 是否设置为云渲染模型 + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // + ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID + Tag *int64 `gorm:"default:1;" json:"tag"` // 类别(1:模型,2:配件,3:场景) + Title *string `gorm:"default:'';" json:"title"` // 标题 + Name *string `gorm:"default:'';" json:"name"` // 详情页展示名称 + ModelInfo *string `gorm:"default:'';" json:"model_info"` // 模型详情 + MaterialId *int64 `gorm:"default:0;" json:"material_id"` // 材质ID + SizeId *int64 `gorm:"default:0;" json:"size_id"` // 尺寸ID + Sort *int64 `gorm:"default:0;" json:"sort"` // 排序 + Light *int64 `gorm:"default:0;" json:"light"` // 灯光组 + LightList *string `gorm:"default:'';" json:"light_list"` // 灯光备选项 + PartId *int64 `gorm:"default:0;" json:"part_id"` // 配件选项id(配件就是模型的id) + PartList *string `gorm:"default:'';" json:"part_list"` // + Status *int64 `gorm:"default:0;" json:"status"` // 状态位 显示 删除 + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 + OptionTemplate *int64 `gorm:"default:0;" json:"option_template"` // 配件绑定的公共模板 + FittingPrice *int64 `gorm:"default:0;" json:"fitting_price"` // 仅配件用,配件的价格, 单位:美分 + Sku *string `gorm:"default:'';" json:"sku"` // sku + IsHot *int64 `gorm:"default:0;" json:"is_hot"` // 是否热门 + IsCloudRender *int64 `gorm:"default:0;" json:"is_cloud_render"` // 是否设置为云渲染模型 + Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // } type FsProductModel3dModel struct { db *gorm.DB diff --git a/server/product/internal/logic/getfittingbypidlogic.go b/server/product/internal/logic/getfittingbypidlogic.go index 53db5460..30d1c9d8 100644 --- a/server/product/internal/logic/getfittingbypidlogic.go +++ b/server/product/internal/logic/getfittingbypidlogic.go @@ -111,7 +111,7 @@ func (l *GetFittingByPidLogic) GetFittingByPid(req *types.GetFittingByPidReq, us Id: fitting.Id, MaterialImg: materialImg, Title: *fitting.Title, - Price: *fitting.Price, + Price: *fitting.FittingPrice, ModelInfo: modelInfo, IsPopular: *fitting.IsHot > 0, }) diff --git a/server/shopping-cart/internal/logic/calculatecartpricelogic.go b/server/shopping-cart/internal/logic/calculatecartpricelogic.go index fc461746..4747760e 100644 --- a/server/shopping-cart/internal/logic/calculatecartpricelogic.go +++ b/server/shopping-cart/internal/logic/calculatecartpricelogic.go @@ -93,7 +93,7 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri } mapFitting := make(map[int64]int64) for _, v := range fittingList { - mapFitting[v.Id] = *v.Price + mapFitting[v.Id] = *v.FittingPrice } //开始计算价格 calculateResultList := make([]types.CalculateResultItem, 0, len(req.CalculateList)) diff --git a/server/shopping-cart/internal/logic/getcartslogic.go b/server/shopping-cart/internal/logic/getcartslogic.go index 1f798027..bd87a7ac 100644 --- a/server/shopping-cart/internal/logic/getcartslogic.go +++ b/server/shopping-cart/internal/logic/getcartslogic.go @@ -109,7 +109,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo fittingPrice := int64(0) if *cart.FittingId > 0 { if curFittingInfo, ok := mapModel[*cart.FittingId]; ok { - fittingPrice = *curFittingInfo.Price + fittingPrice = *curFittingInfo.FittingPrice } else { return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("cart contain some one witch lose fitting:%d", *cart.FittingId)) } diff --git a/service/repositories/order.go b/service/repositories/order.go index e9aa19d8..4e5b135d 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -838,7 +838,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe } /* 计算价格 */ - productPrice, productTotalPrice, stepNum, stepPrice, err := NewShoppingCart(tx, nil, nil).CaculateCartPrice(*shoppingCart.PurchaseQuantity, shoppingCartProductPrice, *shoppingCart.ShoppingCartProductModel3dFitting.Price) + productPrice, productTotalPrice, stepNum, stepPrice, err := NewShoppingCart(tx, nil, nil).CaculateCartPrice(*shoppingCart.PurchaseQuantity, shoppingCartProductPrice, *shoppingCart.ShoppingCartProductModel3dFitting.FittingPrice) if err != nil { errorCode = *basic.CodeErrOrderCreatProductPriceAbsent errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed" From d8d91e92707d7845cc4e2eb0b6d3d0c28301405f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 25 Sep 2023 11:34:53 +0800 Subject: [PATCH 8/9] fix --- model/gmodel/fs_product_model3d_gen.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_product_model3d_gen.go b/model/gmodel/fs_product_model3d_gen.go index 527e4b4d..51024e2c 100644 --- a/model/gmodel/fs_product_model3d_gen.go +++ b/model/gmodel/fs_product_model3d_gen.go @@ -21,13 +21,14 @@ type FsProductModel3d struct { PartId *int64 `gorm:"default:0;" json:"part_id"` // 配件选项id(配件就是模型的id) PartList *string `gorm:"default:'';" json:"part_list"` // Status *int64 `gorm:"default:0;" json:"status"` // 状态位 显示 删除 - Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 + Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // OptionTemplate *int64 `gorm:"default:0;" json:"option_template"` // 配件绑定的公共模板 FittingPrice *int64 `gorm:"default:0;" json:"fitting_price"` // 仅配件用,配件的价格, 单位:美分 Sku *string `gorm:"default:'';" json:"sku"` // sku IsHot *int64 `gorm:"default:0;" json:"is_hot"` // 是否热门 IsCloudRender *int64 `gorm:"default:0;" json:"is_cloud_render"` // 是否设置为云渲染模型 Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // + StepPrice *[]byte `gorm:"default:'';" json:"step_price"` // } type FsProductModel3dModel struct { db *gorm.DB From 29c7dc54e32a6b0f298fda2d2dd16e54ce252e39 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 25 Sep 2023 15:49:59 +0800 Subject: [PATCH 9/9] fix --- model/gmodel/fs_product_model3d_gen.go | 3 ++- server/product/internal/logic/getfittingbypidlogic.go | 2 +- server/shopping-cart/internal/logic/calculatecartpricelogic.go | 2 +- server/shopping-cart/internal/logic/getcartslogic.go | 2 +- service/repositories/order.go | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/model/gmodel/fs_product_model3d_gen.go b/model/gmodel/fs_product_model3d_gen.go index 51024e2c..884d73e4 100644 --- a/model/gmodel/fs_product_model3d_gen.go +++ b/model/gmodel/fs_product_model3d_gen.go @@ -23,12 +23,13 @@ type FsProductModel3d struct { Status *int64 `gorm:"default:0;" json:"status"` // 状态位 显示 删除 Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // OptionTemplate *int64 `gorm:"default:0;" json:"option_template"` // 配件绑定的公共模板 - FittingPrice *int64 `gorm:"default:0;" json:"fitting_price"` // 仅配件用,配件的价格, 单位:美分 + Price *int64 `gorm:"default:0;" json:"price"` // Sku *string `gorm:"default:'';" json:"sku"` // sku IsHot *int64 `gorm:"default:0;" json:"is_hot"` // 是否热门 IsCloudRender *int64 `gorm:"default:0;" json:"is_cloud_render"` // 是否设置为云渲染模型 Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // StepPrice *[]byte `gorm:"default:'';" json:"step_price"` // + PackedUnit *int64 `gorm:"default:0;" json:"packed_unit"` // } type FsProductModel3dModel struct { db *gorm.DB diff --git a/server/product/internal/logic/getfittingbypidlogic.go b/server/product/internal/logic/getfittingbypidlogic.go index 30d1c9d8..53db5460 100644 --- a/server/product/internal/logic/getfittingbypidlogic.go +++ b/server/product/internal/logic/getfittingbypidlogic.go @@ -111,7 +111,7 @@ func (l *GetFittingByPidLogic) GetFittingByPid(req *types.GetFittingByPidReq, us Id: fitting.Id, MaterialImg: materialImg, Title: *fitting.Title, - Price: *fitting.FittingPrice, + Price: *fitting.Price, ModelInfo: modelInfo, IsPopular: *fitting.IsHot > 0, }) diff --git a/server/shopping-cart/internal/logic/calculatecartpricelogic.go b/server/shopping-cart/internal/logic/calculatecartpricelogic.go index 4747760e..fc461746 100644 --- a/server/shopping-cart/internal/logic/calculatecartpricelogic.go +++ b/server/shopping-cart/internal/logic/calculatecartpricelogic.go @@ -93,7 +93,7 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri } mapFitting := make(map[int64]int64) for _, v := range fittingList { - mapFitting[v.Id] = *v.FittingPrice + mapFitting[v.Id] = *v.Price } //开始计算价格 calculateResultList := make([]types.CalculateResultItem, 0, len(req.CalculateList)) diff --git a/server/shopping-cart/internal/logic/getcartslogic.go b/server/shopping-cart/internal/logic/getcartslogic.go index bd87a7ac..1f798027 100644 --- a/server/shopping-cart/internal/logic/getcartslogic.go +++ b/server/shopping-cart/internal/logic/getcartslogic.go @@ -109,7 +109,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo fittingPrice := int64(0) if *cart.FittingId > 0 { if curFittingInfo, ok := mapModel[*cart.FittingId]; ok { - fittingPrice = *curFittingInfo.FittingPrice + fittingPrice = *curFittingInfo.Price } else { return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("cart contain some one witch lose fitting:%d", *cart.FittingId)) } diff --git a/service/repositories/order.go b/service/repositories/order.go index 974be1ca..57364a00 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -838,7 +838,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe } /* 计算价格 */ - productPrice, productTotalPrice, stepNum, stepPrice, err := NewShoppingCart(tx, nil, nil).CaculateCartPrice(*shoppingCart.PurchaseQuantity, shoppingCartProductPrice, *shoppingCart.ShoppingCartProductModel3dFitting.FittingPrice) + productPrice, productTotalPrice, stepNum, stepPrice, err := NewShoppingCart(tx, nil, nil).CaculateCartPrice(*shoppingCart.PurchaseQuantity, shoppingCartProductPrice, *shoppingCart.ShoppingCartProductModel3dFitting.Price) if err != nil { errorCode = *basic.CodeErrOrderCreatProductPriceAbsent errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"