eta_business_config_relate.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package eta_business
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. )
  7. // EtaBusinessConfigRelate ETA商家菜单api关联表
  8. type EtaBusinessConfigRelate struct {
  9. Id int `orm:"column(id);pk"`
  10. EtaBusinessId int `description:"商家ID"`
  11. ConfigCode string `description:"配置编码"`
  12. ConfigValue string `description:"配置值"`
  13. }
  14. func (m *EtaBusinessConfigRelate) TableName() string {
  15. return "eta_business_config_relate"
  16. }
  17. func (m *EtaBusinessConfigRelate) PrimaryId() string {
  18. return "id"
  19. }
  20. func (m *EtaBusinessConfigRelate) CreateMulti(businessId int, items []*EtaBusinessConfigRelate) (err error) {
  21. if businessId == 0 {
  22. return
  23. }
  24. o := orm.NewOrm()
  25. tx, err := o.Begin()
  26. if err != nil {
  27. return
  28. }
  29. defer func() {
  30. if err != nil {
  31. _ = tx.Rollback()
  32. return
  33. }
  34. _ = tx.Commit()
  35. }()
  36. sql := fmt.Sprintf(`DELETE FROM %s WHERE eta_business_id = ?`, m.TableName())
  37. _, err = tx.Raw(sql, businessId).Exec()
  38. if err != nil {
  39. return
  40. }
  41. if len(items) > 0 {
  42. _, err = tx.InsertMulti(len(items), items)
  43. }
  44. return
  45. }
  46. func (m *EtaBusinessConfigRelate) Update(cols []string) (err error) {
  47. o := orm.NewOrm()
  48. _, err = o.Update(m, cols...)
  49. return
  50. }
  51. func (m *EtaBusinessConfigRelate) GetItemById(id int) (item *EtaBusinessConfigRelate, err error) {
  52. o := orm.NewOrm()
  53. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  54. err = o.Raw(sql, id).QueryRow(&item)
  55. return
  56. }
  57. func (m *EtaBusinessConfigRelate) GetItemByCondition(condition string, pars []interface{}) (item *EtaBusinessConfigRelate, err error) {
  58. o := orm.NewOrm()
  59. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  60. err = o.Raw(sql, pars).QueryRow(&item)
  61. return
  62. }
  63. func (m *EtaBusinessConfigRelate) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  64. o := orm.NewOrm()
  65. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  66. err = o.Raw(sql, pars).QueryRow(&count)
  67. return
  68. }
  69. func (m *EtaBusinessConfigRelate) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EtaBusinessConfigRelate, err error) {
  70. o := orm.NewOrm()
  71. fields := strings.Join(fieldArr, ",")
  72. if len(fieldArr) == 0 {
  73. fields = `*`
  74. }
  75. order := ``
  76. if orderRule != "" {
  77. order = ` ORDER BY ` + orderRule
  78. }
  79. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  80. _, err = o.Raw(sql, pars).QueryRows(&items)
  81. return
  82. }
  83. func (m *EtaBusinessConfigRelate) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EtaBusinessConfigRelate, err error) {
  84. o := orm.NewOrm()
  85. fields := strings.Join(fieldArr, ",")
  86. if len(fieldArr) == 0 {
  87. fields = `*`
  88. }
  89. order := ``
  90. if orderRule != "" {
  91. order = ` ORDER BY ` + orderRule
  92. }
  93. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  94. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  95. return
  96. }
  97. // EtaBusinessConfigRelateSaveReq 保存商家菜单关联
  98. type EtaBusinessConfigRelateSaveReq struct {
  99. EtaBusinessId int `description:"商家ID"`
  100. MenuIds []int `description:"菜单IDs"`
  101. HalfMenuIds []int `description:"半选菜单IDs-仅供前端回显用的"`
  102. }