kfc.go 585 B

1234567891011121314151617181920212223242526
  1. package kfc
  2. import (
  3. "context"
  4. kfcmdl "go-common/app/admin/main/activity/model/kfc"
  5. "github.com/jinzhu/gorm"
  6. "github.com/pkg/errors"
  7. )
  8. // SearchList .
  9. func (d *Dao) SearchList(c context.Context, code string, mid int64, pn, ps int) (list []*kfcmdl.BnjKfcCoupon, err error) {
  10. db := d.DB
  11. if code != "" {
  12. db = db.Where("coupon_code = ?", code)
  13. }
  14. if mid != 0 {
  15. db = db.Where("mid = ?", mid)
  16. }
  17. offset := (pn - 1) * ps
  18. if err = db.Offset(offset).Limit(ps).Find(&list).Error; err != nil && err != gorm.ErrRecordNotFound {
  19. err = errors.Wrap(err, "find error")
  20. }
  21. return
  22. }