From 916e05058542e699bdebd21e7df620224195d414 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 26 Sep 2023 10:54:11 +0800 Subject: [PATCH 1/2] fix --- .../handler/getproductsteppricehandler.go | 35 +++++ server/product/internal/handler/routes.go | 5 + .../internal/logic/getpricebypidlogic.go | 77 ----------- .../logic/getproductsteppricelogic.go | 130 ++++++++++++++++++ server/product/internal/types/types.go | 4 + server_api/product.api | 7 + 6 files changed, 181 insertions(+), 77 deletions(-) create mode 100644 server/product/internal/handler/getproductsteppricehandler.go create mode 100644 server/product/internal/logic/getproductsteppricelogic.go diff --git a/server/product/internal/handler/getproductsteppricehandler.go b/server/product/internal/handler/getproductsteppricehandler.go new file mode 100644 index 00000000..62b59e23 --- /dev/null +++ b/server/product/internal/handler/getproductsteppricehandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/product/internal/logic" + "fusenapi/server/product/internal/svc" + "fusenapi/server/product/internal/types" +) + +func GetProductStepPriceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.GetProductStepPriceReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewGetProductStepPriceLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.GetProductStepPrice(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/product/internal/handler/routes.go b/server/product/internal/handler/routes.go index 0a73ed56..260422e3 100644 --- a/server/product/internal/handler/routes.go +++ b/server/product/internal/handler/routes.go @@ -72,6 +72,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/product/get_price_by_pid", Handler: GetPriceByPidHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/api/product/get_product_step_price", + Handler: GetProductStepPriceHandler(serverCtx), + }, { Method: http.MethodGet, Path: "/api/product/get_size_by_pid", diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index 01c7449d..025a9c33 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -35,83 +35,6 @@ func NewGetPriceByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get } } -// 新的阶梯价格(到时候替换) -/*func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) { - req.Pid = strings.Trim(req.Pid, " ") - if req.Pid == "" { - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty") - } - //获取产品信息(只是获取id) - productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id") - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists") - } - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") - } - //查询产品价格 - modelPriceList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdTag(l.ctx, productInfo.Id, constants.TAG_MODEL, "id,part_id,step_price,packed_unit") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model price list") - } - fittingIds := make([]int64, 0, len(modelPriceList)) - for _, v := range modelPriceList { - if *v.PartId > 0 { - fittingIds = append(fittingIds, *v.PartId) - } - } - //查询配件价格列表 - fittingPriceList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIdsTag(l.ctx, fittingIds, constants.TAG_PARTS, "id,price,packed_unit") - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get fitting price list") - } - mapFitting := make(map[int64]gmodel.FsProductModel3d) - for _, v := range fittingPriceList { - mapFitting[v.Id] = v - } - //遍历处理模型价格 - mapRsp := make(map[string]interface{}) - for _, modelPriceInfo := range modelPriceList { - var stepPrice gmodel.StepPriceJsonStruct - if err = json.Unmarshal(*modelPriceInfo.StepPrice, &stepPrice); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse step price json") - } - if len(stepPrice.PriceRange) == 0 { - return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price is not set:%d", modelPriceInfo.Id)) - } - //最小单价 - minPrice := stepPrice.PriceRange[len(stepPrice.PriceRange)-1].Price - //最大单价 - maxPrice := stepPrice.PriceRange[0].Price - //购买数步进基数 - stepPurchaseQuantity := *modelPriceInfo.PackedUnit - if *modelPriceInfo.PartId > 0 { - fittingPriceInfo, ok := mapFitting[*modelPriceInfo.PartId] - if !ok { - return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("fitting price is not exists:%d", *modelPriceInfo.PartId)) - } - //最小价格要加配件 - minPrice += *fittingPriceInfo.Price - //如果配件装箱基数比主体大,则基数以配件为主 - if *fittingPriceInfo.PackedUnit > stepPurchaseQuantity { - stepPurchaseQuantity = *fittingPriceInfo.PackedUnit - } - } - mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{ - "step_purchase_quantity": stepPurchaseQuantity, - "min_price": minPrice, - "max_price": maxPrice, - "step_range": stepPrice.PriceRange, - "min_buy_units_num": stepPrice.MinBuyUnitsNum, - } - } - return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp) -} -*/ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) { req.Pid = strings.Trim(req.Pid, " ") if req.Pid == "" { diff --git a/server/product/internal/logic/getproductsteppricelogic.go b/server/product/internal/logic/getproductsteppricelogic.go new file mode 100644 index 00000000..e30b39bd --- /dev/null +++ b/server/product/internal/logic/getproductsteppricelogic.go @@ -0,0 +1,130 @@ +package logic + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "fusenapi/constants" + "fusenapi/model/gmodel" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + "fusenapi/utils/format" + "gorm.io/gorm" + + "fusenapi/server/product/internal/svc" + "fusenapi/server/product/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetProductStepPriceLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetProductStepPriceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductStepPriceLogic { + return &GetProductStepPriceLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *GetProductStepPriceLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStepPriceReq, userinfo *auth.UserInfo) (resp *basic.Response) { + if req.ProductId <= 0 { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product id") + } + //获取产品信息(只是获取id) + _, err := l.svcCtx.AllModels.FsProduct.FindOne(l.ctx, req.ProductId, "id") + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") + } + //查询产品价格 + modelPriceList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdTag(l.ctx, req.ProductId, constants.TAG_MODEL, "id,size_id,part_id,step_price,packed_unit") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model price list") + } + fittingIds := make([]int64, 0, len(modelPriceList)) + for _, v := range modelPriceList { + if *v.PartId > 0 { + fittingIds = append(fittingIds, *v.PartId) + } + } + //查询配件价格列表 + fittingPriceList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIdsTag(l.ctx, fittingIds, constants.TAG_PARTS, "id,price,packed_unit") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get fitting price list") + } + mapFitting := make(map[int64]gmodel.FsProductModel3d) + for _, v := range fittingPriceList { + mapFitting[v.Id] = v + } + //遍历处理模型价格 + mapRsp := make(map[string]interface{}) + for _, modelPriceInfo := range modelPriceList { + var stepPrice gmodel.StepPriceJsonStruct + if err = json.Unmarshal(*modelPriceInfo.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", modelPriceInfo.Id)) + } + //最小单价 + minPrice := stepPrice.PriceRange[rangeLen-1].Price + //最大单价 + maxPrice := stepPrice.PriceRange[0].Price + //购买数步进基数 + stepPurchaseQuantity := *modelPriceInfo.PackedUnit + //购买数步进基数描述 + stepPurchaseQuantityDescription := "主体装箱数为步进基数" + if *modelPriceInfo.PartId > 0 { + fittingPriceInfo, ok := mapFitting[*modelPriceInfo.PartId] + if !ok { + return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("fitting price is not exists:%d", *modelPriceInfo.PartId)) + } + //最小价格要加配件 + minPrice += *fittingPriceInfo.Price + //如果配件装箱基数比主体大,则基数以配件为主 + if *fittingPriceInfo.PackedUnit > stepPurchaseQuantity { + stepPurchaseQuantity = *fittingPriceInfo.PackedUnit + stepPurchaseQuantityDescription = "配件装箱数为步进基数" + } + } + stepRange := make([]interface{}, 0, rangeLen) + for _, rangeInfo := range stepPrice.PriceRange { + stepRange = append(stepRange, map[string]interface{}{ + "start_quantity": rangeInfo.StartQuantity, + "end_quantity": rangeInfo.EndQuantity, + "item_price": format.CentitoDollar(rangeInfo.Price, 3), + }) + } + mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{ + "step_purchase_quantity": stepPurchaseQuantity, + "step_purchase_quantity_description": stepPurchaseQuantityDescription, + "min_price": minPrice, + "max_price": maxPrice, + "step_range": stepRange, + "min_buy_units_quantity": stepPrice.MinBuyUnitsNum, + } + } + return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *GetProductStepPriceLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index f5d96bd6..b9b96864 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -331,6 +331,10 @@ type PriceItem struct { Price int64 `json:"price"` } +type GetProductStepPriceReq struct { + ProductId int64 `form:"product_id"` +} + type GetSizeByPidReq struct { Pid string `form:"pid"` TemplateTag string `form:"template_tag"` diff --git a/server_api/product.api b/server_api/product.api index 95346d07..94715b66 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -47,6 +47,9 @@ service product { //获取产品阶梯价格列表 @handler GetPriceByPidHandler get /api/product/get_price_by_pid(GetPriceByPidReq) returns (response); + //获取产品阶梯价格信息 + @handler GetProductStepPriceHandler + get /api/product/get_product_step_price(GetProductStepPriceReq) returns (response); //获取产品尺寸列表 @handler GetSizeByPidHandler get /api/product/get_size_by_pid(GetSizeByPidReq) returns (response); @@ -376,6 +379,10 @@ type PriceItem { TotalNum int64 `json:"total_num"` Price int64 `json:"price"` } +//获取产品阶梯价格信息 +type GetProductStepPriceReq { + ProductId int64 `form:"product_id"` +} //获取产品尺寸列表 type GetSizeByPidReq { Pid string `form:"pid"` From 6c2fba2b3aec301ffea1bcb9b4cc01a52ae384cb Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Tue, 26 Sep 2023 10:56:57 +0800 Subject: [PATCH 2/2] =?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 --- constants/orders.go | 30 ++++---- .../pay/internal/logic/stripewebhooklogic.go | 42 +++++----- service/repositories/order.go | 76 ++++++++++++++----- 3 files changed, 93 insertions(+), 55 deletions(-) diff --git a/constants/orders.go b/constants/orders.go index c9eb037b..8556c674 100644 --- a/constants/orders.go +++ b/constants/orders.go @@ -56,18 +56,20 @@ const ( type OrderStatusCode int64 const ( - ORDERSTATUSUNPAIDDEPOSIT OrderStatusCode = 0 // 0,未支付定金 - ORDERSTATUSDIRECTMAILORDERED OrderStatusCode = 10100 // 10100,直邮单--已下单 - ORDERSTATUSDIRECTMAILCANCEL OrderStatusCode = 10101 // 10101,直邮单--已取消 - ORDERSTATUSDIRECTMAILSTARTPRODUCTION OrderStatusCode = 10200 // 10200,直邮单--开始生产 - ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION OrderStatusCode = 10300 // 10300,直邮单--生产完成 - ORDERSTATUSDIRECTMAILSHIPPED OrderStatusCode = 10400 // 10400,直邮单--已发货 - ORDERSTATUSDIRECTMAILARRIVED OrderStatusCode = 10500 // 10500,直邮单--已到达 - ORDERSTATUSCLOUDSTOREORDERED OrderStatusCode = 20100 // 20100,云仓单--已下单 - ORDERSTATUSCLOUDSTORECANCEL OrderStatusCode = 20101 // 20101,云仓单--已取消 - ORDERSTATUSCLOUDSTORESTARTPRODUCTION OrderStatusCode = 20200 // 20200,云仓单--开始生产 - ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION OrderStatusCode = 20300 // 20300,云仓单--生产完成 - ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE OrderStatusCode = 20400 // 20400,云仓单--直达仓库 + ORDERSTATUSUNPAIDDEPOSIT OrderStatusCode = 0 // 0,未支付定金 + ORDERSTATUSDIRECTMAILORDERED OrderStatusCode = 10100 // 10100,直邮单--已下单 + ORDERSTATUSDIRECTMAILORDEREDMAINING OrderStatusCode = 10100001 // 10100001,直邮单--已下单--尾款 + ORDERSTATUSDIRECTMAILCANCEL OrderStatusCode = 10101 // 10101,直邮单--已取消 + ORDERSTATUSDIRECTMAILSTARTPRODUCTION OrderStatusCode = 10200 // 10200,直邮单--开始生产 + ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION OrderStatusCode = 10300 // 10300,直邮单--生产完成 + ORDERSTATUSDIRECTMAILSHIPPED OrderStatusCode = 10400 // 10400,直邮单--已发货 + ORDERSTATUSDIRECTMAILARRIVED OrderStatusCode = 10500 // 10500,直邮单--已到达 + ORDERSTATUSCLOUDSTOREORDERED OrderStatusCode = 20100 // 20100,云仓单--已下单 + ORDERSTATUSCLOUDSTOREORDEREDMAINING OrderStatusCode = 20100001 // 20100001,云仓单--已下单-尾款 + ORDERSTATUSCLOUDSTORECANCEL OrderStatusCode = 20101 // 20101,云仓单--已取消 + ORDERSTATUSCLOUDSTORESTARTPRODUCTION OrderStatusCode = 20200 // 20200,云仓单--开始生产 + ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION OrderStatusCode = 20300 // 20300,云仓单--生产完成 + ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE OrderStatusCode = 20400 // 20400,云仓单--直达仓库 ) // 订单状态名称 @@ -85,8 +87,8 @@ var OrderStatusUserCLOUDSTORE []OrderStatusCode func init() { // 订单状态名称 PayStatusMessage = make(map[PayStatusCode]string) - PayStatusMessage[PAYSTATUSUNPAID] = "Paid" - PayStatusMessage[PAYSTATUSPAID] = "Unpaid" + PayStatusMessage[PAYSTATUSUNPAID] = "Unpaid" + PayStatusMessage[PAYSTATUSPAID] = "Paid" PayStatusMessage[PAYSTATUSREFUNDED] = "Refunded" // 订单状态名称 diff --git a/server/pay/internal/logic/stripewebhooklogic.go b/server/pay/internal/logic/stripewebhooklogic.go index e061cb32..b96966ec 100644 --- a/server/pay/internal/logic/stripewebhooklogic.go +++ b/server/pay/internal/logic/stripewebhooklogic.go @@ -219,26 +219,26 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge) } // session完成 -func (l *StripeWebhookLogic) handlePaymentSessionCompleted(sessionId string, tradeNo string) (err error) { - // 查询支付记录 - payModel := gmodel.NewFsPayModel(l.svcCtx.MysqlConn) - rsbPay := payModel.RowSelectBuilder(nil) - rsbPay = rsbPay.Where("session_id = ?", sessionId) - payInfo, err := payModel.FindOneByQuery(l.ctx, rsbPay, nil) - if err != nil { - return err - } - if *payInfo.PayStatus == 0 { - *payInfo.TradeNo = tradeNo - _, err = payModel.CreateOrUpdate(l.ctx, payInfo) - if err != nil { - return err - } - } else { - return errors.New("pay status 1") - } - return err -} +// func (l *StripeWebhookLogic) handlePaymentSessionCompleted(sessionId string, tradeNo string) (err error) { +// // 查询支付记录 +// payModel := gmodel.NewFsPayModel(l.svcCtx.MysqlConn) +// rsbPay := payModel.RowSelectBuilder(nil) +// rsbPay = rsbPay.Where("session_id = ?", sessionId) +// payInfo, err := payModel.FindOneByQuery(l.ctx, rsbPay, nil) +// if err != nil { +// return err +// } +// if *payInfo.PayStatus == 0 { +// *payInfo.TradeNo = tradeNo +// _, err = payModel.CreateOrUpdate(l.ctx, payInfo) +// if err != nil { +// return err +// } +// } else { +// return errors.New("pay status 1") +// } +// return err +// } // 付款成功 func (l *StripeWebhookLogic) HandleChargeSucceeded(charge *stripe.Charge, eventId string) error { @@ -254,7 +254,7 @@ func (l *StripeWebhookLogic) HandleChargeSucceeded(charge *stripe.Charge, eventI case "product_order": res, err := l.svcCtx.Repositories.NewOrder.PaymentSuccessful(l.ctx, &repositories.PaymentSuccessfulReq{ EventId: eventId, - PaymentMethod: 1, + PaymentMethod: "stripe", Charge: charge, }) if err != nil { diff --git a/service/repositories/order.go b/service/repositories/order.go index 7fe9544e..be8c51d4 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -47,7 +47,7 @@ type ( } PayInfo struct { - PayMethod int64 `json:"pay_method"` // 交易方式 + PayMethod string `json:"pay_method"` // 交易方式 PayTime time.Time `json:"pay_time"` // 支付时间 Status gmodel.PayStatus `json:"status"` // 当前状态 StatusLink []gmodel.PayStatus `json:"status_link"` // 状态链路 @@ -79,7 +79,7 @@ type ( /* 支付成功 */ PaymentSuccessfulReq struct { EventId string - PaymentMethod int64 + PaymentMethod string Charge *stripe.Charge } PaymentSuccessfulRes struct{} @@ -174,6 +174,15 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess var payAmount int64 var payTitle string var payTime time.Time + + var paymentMethod int64 = 1 + if in.PaymentMethod == "stripe" { + paymentMethod = 1 + } + if in.PaymentMethod == "paypal" { + paymentMethod = 2 + } + if in.Charge != nil { charge := in.Charge orderSn, ok = charge.Metadata["order_sn"] @@ -238,20 +247,30 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess payInfo.PayMethod = in.PaymentMethod payInfo.PayTime = payTime payInfo.TradeNo = tradeSn - + // 当前状态 + var statusCode constants.OrderStatusCode + var statusCodePre constants.OrderStatusCode if payStage == "deposit" { + if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { + // 直邮 + statusCode = constants.ORDERSTATUSDIRECTMAILORDERED + } + if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDSCLOUDSTORE { + // 云仓 + statusCode = constants.ORDERSTATUSCLOUDSTOREORDERED + } payStageInt = 1 orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDEPOSIT status = gmodel.OrderStatus{ Ctime: &ntime, Utime: &ntime, - StatusCode: constants.ORDERSTATUSDIRECTMAILORDERED, - StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSDIRECTMAILORDERED], + StatusCode: statusCode, + StatusTitle: constants.OrderStatusMessage[statusCode], } statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{ Utime: &ntime, - StatusCode: constants.ORDERSTATUSDIRECTMAILORDERED, - StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSDIRECTMAILORDERED], + StatusCode: statusCode, + StatusTitle: constants.OrderStatusMessage[statusCode], }) payInfo.Status = gmodel.PayStatus{ StatusCode: int64(constants.PAYSTATUSPAID), @@ -265,19 +284,38 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess } } if payStage == "remaining_balance" { + if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { + // 直邮 + statusCodePre = constants.ORDERSTATUSDIRECTMAILORDERED + statusCode = constants.ORDERSTATUSDIRECTMAILORDEREDMAINING + } + if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDSCLOUDSTORE { + // 云仓 + statusCodePre = constants.ORDERSTATUSCLOUDSTOREORDERED + statusCode = constants.ORDERSTATUSCLOUDSTOREORDEREDMAINING + } payStageInt = 2 orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDREMAINING - status = gmodel.OrderStatus{ - Ctime: &ntime, - Utime: &ntime, - StatusCode: constants.ORDERSTATUSCLOUDSTOREORDERED, - StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSCLOUDSTOREORDERED], + + var statusChildren []*gmodel.OrderStatus + // 更新订单状态链路--子状态 + for oStatusLinkKey, oStatusLink := range ress.OrderDetail.OrderInfo.StatusLink { + if oStatusLink.StatusCode == statusCodePre { + statusChildren = append(oStatusLink.Children, &gmodel.OrderStatus{ + Ctime: &ntime, + Utime: &ntime, + StatusCode: statusCode, + StatusTitle: constants.OrderStatusMessage[statusCode], + }) + ress.OrderDetail.OrderInfo.StatusLink[oStatusLinkKey].Children = statusChildren + } } - statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{ - Utime: &ntime, - StatusCode: constants.ORDERSTATUSCLOUDSTOREORDERED, - StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSCLOUDSTOREORDERED], - }) + + if ress.OrderDetail.OrderInfo.Status.StatusCode == constants.ORDERSTATUSDIRECTMAILORDERED || ress.OrderDetail.OrderInfo.Status.StatusCode == constants.ORDERSTATUSCLOUDSTOREORDERED { + status = ress.OrderDetail.OrderInfo.Status + status.Children = statusChildren + } + payInfo.StatusLink = append(ress.OrderDetail.OrderAmount.RemainingBalance.StatusLink, payInfo.Status) uOrderDetail["order_amount"] = struct { RemainingBalance PayInfo `json:"remaining_balance"` @@ -294,7 +332,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess TradeSn: &tradeSn, PayAmount: &payAmount, PayStatus: &payStatus, - PaymentMethod: &in.PaymentMethod, + PaymentMethod: &paymentMethod, PayStage: &payStageInt, CardSn: &card, CardBrand: &brand, @@ -1037,7 +1075,6 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice) 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 } orderDetail.OrderInfo.StatusLink = order.GetOrderStatusLinkUser(orderDetail.OrderInfo.DeliveryMethod, orderDetail.OrderInfo.StatusLink) @@ -1046,7 +1083,6 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel 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{