|
@@ -4,6 +4,7 @@ import (
|
|
|
logger "eta/eta_mini_ht_api/common/component/log"
|
|
|
"eta/eta_mini_ht_api/common/exception"
|
|
|
"eta/eta_mini_ht_api/common/utils/page"
|
|
|
+ productDao "eta/eta_mini_ht_api/models/merchant"
|
|
|
orderDao "eta/eta_mini_ht_api/models/order"
|
|
|
"fmt"
|
|
|
"math/rand"
|
|
@@ -11,25 +12,30 @@ import (
|
|
|
)
|
|
|
|
|
|
type ProductOrderDTO struct {
|
|
|
- ID int
|
|
|
- OrderID string
|
|
|
- UserID int
|
|
|
- ProductID int
|
|
|
- TotalAmount string
|
|
|
- ProductPrice string
|
|
|
- ProductName string
|
|
|
- PaymentWay string
|
|
|
- PaymentTimeRemain int64
|
|
|
- Status string
|
|
|
- CreatedTime string
|
|
|
+ ID int
|
|
|
+ OrderID string
|
|
|
+ UserID int
|
|
|
+ TemplateUserID int
|
|
|
+ ProductID int
|
|
|
+ TotalAmount string
|
|
|
+ ProductPrice string
|
|
|
+ ProductName string
|
|
|
+ ProductDescription string
|
|
|
+ PaymentWay string
|
|
|
+ PaymentTimeRemain int64
|
|
|
+ Status string
|
|
|
+ StatusCN string
|
|
|
+ CreatedTime string
|
|
|
+ UpdatedTime string
|
|
|
}
|
|
|
|
|
|
type ProductOrderDetailDTO struct {
|
|
|
ProductOrderDTO
|
|
|
- TransactionID int
|
|
|
- PaymentTime string
|
|
|
- RefundStatus string
|
|
|
- Remark string
|
|
|
+ TransactionID int
|
|
|
+ PaymentTime string
|
|
|
+ RefundFinishTime string
|
|
|
+ RefundStatus string
|
|
|
+ Remark string
|
|
|
}
|
|
|
|
|
|
var (
|
|
@@ -73,47 +79,70 @@ func CreateProductOrder(orderDTO ProductOrderDTO) (orderNo string, err error) {
|
|
|
|
|
|
func convertProductOrderDTO(order orderDao.ProductOrder) (orderDTO ProductOrderDTO) {
|
|
|
orderDTO = ProductOrderDTO{
|
|
|
- ID: order.ID,
|
|
|
- OrderID: order.OrderID,
|
|
|
- UserID: order.UserID,
|
|
|
- ProductID: order.ProductID,
|
|
|
- TotalAmount: order.TotalAmount,
|
|
|
- PaymentWay: string(order.PaymentWay),
|
|
|
- Status: transProductOrderStatusMap[order.Status],
|
|
|
- CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
|
+ ID: order.ID,
|
|
|
+ OrderID: order.OrderID,
|
|
|
+ UserID: order.UserID,
|
|
|
+ TemplateUserID: order.UserID,
|
|
|
+ ProductID: order.ProductID,
|
|
|
+ TotalAmount: order.TotalAmount,
|
|
|
+ PaymentWay: string(order.PaymentWay),
|
|
|
+ Status: string(order.Status),
|
|
|
+ StatusCN: transProductOrderStatusMap[order.Status],
|
|
|
+ CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
|
}
|
|
|
if order.Status == orderDao.OrderStatusRefund {
|
|
|
- orderDTO.Status = transRefundStatusMap[order.RefundStatus]
|
|
|
+ orderDTO.Status = string(order.RefundStatus)
|
|
|
+ orderDTO.StatusCN = transRefundStatusMap[order.RefundStatus]
|
|
|
}
|
|
|
if order.Status == orderDao.OrderStatusPending {
|
|
|
duration := time.Now().Sub(order.CreatedTime)
|
|
|
timeout := duration - 15*time.Minute
|
|
|
if timeout > 0 {
|
|
|
logger.Info("订单已超时:%v", order.OrderID)
|
|
|
- orderDTO.Status = transProductOrderStatusMap[orderDao.OrderStatusClosed]
|
|
|
+ orderDTO.Status = string(orderDao.OrderStatusClosed)
|
|
|
+ orderDTO.StatusCN = transProductOrderStatusMap[orderDao.OrderStatusClosed]
|
|
|
} else {
|
|
|
orderDTO.PaymentTimeRemain = int64(duration.Seconds())
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
-func convertProductOrderDetailDTO(order orderDao.ProductOrder) ProductOrderDetailDTO {
|
|
|
- return ProductOrderDetailDTO{
|
|
|
+func convertProductOrderDetailDTO(order orderDao.ProductOrder) (orderDetailDTO ProductOrderDetailDTO) {
|
|
|
+ orderDetailDTO = ProductOrderDetailDTO{
|
|
|
ProductOrderDTO: ProductOrderDTO{
|
|
|
- ID: order.ID,
|
|
|
- OrderID: order.OrderID,
|
|
|
- UserID: order.UserID,
|
|
|
- ProductID: order.ProductID,
|
|
|
- TotalAmount: order.TotalAmount,
|
|
|
- PaymentWay: string(order.PaymentWay),
|
|
|
- Status: transProductOrderStatusMap[order.Status],
|
|
|
- CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
|
+ ID: order.ID,
|
|
|
+ OrderID: order.OrderID,
|
|
|
+ UserID: order.UserID,
|
|
|
+ TemplateUserID: order.TemplateUserID,
|
|
|
+ ProductID: order.ProductID,
|
|
|
+ TotalAmount: order.TotalAmount,
|
|
|
+ PaymentWay: string(order.PaymentWay),
|
|
|
+ Status: string(order.Status),
|
|
|
+ StatusCN: transProductOrderStatusMap[order.Status],
|
|
|
+ CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
|
},
|
|
|
- TransactionID: order.TransactionID,
|
|
|
- PaymentTime: order.PaymentTime.Format(time.DateTime),
|
|
|
- RefundStatus: string(order.RefundStatus),
|
|
|
- Remark: order.Remark,
|
|
|
+ TransactionID: order.TradeID,
|
|
|
+ PaymentTime: order.PaymentTime.Format(time.DateTime),
|
|
|
+ RefundStatus: string(order.RefundStatus),
|
|
|
+ RefundFinishTime: order.RefundFinishTime.Format(time.DateTime),
|
|
|
+ Remark: order.Remark,
|
|
|
+ }
|
|
|
+ if order.Status == orderDao.OrderStatusRefund {
|
|
|
+ orderDetailDTO.Status = string(order.RefundStatus)
|
|
|
+ orderDetailDTO.StatusCN = transRefundStatusMap[order.RefundStatus]
|
|
|
}
|
|
|
+ if order.Status == orderDao.OrderStatusPending {
|
|
|
+ duration := time.Now().Sub(order.CreatedTime)
|
|
|
+ timeout := duration - 15*time.Minute
|
|
|
+ if timeout > 0 {
|
|
|
+ logger.Info("订单已超时:%v", order.OrderID)
|
|
|
+ orderDetailDTO.Status = string(orderDao.OrderStatusClosed)
|
|
|
+ orderDetailDTO.StatusCN = transProductOrderStatusMap[orderDao.OrderStatusClosed]
|
|
|
+ } else {
|
|
|
+ orderDetailDTO.PaymentTimeRemain = int64(duration.Seconds())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func convertProductOrder(order ProductOrderDTO) orderDao.ProductOrder {
|
|
@@ -165,7 +194,14 @@ func GetOrderDetail(orderId int, userId int) (orderDTO ProductOrderDetailDTO, er
|
|
|
logger.Error("查询订单详情失败:%v", err)
|
|
|
return
|
|
|
}
|
|
|
+ product, err := productDao.GetMerchantProductById(order.ProductID)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取产品信息失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
orderDTO = convertProductOrderDetailDTO(order)
|
|
|
+ orderDTO.ProductName = product.Title
|
|
|
+ orderDTO.ProductDescription = product.Description
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -186,3 +222,17 @@ func BatchCloseOrder() (err error) {
|
|
|
//}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func GetOrderByUser(templateUserId int, orderNo string) (orderDTO ProductOrderDTO, err error) {
|
|
|
+ var order orderDao.ProductOrder
|
|
|
+ order, err = orderDao.GetOrderByUser(templateUserId, orderNo)
|
|
|
+ product, err := productDao.GetMerchantProductById(order.ProductID)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("获取产品信息失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ orderDTO = convertProductOrderDTO(order)
|
|
|
+ orderDTO.ProductName = product.Title
|
|
|
+ orderDTO.ProductDescription = product.Description
|
|
|
+ return
|
|
|
+}
|