eta_business_menu.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package eta_business
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hz_crm_api/utils"
  6. "strings"
  7. "time"
  8. )
  9. // EtaBusinessMenu ETA商家基础菜单表
  10. type EtaBusinessMenu struct {
  11. MenuId int `orm:"column(menu_id);pk"`
  12. ParentId int `description:"父级菜单ID"`
  13. Name string `description:"菜单名称或者按钮名称"`
  14. Sort int `description:"排序"`
  15. Path string `description:"路由地址"`
  16. IconPath string `description:"菜单图标地址"`
  17. Component string `description:"组件路径"`
  18. Hidden int `description:"是否隐藏:1-隐藏 0-显示"`
  19. IsLevel int `description:"是否为多级菜单:1,只有一级;2,有多级"`
  20. LevelPath string `description:"兼容以前menu表的字段"`
  21. MenuType int `description:"菜单类型: 0-菜单; 1-按钮; 2-字段(需要特殊处理)"`
  22. ButtonCode string `description:"按钮唯一标识"`
  23. CreateTime time.Time `description:"创建时间"`
  24. ModifyTime time.Time `description:"更新时间"`
  25. }
  26. func (m *EtaBusinessMenu) TableName() string {
  27. return "eta_business_menu"
  28. }
  29. func (m *EtaBusinessMenu) PrimaryId() string {
  30. return "menu_id"
  31. }
  32. func (m *EtaBusinessMenu) Create() (err error) {
  33. o := orm.NewOrm()
  34. id, err := o.Insert(m)
  35. if err != nil {
  36. return
  37. }
  38. m.MenuId = int(id)
  39. return
  40. }
  41. func (m *EtaBusinessMenu) CreateMulti(items []*EtaBusinessMenu) (err error) {
  42. if len(items) == 0 {
  43. return
  44. }
  45. o := orm.NewOrm()
  46. _, err = o.InsertMulti(len(items), items)
  47. return
  48. }
  49. func (m *EtaBusinessMenu) Update(cols []string) (err error) {
  50. o := orm.NewOrm()
  51. _, err = o.Update(m, cols...)
  52. return
  53. }
  54. func (m *EtaBusinessMenu) Del() (err error) {
  55. o := orm.NewOrm()
  56. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  57. _, err = o.Raw(sql, m.MenuId).Exec()
  58. return
  59. }
  60. func (m *EtaBusinessMenu) MultiDel(menuIds []int) (err error) {
  61. if len(menuIds) == 0 {
  62. return
  63. }
  64. o := orm.NewOrm()
  65. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  66. _, err = o.Raw(sql, menuIds).Exec()
  67. return
  68. }
  69. func (m *EtaBusinessMenu) GetItemById(id int) (item *EtaBusinessMenu, err error) {
  70. o := orm.NewOrm()
  71. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  72. err = o.Raw(sql, id).QueryRow(&item)
  73. return
  74. }
  75. func (m *EtaBusinessMenu) GetItemByCondition(condition string, pars []interface{}) (item *EtaBusinessMenu, err error) {
  76. o := orm.NewOrm()
  77. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  78. err = o.Raw(sql, pars).QueryRow(&item)
  79. return
  80. }
  81. func (m *EtaBusinessMenu) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  82. o := orm.NewOrm()
  83. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  84. err = o.Raw(sql, pars).QueryRow(&count)
  85. return
  86. }
  87. func (m *EtaBusinessMenu) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EtaBusinessMenu, err error) {
  88. o := orm.NewOrm()
  89. fields := strings.Join(fieldArr, ",")
  90. if len(fieldArr) == 0 {
  91. fields = `*`
  92. }
  93. order := `ORDER BY create_time DESC`
  94. if orderRule != "" {
  95. order = ` ORDER BY ` + orderRule
  96. }
  97. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  98. _, err = o.Raw(sql, pars).QueryRows(&items)
  99. return
  100. }
  101. func (m *EtaBusinessMenu) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EtaBusinessMenu, err error) {
  102. o := orm.NewOrm()
  103. fields := strings.Join(fieldArr, ",")
  104. if len(fieldArr) == 0 {
  105. fields = `*`
  106. }
  107. order := `ORDER BY create_time DESC`
  108. if orderRule != "" {
  109. order = ` ORDER BY ` + orderRule
  110. }
  111. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  112. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  113. return
  114. }
  115. // GetMenuItemsByKeyword 关键词获取菜单
  116. func GetMenuItemsByKeyword(keyword string, fieldArr []string, orderRule string) (items []*EtaBusinessMenu, err error) {
  117. o := orm.NewOrm()
  118. sql := `SELECT
  119. %s
  120. FROM
  121. (
  122. SELECT * FROM eta_business_menu WHERE parent_id = 0 AND name LIKE ?
  123. UNION
  124. SELECT * FROM eta_business_menu WHERE menu_id IN (
  125. SELECT
  126. parent_id
  127. FROM
  128. eta_business_menu
  129. WHERE
  130. parent_id > 0 AND name LIKE ?
  131. )
  132. ) AS t %s`
  133. fields := strings.Join(fieldArr, ",")
  134. if len(fieldArr) == 0 {
  135. fields = `*`
  136. }
  137. order := `ORDER BY create_time DESC`
  138. if orderRule != "" {
  139. order = ` ORDER BY ` + orderRule
  140. }
  141. sql = fmt.Sprintf(sql, fields, order)
  142. _, err = o.Raw(sql, keyword, keyword).QueryRows(&items)
  143. return
  144. }
  145. // EtaBusinessMenuListResp ETA商家菜单列表响应体
  146. type EtaBusinessMenuListResp struct {
  147. ChoiceList []int `description:"已选菜单"`
  148. HalfChoiceList []int `description:"半选菜单-方便前端回显用的"`
  149. List []*EtaBusinessMenuItem `description:"菜单列表"`
  150. }
  151. // EtaBusinessMenuItem ETA商家菜单
  152. type EtaBusinessMenuItem struct {
  153. MenuId int
  154. ParentId int `description:"父级菜单ID"`
  155. Name string `description:"菜单名称或者按钮名称"`
  156. RootId int `description:"顶层菜单ID"`
  157. Sort int `description:"排序"`
  158. Path string `description:"路由地址"`
  159. PathName string `description:"路由名称"`
  160. IconPath string `description:"菜单图标地址"`
  161. Component string `description:"组件路径"`
  162. Hidden int `description:"是否隐藏:1-隐藏 0-显示"`
  163. HiddenLayout int `description:"是否隐藏layout:1-隐藏 0-显示"`
  164. Level int `description:"菜单等级:1-2-3"`
  165. MenuType int `description:"菜单类型: 0-菜单; 1-按钮; 2-字段(需要特殊处理)"`
  166. ButtonCode string `description:"按钮/菜单唯一标识"`
  167. CreateTime string `description:"创建时间"`
  168. Children []*EtaBusinessMenuItem `description:"子菜单"`
  169. }
  170. // EtaBusinessMenuAddReq 新增菜单请求体
  171. type EtaBusinessMenuAddReq struct {
  172. ParentId int `description:"父级菜单ID"`
  173. Name string `description:"菜单/按钮名称"`
  174. Sort int `description:"排序"`
  175. Path string `description:"路由地址"`
  176. IconPath string `description:"图标地址"`
  177. Component string `description:"组件路径"`
  178. Hidden int `description:"是否隐藏:1-隐藏 0-显示"`
  179. MenuType int `description:"菜单类型:0-菜单; 1-按钮; 2-字段"`
  180. ButtonCode string `description:"按钮唯一标识"`
  181. }
  182. // EtaBusinessMenuEditReq 编辑菜单请求体
  183. type EtaBusinessMenuEditReq struct {
  184. MenuId int
  185. EtaBusinessMenuAddReq
  186. }
  187. // EtaBusinessMenuRemoveReq 删除菜单请求体
  188. type EtaBusinessMenuRemoveReq struct {
  189. MenuId int
  190. }
  191. // BusinessConf 商户配置表
  192. type BusinessConf struct {
  193. ConfKey string `description:"配置Key"`
  194. ConfVal string `description:"配置值"`
  195. }
  196. // SetBusinessConfReq 设置用户的配置
  197. type SetBusinessConfReq struct {
  198. EtaBusinessId int `description:"商家ID"`
  199. List []BusinessConfReq
  200. }
  201. type BusinessConfReq struct {
  202. ConfigCode string `description:"配置编码"`
  203. ConfigValue string `description:"配置值"`
  204. }