52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
package data
|
|
|
|
import (
|
|
"PaymentCenter/app/http/entities"
|
|
"PaymentCenter/app/models/ordersmodel"
|
|
"xorm.io/builder"
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
type OrderRepo struct {
|
|
repo xorm.Interface
|
|
}
|
|
|
|
func NewOrderRepo(repo xorm.Interface) *OrderRepo {
|
|
return &OrderRepo{
|
|
repo: repo,
|
|
}
|
|
}
|
|
|
|
func (m *OrderRepo) OrderList(conn builder.Cond, pageFilter entities.PageRequest, orderList *[]ordersmodel.Orders) (int64, error) {
|
|
repo := m.repo.Where(conn)
|
|
if pageFilter.Page > 0 {
|
|
repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1))
|
|
}
|
|
return repo.Desc("create_time").FindAndCount(orderList)
|
|
}
|
|
|
|
func (m *OrderRepo) OrderInsertOne(order *ordersmodel.Orders) (int64, error) {
|
|
return m.repo.InsertOne(order)
|
|
}
|
|
|
|
func (m *OrderRepo) OrderDelete(order *ordersmodel.Orders, conn builder.Cond) (int64, error) {
|
|
return m.repo.Where(conn).Delete(order)
|
|
}
|
|
|
|
// columns 参数为要更新的字段
|
|
func (m *OrderRepo) OrderUpdate(order *ordersmodel.Orders, conn builder.Cond, columns ...string) (int64, error) {
|
|
return m.repo.Where(conn).MustCols(columns...).Update(order)
|
|
}
|
|
|
|
func (m *OrderRepo) OrdersBackendList(conn builder.Cond, pageFilter entities.PageRequest, orderList *[]ordersmodel.OrdersBackendList) (int64, error) {
|
|
repo := m.repo.Select(`orders.*, merchant.name as merchant_name, app.app_name, pay_channel.pay_name`).
|
|
Where(conn)
|
|
if pageFilter.Page > 0 {
|
|
repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1))
|
|
}
|
|
repo = repo.Join("left", "app", "app.id = orders.app_id").
|
|
Join("left", "merchant", "merchant.id = orders.merchant_id").
|
|
Join("left", "pay_channel", "pay_channel.id = orders.pay_id")
|
|
return repo.Desc("create_time").FindAndCount(orderList)
|
|
}
|