Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
laodaming 2023-09-21 14:31:32 +08:00
commit bdc5b6edb7
12 changed files with 201 additions and 43 deletions

View File

@ -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 {

View File

@ -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)

View File

@ -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)
}
}
}

View File

@ -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,

View File

@ -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)
// }

View File

@ -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)
// }

View File

@ -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,
})
}

View File

@ -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 {

View File

@ -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"`
}

View File

@ -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,
})
}

View File

@ -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))
}

View File

@ -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{}