123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- package http
- import (
- "strings"
- "go-common/app/admin/main/feed/model/channel"
- cardmodel "go-common/app/admin/main/feed/model/channel"
- "go-common/app/admin/main/feed/model/common"
- "go-common/app/admin/main/feed/model/show"
- "go-common/app/admin/main/feed/util"
- "go-common/library/ecode"
- bm "go-common/library/net/http/blademaster"
- )
- func trimSpace(v string) string {
- return strings.TrimSpace(v)
- }
- func addCardSetup(c *bm.Context) {
- var (
- err error
- )
- res := map[string]interface{}{}
- req := &channel.AddCardSetup{}
- if err = c.Bind(req); err != nil {
- return
- }
- uid, name := util.UserInfo(c)
- if name == "" {
- c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
- c.Abort()
- return
- }
- req.Value = trimSpace(req.Value)
- if err = chanelSvc.AddCardSetup(req, name, uid); err != nil {
- res["message"] = "卡片创建失败 " + err.Error()
- c.JSONMap(res, ecode.RequestErr)
- return
- }
- c.JSON(nil, nil)
- }
- func cardSetupList(c *bm.Context) {
- var (
- err error
- cPager *cardmodel.SetupPager
- )
- res := map[string]interface{}{}
- req := &struct {
- ID int `form:"id"`
- Type string `form:"type" validate:"required"`
- Person string `form:"person"`
- Title string `form:"title"`
- Ps int `json:"ps" form:"ps" default:"20"` // 分页大小
- Pn int `json:"pn" form:"pn" default:"1"` // 第几个分页
- }{}
- if err = c.Bind(req); err != nil {
- return
- }
- if cPager, err = chanelSvc.CardSetupList(req.ID, req.Type, req.Person, req.Title, req.Pn, req.Ps); err != nil {
- res["message"] = "卡片获取失败 " + err.Error()
- c.JSONMap(res, ecode.RequestErr)
- return
- }
- c.JSON(cPager, nil)
- }
- func delCardSetup(c *bm.Context) {
- var (
- err error
- )
- res := map[string]interface{}{}
- req := &struct {
- ID int `form:"id" validate:"required"`
- Type string `form:"type" validate:"required"`
- }{}
- if err = c.Bind(req); err != nil {
- return
- }
- uid, name := util.UserInfo(c)
- if name == "" {
- c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
- c.Abort()
- return
- }
- if err = chanelSvc.DelCardSetup(req.ID, req.Type, name, uid); err != nil {
- res["message"] = "卡片删除失败 " + err.Error()
- c.JSONMap(res, ecode.RequestErr)
- return
- }
- c.JSON(nil, nil)
- }
- func updateCardSetup(c *bm.Context) {
- var (
- err error
- )
- res := map[string]interface{}{}
- req := &cardmodel.UpdateCardSetup{}
- if err = c.Bind(req); err != nil {
- return
- }
- req.Value = trimSpace(req.Value)
- card := &cardmodel.AddCardSetup{
- Type: req.Type,
- Value: req.Value,
- Title: req.Title,
- LongTitle: req.LongTitle,
- Content: req.Content,
- }
- uid, name := util.UserInfo(c)
- if name == "" {
- c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
- c.Abort()
- return
- }
- if err = chanelSvc.UpdateCardSetup(req.ID, card, name, uid); err != nil {
- res["message"] = "卡片更新失败 " + err.Error()
- c.JSONMap(res, ecode.RequestErr)
- return
- }
- c.JSON(nil, nil)
- }
- func tabList(c *bm.Context) {
- var (
- err error
- pager *show.ChannelTabPager
- )
- res := map[string]interface{}{}
- req := &show.ChannelTabLP{}
- if err = c.Bind(req); err != nil {
- return
- }
- if pager, err = chanelSvc.TabList(req); err != nil {
- res["message"] = "列表获取失败 " + err.Error()
- c.JSONMap(res, ecode.RequestErr)
- return
- }
- c.JSON(pager, nil)
- }
- func addTab(c *bm.Context) {
- var (
- err error
- //title string
- )
- res := map[string]interface{}{}
- req := &show.ChannelTabAP{}
- if err = c.Bind(req); err != nil {
- return
- }
- uid, name := util.UserInfo(c)
- if name == "" {
- c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
- c.Abort()
- return
- }
- req.Person = name
- req.UID = uid
- if _, err = commonSvc.CardPreview(c, common.CardChannelTab, req.TabID); err != nil {
- return
- }
- if err = chanelSvc.AddTab(c, req, name, uid); err != nil {
- res["message"] = "卡片创建失败 " + err.Error()
- c.JSONMap(res, ecode.RequestErr)
- return
- }
- c.JSON(nil, nil)
- }
- func updateTab(c *bm.Context) {
- var (
- err error
- //title string
- )
- res := map[string]interface{}{}
- req := &show.ChannelTabUP{}
- if err = c.Bind(req); err != nil {
- return
- }
- uid, name := util.UserInfo(c)
- if name == "" {
- c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
- c.Abort()
- return
- }
- if req.ID <= 0 {
- c.JSONMap(map[string]interface{}{"message": "ID 参数不合法"}, ecode.RequestErr)
- c.Abort()
- return
- }
- req.Person = name
- req.UID = uid
- if _, err = commonSvc.CardPreview(c, common.CardChannelTab, req.TabID); err != nil {
- return
- }
- if err = chanelSvc.UpdateTab(c, req, name, uid); err != nil {
- res["message"] = "卡片创建失败 " + err.Error()
- c.JSONMap(res, ecode.RequestErr)
- return
- }
- c.JSON(nil, nil)
- }
- func deleteTab(c *bm.Context) {
- var (
- err error
- )
- res := map[string]interface{}{}
- req := &struct {
- ID int64 `form:"id" validate:"required"`
- }{}
- if err = c.Bind(req); err != nil {
- return
- }
- uid, name := util.UserInfo(c)
- if name == "" {
- c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
- c.Abort()
- return
- }
- if req.ID <= 0 {
- c.JSONMap(map[string]interface{}{"message": "ID 参数不合法"}, ecode.RequestErr)
- c.Abort()
- return
- }
- if err = chanelSvc.DeleteTab(req.ID, name, uid); err != nil {
- res["message"] = "卡片创建失败 " + err.Error()
- c.JSONMap(res, ecode.RequestErr)
- return
- }
- c.JSON(nil, nil)
- }
- func offlineTab(c *bm.Context) {
- var (
- err error
- )
- res := map[string]interface{}{}
- req := &struct {
- ID int64 `form:"id" validate:"required"`
- }{}
- if err = c.Bind(req); err != nil {
- return
- }
- uid, name := util.UserInfo(c)
- if name == "" {
- c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
- c.Abort()
- return
- }
- if req.ID <= 0 {
- c.JSONMap(map[string]interface{}{"message": "ID 参数不合法"}, ecode.RequestErr)
- c.Abort()
- return
- }
- if err = chanelSvc.OfflineTab(req.ID, name, uid); err != nil {
- res["message"] = "卡片下线失败 " + err.Error()
- c.JSONMap(res, ecode.RequestErr)
- return
- }
- c.JSON(nil, nil)
- }
|