diff --git a/model/gmodel/fs_order_logic.go b/model/gmodel/fs_order_logic.go index 3edc5d6b..5c8ce661 100644 --- a/model/gmodel/fs_order_logic.go +++ b/model/gmodel/fs_order_logic.go @@ -109,6 +109,7 @@ type OrderProduct struct { SizeInfo *OrderProductSizeInfo `json:"size_info"` FittingInfo *OrderProductFittingInfo `json:"fitting_info"` StepNum []int `json:"step_num"` // 阶梯数量 + IsHighlyCustomized int64 `json:"is_highly_customized"` } type OrderProductSizeInfo struct { diff --git a/server/order/internal/handler/createprepaymentdeposithandler.go b/server/order/internal/handler/createprepaymentbybalancehandler.go similarity index 67% rename from server/order/internal/handler/createprepaymentdeposithandler.go rename to server/order/internal/handler/createprepaymentbybalancehandler.go index 5beb1933..dfb956ac 100644 --- a/server/order/internal/handler/createprepaymentdeposithandler.go +++ b/server/order/internal/handler/createprepaymentbybalancehandler.go @@ -11,22 +11,22 @@ import ( "fusenapi/server/order/internal/types" ) -func CreatePrePaymentDepositHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func CreatePrePaymentByBalanceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - var req types.CreatePrePaymentDepositReq + var req types.CreatePrePaymentByBalanceReq userinfo, err := basic.RequestParse(w, r, svcCtx, &req) if err != nil { return } // 创建一个业务逻辑层实例 - l := logic.NewCreatePrePaymentDepositLogic(r.Context(), svcCtx) + l := logic.NewCreatePrePaymentByBalanceLogic(r.Context(), svcCtx) rl := reflect.ValueOf(l) basic.BeforeLogic(w, r, rl) - resp := l.CreatePrePaymentDeposit(&req, userinfo) + resp := l.CreatePrePaymentByBalance(&req, userinfo) if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) diff --git a/server/order/internal/handler/createprepaymentbydeposithandler.go b/server/order/internal/handler/createprepaymentbydeposithandler.go new file mode 100644 index 00000000..b6dd9e05 --- /dev/null +++ b/server/order/internal/handler/createprepaymentbydeposithandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/order/internal/logic" + "fusenapi/server/order/internal/svc" + "fusenapi/server/order/internal/types" +) + +func CreatePrePaymentByDepositHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.CreatePrePaymentByDepositReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewCreatePrePaymentByDepositLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.CreatePrePaymentByDeposit(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/order/internal/handler/routes.go b/server/order/internal/handler/routes.go index e3554925..8e1d47a9 100644 --- a/server/order/internal/handler/routes.go +++ b/server/order/internal/handler/routes.go @@ -20,7 +20,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { { Method: http.MethodPost, Path: "/api/order/create-prepayment-deposit", - Handler: CreatePrePaymentDepositHandler(serverCtx), + Handler: CreatePrePaymentByDepositHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/api/order/create-prepayment-balance", + Handler: CreatePrePaymentByBalanceHandler(serverCtx), }, { Method: http.MethodGet, diff --git a/server/order/internal/logic/createprepaymentdepositlogic.go b/server/order/internal/logic/createprepaymentbybalancelogic.go similarity index 53% rename from server/order/internal/logic/createprepaymentdepositlogic.go rename to server/order/internal/logic/createprepaymentbybalancelogic.go index 42ba75ff..3a4915ee 100644 --- a/server/order/internal/logic/createprepaymentdepositlogic.go +++ b/server/order/internal/logic/createprepaymentbybalancelogic.go @@ -12,14 +12,14 @@ import ( "github.com/zeromicro/go-zero/core/logx" ) -type CreatePrePaymentDepositLogic struct { +type CreatePrePaymentByBalanceLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } -func NewCreatePrePaymentDepositLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePrePaymentDepositLogic { - return &CreatePrePaymentDepositLogic{ +func NewCreatePrePaymentByBalanceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePrePaymentByBalanceLogic { + return &CreatePrePaymentByBalanceLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, @@ -27,10 +27,10 @@ func NewCreatePrePaymentDepositLogic(ctx context.Context, svcCtx *svc.ServiceCon } // 处理进入前逻辑w,r -// func (l *CreatePrePaymentDepositLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// func (l *CreatePrePaymentByBalanceLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } -func (l *CreatePrePaymentDepositLogic) CreatePrePaymentDeposit(req *types.CreatePrePaymentDepositReq, userinfo *auth.UserInfo) (resp *basic.Response) { +func (l *CreatePrePaymentByBalanceLogic) CreatePrePaymentByBalance(req *types.CreatePrePaymentByBalanceReq, userinfo *auth.UserInfo) (resp *basic.Response) { // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // userinfo 传入值时, 一定不为null @@ -38,6 +38,6 @@ func (l *CreatePrePaymentDepositLogic) CreatePrePaymentDeposit(req *types.Create } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 -// func (l *CreatePrePaymentDepositLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// func (l *CreatePrePaymentByBalanceLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) // } diff --git a/server/order/internal/logic/createprepaymentbydepositlogic.go b/server/order/internal/logic/createprepaymentbydepositlogic.go new file mode 100644 index 00000000..23f54c69 --- /dev/null +++ b/server/order/internal/logic/createprepaymentbydepositlogic.go @@ -0,0 +1,43 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/order/internal/svc" + "fusenapi/server/order/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CreatePrePaymentByDepositLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewCreatePrePaymentByDepositLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePrePaymentByDepositLogic { + return &CreatePrePaymentByDepositLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *CreatePrePaymentByDepositLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *CreatePrePaymentByDepositLogic) CreatePrePaymentByDeposit(req *types.CreatePrePaymentByDepositReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *CreatePrePaymentByDepositLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/order/internal/logic/orderdetaillogic.go b/server/order/internal/logic/orderdetaillogic.go index b4b2aef9..cd974870 100644 --- a/server/order/internal/logic/orderdetaillogic.go +++ b/server/order/internal/logic/orderdetaillogic.go @@ -47,7 +47,7 @@ func (l *OrderDetailLogic) OrderDetail(req *types.OrderDetailReq, userinfo *auth } return resp.SetStatus(basic.CodeOK, map[string]interface{}{ - "order_detail": res, + "order_detail": res.OrderDetail, }) } diff --git a/server/order/internal/types/types.go b/server/order/internal/types/types.go index ce2e2805..68118bcc 100644 --- a/server/order/internal/types/types.go +++ b/server/order/internal/types/types.go @@ -14,9 +14,9 @@ type CreateOrderReq struct { DeliveryMethod int64 `json:"delivery_method,options=[1,2]"` } -type CreatePrePaymentDepositReq struct { +type CreatePrePaymentByDepositReq struct { OrderSn string `json:"order_sn"` - DeliveryMethod int64 `json:"delivery_method"` + DeliveryMethod int64 `json:"delivery_method,options=[1,2]"` DeliveryAddres DeliveryAddres `json:"delivery_addres,optional"` } @@ -26,7 +26,15 @@ type DeliveryAddres struct { Mobile string `json:"mobile,optional"` } +type CreatePrePaymentByBalanceReq struct { + OrderSn string `json:"order_sn"` +} + type OrderListReq struct { + DeliveryMethod int64 `json:"delivery_method,options=[0,1,2],optional"` + OrderCycle string `json:"order_cycle,optional"` + Current_page int64 `json:"current_page,optional,default=1"` + Page_size int64 `json:"page_size,optional,default=10"` } type Request struct { diff --git a/server_api/order.api b/server_api/order.api index cf61669a..1a0747e7 100644 --- a/server_api/order.api +++ b/server_api/order.api @@ -14,8 +14,11 @@ service order { @handler CreateOrderHandler post /api/order/create(CreateOrderReq) returns (response); - @handler CreatePrePaymentDepositHandler - post /api/order/create-prepayment-deposit(CreatePrePaymentDepositReq) returns (response); + @handler CreatePrePaymentByDepositHandler + post /api/order/create-prepayment-deposit(CreatePrePaymentByDepositReq) returns (response); + + @handler CreatePrePaymentByBalanceHandler + post /api/order/create-prepayment-balance(CreatePrePaymentByBalanceReq) returns (response); @handler OrderListHandler get /api/order/list(OrderListReq) returns (response); @@ -34,9 +37,9 @@ type CreateOrderReq { DeliveryMethod int64 `json:"delivery_method,options=[1,2]"` } -type CreatePrePaymentDepositReq { +type CreatePrePaymentByDepositReq { OrderSn string `json:"order_sn"` - DeliveryMethod int64 `json:"delivery_method"` + DeliveryMethod int64 `json:"delivery_method,options=[1,2]"` DeliveryAddres DeliveryAddres `json:"delivery_addres,optional"` } @@ -46,5 +49,13 @@ type DeliveryAddres { Mobile string `json:"mobile,optional"` } +type CreatePrePaymentByBalanceReq { + OrderSn string `json:"order_sn"` +} + type OrderListReq { + DeliveryMethod int64 `json:"delivery_method,options=[0,1,2],optional"` + OrderCycle string `json:"order_cycle,optional"` + Current_page int64 `json:"current_page,optional,default=1"` + Page_size int64 `json:"page_size,optional,default=10"` } \ No newline at end of file diff --git a/service/repositories/order.go b/service/repositories/order.go index 6e96a452..b6afc6ae 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "errors" - "fmt" "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/basic" @@ -64,6 +63,7 @@ type ( OrderSn string `json:"order_sn"` } DetailRes struct { + OrderDetail gmodel.OrderDetail } /* 详情 */ ) @@ -73,23 +73,40 @@ func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRe var order gmodel.FsOrder result := d.MysqlConn.Where("order_sn = ?", in.OrderSn).Where("user_id = ?", in.UserId).Take(&order) if result.Error != nil { + logx.Errorf("detail failed, err: %v", err) return nil, result.Error } - d.OrderDetailHandler(ctx, &order) - return &DetailRes{}, nil -} - -func (d *defaultOrder) OrderDetailHandler(ctx context.Context, order *gmodel.FsOrder) (res *DetailRes, err error) { - var orderDetail gmodel.OrderDetail - - err = json.Unmarshal(*order.Metadata, &orderDetail) + ress, err := d.OrderDetailHandler(ctx, &order) if err != nil { - logx.Errorf("create handler unmarshal metadata failed, err: %v", err) return nil, err } - fmt.Println(orderDetail) + return &DetailRes{ + ress.OrderDetail, + }, nil +} - return nil, nil +func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel.FsOrder) (res *DetailRes, err error) { + var orderDetail gmodel.OrderDetail + + err = json.Unmarshal(*orderInfo.Metadata, &orderDetail) + if err != nil { + logx.Errorf("detail handler unmarshal metadata failed, err: %v", err) + return nil, err + } + 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) + return &DetailRes{ + OrderDetail: orderDetail, + }, nil } // 下单 @@ -294,7 +311,8 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe Cm: shoppingCartSnapshot.SizeInfo.Cm, }, }, - StepNum: stepNum, + StepNum: stepNum, + IsHighlyCustomized: *shoppingCart.IsHighlyCustomized, }) } diff --git a/utils/format/price.go b/utils/format/price.go index f89e3f0a..9af4a35e 100644 --- a/utils/format/price.go +++ b/utils/format/price.go @@ -16,3 +16,9 @@ func CentitoDollar(price int64, remainFloatPoint ...uint) float64 { dollar, _ := strconv.ParseFloat(str, 64) return dollar } + +// 厘转美元 +func CentitoDollarStr(price float64) string { + s := "%.2f" + return fmt.Sprintf(s, price/float64(1000)) +} diff --git a/utils/order/order.go b/utils/order/order.go index d6602860..60c25905 100644 --- a/utils/order/order.go +++ b/utils/order/order.go @@ -4,6 +4,7 @@ import ( "fmt" "fusenapi/constants" "fusenapi/model/gmodel" + "fusenapi/utils/format" "time" ) @@ -87,21 +88,31 @@ type GetAmountCurrencyUSDReq struct { OriginalCurrency string `json:"original_currency"` // 原始货币 } -type GetAmountCurrencyUSDRes struct { - ExchangeRate string `json:"exchange_rate"` // 换算汇率 - CurrentAmount string `json:"current_amount"` // 当前金额 - OriginalAmount string `json:"original_amount"` // 原始金额 - CurrentCurrency string `json:"current_currency"` // 当前货币 - OriginalCurrency string `json:"original_currency"` // 原始货币 -} - -// 处理金额(美元) -func GetAmountCurrencyUSD(req *GetAmountCurrencyUSDReq) (res GetAmountCurrencyUSDRes) { - return GetAmountCurrencyUSDRes{ - ExchangeRate: fmt.Sprintf("%.2f", float64(req.ExchangeRate)/1000), +// 处理金额(元) +func GetAmountCurrencyFormat(req *gmodel.AmountCurrency) (res gmodel.AmountCurrency) { + return gmodel.AmountCurrency{ + ExchangeRate: format.CentitoDollarStr(req.ExchangeRate.(float64)), + CurrentAmount: format.CentitoDollarStr(req.CurrentAmount.(float64)), + OriginalAmount: format.CentitoDollarStr(req.OriginalAmount.(float64)), + CurrentCurrency: req.CurrentCurrency, + OriginalCurrency: req.OriginalCurrency, } } +// 处理金额(元) +func GetAmountInfoFormat(req *gmodel.AmountInfo) gmodel.AmountInfo { + Current := GetAmountCurrencyFormat(&req.Current) + fmt.Println(Current) + return gmodel.AmountInfo{ + Change: GetAmountCurrencyFormat(&req.Change), + ChangeRemark: req.ChangeRemark, + Current: GetAmountCurrencyFormat(&req.Current), + Initiate: GetAmountCurrencyFormat(&req.Initiate), + Metadata: req.Metadata, + } +} + +// 生成订单编号 func GenerateOrderNumber() string { t := time.Now() orderNumber := fmt.Sprintf("%d%02d%02d%08d", t.Year(), t.Month(), t.Day(), t.UnixNano()%100000000) @@ -131,6 +142,26 @@ func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time, expectedTim return list } +// 获取订单状态 +func GetOrderStatusLinkUser(deliveryMethod int64, statusLink []gmodel.OrderStatus) []gmodel.OrderStatus { + var list []gmodel.OrderStatus + + var orderStatus []constants.OrderStatusCode + if deliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { + orderStatus = constants.OrderStatusUserDIRECTMAIL + } else { + orderStatus = constants.OrderStatusUserCLOUDSTORE + } + for _, v := range statusLink { + for _, orderStatusCode := range orderStatus { + if v.StatusCode == orderStatusCode { + list = append(list, v) + } + } + } + return list +} + // 获取订单当前状态 func GenerateOrderStatusCurrent() gmodel.OrderStatus { return gmodel.OrderStatus{}