yb_poster_resource.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package yb
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. // YbPosterResource 研报小程序海报
  10. type YbPosterResource struct {
  11. Id int `orm:"column(id);pk" description:"价格驱动ID"`
  12. Path string `description:"请求路径"`
  13. ImgUrl string `description:"图片地址"`
  14. Type string `description:"类型 poster-海报; qrcode-太阳码"`
  15. Version string `description:"版本号"`
  16. CreateTime time.Time `description:"创建时间"`
  17. }
  18. func (m *YbPosterResource) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*YbPosterResource, err error) {
  19. o := orm.NewOrmUsingDB("weekly")
  20. fields := strings.Join(fieldArr, ",")
  21. if len(fieldArr) == 0 {
  22. fields = `*`
  23. }
  24. order := `ORDER BY create_time DESC`
  25. if orderRule != "" {
  26. order = ` ORDER BY ` + orderRule
  27. }
  28. sql := fmt.Sprintf(`SELECT %s FROM yb_poster_resource WHERE 1=1 %s %s`, fields, condition, order)
  29. _, err = o.Raw(sql, pars).QueryRows(&items)
  30. return
  31. }
  32. func (m *YbPosterResource) RemovePosters(ids []int) (err error) {
  33. num := len(ids)
  34. if num == 0 {
  35. return
  36. }
  37. o := orm.NewOrmUsingDB("weekly")
  38. sql := fmt.Sprintf(`DELETE FROM yb_poster_resource WHERE id IN (%s) LIMIT %d`, utils.GetOrmInReplace(num), num)
  39. _, err = o.Raw(sql, ids).Exec()
  40. return
  41. }