|
@@ -2,6 +2,7 @@ package order
|
|
|
|
|
|
import (
|
|
import (
|
|
logger "eta/eta_mini_ht_api/common/component/log"
|
|
logger "eta/eta_mini_ht_api/common/component/log"
|
|
|
|
+ "eta/eta_mini_ht_api/common/exception"
|
|
"eta/eta_mini_ht_api/common/utils/page"
|
|
"eta/eta_mini_ht_api/common/utils/page"
|
|
orderDao "eta/eta_mini_ht_api/models/order"
|
|
orderDao "eta/eta_mini_ht_api/models/order"
|
|
"fmt"
|
|
"fmt"
|
|
@@ -10,16 +11,17 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
type ProductOrderDTO struct {
|
|
type ProductOrderDTO struct {
|
|
- ID int
|
|
|
|
- OrderID string
|
|
|
|
- UserID int
|
|
|
|
- ProductID int
|
|
|
|
- TotalAmount string
|
|
|
|
- ProductPrice string
|
|
|
|
- ProductName string
|
|
|
|
- PaymentWay string
|
|
|
|
- Status string
|
|
|
|
- CreatedTime string
|
|
|
|
|
|
+ ID int
|
|
|
|
+ OrderID string
|
|
|
|
+ UserID int
|
|
|
|
+ ProductID int
|
|
|
|
+ TotalAmount string
|
|
|
|
+ ProductPrice string
|
|
|
|
+ ProductName string
|
|
|
|
+ PaymentWay string
|
|
|
|
+ PaymentTimeRemain int64
|
|
|
|
+ Status string
|
|
|
|
+ CreatedTime string
|
|
}
|
|
}
|
|
|
|
|
|
type ProductOrderDetailDTO struct {
|
|
type ProductOrderDetailDTO struct {
|
|
@@ -31,11 +33,25 @@ type ProductOrderDetailDTO struct {
|
|
}
|
|
}
|
|
|
|
|
|
var (
|
|
var (
|
|
- transProductOrderStatus = map[orderDao.OrderStatus]string{
|
|
|
|
- orderDao.OrderStatusClosed: "已关闭",
|
|
|
|
- orderDao.OrderStatusPaid: "已支付",
|
|
|
|
- orderDao.OrderStatusPending: "待支付",
|
|
|
|
- orderDao.OrderStatusRefunded: "已退款",
|
|
|
|
|
|
+ transProductOrderStatusMap = map[orderDao.OrderStatus]string{
|
|
|
|
+ orderDao.OrderStatusClosed: "已关闭",
|
|
|
|
+ orderDao.OrderStatusPaid: "已支付",
|
|
|
|
+ orderDao.OrderStatusPending: "待支付",
|
|
|
|
+ orderDao.OrderStatusRefund: "售后",
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ transRefundStatusMap = map[orderDao.RefundStatus]string{
|
|
|
|
+ orderDao.RefundStatusPending: "待退款",
|
|
|
|
+ orderDao.RefundStatusFailed: "退款失败",
|
|
|
|
+ orderDao.RefundStatusProcessing: "退款中",
|
|
|
|
+ orderDao.RefundStatusSuccess: "退款成功",
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ productOrderStatusMap = map[string]orderDao.OrderStatus{
|
|
|
|
+ "closed": orderDao.OrderStatusClosed,
|
|
|
|
+ "paid": orderDao.OrderStatusPaid,
|
|
|
|
+ "pending": orderDao.OrderStatusPending,
|
|
|
|
+ "refund": orderDao.OrderStatusRefund,
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
@@ -55,17 +71,31 @@ func CreateProductOrder(orderDTO ProductOrderDTO) (orderNo string, err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-func convertProductOrderDTO(order orderDao.ProductOrder) ProductOrderDTO {
|
|
|
|
- return ProductOrderDTO{
|
|
|
|
|
|
+func convertProductOrderDTO(order orderDao.ProductOrder) (orderDTO ProductOrderDTO) {
|
|
|
|
+ orderDTO = ProductOrderDTO{
|
|
ID: order.ID,
|
|
ID: order.ID,
|
|
OrderID: order.OrderID,
|
|
OrderID: order.OrderID,
|
|
UserID: order.UserID,
|
|
UserID: order.UserID,
|
|
ProductID: order.ProductID,
|
|
ProductID: order.ProductID,
|
|
TotalAmount: order.TotalAmount,
|
|
TotalAmount: order.TotalAmount,
|
|
PaymentWay: string(order.PaymentWay),
|
|
PaymentWay: string(order.PaymentWay),
|
|
- Status: transProductOrderStatus[order.Status],
|
|
|
|
|
|
+ Status: transProductOrderStatusMap[order.Status],
|
|
CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
}
|
|
}
|
|
|
|
+ if order.Status == orderDao.OrderStatusRefund {
|
|
|
|
+ orderDTO.Status = 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]
|
|
|
|
+ } else {
|
|
|
|
+ orderDTO.PaymentTimeRemain = int64(duration.Seconds())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
}
|
|
}
|
|
func convertProductOrderDetailDTO(order orderDao.ProductOrder) ProductOrderDetailDTO {
|
|
func convertProductOrderDetailDTO(order orderDao.ProductOrder) ProductOrderDetailDTO {
|
|
return ProductOrderDetailDTO{
|
|
return ProductOrderDetailDTO{
|
|
@@ -76,7 +106,7 @@ func convertProductOrderDetailDTO(order orderDao.ProductOrder) ProductOrderDetai
|
|
ProductID: order.ProductID,
|
|
ProductID: order.ProductID,
|
|
TotalAmount: order.TotalAmount,
|
|
TotalAmount: order.TotalAmount,
|
|
PaymentWay: string(order.PaymentWay),
|
|
PaymentWay: string(order.PaymentWay),
|
|
- Status: transProductOrderStatus[order.Status],
|
|
|
|
|
|
+ Status: transProductOrderStatusMap[order.Status],
|
|
CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
},
|
|
},
|
|
TransactionID: order.TransactionID,
|
|
TransactionID: order.TransactionID,
|
|
@@ -96,13 +126,29 @@ func convertProductOrder(order ProductOrderDTO) orderDao.ProductOrder {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func GetTotalPageCountByUserId(userId int) (total int64, latestId int64) {
|
|
|
|
- return orderDao.GetTotalPageCountByUserId(userId)
|
|
|
|
|
|
+func GetTotalPageCountByUserId(userId int, orderStatus string) (total int64, latestId int64) {
|
|
|
|
+ var orderStatusEnum orderDao.OrderStatus
|
|
|
|
+ if orderStatus != "" {
|
|
|
|
+ orderStatusEnum = productOrderStatusMap[orderStatus]
|
|
|
|
+ if string(orderStatusEnum) == "" {
|
|
|
|
+ //err := exception.New(exception.IllegalOrderStatus)
|
|
|
|
+ logger.Error("订单状态不合法:%v", orderStatus)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return orderDao.GetTotalPageCountByUserId(userId, orderStatusEnum)
|
|
}
|
|
}
|
|
-
|
|
|
|
-func GetOrderPage(pageInfo page.PageInfo, userId int) (orderDTOS []ProductOrderDTO, err error) {
|
|
|
|
|
|
+func GetOrderPage(pageInfo page.PageInfo, userId int, orderStatus string) (orderDTOS []ProductOrderDTO, err error) {
|
|
|
|
+ var orderStatusEnum orderDao.OrderStatus
|
|
|
|
+ if orderStatus != "" {
|
|
|
|
+ orderStatusEnum = productOrderStatusMap[orderStatus]
|
|
|
|
+ if string(orderStatusEnum) == "" {
|
|
|
|
+ err = exception.New(exception.IllegalOrderStatus)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
|
|
offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
|
|
- orderList, err := orderDao.GetOrderPage(pageInfo.LatestId, offset, pageInfo.PageSize, userId)
|
|
|
|
|
|
+ orderList, err := orderDao.GetOrderPage(pageInfo.LatestId, offset, pageInfo.PageSize, userId, orderStatusEnum)
|
|
if err != nil {
|
|
if err != nil {
|
|
logger.Error("分页查询订单列表失败:%v", err)
|
|
logger.Error("分页查询订单列表失败:%v", err)
|
|
return
|
|
return
|