105 lines
3.3 KiB
Go
105 lines
3.3 KiB
Go
package services
|
|
|
|
import (
|
|
"PaymentCenter/app/constants/errorcode"
|
|
"PaymentCenter/app/data"
|
|
"PaymentCenter/app/http/entities/backend"
|
|
"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{"id": req.Id})
|
|
}
|
|
if req.MerchantId > 0 {
|
|
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
|
|
}
|
|
if req.PayChannelId > 0 {
|
|
conn = conn.And(builder.Eq{"pay_channel_id": req.PayChannelId})
|
|
}
|
|
if req.AppId > 0 {
|
|
conn = conn.And(builder.Eq{"app_id": req.AppId})
|
|
}
|
|
if req.OutTreadNo != "" {
|
|
conn = conn.And(builder.Like{"out_tread_no", req.OutTreadNo})
|
|
}
|
|
if req.Status > 0 {
|
|
conn = conn.And(builder.Eq{"status": req.Status})
|
|
}
|
|
if req.OrderType > 0 {
|
|
conn = conn.And(builder.Eq{"order_type": req.OrderType})
|
|
}
|
|
if !req.StartTime.IsZero() {
|
|
conn = conn.And(builder.Gte{"start_time": req.StartTime})
|
|
}
|
|
if !req.EndTime.IsZero() {
|
|
conn = conn.And(builder.Lte{"end_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 OrderLogsList(req backend.OrderLogsListRequest) (requestLog []orderrequestlogmodel.OrderRequestLog, thirdLod []orderthirdpaylogmodel.OrderThirdPayLog, 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{"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)
|
|
code = handErr(err)
|
|
|
|
return orderLogList, thirdLogList, 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 OrderFindOne(order *ordersmodel.Orders, conn builder.Cond, col ...string) (merchantInfo *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.OrdersExist
|
|
}
|
|
|
|
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
|
|
}
|