114 lines
3.2 KiB
Go
114 lines
3.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/rpc/order/pb"
|
|
"lone-services/services/order/internal/dao"
|
|
"lone-services/services/order/internal/model"
|
|
"lone-services/services/order/internal/svc"
|
|
"strconv"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
type GetOrderInfoLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetOrderInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderInfoLogic {
|
|
return &GetOrderInfoLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *GetOrderInfoLogic) GetOrderInfo(in *order.GetOrderInfoRequest) (*order.OrderInfoResponse, error) {
|
|
var info dao.OrderInfo
|
|
modelObj := model.OrderModel{}.Init()
|
|
w := modelbase.Params{Eq: map[string]string{"order_sn": in.OrderSn}}
|
|
|
|
switch in.Type {
|
|
case dao.OrderTypeSale:
|
|
w.Eq["sale_id"] = strconv.FormatInt(in.UserId, utils.NumberTen)
|
|
case dao.OrderTypePersonal:
|
|
w.Eq["user_id"] = strconv.FormatInt(in.UserId, utils.NumberTen)
|
|
case dao.OrderTypeStore:
|
|
w.Eq["store_id"] = strconv.FormatInt(in.UserId, utils.NumberTen)
|
|
default:
|
|
return nil, status.Error(codes.Internal, utils.ErrorParams.Msg)
|
|
}
|
|
|
|
err := modelObj.GetOne(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return nil, status.Error(codes.Internal, utils.ErrorNotFund.Msg)
|
|
}
|
|
|
|
if info.Id < utils.NumberOne {
|
|
return nil, status.Error(codes.Internal, utils.ErrorNotFund.Msg)
|
|
}
|
|
|
|
var productItems []dao.OrderProducts
|
|
ww := modelbase.Params{
|
|
Eq: map[string]string{"order_sn": in.OrderSn},
|
|
}
|
|
err = model.OrderProductModel{}.Init().Items(ww, &productItems)
|
|
if err != nil {
|
|
l.Logger.Error("product err:", err)
|
|
return nil, status.Error(codes.Internal, utils.ErrorNotFund.Msg)
|
|
}
|
|
|
|
info.ProductItems = productItems
|
|
mobile, _ := utils.DecryptPhone(info.Mobile)
|
|
info.AesMobile = info.Mobile
|
|
info.Mobile = mobile
|
|
|
|
res := order.OrderInfoResponse{
|
|
Id: info.Id,
|
|
OrderSn: info.OrderSn,
|
|
StoreId: int64(info.StoreId),
|
|
StoreName: info.SaleName,
|
|
SaleName: info.SaleName,
|
|
SaleMobile: info.SaleMobile,
|
|
UserId: int64(info.UserId),
|
|
UserName: info.UserName,
|
|
SaleId: int64(info.SaleId),
|
|
Mobile: info.Mobile,
|
|
Address: info.Address,
|
|
Addressee: info.Addressee,
|
|
DistrictIds: info.DistrictIds,
|
|
TotalPrice: utils.RoundFloat(info.TotalPrice),
|
|
PayPrice: utils.RoundFloat(info.PayPrice),
|
|
PayType: int32(info.PayType),
|
|
DeliverStatus: int32(info.DeliverStatus),
|
|
Status: int32(info.Status),
|
|
IsSupply: int32(info.IsSupply),
|
|
Note: info.Note,
|
|
ProductIds: info.ProductIds,
|
|
OutTradeNo: info.OutTradeNo,
|
|
Type: int32(info.Type),
|
|
VerifyStatus: int32(info.VerifyStatus),
|
|
CreateType: int32(info.CreateType),
|
|
RefundStatus: int32(info.RefundStatus),
|
|
}
|
|
for _, v := range productItems {
|
|
res.ProductItems = append(res.ProductItems, &order.ProductItemsResponse{
|
|
Id: int64(v.Id),
|
|
ProductId: int64(v.ProductId),
|
|
ProductName: v.ProductName,
|
|
Price: utils.RoundFloat(float64(v.Price)),
|
|
Number: int32(v.Number),
|
|
OrderSn: v.OrderSn,
|
|
})
|
|
}
|
|
|
|
return &res, nil
|
|
}
|