channel.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. package http
  2. import (
  3. "strings"
  4. "go-common/app/admin/main/feed/model/channel"
  5. cardmodel "go-common/app/admin/main/feed/model/channel"
  6. "go-common/app/admin/main/feed/model/common"
  7. "go-common/app/admin/main/feed/model/show"
  8. "go-common/app/admin/main/feed/util"
  9. "go-common/library/ecode"
  10. bm "go-common/library/net/http/blademaster"
  11. )
  12. func trimSpace(v string) string {
  13. return strings.TrimSpace(v)
  14. }
  15. func addCardSetup(c *bm.Context) {
  16. var (
  17. err error
  18. )
  19. res := map[string]interface{}{}
  20. req := &channel.AddCardSetup{}
  21. if err = c.Bind(req); err != nil {
  22. return
  23. }
  24. uid, name := util.UserInfo(c)
  25. if name == "" {
  26. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  27. c.Abort()
  28. return
  29. }
  30. req.Value = trimSpace(req.Value)
  31. if err = chanelSvc.AddCardSetup(req, name, uid); err != nil {
  32. res["message"] = "卡片创建失败 " + err.Error()
  33. c.JSONMap(res, ecode.RequestErr)
  34. return
  35. }
  36. c.JSON(nil, nil)
  37. }
  38. func cardSetupList(c *bm.Context) {
  39. var (
  40. err error
  41. cPager *cardmodel.SetupPager
  42. )
  43. res := map[string]interface{}{}
  44. req := &struct {
  45. ID int `form:"id"`
  46. Type string `form:"type" validate:"required"`
  47. Person string `form:"person"`
  48. Title string `form:"title"`
  49. Ps int `json:"ps" form:"ps" default:"20"` // 分页大小
  50. Pn int `json:"pn" form:"pn" default:"1"` // 第几个分页
  51. }{}
  52. if err = c.Bind(req); err != nil {
  53. return
  54. }
  55. if cPager, err = chanelSvc.CardSetupList(req.ID, req.Type, req.Person, req.Title, req.Pn, req.Ps); err != nil {
  56. res["message"] = "卡片获取失败 " + err.Error()
  57. c.JSONMap(res, ecode.RequestErr)
  58. return
  59. }
  60. c.JSON(cPager, nil)
  61. }
  62. func delCardSetup(c *bm.Context) {
  63. var (
  64. err error
  65. )
  66. res := map[string]interface{}{}
  67. req := &struct {
  68. ID int `form:"id" validate:"required"`
  69. Type string `form:"type" validate:"required"`
  70. }{}
  71. if err = c.Bind(req); err != nil {
  72. return
  73. }
  74. uid, name := util.UserInfo(c)
  75. if name == "" {
  76. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  77. c.Abort()
  78. return
  79. }
  80. if err = chanelSvc.DelCardSetup(req.ID, req.Type, name, uid); err != nil {
  81. res["message"] = "卡片删除失败 " + err.Error()
  82. c.JSONMap(res, ecode.RequestErr)
  83. return
  84. }
  85. c.JSON(nil, nil)
  86. }
  87. func updateCardSetup(c *bm.Context) {
  88. var (
  89. err error
  90. )
  91. res := map[string]interface{}{}
  92. req := &cardmodel.UpdateCardSetup{}
  93. if err = c.Bind(req); err != nil {
  94. return
  95. }
  96. req.Value = trimSpace(req.Value)
  97. card := &cardmodel.AddCardSetup{
  98. Type: req.Type,
  99. Value: req.Value,
  100. Title: req.Title,
  101. LongTitle: req.LongTitle,
  102. Content: req.Content,
  103. }
  104. uid, name := util.UserInfo(c)
  105. if name == "" {
  106. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  107. c.Abort()
  108. return
  109. }
  110. if err = chanelSvc.UpdateCardSetup(req.ID, card, name, uid); err != nil {
  111. res["message"] = "卡片更新失败 " + err.Error()
  112. c.JSONMap(res, ecode.RequestErr)
  113. return
  114. }
  115. c.JSON(nil, nil)
  116. }
  117. func tabList(c *bm.Context) {
  118. var (
  119. err error
  120. pager *show.ChannelTabPager
  121. )
  122. res := map[string]interface{}{}
  123. req := &show.ChannelTabLP{}
  124. if err = c.Bind(req); err != nil {
  125. return
  126. }
  127. if pager, err = chanelSvc.TabList(req); err != nil {
  128. res["message"] = "列表获取失败 " + err.Error()
  129. c.JSONMap(res, ecode.RequestErr)
  130. return
  131. }
  132. c.JSON(pager, nil)
  133. }
  134. func addTab(c *bm.Context) {
  135. var (
  136. err error
  137. //title string
  138. )
  139. res := map[string]interface{}{}
  140. req := &show.ChannelTabAP{}
  141. if err = c.Bind(req); err != nil {
  142. return
  143. }
  144. uid, name := util.UserInfo(c)
  145. if name == "" {
  146. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  147. c.Abort()
  148. return
  149. }
  150. req.Person = name
  151. req.UID = uid
  152. if _, err = commonSvc.CardPreview(c, common.CardChannelTab, req.TabID); err != nil {
  153. return
  154. }
  155. if err = chanelSvc.AddTab(c, req, name, uid); err != nil {
  156. res["message"] = "卡片创建失败 " + err.Error()
  157. c.JSONMap(res, ecode.RequestErr)
  158. return
  159. }
  160. c.JSON(nil, nil)
  161. }
  162. func updateTab(c *bm.Context) {
  163. var (
  164. err error
  165. //title string
  166. )
  167. res := map[string]interface{}{}
  168. req := &show.ChannelTabUP{}
  169. if err = c.Bind(req); err != nil {
  170. return
  171. }
  172. uid, name := util.UserInfo(c)
  173. if name == "" {
  174. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  175. c.Abort()
  176. return
  177. }
  178. if req.ID <= 0 {
  179. c.JSONMap(map[string]interface{}{"message": "ID 参数不合法"}, ecode.RequestErr)
  180. c.Abort()
  181. return
  182. }
  183. req.Person = name
  184. req.UID = uid
  185. if _, err = commonSvc.CardPreview(c, common.CardChannelTab, req.TabID); err != nil {
  186. return
  187. }
  188. if err = chanelSvc.UpdateTab(c, req, name, uid); err != nil {
  189. res["message"] = "卡片创建失败 " + err.Error()
  190. c.JSONMap(res, ecode.RequestErr)
  191. return
  192. }
  193. c.JSON(nil, nil)
  194. }
  195. func deleteTab(c *bm.Context) {
  196. var (
  197. err error
  198. )
  199. res := map[string]interface{}{}
  200. req := &struct {
  201. ID int64 `form:"id" validate:"required"`
  202. }{}
  203. if err = c.Bind(req); err != nil {
  204. return
  205. }
  206. uid, name := util.UserInfo(c)
  207. if name == "" {
  208. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  209. c.Abort()
  210. return
  211. }
  212. if req.ID <= 0 {
  213. c.JSONMap(map[string]interface{}{"message": "ID 参数不合法"}, ecode.RequestErr)
  214. c.Abort()
  215. return
  216. }
  217. if err = chanelSvc.DeleteTab(req.ID, name, uid); err != nil {
  218. res["message"] = "卡片创建失败 " + err.Error()
  219. c.JSONMap(res, ecode.RequestErr)
  220. return
  221. }
  222. c.JSON(nil, nil)
  223. }
  224. func offlineTab(c *bm.Context) {
  225. var (
  226. err error
  227. )
  228. res := map[string]interface{}{}
  229. req := &struct {
  230. ID int64 `form:"id" validate:"required"`
  231. }{}
  232. if err = c.Bind(req); err != nil {
  233. return
  234. }
  235. uid, name := util.UserInfo(c)
  236. if name == "" {
  237. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  238. c.Abort()
  239. return
  240. }
  241. if req.ID <= 0 {
  242. c.JSONMap(map[string]interface{}{"message": "ID 参数不合法"}, ecode.RequestErr)
  243. c.Abort()
  244. return
  245. }
  246. if err = chanelSvc.OfflineTab(req.ID, name, uid); err != nil {
  247. res["message"] = "卡片下线失败 " + err.Error()
  248. c.JSONMap(res, ecode.RequestErr)
  249. return
  250. }
  251. c.JSON(nil, nil)
  252. }