PaymentCenter/app/services/order.go

65 lines
1.9 KiB
Go

package services
import (
"PaymentCenter/app/data"
"PaymentCenter/app/http/entities/backend"
"PaymentCenter/app/models/orderlogmodel"
"PaymentCenter/app/models/ordersmodel"
"PaymentCenter/app/models/paychannelmodel"
"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.PayId > 0 {
conn = conn.And(builder.Eq{"pay_id": req.PayId})
}
if req.AppId > 0 {
conn = conn.And(builder.Eq{"app_id": req.AppId})
}
if req.MerchantOrderId != "" {
conn = conn.And(builder.Like{"merchant_order_id", req.MerchantOrderId})
}
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) (result []orderlogmodel.OrderLog, total int64, code int) {
repo := data.NewOrderLogRepo(paychannelmodel.GetInstance().GetDb())
conn := builder.NewCond()
if req.OrderId > 0 {
conn = conn.And(builder.Eq{"order_id": req.OrderId})
}
// 调用repo
orderLogList := make([]orderlogmodel.OrderLog, 0)
count, err := repo.OrderLogList(conn, req.PageRequest, &orderLogList)
code = handErr(err)
return orderLogList, count, code
}