123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- package ordersrv
- import (
- "Cold_Logistic/internal/server/infra/dao"
- "Cold_Logistic/internal/server/infra/models"
- "context"
- "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
- "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
- )
- // QueryExpressOrder 订单号查订单
- func (srv *OrderService) QueryExpressOrder(ctx context.Context, req QueryExpressOrderReqVO) (res QueryExpressOrderRespVO, err error) {
- order, err := srv.store.ExpressOrder().FindByOrderNo(ctx, req.OrderNo)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- if order.Id == 0 {
- return res, nil
- }
- logisticName, err := srv.store.LogisticCompany().FindNameById(ctx, order.LogisticId)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- log := models.OrderLogisticLog{}
- err = srv.store.OrderLogisticLog().FirstById(ctx, &log, order.LatestLogId)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- res.OrderId = order.Id
- res.OrderNo = order.OrderNo
- res.OrderStatus = order.OrderStatus
- res.LogisticName = logisticName
- res.LatestLocation = LocationInfoVO{
- LocationTime: log.CreatedTime,
- Location: log.Location,
- ContactPerson: log.ContactPerson,
- ContactPhone: log.ContactPhone,
- Extend: log.Extend,
- }
- return res, nil
- }
- // OrderDetail 订单详情
- func (srv *OrderService) OrderDetail(ctx context.Context, req OrderDetailReqVO) (res OrderDetailRespVO, err error) {
- order := models.ExpressOrder{}
- if err = srv.store.ExpressOrder().FirstById(ctx, &order, req.OrderId); err != nil {
- return res, errors.WithStackOnce(err)
- }
- logisticName, err := srv.store.LogisticCompany().FindNameById(ctx, order.LogisticId)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- addressIds := []int{order.SenderAddressId, order.ConsigneeAddressId}
- addressMap, err := srv.store.AddressBook().GetMapByIds(ctx, addressIds)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- res = OrderDetailRespVO{
- OrderId: order.Id,
- OrderNo: order.OrderNo,
- LogisticName: logisticName,
- OrderStatus: order.OrderStatus,
- Sender: ConvertAddressReqVO(addressMap[order.SenderAddressId]),
- Consignee: ConvertAddressReqVO(addressMap[order.ConsigneeAddressId]),
- CargoType: order.CargoType,
- TemperatureInterval: order.TemperatureInterval,
- CargoNumber: order.CargoNumber,
- DeliveryCondition: order.DeliveryCondition,
- DeliveryRemark: order.DeliveryRemark,
- TimeLimit: order.TimeLimit,
- PickupTime: order.PickupTime,
- IsWeekendPickup: order.IsWeekendPickup,
- IsInsuredValue: order.IsInsuredValue,
- }
- return res, nil
- }
- // OrderLogisticDetail 订单物流详情
- func (srv *OrderService) OrderLogisticDetail(ctx context.Context, req OrderLogisticDetailReqVO) (res OrderLogisticDetailRespVO, err error) {
- order := models.ExpressOrder{}
- if err = srv.store.ExpressOrder().FirstById(ctx, &order, req.OrderId); err != nil {
- return res, errors.WithStackOnce(err)
- }
- logLink, err := srv.getLogisticLink(ctx, order)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- addressIds := []int{order.SenderAddressId, order.ConsigneeAddressId}
- addressMap, err := srv.store.AddressBook().GetMapByIds(ctx, addressIds)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- res.Sender = ConvertAddressReqVO(addressMap[order.SenderAddressId])
- res.Consignee = ConvertAddressReqVO(addressMap[order.ConsigneeAddressId])
- res.LogisticLink = logLink
- return res, nil
- }
- func (srv *OrderService) getLogisticLink(ctx context.Context, order models.ExpressOrder) ([]LocationInfoVO, error) {
- logs, err := srv.store.OrderLogisticLog().FindAllByOrderId(ctx, order.Id)
- if err != nil {
- return nil, errors.WithStackOnce(err)
- }
- ret := make([]LocationInfoVO, 0, len(logs))
- for _, v := range logs {
- ret = append(ret, LocationInfoVO{
- LocationTime: v.CreatedTime,
- Location: v.Location,
- ContactPerson: v.ContactPerson,
- ContactPhone: v.ContactPhone,
- Extend: v.Extend,
- SnCode: v.SnCode,
- })
- }
- return ret, nil
- }
- // ManageOrderPage 管理后台订单列表
- func (srv *OrderService) ManageOrderPage(ctx context.Context, req ManageOrderPageReqVO) (res core.PageListResponse, err error) {
- dto := dao.ExpressOrderPageDTO{
- Page: req.Page,
- OrderNo: req.Search.OrderNo,
- OrderStatus: []int{req.Search.OrderStatus},
- }
- list, total, err := srv.store.ExpressOrder().ManagePage(ctx, dto)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- res.Total = total
- res.TotalPage = total / int64(req.Page.Size)
- res.Count = len(list)
- res.List = list
- return res, nil
- }
|