package data import ( "PaymentCenter/app/http/entities" "PaymentCenter/app/models/merchantmodel" "PaymentCenter/app/utils/snowflake" "database/sql" "xorm.io/builder" "xorm.io/xorm" ) type MerchantRepo struct { repo xorm.Interface } func NewMerchantRepo(repo xorm.Interface) *MerchantRepo { return &MerchantRepo{ repo: repo, } } func (m *MerchantRepo) MerchantList(conn builder.Cond, pageFilter entities.PageRequest, merchantList *[]merchantmodel.Merchant) (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(merchantList) } func (m *MerchantRepo) MerchantInsertOne(merchant *merchantmodel.Merchant) (int64, error) { merchant.Id = snowflake.GetID() return m.repo.InsertOne(merchant) } func (m *MerchantRepo) MerchantDelete(merchant *merchantmodel.Merchant, conn builder.Cond) (int64, error) { return m.repo.Where(conn).Delete(merchant) } // columns 参数为要更新的字段 func (m *MerchantRepo) MerchantUpdate(merchant *merchantmodel.Merchant, conn builder.Cond, columns ...string) (int64, error) { return m.repo.Where(conn).MustCols(columns...).Update(merchant) } func (m *MerchantRepo) MerchantDetail(merchant *merchantmodel.Merchant, conn builder.Cond) (bool, error) { return m.repo.Where(conn).Get(merchant) } func (m *MerchantRepo) MerchantFindOne(merchant *merchantmodel.Merchant, conn builder.Cond, columns ...string) (*merchantmodel.Merchant, error) { has, err := m.repo.Where(conn).Get(merchant) if !has { return nil, sql.ErrNoRows } return merchant, err }