152 lines
4.9 KiB
Go
152 lines
4.9 KiB
Go
package services
|
|
|
|
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"
|
|
"PaymentCenter/app/models/paychannelmodel"
|
|
"database/sql"
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
// 订单列表,后台查询
|
|
func OrderList(req backend.OrderList) (result []ordersmodel.OrdersBackendList, total int64, code int) {
|
|
repo := data.NewOrderRepo(paychannelmodel.GetInstance().GetDb())
|
|
// 拼接查询条件
|
|
conn := builder.NewCond()
|
|
if req.Id > 0 {
|
|
conn = conn.And(builder.Eq{"orders.id": req.Id})
|
|
}
|
|
if req.MerchantId > 0 {
|
|
conn = conn.And(builder.Eq{"orders.merchant_id": req.MerchantId})
|
|
}
|
|
if req.PayChannelId > 0 {
|
|
conn = conn.And(builder.Eq{"orders.pay_channel_id": req.PayChannelId})
|
|
}
|
|
if req.AppId > 0 {
|
|
conn = conn.And(builder.Eq{"orders.app_id": req.AppId})
|
|
}
|
|
if req.OutTradeNo != "" {
|
|
conn = conn.And(builder.Like{"orders.out_trade_no", req.OutTradeNo})
|
|
}
|
|
if req.Status > 0 {
|
|
conn = conn.And(builder.Eq{"orders.status": req.Status})
|
|
}
|
|
if req.OrderType > 0 {
|
|
conn = conn.And(builder.Eq{"orders.order_type": req.OrderType})
|
|
}
|
|
if !req.StartTime.IsZero() {
|
|
conn = conn.And(builder.Gte{"orders.create_time": req.StartTime})
|
|
}
|
|
if !req.EndTime.IsZero() {
|
|
conn = conn.And(builder.Lte{"orders.create_time": req.EndTime})
|
|
}
|
|
|
|
// 调用repo
|
|
orderList := make([]ordersmodel.OrdersBackendList, 0)
|
|
count, err := repo.OrdersBackendList(conn, req.PageRequest, &orderList)
|
|
code = handErr(err)
|
|
return orderList, count, code
|
|
}
|
|
|
|
// 请求日志列表
|
|
func OrderRequestLogsList(req backend.OrderLogsListRequest) (requestLog []orderrequestlogmodel.OrderRequestLog, total int64, code int) {
|
|
requestRepo := data.NewOrderRequestLogRepo(paychannelmodel.GetInstance().GetDb())
|
|
conn := builder.NewCond()
|
|
if req.OrderId > 0 {
|
|
conn = conn.And(builder.Eq{"orders.id": req.OrderId})
|
|
}
|
|
if req.Id > 0 {
|
|
conn = conn.And(builder.Eq{"order_request_log.id": req.Id})
|
|
}
|
|
if req.AppId > 0 {
|
|
conn = conn.And(builder.Eq{"order_request_log.app_id": req.AppId})
|
|
}
|
|
if req.OutTradeNo != "" {
|
|
conn = conn.And(builder.Like{"order_request_log.out_trade_no", req.OutTradeNo})
|
|
}
|
|
// 请求日志
|
|
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})
|
|
}
|
|
if req.Id > 0 {
|
|
conn = conn.And(builder.Eq{"id": req.Id})
|
|
}
|
|
// 回调日志
|
|
callbackLogList := make([]ordercallbacklogmodel.OrderCallbackLog, 0)
|
|
total, err := callbackRepo.OrderCallbackLogList(conn, req.PageRequest, &callbackLogList)
|
|
code = handErr(err)
|
|
|
|
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})
|
|
}
|
|
if req.Id > 0 {
|
|
conn = conn.And(builder.Eq{"id": req.Id})
|
|
}
|
|
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) {
|
|
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
|
_, err := repo.OrderInsertOne(orderIn)
|
|
code = handErr(err)
|
|
return orderIn, code
|
|
}
|
|
|
|
func OrderUpdate(order *ordersmodel.Orders, col ...string) (code int) {
|
|
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
|
// 拼接查询条件
|
|
conn := builder.NewCond()
|
|
conn = conn.And(builder.Eq{"Id": order.Id})
|
|
_, err := repo.OrderUpdate(order, conn, col...)
|
|
|
|
code = handErr(err)
|
|
return
|
|
}
|
|
|
|
func OrderFindOne(order *ordersmodel.Orders, conn builder.Cond, col ...string) (orderInfo *ordersmodel.Orders, code int) {
|
|
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
|
// 拼接查询条件
|
|
orderInfo, err := repo.OrderFindOne(order, conn, col...)
|
|
if err != nil {
|
|
if err == sql.ErrNoRows {
|
|
return nil, errorcode.OrdersNotFound
|
|
}
|
|
return nil, errorcode.SystemError
|
|
}
|
|
return orderInfo, errorcode.Success
|
|
}
|
|
|
|
func PayOrderCheckRepeat(order *ordersmodel.Orders, conn builder.Cond) (exist bool, code int) {
|
|
_, code = OrderFindOne(order, conn)
|
|
if code != errorcode.OrdersNotFound {
|
|
return false, errorcode.Success
|
|
}
|
|
return true, code
|
|
}
|