MCPcopy Index your code
hub / github.com/53AI/53AIHub / QueryOrderStatus

Function QueryOrderStatus

api/controller/pay.go:672–805  ·  view source on GitHub ↗

QueryOrderStatus queries the status of an order @Summary Query order status @Description Query the status of an order @Tags Order @Accept json @Produce json @Security BearerAuth @Param order_id path string true "Order ID" @Success 200 {object} model.CommonResponse{data=OrderStatusResponse} @Router /

(c *gin.Context)

Source from the content-addressed store, hash-verified

670// @Router /api/orders/status/{order_id} [get]
671// QueryOrderStatus queries the status of an order
672func QueryOrderStatus(c *gin.Context) {
673 orderId := c.Param("order_id")
674 if orderId == "" {
675 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse("Order ID is required"))
676 return
677 }
678
679 eid := config.GetEID(c)
680
681 // Try to get order from database
682 order, err := model.GetOrderByOrderId(eid, orderId)
683 if err != nil {
684 // Order not found in database, check cache
685 cachedOrder, found := getCachedOrder(orderId)
686 if !found {
687 c.JSON(http.StatusNotFound, model.NotFound.ToNewErrorResponse(model.OrderNotFound))
688 return
689 }
690
691 // Use cached order
692 order = cachedOrder
693 }
694
695 // Initialize response structure
696 response := &OrderStatusResponse{
697 Order: order,
698 OriginalStatus: "",
699 OriginalStatusDesc: "",
700 }
701
702 if order.PayType == model.PayTypeWechat {
703 // Query WeChat payment status
704 status, transactionId, originalStatus, payTime, err := queryWechatOrderStatusWithOriginal(eid, orderId)
705 if err == nil {
706 // Set original status
707 response.OriginalStatus = originalStatus
708 response.OriginalStatusDesc = getTradeStateDesc(originalStatus)
709
710 // Handle different payment states
711 if status == model.OrderStatusPaid {
712 // Payment successful, create or update order with payment time
713 updatedOrder, err := createOrUpdateOrderFromCacheWithTime(eid, orderId, model.OrderStatusPaid, transactionId, payTime)
714 if err == nil {
715 order = updatedOrder
716 xlog.Info("Order updated with payment time:", time.UnixMilli(payTime).Format(time.RFC3339))
717 } else {
718 xlog.Error("Failed to update order:", err)
719 }
720 } else if originalStatus == model.TradeStateUserPaying {
721 // User is paying, record this status but don't mark as paid
722 xlog.Info("User is paying for order:", orderId)
723
724 // If order is not in database yet, create it with pending status
725 if order.ID == 0 {
726 updatedOrder, err := createOrUpdateOrderFromCache(eid, orderId, model.OrderStatusPending, "")
727 if err == nil {
728 order = updatedOrder
729 } else {

Callers

nothing calls this directly

Calls 12

getCachedOrderFunction · 0.85
getTradeStateDescFunction · 0.85
removeCachedOrderFunction · 0.85
ToResponseMethod · 0.80
GetEIDMethod · 0.80
ToNewErrorResponseMethod · 0.80
InfoMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected