代码拉取完成,页面将自动刷新
package orderslogic
import (
"context"
"fmt"
"gitee.com/lzzandlyx/orders/model"
"github.com/google/uuid"
"github.com/jinzhu/copier"
"time"
"gitee.com/lzzandlyx/orders/internal/svc"
"gitee.com/lzzandlyx/orders/orders"
"github.com/zeromicro/go-zero/core/logx"
)
type GetOrderBySnLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetOrderBySnLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderBySnLogic {
return &GetOrderBySnLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetOrderBySnLogic) GetOrderBySn(in *orders.GetOrderBySnRequest) (*orders.GetOrderBySnResponse, error) {
if _, err := uuid.Parse(in.Sn); err != nil {
return nil, fmt.Errorf("订单编号校验不通过: %v", err)
}
orderInfo, err := l.getOrder(in)
if err != nil {
return nil, err
}
err = l.getOrderItem(orderInfo)
if err != nil {
return nil, err
}
err = l.getOrderAddress(orderInfo)
if err != nil {
return nil, err
}
return &orders.GetOrderBySnResponse{OrderInfo: orderInfo}, nil
}
func (l *GetOrderBySnLogic) getOrder(in *orders.GetOrderBySnRequest) (*orders.OrderInfo, error) {
order, err := model.GetOrderBySn(l.svcCtx, in.Sn)
var orderInfo orders.OrderInfo
err = copier.Copy(&orderInfo, &order)
if err != nil {
return nil, err
}
orderInfo.OrderId = int64(order.ID)
orderInfo.PayTime = order.PayTime.Format(time.DateTime)
return &orderInfo, nil
}
func (l *GetOrderBySnLogic) getOrderItem(orderInfo *orders.OrderInfo) (err error) {
items, err := model.GetOrderItem(l.svcCtx, orderInfo.OrderId)
var itemInfos []*orders.OrderItemInfo
for _, v := range items {
itemInfos = append(itemInfos, &orders.OrderItemInfo{
OrderItemId: int64(v.ID),
OrderId: v.OrderId,
GoodsId: v.GoodsId,
Quantity: v.Quantity,
GoodsTitle: v.GoodsTitle,
GoodsPrice: v.GoodsPrice,
Img: v.Img,
})
}
orderInfo.Items = itemInfos
return
}
func (l *GetOrderBySnLogic) getOrderAddress(orderInfo *orders.OrderInfo) error {
address, err := model.GetOrderAddress(l.svcCtx, orderInfo.OrderId)
if err != nil {
return err
}
orderInfo.OrderAddr = &orders.OrderAddr{
OrderAddrId: int64(address.ID),
OrderId: address.OrderId,
Mobile: address.Mobile,
Nickname: address.Nickname,
Address: address.Address,
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。