From b0be00741f68d8348edc5bd33a8fb0897b418df4 Mon Sep 17 00:00:00 2001 From: wolter Date: Fri, 9 Aug 2024 16:05:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0,=E8=AE=A2=E5=8D=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/order_request_log.go | 10 ++++++ app/http/controllers/backend/order.go | 39 +++++++++++++++++++--- app/http/entities/backend/order.go | 19 +++++++++++ app/http/requestmapping/backend.go | 6 ++-- app/http/routes/admin.go | 6 ++-- app/services/order.go | 47 +++++++++++++++++++-------- 6 files changed, 105 insertions(+), 22 deletions(-) diff --git a/app/data/order_request_log.go b/app/data/order_request_log.go index c0c0568..0fc2126 100644 --- a/app/data/order_request_log.go +++ b/app/data/order_request_log.go @@ -37,3 +37,13 @@ func (m *OrderRequestLogRepo) OrderRequestLogDelete(orderLog *orderrequestlogmod func (m *OrderRequestLogRepo) OrderRequestLogUpdate(orderLog *orderrequestlogmodel.OrderRequestLog, conn builder.Cond, columns ...string) (int64, error) { return m.repo.Where(conn).MustCols(columns...).Update(orderLog) } + +// 后台查询订单日志列表 +func (m *OrderRequestLogRepo) OrderRequestLogBackendList(conn builder.Cond, pageFilter entities.PageRequest, orderLogList *[]orderrequestlogmodel.OrderRequestLog) (int64, error) { + repo := m.repo.Where(conn) + if pageFilter.Page > 0 { + repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1)) + } + repo.Join("left", "orders", "orders.app_id = order_request_log.app_id and orders.out_trade_no = order_request_log.out_trade_no") + return repo.Desc("order_request_log.create_time").FindAndCount(orderLogList) +} diff --git a/app/http/controllers/backend/order.go b/app/http/controllers/backend/order.go index 15d82f0..352bcca 100644 --- a/app/http/controllers/backend/order.go +++ b/app/http/controllers/backend/order.go @@ -5,6 +5,7 @@ import ( "PaymentCenter/app/http/controllers" "PaymentCenter/app/http/entities" "PaymentCenter/app/http/entities/backend" + "PaymentCenter/app/models/ordercallbacklogmodel" "PaymentCenter/app/models/orderrequestlogmodel" "PaymentCenter/app/models/ordersmodel" "PaymentCenter/app/models/orderthirdpaylogmodel" @@ -34,10 +35,10 @@ func OrderList(c *gin.Context) { controllers.HandCodeRes(c, data, code) } -func OrderLogsList(c *gin.Context) { +func OrderRequestLogsList(c *gin.Context) { req, _ := controllers.GetRequest(c).(*backend.OrderLogsListRequest) req.SetDefault() - requestLog, thirdLog, code := services.OrderLogsList(*req) + requestLog, total, code := services.OrderRequestLogsList(*req) requestLogList := make([]backend.OrderRequestLogResponse, 0, len(requestLog)) linq.From(requestLog).SelectT(func(in orderrequestlogmodel.OrderRequestLog) (out backend.OrderRequestLogResponse) { @@ -45,14 +46,42 @@ func OrderLogsList(c *gin.Context) { return }).ToSlice(&requestLogList) + controllers.HandCodeRes(c, entities.PageRsp{ + Total: total, + Data: requestLogList, + }, code) +} + +func OrderThirdLogsList(c *gin.Context) { + req, _ := controllers.GetRequest(c).(*backend.OrderLogsListRequest) + req.SetDefault() + thirdLog, total, code := services.OrderThirdLogsList(*req) + thirdLogList := make([]backend.OrderThirdLogResponse, 0, len(thirdLog)) linq.From(thirdLog).SelectT(func(in orderthirdpaylogmodel.OrderThirdPayLog) (out backend.OrderThirdLogResponse) { out.ResponseFromDb(in) return }).ToSlice(&thirdLogList) - controllers.HandCodeRes(c, gin.H{ - "request_log_list": requestLogList, - "third_log_list": thirdLogList, + controllers.HandCodeRes(c, entities.PageRsp{ + Total: total, + Data: thirdLogList, + }, code) +} + +func OrderCallbackLogsList(c *gin.Context) { + req, _ := controllers.GetRequest(c).(*backend.OrderLogsListRequest) + req.SetDefault() + callbackLog, total, code := services.OrderCallbackLogsList(*req) + + callbackLogList := make([]backend.OrderCallbackLogResponse, 0, len(callbackLog)) + linq.From(callbackLog).SelectT(func(in ordercallbacklogmodel.OrderCallbackLog) (out backend.OrderCallbackLogResponse) { + out.ResponseFromDb(in) + return + }).ToSlice(&callbackLogList) + + controllers.HandCodeRes(c, entities.PageRsp{ + Total: total, + Data: callbackLogList, }, code) } diff --git a/app/http/entities/backend/order.go b/app/http/entities/backend/order.go index 3b030d6..b60f97e 100644 --- a/app/http/entities/backend/order.go +++ b/app/http/entities/backend/order.go @@ -2,6 +2,7 @@ package backend import ( "PaymentCenter/app/http/entities" + "PaymentCenter/app/models/ordercallbacklogmodel" "PaymentCenter/app/models/orderrequestlogmodel" "PaymentCenter/app/models/ordersmodel" "PaymentCenter/app/models/orderthirdpaylogmodel" @@ -149,3 +150,21 @@ func (o *OrderThirdLogResponse) ResponseFromDb(db orderthirdpaylogmodel.OrderThi o.MerchantCallback = db.MerchantCallback o.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05") } + +type OrderCallbackLogResponse struct { + Id int64 `json:"id"` + OrderId int64 `json:"order_id"` + MerchantRequest string `json:"merchant_request"` + Status int `json:"status"` + MerchantResponse string `json:"merchant_response"` + CreateTime string `json:"create_time"` +} + +func (o *OrderCallbackLogResponse) ResponseFromDb(db ordercallbacklogmodel.OrderCallbackLog) { + o.Id = db.Id + o.OrderId = db.OrderId + o.MerchantRequest = db.MerchantRequest + o.Status = db.Status + o.MerchantResponse = db.MerchantResponse + o.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05") +} diff --git a/app/http/requestmapping/backend.go b/app/http/requestmapping/backend.go index 5d76b3f..0e75471 100644 --- a/app/http/requestmapping/backend.go +++ b/app/http/requestmapping/backend.go @@ -25,6 +25,8 @@ var BackendRequestMap = map[string]func() interface{}{ common.ADMIN_V1 + "/app/delete": func() interface{} { return new(entities.IdRequest) }, common.ADMIN_V1 + "/app/decrypt": func() interface{} { return new(backend.GenerateDecryptKeyRequest) }, // 订单 - common.ADMIN_V1 + "/order/list": func() interface{} { return new(backend.OrderListRequest) }, - common.ADMIN_V1 + "/order/log/list": func() interface{} { return new(backend.OrderLogsListRequest) }, + common.ADMIN_V1 + "/order/list": func() interface{} { return new(backend.OrderListRequest) }, + common.ADMIN_V1 + "/order/log/request": func() interface{} { return new(backend.OrderLogsListRequest) }, + common.ADMIN_V1 + "/order/log/callback": func() interface{} { return new(backend.OrderLogsListRequest) }, + common.ADMIN_V1 + "/order/log/third": func() interface{} { return new(backend.OrderLogsListRequest) }, } diff --git a/app/http/routes/admin.go b/app/http/routes/admin.go index 9d81e75..a15c83d 100644 --- a/app/http/routes/admin.go +++ b/app/http/routes/admin.go @@ -48,8 +48,10 @@ func RegisterAdminRoute(router *gin.Engine) { // 订单 order := v1.Group("/order") - order.GET("/list", backend.OrderList) // 订单列表 - order.GET("/log/list", backend.OrderLogsList) // 订单日志列表 + order.GET("/list", backend.OrderList) // 订单列表 + order.GET("/log/request", backend.OrderRequestLogsList) // 请求日志列表 + order.GET("/log/callback", backend.OrderCallbackLogsList) // 回调日志列表 + order.GET("/log/third", backend.OrderThirdLogsList) // 三方日志列表 } diff --git a/app/services/order.go b/app/services/order.go index cf42fbb..59d53e4 100644 --- a/app/services/order.go +++ b/app/services/order.go @@ -4,6 +4,7 @@ import ( "PaymentCenter/app/constants/errorcode" "PaymentCenter/app/data" "PaymentCenter/app/http/entities/backend" + "PaymentCenter/app/models/ordercallbacklogmodel" "PaymentCenter/app/models/orderrequestlogmodel" "PaymentCenter/app/models/ordersmodel" "PaymentCenter/app/models/orderthirdpaylogmodel" @@ -52,27 +53,47 @@ func OrderList(req backend.OrderList) (result []ordersmodel.OrdersBackendList, t return orderList, count, code } -func OrderLogsList(req backend.OrderLogsListRequest) (requestLog []orderrequestlogmodel.OrderRequestLog, thirdLod []orderthirdpaylogmodel.OrderThirdPayLog, code int) { +// 请求日志列表 +func OrderRequestLogsList(req backend.OrderLogsListRequest) (requestLog []orderrequestlogmodel.OrderRequestLog, total int64, code int) { requestRepo := data.NewOrderRequestLogRepo(paychannelmodel.GetInstance().GetDb()) - thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb()) + conn := builder.NewCond() + if req.OrderId > 0 { + conn = conn.And(builder.Eq{"orders.id": req.OrderId}) + } + // 请求日志 + orderLogList := make([]orderrequestlogmodel.OrderRequestLog, 0) + total, err := requestRepo.OrderRequestLogBackendList(conn, req.PageRequest, &orderLogList) + code = handErr(err) + return orderLogList, total, code +} +// 回调日志列表 +func OrderCallbackLogsList(req backend.OrderLogsListRequest) (callback []ordercallbacklogmodel.OrderCallbackLog, total int64, code int) { + callbackRepo := data.NewOrderCallbackLogRepo(paychannelmodel.GetInstance().GetDb()) conn := builder.NewCond() if req.OrderId > 0 { conn = conn.And(builder.Eq{"order_id": req.OrderId}) } - // 请求日志 - orderLogList := make([]orderrequestlogmodel.OrderRequestLog, 0) - _, err := requestRepo.OrderRequestLogList(conn, req.PageRequest, &orderLogList) - if err != nil { - code = handErr(err) - return - } - // 三方日志 - thirdLogList := make([]orderthirdpaylogmodel.OrderThirdPayLog, 0) - _, err = thirdRepo.OrderThirdPayLogList(conn, req.PageRequest, &thirdLogList) + // 回调日志 + callbackLogList := make([]ordercallbacklogmodel.OrderCallbackLog, 0) + total, err := callbackRepo.OrderCallbackLogList(conn, req.PageRequest, &callbackLogList) code = handErr(err) - return orderLogList, thirdLogList, code + return callbackLogList, total, code +} + +// 三方日志列表 +func OrderThirdLogsList(req backend.OrderLogsListRequest) (thirdLod []orderthirdpaylogmodel.OrderThirdPayLog, total int64, code int) { + thirdRepo := data.NewOrderThirdPayLogRepo(paychannelmodel.GetInstance().GetDb()) + // 三方日志 + conn := builder.NewCond() + if req.OrderId > 0 { + conn = conn.And(builder.Eq{"order_id": req.OrderId}) + } + thirdLogList := make([]orderthirdpaylogmodel.OrderThirdPayLog, 0) + total, err := thirdRepo.OrderThirdPayLogList(conn, req.PageRequest, &thirdLogList) + code = handErr(err) + return thirdLogList, total, code } func OrderCreate(orderIn *ordersmodel.Orders) (orderOut *ordersmodel.Orders, code int) {