eta_business_menu.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. package eta_business
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/eta_business"
  7. etaBusinessService "hongze/hz_crm_api/services/eta_business"
  8. "hongze/hz_crm_api/utils"
  9. "html/template"
  10. "sort"
  11. "strings"
  12. "time"
  13. )
  14. // EtaBusinessMenuController ETA商家菜单
  15. type EtaBusinessMenuController struct {
  16. controllers.BaseAuthController
  17. }
  18. // List
  19. // @Title 商家菜单列表
  20. // @Description 商家菜单列表
  21. // @Param BusinessId query int false "商家ID"
  22. // @Param Keyword query string false "关键词: 菜单名称"
  23. // @Success 200 Ret=200 获取成功
  24. // @router /menu/list [get]
  25. func (this *EtaBusinessMenuController) List() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. if br.ErrMsg == "" {
  29. br.IsSendEmail = false
  30. }
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. sysUser := this.SysUser
  35. if sysUser == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. resp := new(eta_business.EtaBusinessMenuListResp)
  42. resp.ChoiceList = make([]int, 0)
  43. resp.HalfChoiceList = make([]int, 0)
  44. resp.List = make([]*eta_business.EtaBusinessMenuItem, 0)
  45. // 权限校验
  46. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  47. if e != nil {
  48. br.Msg = "操作失败"
  49. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  50. return
  51. }
  52. if !ok {
  53. br.Data = resp
  54. br.Ret = 200
  55. br.Success = true
  56. br.Msg = "获取成功"
  57. return
  58. }
  59. menuCond := ``
  60. menuPars := make([]interface{}, 0)
  61. // 商家勾选的权限
  62. {
  63. businessId, _ := this.GetInt("EtaBusinessId", 0)
  64. if businessId > 0 {
  65. relateOb := new(eta_business.EtaBusinessMenuRelate)
  66. cond := ` AND eta_business_id = ?`
  67. pars := make([]interface{}, 0)
  68. pars = append(pars, businessId)
  69. relates, e := relateOb.GetItemsByCondition(cond, pars, []string{}, "")
  70. if e != nil {
  71. br.Msg = "获取失败"
  72. br.ErrMsg = "获取商家菜单关联列表失败, Err: " + e.Error()
  73. return
  74. }
  75. for _, r := range relates {
  76. if r.Type == 1 {
  77. resp.HalfChoiceList = append(resp.HalfChoiceList, r.MenuId)
  78. continue
  79. }
  80. resp.ChoiceList = append(resp.ChoiceList, r.MenuId)
  81. }
  82. menuCond += ` AND hidden = 0`
  83. }
  84. }
  85. // 关键词
  86. keyword := this.GetString("Keyword")
  87. keyword = strings.TrimSpace(keyword)
  88. keyword = template.HTMLEscapeString(keyword)
  89. // 所有菜单列表
  90. menuOb := new(eta_business.EtaBusinessMenu)
  91. order := `sort ASC, create_time DESC, menu_id DESC`
  92. menus, e := menuOb.GetItemsByCondition(menuCond, menuPars, []string{}, order)
  93. if e != nil {
  94. br.Msg = "获取失败"
  95. br.ErrMsg = "获取商家菜单列表失败, Err: " + e.Error()
  96. return
  97. }
  98. list := make([]*eta_business.EtaBusinessMenu, 0)
  99. if keyword != "" {
  100. menuMap := make(map[int]*eta_business.EtaBusinessMenu)
  101. parentMap := make(map[int]*eta_business.EtaBusinessMenu)
  102. existMap := make(map[int]bool)
  103. for _, m := range menus {
  104. menuMap[m.MenuId] = m
  105. }
  106. for _, m := range menus {
  107. if m.ParentId > 0 {
  108. parentMap[m.MenuId] = menuMap[m.ParentId]
  109. }
  110. }
  111. // 遍历菜单, 取出跟关键词匹配的菜单(层级比较深, 递归效率很低, 产品要这个需求暂时也没啥办法优化=_=!)
  112. for _, m := range menus {
  113. if !strings.Contains(m.Name, keyword) {
  114. continue
  115. }
  116. if existMap[m.MenuId] {
  117. continue
  118. }
  119. existMap[m.MenuId] = true
  120. list = append(list, m)
  121. // 取出关键词所匹配的所有父级菜单
  122. if m.ParentId > 0 {
  123. parents := etaBusinessService.GetMenuParentsRecursive(menus, m.ParentId)
  124. for _, p := range parents {
  125. if !existMap[p.MenuId] {
  126. existMap[p.MenuId] = true
  127. list = append(list, p)
  128. }
  129. }
  130. }
  131. }
  132. sort.Slice(list, func(i, j int) bool {
  133. return list[j].Sort > list[i].Sort
  134. })
  135. } else {
  136. list = menus
  137. }
  138. items := make([]*eta_business.EtaBusinessMenuItem, 0)
  139. for _, v := range list {
  140. t := &eta_business.EtaBusinessMenuItem{
  141. MenuId: v.MenuId,
  142. ParentId: v.ParentId,
  143. Name: v.Name,
  144. Sort: v.Sort,
  145. Path: v.Path,
  146. IconPath: v.IconPath,
  147. Component: v.Component,
  148. Hidden: v.Hidden,
  149. MenuType: v.MenuType,
  150. ButtonCode: v.ButtonCode,
  151. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  152. Children: make([]*eta_business.EtaBusinessMenuItem, 0),
  153. }
  154. items = append(items, t)
  155. }
  156. // 递归返回树形结构
  157. items = etaBusinessService.GetMenuTreeRecursive(items, 0)
  158. resp.List = items
  159. br.Data = resp
  160. br.Ret = 200
  161. br.Success = true
  162. br.Msg = "获取成功"
  163. }
  164. // SaveRelate
  165. // @Title 保存商家菜单关联
  166. // @Description 保存商家菜单关联
  167. // @Param request body eta_business.EtaBusinessAddReq true "type json string"
  168. // @Success 200 Ret=200 操作成功
  169. // @router /menu/relate/save [post]
  170. func (this *EtaBusinessMenuController) SaveRelate() {
  171. br := new(models.BaseResponse).Init()
  172. defer func() {
  173. if br.ErrMsg == "" {
  174. br.IsSendEmail = false
  175. }
  176. this.Data["json"] = br
  177. this.ServeJSON()
  178. }()
  179. sysUser := this.SysUser
  180. if sysUser == nil {
  181. br.Msg = "请登录"
  182. br.ErrMsg = "请登录,SysUser Is Empty"
  183. br.Ret = 408
  184. return
  185. }
  186. // 操作权限校验
  187. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  188. if e != nil {
  189. br.Msg = "操作失败"
  190. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  191. return
  192. }
  193. if !ok {
  194. br.Msg = "无权操作"
  195. return
  196. }
  197. // 参数校验
  198. var req eta_business.EtaBusinessMenuRelateSaveReq
  199. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  200. br.Msg = "参数解析异常!"
  201. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  202. return
  203. }
  204. if req.EtaBusinessId <= 0 {
  205. br.Msg = "参数有误"
  206. return
  207. }
  208. if len(req.MenuIds) == 0 {
  209. br.Msg = "请选择菜单"
  210. return
  211. }
  212. ob := new(eta_business.EtaBusinessMenuRelate)
  213. items := make([]*eta_business.EtaBusinessMenuRelate, 0)
  214. for _, v := range req.MenuIds {
  215. t := new(eta_business.EtaBusinessMenuRelate)
  216. t.MenuId = v
  217. t.EtaBusinessId = req.EtaBusinessId
  218. items = append(items, t)
  219. }
  220. for _, v := range req.HalfMenuIds {
  221. t := new(eta_business.EtaBusinessMenuRelate)
  222. t.MenuId = v
  223. t.Type = 1
  224. t.EtaBusinessId = req.EtaBusinessId
  225. items = append(items, t)
  226. }
  227. if e := ob.CreateMulti(req.EtaBusinessId, items); e != nil {
  228. br.Msg = "保存失败"
  229. br.ErrMsg = "保存商家菜单关联失败, Err: " + e.Error()
  230. return
  231. }
  232. br.Ret = 200
  233. br.Success = true
  234. br.Msg = "操作成功"
  235. }
  236. // Add
  237. // @Title 新增菜单
  238. // @Description 新增菜单
  239. // @Param request body eta_business.EtaBusinessMenuAddReq true "type json string"
  240. // @Success 200 Ret=200 操作成功
  241. // @router /menu/add [post]
  242. func (this *EtaBusinessMenuController) Add() {
  243. br := new(models.BaseResponse).Init()
  244. defer func() {
  245. if br.ErrMsg == "" {
  246. br.IsSendEmail = false
  247. }
  248. this.Data["json"] = br
  249. this.ServeJSON()
  250. }()
  251. sysUser := this.SysUser
  252. if sysUser == nil {
  253. br.Msg = "请登录"
  254. br.ErrMsg = "请登录,SysUser Is Empty"
  255. br.Ret = 408
  256. return
  257. }
  258. // 操作权限校验
  259. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  260. if e != nil {
  261. br.Msg = "操作失败"
  262. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  263. return
  264. }
  265. if !ok {
  266. br.Msg = "无权操作"
  267. return
  268. }
  269. // 参数校验
  270. var req eta_business.EtaBusinessMenuAddReq
  271. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  272. br.Msg = "参数解析异常!"
  273. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  274. return
  275. }
  276. req.Name = strings.TrimSpace(req.Name)
  277. if req.Name == "" {
  278. br.Msg = "请输入名称"
  279. return
  280. }
  281. if req.MenuType == 0 {
  282. req.Path = strings.TrimSpace(req.Path)
  283. if req.Path == "" {
  284. br.Msg = "请输入路由地址"
  285. return
  286. }
  287. req.Component = strings.TrimSpace(req.Component)
  288. if req.Component == "" {
  289. br.Msg = "请输入组件路径"
  290. return
  291. }
  292. } else {
  293. req.ButtonCode = strings.TrimSpace(req.ButtonCode)
  294. if req.ButtonCode == "" {
  295. br.Msg = "请输入按钮/字段ID"
  296. return
  297. }
  298. }
  299. // 重名校验
  300. {
  301. ob := new(eta_business.EtaBusinessMenu)
  302. cond := ` AND parent_id = ? AND name = ?`
  303. pars := make([]interface{}, 0)
  304. pars = append(pars, req.ParentId, req.Name)
  305. exist, e := ob.GetItemByCondition(cond, pars)
  306. if e != nil && e.Error() != utils.ErrNoRow() {
  307. br.Msg = "操作失败"
  308. br.ErrMsg = "获取同名菜单失败, Err: " + e.Error()
  309. return
  310. }
  311. if exist != nil {
  312. br.Msg = "名称已存在"
  313. return
  314. }
  315. }
  316. // 新增
  317. menuOb := new(eta_business.EtaBusinessMenu)
  318. menuOb.ParentId = req.ParentId
  319. menuOb.Name = req.Name
  320. menuOb.Sort = req.Sort
  321. menuOb.Path = req.Path
  322. menuOb.IconPath = req.IconPath
  323. menuOb.Component = req.Component
  324. menuOb.Hidden = req.Hidden
  325. menuOb.MenuType = req.MenuType
  326. menuOb.ButtonCode = req.ButtonCode
  327. menuOb.CreateTime = time.Now().Local()
  328. menuOb.ModifyTime = time.Now().Local()
  329. // TODO:多级菜单
  330. if menuOb.ParentId > 0 {
  331. menuOb.LevelPath = menuOb.Component
  332. }
  333. if e := menuOb.Create(); e != nil {
  334. br.Msg = "操作失败"
  335. br.ErrMsg = "新增菜单失败, Err: " + e.Error()
  336. return
  337. }
  338. br.Ret = 200
  339. br.Success = true
  340. br.Msg = "操作成功"
  341. }
  342. // Edit
  343. // @Title 编辑菜单
  344. // @Description 编辑菜单
  345. // @Param request body eta_business.EtaBusinessMenuEditReq true "type json string"
  346. // @Success 200 Ret=200 操作成功
  347. // @router /menu/edit [post]
  348. func (this *EtaBusinessMenuController) Edit() {
  349. br := new(models.BaseResponse).Init()
  350. defer func() {
  351. if br.ErrMsg == "" {
  352. br.IsSendEmail = false
  353. }
  354. this.Data["json"] = br
  355. this.ServeJSON()
  356. }()
  357. sysUser := this.SysUser
  358. if sysUser == nil {
  359. br.Msg = "请登录"
  360. br.ErrMsg = "请登录,SysUser Is Empty"
  361. br.Ret = 408
  362. return
  363. }
  364. // 操作权限校验
  365. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  366. if e != nil {
  367. br.Msg = "操作失败"
  368. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  369. return
  370. }
  371. if !ok {
  372. br.Msg = "无权操作"
  373. return
  374. }
  375. // 参数校验
  376. var req eta_business.EtaBusinessMenuEditReq
  377. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  378. br.Msg = "参数解析异常!"
  379. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  380. return
  381. }
  382. if req.MenuId <= 0 {
  383. br.Msg = "参数有误"
  384. br.ErrMsg = "参数有误, MenuId"
  385. return
  386. }
  387. req.Name = strings.TrimSpace(req.Name)
  388. if req.Name == "" {
  389. br.Msg = "请输入名称"
  390. return
  391. }
  392. if req.MenuType == 0 {
  393. req.Path = strings.TrimSpace(req.Path)
  394. if req.Path == "" {
  395. br.Msg = "请输入路由地址"
  396. return
  397. }
  398. req.Component = strings.TrimSpace(req.Component)
  399. if req.Component == "" {
  400. br.Msg = "请输入组件路径"
  401. return
  402. }
  403. } else {
  404. req.ButtonCode = strings.TrimSpace(req.ButtonCode)
  405. if req.ButtonCode == "" {
  406. br.Msg = "请输入按钮/字段ID"
  407. return
  408. }
  409. }
  410. menuOb := new(eta_business.EtaBusinessMenu)
  411. item, e := menuOb.GetItemById(req.MenuId)
  412. if e != nil {
  413. if e.Error() == utils.ErrNoRow() {
  414. br.Msg = "菜单不存在, 请刷新页面"
  415. return
  416. }
  417. br.Msg = "操作失败"
  418. br.ErrMsg = "获取菜单失败, Err: " + e.Error()
  419. return
  420. }
  421. // 重名校验
  422. {
  423. ob := new(eta_business.EtaBusinessMenu)
  424. cond := ` AND parent_id = ? AND name = ?`
  425. pars := make([]interface{}, 0)
  426. pars = append(pars, req.ParentId, req.Name)
  427. exist, e := ob.GetItemByCondition(cond, pars)
  428. if e != nil && e.Error() != utils.ErrNoRow() {
  429. br.Msg = "操作失败"
  430. br.ErrMsg = "获取同名菜单失败, Err: " + e.Error()
  431. return
  432. }
  433. if exist != nil && exist.MenuId != item.MenuId {
  434. br.Msg = "名称已存在"
  435. return
  436. }
  437. }
  438. // 更新
  439. item.Name = req.Name
  440. item.Sort = req.Sort
  441. item.Path = req.Path
  442. item.IconPath = req.IconPath
  443. item.Component = req.Component
  444. item.Hidden = req.Hidden
  445. item.ButtonCode = req.ButtonCode
  446. item.ModifyTime = time.Now().Local()
  447. // TODO:多级菜单
  448. cols := make([]string, 0)
  449. cols = append(cols, "Name", "Sort", "Path", "IconPath", "Component", "Hidden", "ButtonCode", "ModifyTime")
  450. if item.ParentId > 0 {
  451. item.LevelPath = item.Component
  452. cols = append(cols, "LevelPath")
  453. }
  454. if e := item.Update(cols); e != nil {
  455. br.Msg = "操作失败"
  456. br.ErrMsg = "更新菜单失败, Err: " + e.Error()
  457. return
  458. }
  459. br.Ret = 200
  460. br.Success = true
  461. br.Msg = "操作成功"
  462. }
  463. // Remove
  464. // @Title 删除菜单
  465. // @Description 删除菜单
  466. // @Param request body eta_business.EtaBusinessMenuRemoveReq true "type json string"
  467. // @Success 200 Ret=200 操作成功
  468. // @router /menu/remove [post]
  469. func (this *EtaBusinessMenuController) Remove() {
  470. br := new(models.BaseResponse).Init()
  471. defer func() {
  472. if br.ErrMsg == "" {
  473. br.IsSendEmail = false
  474. }
  475. this.Data["json"] = br
  476. this.ServeJSON()
  477. }()
  478. sysUser := this.SysUser
  479. if sysUser == nil {
  480. br.Msg = "请登录"
  481. br.ErrMsg = "请登录,SysUser Is Empty"
  482. br.Ret = 408
  483. return
  484. }
  485. // 操作权限校验
  486. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  487. if e != nil {
  488. br.Msg = "操作失败"
  489. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  490. return
  491. }
  492. if !ok {
  493. br.Msg = "无权操作"
  494. return
  495. }
  496. // 参数校验
  497. var req eta_business.EtaBusinessMenuRemoveReq
  498. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  499. br.Msg = "参数解析异常!"
  500. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  501. return
  502. }
  503. if req.MenuId <= 0 {
  504. br.Msg = "参数有误"
  505. br.ErrMsg = "参数有误, MenuId"
  506. return
  507. }
  508. menuOb := new(eta_business.EtaBusinessMenu)
  509. _, e = menuOb.GetItemById(req.MenuId)
  510. if e != nil {
  511. if e.Error() == utils.ErrNoRow() {
  512. br.Msg = "菜单不存在, 请刷新页面"
  513. return
  514. }
  515. br.Msg = "操作失败"
  516. br.ErrMsg = "获取菜单失败, Err: " + e.Error()
  517. return
  518. }
  519. // 获取所有菜单列表, 筛选出该菜单及子菜单
  520. menus, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  521. if e != nil {
  522. br.Msg = "操作失败"
  523. br.ErrMsg = "获取菜单列表失败, Err: " + e.Error()
  524. return
  525. }
  526. menuIds := etaBusinessService.GetMenuChildrenIdsRecursive(menus, req.MenuId)
  527. menuIds = append(menuIds, req.MenuId)
  528. // 删除菜单
  529. if e = menuOb.MultiDel(menuIds); e != nil {
  530. br.Msg = "操作失败"
  531. br.ErrMsg = "删除菜单及子菜单失败, Err: " + e.Error()
  532. return
  533. }
  534. br.Ret = 200
  535. br.Success = true
  536. br.Msg = "操作成功"
  537. }
  538. // IconList
  539. // @Title 图标列表
  540. // @Description 图标列表
  541. // @Success 200 Ret=200 操作成功
  542. // @router /menu/icon/list [get]
  543. func (this *EtaBusinessMenuController) IconList() {
  544. br := new(models.BaseResponse).Init()
  545. defer func() {
  546. if br.ErrMsg == "" {
  547. br.IsSendEmail = false
  548. }
  549. this.Data["json"] = br
  550. this.ServeJSON()
  551. }()
  552. sysUser := this.SysUser
  553. if sysUser == nil {
  554. br.Msg = "请登录"
  555. br.ErrMsg = "请登录,SysUser Is Empty"
  556. br.Ret = 408
  557. return
  558. }
  559. iconOb := new(eta_business.EtaBusinessMenuIcon)
  560. icons, e := iconOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  561. if e != nil {
  562. br.Msg = "获取失败"
  563. br.ErrMsg = "获取菜单列表失败, Err: " + e.Error()
  564. return
  565. }
  566. list := make([]*eta_business.EtaBusinessMenuIconItem, 0)
  567. for _, v := range icons {
  568. list = append(list, &eta_business.EtaBusinessMenuIconItem{
  569. IconId: v.IconId,
  570. IconPath: v.IconPath,
  571. })
  572. }
  573. br.Data = list
  574. br.Ret = 200
  575. br.Success = true
  576. br.Msg = "获取成功"
  577. }
  578. // IconAdd
  579. // @Title 新增图标
  580. // @Description 新增图标
  581. // @Success 200 Ret=200 操作成功
  582. // @router /menu/icon/add [post]
  583. func (this *EtaBusinessMenuController) IconAdd() {
  584. br := new(models.BaseResponse).Init()
  585. defer func() {
  586. if br.ErrMsg == "" {
  587. br.IsSendEmail = false
  588. }
  589. this.Data["json"] = br
  590. this.ServeJSON()
  591. }()
  592. sysUser := this.SysUser
  593. if sysUser == nil {
  594. br.Msg = "请登录"
  595. br.ErrMsg = "请登录,SysUser Is Empty"
  596. br.Ret = 408
  597. return
  598. }
  599. var req eta_business.EtaBusinessMenuIconAddReq
  600. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  601. br.Msg = "参数解析异常!"
  602. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  603. return
  604. }
  605. req.IconPath = strings.TrimSpace(req.IconPath)
  606. if req.IconPath == "" {
  607. br.Msg = "请上传图片"
  608. return
  609. }
  610. iconOb := new(eta_business.EtaBusinessMenuIcon)
  611. iconOb.IconPath = req.IconPath
  612. iconOb.CreateTime = time.Now().Local()
  613. if e := iconOb.Create(); e != nil {
  614. br.Msg = "操作失败"
  615. br.ErrMsg = "新增菜单icon失败, Err: " + e.Error()
  616. return
  617. }
  618. br.Ret = 200
  619. br.Success = true
  620. br.Msg = "操作成功"
  621. }
  622. // SystemApiConfig
  623. // @Title 系统配置接口列表
  624. // @Description 系统配置接口列表
  625. // @Success 200 {object} []system.BusinessConf
  626. // @router /api/config/list [get]
  627. func (this *EtaBusinessMenuController) SystemApiConfig() {
  628. br := new(models.BaseResponse).Init()
  629. defer func() {
  630. if br.ErrMsg == "" {
  631. br.IsSendEmail = false
  632. }
  633. this.Data["json"] = br
  634. this.ServeJSON()
  635. }()
  636. sysUser := this.SysUser
  637. if sysUser == nil {
  638. br.Msg = "请登录"
  639. br.ErrMsg = "请登录,SysUser Is Empty"
  640. br.Ret = 408
  641. return
  642. }
  643. var relates []*eta_business.EtaBusinessConfigRelate
  644. businessId, _ := this.GetInt("EtaBusinessId", 0)
  645. var err error
  646. if businessId > 0 {
  647. relateOb := new(eta_business.EtaBusinessConfigRelate)
  648. cond := ` AND eta_business_id = ?`
  649. pars := make([]interface{}, 0)
  650. pars = append(pars, businessId)
  651. relates, err = relateOb.GetItemsByCondition(cond, pars, []string{}, "")
  652. if err != nil {
  653. br.Msg = "获取失败"
  654. br.ErrMsg = "获取商家菜单关联列表失败, Err: " + err.Error()
  655. return
  656. }
  657. }
  658. br.Data = relates
  659. br.Ret = 200
  660. br.Success = true
  661. br.Msg = "获取成功"
  662. }
  663. // SystemApiConfig
  664. // @Title 系统配置接口列表
  665. // @Description 系统配置接口列表
  666. // @Success 200 {object} []system.BusinessConf
  667. // @router /api/config/set [post]
  668. func (this *EtaBusinessMenuController) SystemApiConfigSet() {
  669. br := new(models.BaseResponse).Init()
  670. defer func() {
  671. if br.ErrMsg == "" {
  672. br.IsSendEmail = false
  673. }
  674. this.Data["json"] = br
  675. this.ServeJSON()
  676. }()
  677. sysUser := this.SysUser
  678. if sysUser == nil {
  679. br.Msg = "请登录"
  680. br.ErrMsg = "请登录,SysUser Is Empty"
  681. br.Ret = 408
  682. return
  683. }
  684. var req eta_business.SetBusinessConfReq
  685. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  686. br.Msg = "参数解析异常!"
  687. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  688. return
  689. }
  690. ob := new(eta_business.EtaBusinessConfigRelate)
  691. items := make([]*eta_business.EtaBusinessConfigRelate, 0)
  692. for _, v := range req.List {
  693. t := new(eta_business.EtaBusinessConfigRelate)
  694. t.ConfigCode = v.ConfigCode
  695. t.ConfigValue = v.ConfigValue
  696. t.EtaBusinessId = req.EtaBusinessId
  697. items = append(items, t)
  698. }
  699. if e := ob.CreateMulti(req.EtaBusinessId, items); e != nil {
  700. br.Msg = "保存失败"
  701. br.ErrMsg = "保存商家菜单关联失败, Err: " + e.Error()
  702. return
  703. }
  704. br.Ret = 200
  705. br.Success = true
  706. br.Msg = "操作成功"
  707. br.Ret = 200
  708. br.Success = true
  709. br.Msg = "设置成功"
  710. }