|
@@ -1,6 +1,8 @@
|
|
|
package order
|
|
|
|
|
|
import (
|
|
|
+ logger "eta/eta_mini_ht_api/common/component/log"
|
|
|
+ "eta/eta_mini_ht_api/common/utils/page"
|
|
|
orderDao "eta/eta_mini_ht_api/models/order"
|
|
|
"fmt"
|
|
|
"math/rand"
|
|
@@ -8,19 +10,35 @@ import (
|
|
|
)
|
|
|
|
|
|
type ProductOrderDTO struct {
|
|
|
- ID int
|
|
|
- OrderID string
|
|
|
- UserID int
|
|
|
- ProductID int
|
|
|
- TotalAmount string
|
|
|
+ ID int
|
|
|
+ OrderID string
|
|
|
+ UserID int
|
|
|
+ ProductID int
|
|
|
+ TotalAmount string
|
|
|
+ ProductPrice string
|
|
|
+ ProductName string
|
|
|
+ PaymentWay string
|
|
|
+ Status string
|
|
|
+ CreatedTime string
|
|
|
+}
|
|
|
+
|
|
|
+type ProductOrderDetailDTO struct {
|
|
|
+ ProductOrderDTO
|
|
|
TransactionID int
|
|
|
- RefundAmount string
|
|
|
- PaymentTime time.Time
|
|
|
- Status string
|
|
|
+ PaymentTime string
|
|
|
RefundStatus string
|
|
|
Remark string
|
|
|
}
|
|
|
|
|
|
+var (
|
|
|
+ transProductOrderStatus = map[orderDao.OrderStatus]string{
|
|
|
+ orderDao.OrderStatusClosed: "已关闭",
|
|
|
+ orderDao.OrderStatusPaid: "已支付",
|
|
|
+ orderDao.OrderStatusPending: "待支付",
|
|
|
+ orderDao.OrderStatusRefunded: "已退款",
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
func GenerateProductOrderNo() string {
|
|
|
timestamp := time.Now().UnixNano() / 1000000 // 毫秒级时间戳
|
|
|
// 生成随机数
|
|
@@ -39,28 +57,68 @@ func CreateProductOrder(orderDTO ProductOrderDTO) (orderNo string, err error) {
|
|
|
|
|
|
func convertProductOrderDTO(order orderDao.ProductOrder) ProductOrderDTO {
|
|
|
return ProductOrderDTO{
|
|
|
- ID: order.ID,
|
|
|
- OrderID: order.OrderID,
|
|
|
- UserID: order.UserID,
|
|
|
- ProductID: order.ProductID,
|
|
|
- TotalAmount: order.TotalAmount,
|
|
|
+ ID: order.ID,
|
|
|
+ OrderID: order.OrderID,
|
|
|
+ UserID: order.UserID,
|
|
|
+ ProductID: order.ProductID,
|
|
|
+ TotalAmount: order.TotalAmount,
|
|
|
+ PaymentWay: string(order.PaymentWay),
|
|
|
+ Status: transProductOrderStatus[order.Status],
|
|
|
+ CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
|
+ }
|
|
|
+}
|
|
|
+func convertProductOrderDetailDTO(order orderDao.ProductOrder) ProductOrderDetailDTO {
|
|
|
+ return ProductOrderDetailDTO{
|
|
|
+ ProductOrderDTO: ProductOrderDTO{
|
|
|
+ ID: order.ID,
|
|
|
+ OrderID: order.OrderID,
|
|
|
+ UserID: order.UserID,
|
|
|
+ ProductID: order.ProductID,
|
|
|
+ TotalAmount: order.TotalAmount,
|
|
|
+ PaymentWay: string(order.PaymentWay),
|
|
|
+ Status: transProductOrderStatus[order.Status],
|
|
|
+ CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
|
+ },
|
|
|
TransactionID: order.TransactionID,
|
|
|
- RefundAmount: order.RefundAmount,
|
|
|
- PaymentTime: order.PaymentTime,
|
|
|
+ PaymentTime: order.PaymentTime.Format(time.DateTime),
|
|
|
+ RefundStatus: string(order.RefundStatus),
|
|
|
Remark: order.Remark,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func convertProductOrder(order ProductOrderDTO) orderDao.ProductOrder {
|
|
|
return orderDao.ProductOrder{
|
|
|
- ID: order.ID,
|
|
|
- OrderID: order.OrderID,
|
|
|
- UserID: order.UserID,
|
|
|
- ProductID: order.ProductID,
|
|
|
- TotalAmount: order.TotalAmount,
|
|
|
- TransactionID: order.TransactionID,
|
|
|
- RefundAmount: order.RefundAmount,
|
|
|
- PaymentTime: order.PaymentTime,
|
|
|
- Remark: order.Remark,
|
|
|
+ ID: order.ID,
|
|
|
+ OrderID: order.OrderID,
|
|
|
+ UserID: order.UserID,
|
|
|
+ ProductID: order.ProductID,
|
|
|
+ TotalAmount: order.TotalAmount,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func GetTotalPageCountByUserId(userId int) (total int64, latestId int64) {
|
|
|
+ return orderDao.GetTotalPageCountByUserId(userId)
|
|
|
+}
|
|
|
+
|
|
|
+func GetOrderPage(pageInfo page.PageInfo, userId int) (orderDTOS []ProductOrderDTO, err error) {
|
|
|
+ offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
|
|
|
+ orderList, err := orderDao.GetOrderPage(pageInfo.LatestId, offset, pageInfo.PageSize, userId)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("分页查询订单列表失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, order := range orderList {
|
|
|
+ orderDTOS = append(orderDTOS, convertProductOrderDTO(order))
|
|
|
}
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetOrderDetail(orderId int, userId int) (orderDTO ProductOrderDetailDTO, err error) {
|
|
|
+ order, err := orderDao.GetOrderDetail(orderId, userId)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("查询订单详情失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ orderDTO = convertProductOrderDetailDTO(order)
|
|
|
+ return
|
|
|
}
|