PaymentCenter/app/data/orders.go

40 lines
1.1 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) MerchantList(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) MerchantInsertOne(order *ordersmodel.Orders) (int64, error) {
return m.repo.InsertOne(order)
}
func (m *OrderRepo) MerchantDelete(order *ordersmodel.Orders, conn builder.Cond) (int64, error) {
return m.repo.Where(conn).Delete(order)
}
// columns 参数为要更新的字段
func (m *OrderRepo) MerchantUpdate(order *ordersmodel.Orders, conn builder.Cond, columns ...string) (int64, error) {
return m.repo.Where(conn).MustCols(columns...).Update(order)
}