common.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package task
  2. import (
  3. "fmt"
  4. "go.uber.org/zap"
  5. "log-server/global"
  6. "log-server/model/task"
  7. "log-server/model/typeManage"
  8. "log-server/utils"
  9. "time"
  10. )
  11. type Common struct {
  12. Person typeManage.ResponsiblePerson
  13. TConf task.TaskConf
  14. }
  15. type SendMsg struct {
  16. MsgType string `json:"msgtype"`
  17. Markdown struct {
  18. Content string `json:"content"`
  19. } `json:"markdown"`
  20. }
  21. type SendTextMsg struct {
  22. MsgType string `json:"msgtype"`
  23. Text struct {
  24. MentionedMobileList []string `json:"mentioned_mobile_list"`
  25. } `json:"text"`
  26. }
  27. type SendTextContent struct {
  28. MsgType string `json:"msgtype"`
  29. Text struct {
  30. Content string `json:"content"`
  31. MentionedMobileList []string `json:"mentioned_mobile_list"`
  32. } `json:"text"`
  33. }
  34. func (s *Common) RemindSend(url, content string, mobile []string) {
  35. var sendTextData SendTextContent
  36. sendTextData.MsgType = "text"
  37. sendTextData.Text.MentionedMobileList = mobile
  38. sendTextData.Text.Content = content
  39. s.SendMsgData(url, sendTextData)
  40. }
  41. func (s *Common) SendMsgData(url string, params interface{}) {
  42. _, _ = utils.HttpPost(url, params)
  43. return
  44. }
  45. func (s *Common) SaveGameAddFee(num, target int, taskName string) {
  46. fee := new(task.GameAddFee)
  47. fee.TaskName = taskName
  48. fee.Num = num
  49. fee.Target = target
  50. fee.CreateDate = time.Now()
  51. global.GVA_DB.Omit("create_time").Create(&fee)
  52. return
  53. }
  54. // 加付费通知
  55. func (s *Common) FreeSendMsg(num, target, taskId int, taskName, director string) {
  56. taskConf, err := s.TConf.GetTaskConfByTaskId(taskId)
  57. if err != nil {
  58. global.GVA_LOG.Error("FreeSendMsg获取任务配置失败"+director, zap.Error(err))
  59. return
  60. }
  61. if taskConf.AddFeeNotice == 0 {
  62. taskConf.AddFeeNotice = 10
  63. }
  64. hour := time.Now().Hour()
  65. if hour < 8 || num < taskConf.AddFeeNotice {
  66. return
  67. }
  68. person, err := s.Person.GetUserInfoByName(director)
  69. if err != nil {
  70. global.GVA_LOG.Error("FreeSendMsg获取用户数据失败"+director, zap.Error(err))
  71. }
  72. if person.PushStatus != 1 {
  73. return
  74. }
  75. personMsg := "# 加付费"
  76. personMsg += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
  77. personMsg += "\n"
  78. personMsg += taskName
  79. personMsg += fmt.Sprintf("<font color=\"warning\"> 加付费 %d, 当前付费目标 %d</font>", num, target)
  80. url := person.Url
  81. var sendData SendMsg
  82. sendData.MsgType = "markdown"
  83. sendData.Markdown.Content = personMsg
  84. s.SendMsgData(url, sendData)
  85. }