后台,订单日志列表

This commit is contained in:
wolter 2024-08-09 16:05:34 +08:00
parent 966aba1dc4
commit b0be00741f
6 changed files with 105 additions and 22 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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")
}

View File

@ -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) },
}

View File

@ -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) // 三方日志列表
}

View File

@ -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) {