diff --git a/app/constants/common/common.go b/app/constants/common/common.go index d495754..8af757c 100644 --- a/app/constants/common/common.go +++ b/app/constants/common/common.go @@ -19,4 +19,5 @@ const ( ORDER_STATUS_ReFUNDING = 6 ORDER_STATUS_ReFUNDEND = 7 ORDER_STATUS_ReFUNDFAIL = 8 + ORDER_STATUS_TIMEOUT = 9 ) diff --git a/app/http/controllers/front/OrderController.go b/app/http/controllers/front/OrderController.go index ced8565..b01e757 100644 --- a/app/http/controllers/front/OrderController.go +++ b/app/http/controllers/front/OrderController.go @@ -127,6 +127,6 @@ func OrderNotify(c *gin.Context) { c.Header("partnerTxSriNo", time.Now().Format("20060102150405")+utils.RandomNumber(10)) c.Header("reqTime", time.Now().Format("20060102150405")) var request = controllers.GetRequest(c).(*front.YouChuRequest) - response := services.OrderNotify(*request) + response := services.OrderNotify(*request, c) c.JSON(http.StatusOK, response) } diff --git a/app/services/OrderService.go b/app/services/OrderService.go index fda8e82..8c2bfea 100644 --- a/app/services/OrderService.go +++ b/app/services/OrderService.go @@ -2,6 +2,7 @@ package services import ( "encoding/json" + "github.com/gin-gonic/gin" "qteam/app/constants/common" "qteam/app/constants/errorcode" "qteam/app/http/entities/front" @@ -194,7 +195,7 @@ func OrderDelete(id string) error { return err } -func OrderNotify(request front.YouChuRequest) (NotifyResponse front.YouChuOrderNotifyResponse) { +func OrderNotify(request front.YouChuRequest, c *gin.Context) (NotifyResponse front.YouChuOrderNotifyResponse) { requestStr, _ := json.Marshal(request) utils.Log(nil, "订单回调请求--原始数据:", string(requestStr)) response := youchu.DecryptResponse(string(requestStr), true) @@ -213,6 +214,15 @@ func OrderNotify(request front.YouChuRequest) (NotifyResponse front.YouChuOrderN var orderDetail ordersmodel.Orders var order ordersmodel.Orders has, err := ordersmodel.GetInstance().GetDb().Where("voucher_link = ?", "").Where("order_no = ?", YouChuOrderNotifyRequest.ReqTraceId).Get(&orderDetail) + //金额对不上 + if orderDetail.Price != YouChuOrderNotifyRequest.TxnAmt { + ip, _ := c.RemoteIP() + _, err = ordersmodel.GetInstance().GetDb().Where("id = ?", orderDetail.Id).Update(ordersmodel.Orders{State: common.ORDER_STATUS_TIMEOUT}) + if ip != nil { + utils.Log(nil, "OrderNotify-fail", ip.String()) + } + return front.YouChuOrderNotifyResponse{RespCode: "000004", RespMsg: "金额不匹配"} + } if err != nil || !has { utils.Log(nil, "notify err", err, YouChuOrderNotifyRequest.ReqTraceId, YouChuOrderNotifyRequest.OrderNo) return front.YouChuOrderNotifyResponse{RespCode: "000003", RespMsg: "订单不存在"}