eta_business_menu.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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.ParentId = req.ParentId
  447. item.ModifyTime = time.Now().Local()
  448. // TODO:多级菜单
  449. cols := make([]string, 0)
  450. cols = append(cols, "Name", "Sort", "Path", "IconPath", "Component", "Hidden", "ButtonCode", "ParentId", "ModifyTime")
  451. if item.ParentId > 0 {
  452. item.LevelPath = item.Component
  453. cols = append(cols, "LevelPath")
  454. }
  455. if e := item.Update(cols); e != nil {
  456. br.Msg = "操作失败"
  457. br.ErrMsg = "更新菜单失败, Err: " + e.Error()
  458. return
  459. }
  460. br.Ret = 200
  461. br.Success = true
  462. br.Msg = "操作成功"
  463. }
  464. // Remove
  465. // @Title 删除菜单
  466. // @Description 删除菜单
  467. // @Param request body eta_business.EtaBusinessMenuRemoveReq true "type json string"
  468. // @Success 200 Ret=200 操作成功
  469. // @router /menu/remove [post]
  470. func (this *EtaBusinessMenuController) Remove() {
  471. br := new(models.BaseResponse).Init()
  472. defer func() {
  473. if br.ErrMsg == "" {
  474. br.IsSendEmail = false
  475. }
  476. this.Data["json"] = br
  477. this.ServeJSON()
  478. }()
  479. sysUser := this.SysUser
  480. if sysUser == nil {
  481. br.Msg = "请登录"
  482. br.ErrMsg = "请登录,SysUser Is Empty"
  483. br.Ret = 408
  484. return
  485. }
  486. // 操作权限校验
  487. ok, e := etaBusinessService.CheckEtaBusinessOperateAuth(sysUser.RoleTypeCode)
  488. if e != nil {
  489. br.Msg = "操作失败"
  490. br.ErrMsg = "操作权限校验失败, ErrMsg: " + e.Error()
  491. return
  492. }
  493. if !ok {
  494. br.Msg = "无权操作"
  495. return
  496. }
  497. // 参数校验
  498. var req eta_business.EtaBusinessMenuRemoveReq
  499. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  500. br.Msg = "参数解析异常!"
  501. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  502. return
  503. }
  504. if req.MenuId <= 0 {
  505. br.Msg = "参数有误"
  506. br.ErrMsg = "参数有误, MenuId"
  507. return
  508. }
  509. menuOb := new(eta_business.EtaBusinessMenu)
  510. _, e = menuOb.GetItemById(req.MenuId)
  511. if e != nil {
  512. if e.Error() == utils.ErrNoRow() {
  513. br.Msg = "菜单不存在, 请刷新页面"
  514. return
  515. }
  516. br.Msg = "操作失败"
  517. br.ErrMsg = "获取菜单失败, Err: " + e.Error()
  518. return
  519. }
  520. // 获取所有菜单列表, 筛选出该菜单及子菜单
  521. menus, e := menuOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  522. if e != nil {
  523. br.Msg = "操作失败"
  524. br.ErrMsg = "获取菜单列表失败, Err: " + e.Error()
  525. return
  526. }
  527. menuIds := etaBusinessService.GetMenuChildrenIdsRecursive(menus, req.MenuId)
  528. menuIds = append(menuIds, req.MenuId)
  529. // 删除菜单
  530. if e = menuOb.MultiDel(menuIds); e != nil {
  531. br.Msg = "操作失败"
  532. br.ErrMsg = "删除菜单及子菜单失败, Err: " + e.Error()
  533. return
  534. }
  535. br.Ret = 200
  536. br.Success = true
  537. br.Msg = "操作成功"
  538. }
  539. // IconList
  540. // @Title 图标列表
  541. // @Description 图标列表
  542. // @Success 200 Ret=200 操作成功
  543. // @router /menu/icon/list [get]
  544. func (this *EtaBusinessMenuController) IconList() {
  545. br := new(models.BaseResponse).Init()
  546. defer func() {
  547. if br.ErrMsg == "" {
  548. br.IsSendEmail = false
  549. }
  550. this.Data["json"] = br
  551. this.ServeJSON()
  552. }()
  553. sysUser := this.SysUser
  554. if sysUser == nil {
  555. br.Msg = "请登录"
  556. br.ErrMsg = "请登录,SysUser Is Empty"
  557. br.Ret = 408
  558. return
  559. }
  560. iconOb := new(eta_business.EtaBusinessMenuIcon)
  561. icons, e := iconOb.GetItemsByCondition(``, make([]interface{}, 0), []string{}, "")
  562. if e != nil {
  563. br.Msg = "获取失败"
  564. br.ErrMsg = "获取菜单列表失败, Err: " + e.Error()
  565. return
  566. }
  567. list := make([]*eta_business.EtaBusinessMenuIconItem, 0)
  568. for _, v := range icons {
  569. list = append(list, &eta_business.EtaBusinessMenuIconItem{
  570. IconId: v.IconId,
  571. IconPath: v.IconPath,
  572. })
  573. }
  574. br.Data = list
  575. br.Ret = 200
  576. br.Success = true
  577. br.Msg = "获取成功"
  578. }
  579. // IconAdd
  580. // @Title 新增图标
  581. // @Description 新增图标
  582. // @Success 200 Ret=200 操作成功
  583. // @router /menu/icon/add [post]
  584. func (this *EtaBusinessMenuController) IconAdd() {
  585. br := new(models.BaseResponse).Init()
  586. defer func() {
  587. if br.ErrMsg == "" {
  588. br.IsSendEmail = false
  589. }
  590. this.Data["json"] = br
  591. this.ServeJSON()
  592. }()
  593. sysUser := this.SysUser
  594. if sysUser == nil {
  595. br.Msg = "请登录"
  596. br.ErrMsg = "请登录,SysUser Is Empty"
  597. br.Ret = 408
  598. return
  599. }
  600. var req eta_business.EtaBusinessMenuIconAddReq
  601. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  602. br.Msg = "参数解析异常!"
  603. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  604. return
  605. }
  606. req.IconPath = strings.TrimSpace(req.IconPath)
  607. if req.IconPath == "" {
  608. br.Msg = "请上传图片"
  609. return
  610. }
  611. iconOb := new(eta_business.EtaBusinessMenuIcon)
  612. iconOb.IconPath = req.IconPath
  613. iconOb.CreateTime = time.Now().Local()
  614. if e := iconOb.Create(); e != nil {
  615. br.Msg = "操作失败"
  616. br.ErrMsg = "新增菜单icon失败, Err: " + e.Error()
  617. return
  618. }
  619. br.Ret = 200
  620. br.Success = true
  621. br.Msg = "操作成功"
  622. }
  623. // SystemApiConfig
  624. // @Title 系统配置接口列表
  625. // @Description 系统配置接口列表
  626. // @Success 200 {object} []system.BusinessConf
  627. // @router /api/config/list [get]
  628. func (this *EtaBusinessMenuController) SystemApiConfig() {
  629. br := new(models.BaseResponse).Init()
  630. defer func() {
  631. if br.ErrMsg == "" {
  632. br.IsSendEmail = false
  633. }
  634. this.Data["json"] = br
  635. this.ServeJSON()
  636. }()
  637. sysUser := this.SysUser
  638. if sysUser == nil {
  639. br.Msg = "请登录"
  640. br.ErrMsg = "请登录,SysUser Is Empty"
  641. br.Ret = 408
  642. return
  643. }
  644. var relates []*eta_business.EtaBusinessConfigRelate
  645. businessId, _ := this.GetInt("EtaBusinessId", 0)
  646. var err error
  647. if businessId > 0 {
  648. relateOb := new(eta_business.EtaBusinessConfigRelate)
  649. cond := ` AND eta_business_id = ?`
  650. pars := make([]interface{}, 0)
  651. pars = append(pars, businessId)
  652. relates, err = relateOb.GetItemsByCondition(cond, pars, []string{}, "")
  653. if err != nil {
  654. br.Msg = "获取失败"
  655. br.ErrMsg = "获取商家菜单关联列表失败, Err: " + err.Error()
  656. return
  657. }
  658. }
  659. br.Data = relates
  660. br.Ret = 200
  661. br.Success = true
  662. br.Msg = "获取成功"
  663. }
  664. // SystemApiConfig
  665. // @Title 系统配置接口列表
  666. // @Description 系统配置接口列表
  667. // @Success 200 {object} []system.BusinessConf
  668. // @router /api/config/set [post]
  669. func (this *EtaBusinessMenuController) SystemApiConfigSet() {
  670. br := new(models.BaseResponse).Init()
  671. defer func() {
  672. if br.ErrMsg == "" {
  673. br.IsSendEmail = false
  674. }
  675. this.Data["json"] = br
  676. this.ServeJSON()
  677. }()
  678. sysUser := this.SysUser
  679. if sysUser == nil {
  680. br.Msg = "请登录"
  681. br.ErrMsg = "请登录,SysUser Is Empty"
  682. br.Ret = 408
  683. return
  684. }
  685. var req eta_business.SetBusinessConfReq
  686. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  687. br.Msg = "参数解析异常!"
  688. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  689. return
  690. }
  691. ob := new(eta_business.EtaBusinessConfigRelate)
  692. items := make([]*eta_business.EtaBusinessConfigRelate, 0)
  693. for _, v := range req.List {
  694. t := new(eta_business.EtaBusinessConfigRelate)
  695. t.ConfigCode = v.ConfigCode
  696. t.ConfigValue = v.ConfigValue
  697. t.EtaBusinessId = req.EtaBusinessId
  698. items = append(items, t)
  699. }
  700. if e := ob.CreateMulti(req.EtaBusinessId, items); e != nil {
  701. br.Msg = "保存失败"
  702. br.ErrMsg = "保存商家菜单关联失败, Err: " + e.Error()
  703. return
  704. }
  705. br.Ret = 200
  706. br.Success = true
  707. br.Msg = "操作成功"
  708. br.Ret = 200
  709. br.Success = true
  710. br.Msg = "设置成功"
  711. }