group_send_msg.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "strings"
  8. "time"
  9. )
  10. // GroupSendMsgController 报告
  11. type GroupSendMsgController struct {
  12. BaseAuthController
  13. }
  14. // @Title 新增群发消息接口
  15. // @Description 新增群发消息
  16. // @Param request body models.GroupSendMsgAddReq true "type json string"
  17. // @Success 200 {object} 发送成功
  18. // @router /add [post]
  19. func (this *GroupSendMsgController) Add() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. var req models.GroupSendMsgAddReq
  26. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  27. if err != nil {
  28. br.Msg = "参数解析异常!"
  29. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  30. return
  31. }
  32. switch req.JumpType {
  33. case 1, 2:
  34. if req.LinkUrl == "" {
  35. br.Msg = "请填写推送链接"
  36. return
  37. }
  38. if req.Title == "" {
  39. br.Msg = "请填写推送标题"
  40. return
  41. }
  42. case 3:
  43. if req.Description == "" {
  44. br.Msg = "请填写描述"
  45. return
  46. }
  47. req.Title = "纯文字"
  48. case 4:
  49. if req.ImgUrl == "" {
  50. br.Msg = "请上传图片"
  51. return
  52. }
  53. req.Title = "纯图片"
  54. req.Description = "这是一张图片"
  55. req.LinkUrl = req.ImgUrl
  56. //req.ImgUrl = ""
  57. default:
  58. br.Msg = "跳转类型有误"
  59. br.ErrMsg = "跳转类型有误"
  60. return
  61. }
  62. if req.Label == "" {
  63. br.Msg = "请选择标签"
  64. return
  65. }
  66. item := &models.GroupSendMsg{
  67. JumpType: req.JumpType,
  68. LinkUrl: req.LinkUrl,
  69. ImgUrl: req.ImgUrl,
  70. Title: req.Title,
  71. Description: req.Description,
  72. Label: req.Label,
  73. Status: 0,
  74. CreateTime: time.Now(),
  75. }
  76. err = item.Add()
  77. if err != nil {
  78. br.Msg = "发送失败"
  79. br.ErrMsg = "发送失败,Err:" + err.Error()
  80. return
  81. }
  82. //向同花顺发送信息
  83. //err = services.SendMsgToThs(item)
  84. //if err != nil {
  85. // item.Status = -1
  86. // item.Remark = err.Error()
  87. // _ = item.Update([]string{"Status", "Remark"})
  88. // br.Msg = "发送失败"
  89. // br.ErrMsg = "发送失败,Err:" + err.Error()
  90. // return
  91. //}
  92. item.Status = 1
  93. _ = item.Update([]string{"Status"})
  94. br.Ret = 200
  95. br.Success = true
  96. br.Msg = "发送成功"
  97. }
  98. // GetLabelList
  99. // @Title 获取标签
  100. // @Description 获取标签接口
  101. // @Success 200 {object} []string
  102. // @router /label_list [get]
  103. func (this *GroupSendMsgController) GetLabelList() {
  104. br := new(models.BaseResponse).Init()
  105. defer func() {
  106. this.Data["json"] = br
  107. this.ServeJSON()
  108. }()
  109. configName := `ths_send_label`
  110. conf, err := company.GetConfigDetailByCode(configName)
  111. if err != nil {
  112. fmt.Println("GetConfigDetailByCode Err:" + err.Error())
  113. }
  114. labelStr := conf.ConfigValue
  115. labelList := strings.Split(labelStr, ",")
  116. br.Ret = 200
  117. br.Success = true
  118. br.Msg = "发送成功"
  119. br.Data = labelList
  120. }