sync_data.go 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  1. package task
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "github.com/go-redis/redis/v8"
  8. "go.uber.org/zap"
  9. "gorm.io/gorm"
  10. "log-server/global"
  11. "log-server/model/log/request"
  12. "log-server/model/task"
  13. "log-server/model/task/control"
  14. request2 "log-server/model/task/request"
  15. "log-server/model/typeManage"
  16. "log-server/service/cache"
  17. "log-server/utils"
  18. "strconv"
  19. "time"
  20. )
  21. type SyncData struct {
  22. GameTask GameTask
  23. cache cache.Cache
  24. common Common
  25. Person typeManage.ResponsiblePerson
  26. }
  27. func (s *SyncData) SyncXmyGameData(date string) (mps map[int]control.XmyPayRequestReplyData, err error) {
  28. xmyUrl := "http://api.sheepsdk.17xmy.com/foreign/api/get_youhua_data.php"
  29. xmyParams := map[string]string{
  30. "start_day": date,
  31. "end_day": date,
  32. }
  33. requestData := new(control.XmyReply)
  34. xmyByteData, err := utils.HttpGet(xmyUrl, xmyParams)
  35. if err != nil {
  36. return
  37. }
  38. _ = json.Unmarshal(xmyByteData, &requestData)
  39. mps = map[int]control.XmyPayRequestReplyData{}
  40. for _, data := range requestData.Data.List {
  41. gameId, _ := strconv.Atoi(data.GameId)
  42. mps[gameId] = data
  43. }
  44. return
  45. }
  46. func (s *SyncData) SyncXmyFreeData(date string, gameId int) (num int, err error) {
  47. xmyFreeUrl := "http://rtd.kfzs.com/fake.php"
  48. xmyFreeParams := map[string]string{
  49. "day": date,
  50. "game_id": strconv.Itoa(gameId),
  51. }
  52. requestData := new(control.XmyFreeReply)
  53. xmyByteData, err := utils.HttpGet(xmyFreeUrl, xmyFreeParams)
  54. if err != nil {
  55. return
  56. }
  57. _ = json.Unmarshal(xmyByteData, &requestData)
  58. if len(requestData.Data) != 0 {
  59. num, _ = strconv.Atoi(requestData.Data[0].Num)
  60. }
  61. return
  62. }
  63. func (s *SyncData) SyncWslGameData(date string) (mps map[string]int, err error) {
  64. wslUrl := "http://148.70.251.170/wsl-A/get_sheep_pay.php"
  65. wslParams := map[string]string{
  66. "times": date,
  67. }
  68. var requestData []control.WslReply
  69. wslByteData, err := utils.HttpGet(wslUrl, wslParams)
  70. if err != nil {
  71. return
  72. }
  73. _ = json.Unmarshal(wslByteData, &requestData)
  74. mps = map[string]int{}
  75. for _, data := range requestData {
  76. num, _ := strconv.Atoi(data.Money)
  77. mps[data.GameId] = num
  78. }
  79. return
  80. }
  81. var taskStatistics = "%s:taskStatistics"
  82. func (s *SyncData) SyncRoomData(date string, gameIdInt int) (ts request.TaskStatistics, err error) {
  83. ctx := context.Background()
  84. key := fmt.Sprintf(taskStatistics, date)
  85. gameIdStr := strconv.Itoa(gameIdInt)
  86. data, err := global.GVA_REDIS.HGet(ctx, key, gameIdStr).Result()
  87. if err != nil {
  88. if err == redis.Nil {
  89. global.GVA_LOG.Info("SyncRoomData not data", zap.Error(err))
  90. } else {
  91. global.GVA_LOG.Error("SyncRoomData fail", zap.Error(err))
  92. return
  93. }
  94. }
  95. _ = json.Unmarshal([]byte(data), &ts)
  96. return
  97. }
  98. // 获取任务完成数据
  99. func (s *SyncData) CompleteTaskData(date string) (mps map[int]task.GameTargetComplete, err error) {
  100. db := global.GVA_DB.Table("game_target_complete")
  101. db = db.Where("create_date = ?", date)
  102. var apiList []task.GameTargetComplete
  103. mps = map[int]task.GameTargetComplete{}
  104. err = db.Order("id desc").Find(&apiList).Error
  105. for _, api := range apiList {
  106. mps[api.TaskId] = api
  107. }
  108. return
  109. }
  110. // 同步每天的任务基础数据
  111. func (s *SyncData) EveryDaySyncTaskData() {
  112. db := global.GVA_DB.Model(&task.GameTask{})
  113. var apiList []task.GameTask
  114. db = db.Where("is_del = ?", -1)
  115. db = db.Where("status = ?", 1)
  116. err := db.Order("id desc").Find(&apiList).Error
  117. if err != nil {
  118. global.GVA_LOG.Error("EveryDaySyncTaskData fail", zap.Error(err))
  119. return
  120. }
  121. date := time.Now().Add(+time.Hour * 24)
  122. var gameTargetCompletes []*task.GameTargetComplete
  123. for _, gameTask := range apiList {
  124. if !errors.Is(global.GVA_DB.Where("task_id = ?", gameTask.TaskId).Where("create_date = ?", date).First(&task.GameTargetComplete{}).Error, gorm.ErrRecordNotFound) {
  125. continue
  126. }
  127. gameTargetComplete := s.GameTask.CreateGameTargetCompleteModel(gameTask, date)
  128. gameTargetCompletes = append(gameTargetCompletes, gameTargetComplete)
  129. }
  130. err = global.GVA_DB.Model(&task.GameTargetComplete{}).Omit("update_time", "game_rate", "is_complete").Create(gameTargetCompletes).Error
  131. if err != nil {
  132. global.GVA_LOG.Error("create GameTargetComplete fail", zap.Error(err))
  133. return
  134. }
  135. return
  136. }
  137. // 定时同步机房群控、小绵羊数据
  138. func (s *SyncData) SyncTaskData() {
  139. db := global.GVA_DB.Model(&task.GameTask{})
  140. var apiList []task.GameTask
  141. db = db.Where("is_del = ?", -1)
  142. db = db.Where("status = ?", 1)
  143. err := db.Order("id desc").Find(&apiList).Error
  144. if err != nil {
  145. global.GVA_LOG.Error("EveryDaySyncTaskData fail", zap.Error(err))
  146. return
  147. }
  148. if len(apiList) == 0 {
  149. global.GVA_LOG.Info("没有任务数据")
  150. return
  151. }
  152. date := time.Now().Format("2006-01-02")
  153. xmyGameData, err := s.SyncXmyGameData(date)
  154. if err != nil {
  155. global.GVA_LOG.Error("SyncTaskData get xmy data fail", zap.Error(err))
  156. return
  157. }
  158. completeTaskData, err := s.CompleteTaskData(date)
  159. if err != nil {
  160. global.GVA_LOG.Error("CompleteTaskData get data fail", zap.Error(err))
  161. return
  162. }
  163. wslData, err := s.SyncWslGameData(date)
  164. if err != nil {
  165. global.GVA_LOG.Error("SyncWslGameData get wsl data fail", zap.Error(err))
  166. return
  167. }
  168. for _, gameTask := range apiList {
  169. var gameTarget task.GameTargetComplete
  170. roomData, _ := s.SyncRoomData(date, gameTask.TaskId)
  171. if gameTask.GameIdXmy != "" {
  172. gameIdXmy, _ := strconv.Atoi(gameTask.GameIdXmy)
  173. xmyGameInfo := xmyGameData[gameIdXmy]
  174. gameTarget.NewComplete, _ = strconv.Atoi(xmyGameInfo.UserNum)
  175. gameTarget.PayComplete, _ = strconv.Atoi(xmyGameInfo.Cnt)
  176. gameTarget.RetainedComplete, _ = strconv.Atoi(xmyGameInfo.ActiveUserNum)
  177. f, _ := strconv.ParseFloat(xmyGameInfo.Amount, 64)
  178. gameTarget.Amount = int(f)
  179. num, _ := s.SyncXmyFreeData(date, gameIdXmy)
  180. if num != 0 {
  181. gameTarget.PayTarget = num
  182. if gameTarget.PayTarget > completeTaskData[gameTask.TaskId].PayTarget {
  183. lastPayAddUpdateTimeKey := fmt.Sprintf(LastPayAddUpdateTimeKey, date, gameTask.TaskId)
  184. _ = s.cache.SetCacheStr(context.Background(), lastPayAddUpdateTimeKey, time.Now().Unix())
  185. // 本次加付费目标数据
  186. lastPayAddNumKey := fmt.Sprintf(LastPayAddNumKey, date, gameTask.TaskId)
  187. _ = s.cache.SetCacheStr(context.Background(), lastPayAddNumKey, gameTarget.PayTarget-completeTaskData[gameTask.TaskId].PayTarget)
  188. payErrAddNumKey := fmt.Sprintf(PayErrAddNumKey, date, gameTask.TaskId)
  189. diffNum := gameTarget.PayTarget - completeTaskData[gameTask.TaskId].PayTarget
  190. s.common.SaveGameAddFee(diffNum, gameTarget.PayTarget, gameTask.TaskName)
  191. go s.FreeSendMsg(diffNum, gameTarget.PayTarget, gameTask.TaskName, gameTask.User)
  192. // 如果当前付费目标完成,加入一下逻辑
  193. if completeTaskData[gameTask.TaskId].PayTarget <= completeTaskData[gameTask.TaskId].PayComplete {
  194. lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, gameTask.TaskId)
  195. _ = s.cache.SetCacheStr(context.Background(), lastPayCompletedUpdateTimeKey, time.Now().Unix())
  196. _ = s.cache.SetCacheStr(context.Background(), payErrAddNumKey, gameTarget.PayTarget-completeTaskData[gameTask.TaskId].PayTarget)
  197. } else {
  198. n, _ := s.cache.GetCacheNum(context.Background(), payErrAddNumKey)
  199. _ = s.cache.SetCacheStr(context.Background(), payErrAddNumKey, gameTarget.PayTarget-completeTaskData[gameTask.TaskId].PayTarget+n)
  200. }
  201. }
  202. }
  203. } else {
  204. gameTarget.NewComplete = roomData.NewCompleteLocal
  205. gameTarget.PayComplete = roomData.PayCompleteLocal
  206. gameTarget.RetainedComplete = roomData.NewCompleteLocal + roomData.RetainedCompleteLocal
  207. gameTarget.Amount = gameTask.PayPrice * roomData.PayCompleteLocal
  208. if gameTarget.RetainedComplete < roomData.RetainedComplete {
  209. gameTarget.RetainedComplete = roomData.RetainedComplete
  210. }
  211. }
  212. gameTarget.GameRate = roomData.GameRate
  213. if gameTask.GamePortId == 5 && gameTask.LoginMethod == 2 {
  214. mzGameId := gameTask.MzGameId + "-" + gameTask.MzChannel
  215. if _, ok := wslData[mzGameId]; ok {
  216. gameTarget.PayTarget = wslData[mzGameId]
  217. if gameTarget.PayTarget > completeTaskData[gameTask.TaskId].PayTarget {
  218. lastPayAddUpdateTimeKey := fmt.Sprintf(LastPayAddUpdateTimeKey, date, gameTask.TaskId)
  219. _ = s.cache.SetCacheStr(context.Background(), lastPayAddUpdateTimeKey, time.Now().Unix())
  220. // 本次加付费目标数据
  221. lastPayAddNumKey := fmt.Sprintf(LastPayAddNumKey, date, gameTask.TaskId)
  222. _ = s.cache.SetCacheStr(context.Background(), lastPayAddNumKey, gameTarget.PayTarget-completeTaskData[gameTask.TaskId].PayTarget)
  223. payErrAddNumKey := fmt.Sprintf(PayErrAddNumKey, date, gameTask.TaskId)
  224. diffNum := gameTarget.PayTarget - completeTaskData[gameTask.TaskId].PayTarget
  225. s.common.SaveGameAddFee(diffNum, gameTarget.PayTarget, gameTask.TaskName)
  226. go s.FreeSendMsg(diffNum, gameTarget.PayTarget, gameTask.TaskName, gameTask.User)
  227. // 如果当前付费目标完成,加入一下逻辑
  228. if completeTaskData[gameTask.TaskId].PayTarget <= completeTaskData[gameTask.TaskId].PayComplete {
  229. lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, gameTask.TaskId)
  230. _ = s.cache.SetCacheStr(context.Background(), lastPayCompletedUpdateTimeKey, time.Now().Unix())
  231. _ = s.cache.SetCacheStr(context.Background(), payErrAddNumKey, gameTarget.PayTarget-completeTaskData[gameTask.TaskId].PayTarget)
  232. } else {
  233. n, _ := s.cache.GetCacheNum(context.Background(), payErrAddNumKey)
  234. _ = s.cache.SetCacheStr(context.Background(), payErrAddNumKey, gameTarget.PayTarget-completeTaskData[gameTask.TaskId].PayTarget+n)
  235. }
  236. }
  237. }
  238. }
  239. gameTarget.IsComplete = -1
  240. if gameTarget.RetainedComplete+completeTaskData[gameTask.TaskId].HandRetainedComplete >= completeTaskData[gameTask.TaskId].RetainedTarget && gameTarget.PayComplete >= completeTaskData[gameTask.TaskId].PayTarget && gameTarget.NewComplete+completeTaskData[gameTask.TaskId].HandNewComplete >= completeTaskData[gameTask.TaskId].NewTarget {
  241. gameTarget.IsComplete = 1
  242. }
  243. global.GVA_DB.Model(&task.GameTargetComplete{}).Where("task_id = ?", gameTask.TaskId).Where("create_date = ?", date).Omit("create_date", "update_time", "task_id").Updates(gameTarget)
  244. }
  245. return
  246. }
  247. func (s *SyncData) DayTargetDataStatistics() {
  248. date := time.Now().Add(-time.Hour * 24).Format("2006-01-02")
  249. request1 := request2.GameTaskStatisticsRequest{
  250. GroupKey: "user,gt.game_port_id",
  251. Date: date,
  252. }
  253. gameTargets, err := s.GameTask.EveryDayTargetData(date, request1)
  254. if err != nil {
  255. global.GVA_LOG.Error("DayTargetDataStatistics 统计数据失败", zap.Error(err))
  256. return
  257. }
  258. if len(gameTargets) == 0 {
  259. global.GVA_LOG.Info("没有数据统计", zap.Error(err))
  260. return
  261. }
  262. var gameTargetDates []task.GameTargetStatistics
  263. for _, gameTarget := range gameTargets {
  264. var gameTargetDate task.GameTargetStatistics
  265. gameTargetDate.PayTarget = gameTarget.PayTarget
  266. gameTargetDate.NewTarget = gameTarget.NewTarget
  267. gameTargetDate.RetainedTarget = gameTarget.RetainedTarget
  268. gameTargetDate.PayComplete = gameTarget.PayComplete
  269. gameTargetDate.NewComplete = gameTarget.NewComplete + gameTarget.HandNewComplete
  270. gameTargetDate.RetainedComplete = gameTarget.RetainedComplete + gameTarget.HandRetainedComplete
  271. gameTargetDate.Amount = gameTarget.Amount
  272. gameTargetDate.GamePortId = gameTarget.GamePortId
  273. gameTargetDate.User = gameTarget.User
  274. gameTargetDate.TaskDate = gameTarget.CreateDate
  275. if !errors.Is(global.GVA_DB.Where("user = ?", gameTarget.User).Where("task_date = ?", gameTarget.CreateDate).Where("game_port_id = ?", gameTarget.GamePortId).First(&task.GameTargetStatistics{}).Error, gorm.ErrRecordNotFound) {
  276. err := global.GVA_DB.Where("user = ?", gameTarget.User).Where("task_date = ?", gameTarget.CreateDate).Where("game_port_id = ?", gameTarget.GamePortId).Omit("update_time", "task_date", "user", "game_port_id", "task_month", "task_year").Updates(&gameTargetDate).Error
  277. if err != nil {
  278. global.GVA_LOG.Error("DayTargetDataStatistics 更新统计数据失败", zap.Error(err))
  279. }
  280. continue
  281. }
  282. year, month, _ := time.Now().Date()
  283. gameTargetDate.TaskMonth = int(month)
  284. gameTargetDate.TaskYear = year
  285. gameTargetDates = append(gameTargetDates, gameTargetDate)
  286. }
  287. if len(gameTargetDates) < 1 {
  288. return
  289. }
  290. global.GVA_DB.Omit("update_time").Create(gameTargetDates)
  291. }
  292. var LastMsgSendTimeKey = "%s:lastMsgSendTime" // 上次活跃发送消息时间
  293. var LastNewCompletedKey = "%s:msgSendInfo:%d:lastNewCompleted" // 最后新增完成数量
  294. var LastPayCompletedKey = "%s:msgSendInfo:%d:lastPayCompleted" // 最后支付完成数量
  295. var LastRetainedCompletedKey = "%s:msgSendInfo:%d:lastRetainedCompleted" // 最后留存完成数量
  296. var LastNewCompletedUpdateTimeKey = "%s:msgSendInfo:%d:lastNewCompletedUpdateTime" // 最后新增完成更新时间
  297. var LastPayCompletedUpdateTimeKey = "%s:msgSendInfo:%d:lastPayCompletedUpdateTime" // 最后支付完成更新时间
  298. var LastRetainedCompletedUpdateTimeKey = "%s:msgSendInfo:%d:lastRetainedCompletedUpdateTime" // 最后留存完成更新时间
  299. var LastPayAddUpdateTimeKey = "%s:msgSendInfo:%d:lastPayAddUpdateTime" // 最后加付费时间
  300. var LastPayAddNumKey = "%s:msgSendInfo:%d:lastPayAddNum" // 最后加付费数量
  301. var PayErrAddNumKey = "%s:msgSendInfo:%d:PayErrAddNum" // 支付异常累加数量
  302. var TaskCompletedStatusKey = "%s:taskCompletedStatus" // 任务完成状态-1,1
  303. var LastFreeMsgSendTimeKey = "%s:lastFreeMsgSendTime" // 上次付费发送消息时间
  304. type CompletedInfo struct {
  305. AlsoTarget int //剩余数量
  306. Rate int //时间段做的任务数
  307. TimeRate int // 完成任务数据更新时间
  308. TaskId int
  309. AddPayUpdateTime int
  310. }
  311. // 获取未完成的任务数据
  312. func (s *SyncData) TaskNoCompleteDate(date string) (completesInfo []task.GameTargetComplete, err error) {
  313. db := global.GVA_DB.Table("game_target_complete")
  314. db = db.Where("is_complete = ?", -1)
  315. db = db.Where("create_date = ?", date)
  316. err = db.Find(&completesInfo).Error
  317. if err != nil {
  318. return
  319. }
  320. return
  321. }
  322. func (s *SyncData) TaskMsgSendInitData(ctx context.Context, completesInfo []task.GameTargetComplete, ctime int64, date, taskCompletedStatusKey, lastMsgSendTimeKey string) {
  323. for _, complete := range completesInfo {
  324. lastNewCompletedKey := fmt.Sprintf(LastNewCompletedKey, date, complete.TaskId)
  325. lastPayCompletedKey := fmt.Sprintf(LastPayCompletedKey, date, complete.TaskId)
  326. lastRetainedCompletedKey := fmt.Sprintf(LastRetainedCompletedKey, date, complete.TaskId)
  327. lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, complete.TaskId)
  328. lastNewCompletedUpdateTimeKey := fmt.Sprintf(LastNewCompletedUpdateTimeKey, date, complete.TaskId)
  329. lastRetainedCompletedUpdateTimeKey := fmt.Sprintf(LastRetainedCompletedUpdateTimeKey, date, complete.TaskId)
  330. lastNewCompleted := complete.NewComplete + complete.HandNewComplete //上次新增完成数
  331. _ = s.cache.SetCacheStr(ctx, lastNewCompletedKey, lastNewCompleted)
  332. lastPayCompleted := complete.PayComplete + complete.HandPayComplete //上次支付完成数
  333. _ = s.cache.SetCacheStr(ctx, lastPayCompletedKey, lastPayCompleted)
  334. lastRetainedCompleted := complete.RetainedComplete + complete.HandRetainedComplete //上次活跃完成数
  335. _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedKey, lastRetainedCompleted)
  336. //lastNewCompletedUpdateTime := complete.NewComplete //上次新增完成更新时间
  337. _ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime)
  338. //lastPayCompletedUpdateTime := complete.NewComplete //上次支付完成更新时间
  339. _ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime)
  340. //lastRetainedCompletedUpdateTime := complete.NewComplete //上次留存完成更新时间
  341. _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime)
  342. //lastPayAddUpdateTime := complete.NewComplete //上次付费增加更新时间
  343. }
  344. _ = s.cache.SetCacheStr(ctx, taskCompletedStatusKey, -1)
  345. _ = s.cache.SetCacheStr(ctx, lastMsgSendTimeKey, time.Now().Unix())
  346. }
  347. func (s *SyncData) TaskMsgSendRetainedData(ctx context.Context, completesInfo []task.GameTargetComplete, ctime int64, date, lastMsgSendTimeKey string) {
  348. var mps = make(map[int]map[string]CompletedInfo)
  349. lastMsgSendTime, _ := s.cache.GetCacheNum(ctx, lastMsgSendTimeKey)
  350. for _, complete := range completesInfo {
  351. lastNewCompletedKey := fmt.Sprintf(LastNewCompletedKey, date, complete.TaskId)
  352. lastRetainedCompletedKey := fmt.Sprintf(LastRetainedCompletedKey, date, complete.TaskId)
  353. lastNewCompletedUpdateTimeKey := fmt.Sprintf(LastNewCompletedUpdateTimeKey, date, complete.TaskId)
  354. lastRetainedCompletedUpdateTimeKey := fmt.Sprintf(LastRetainedCompletedUpdateTimeKey, date, complete.TaskId)
  355. currentNewCompleted := complete.NewComplete + complete.HandNewComplete
  356. currentRetainedCompleted := complete.RetainedComplete + complete.HandRetainedComplete
  357. var RateMp = make(map[string]CompletedInfo)
  358. var newBool = false
  359. var retainedBoll = false
  360. // 处理新增
  361. if complete.NewTarget > currentNewCompleted {
  362. lastNewCompleted, _ := s.cache.GetCacheNum(ctx, lastNewCompletedKey)
  363. alsoNewTarget := complete.NewTarget - currentNewCompleted
  364. newRate := 0
  365. lastNewCompletedUpdateTime, _ := s.cache.GetCacheNum(ctx, lastNewCompletedUpdateTimeKey)
  366. timeRate := int(ctime) - lastNewCompletedUpdateTime
  367. if lastNewCompleted < currentNewCompleted {
  368. newRate = currentNewCompleted - lastNewCompleted
  369. _ = s.cache.SetCacheStr(ctx, lastNewCompletedKey, currentNewCompleted)
  370. _ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime) //上次新增完成更新时间
  371. }
  372. RateMp["newRate"] = CompletedInfo{
  373. AlsoTarget: alsoNewTarget,
  374. Rate: newRate,
  375. TimeRate: timeRate,
  376. TaskId: complete.TaskId,
  377. }
  378. } else {
  379. newBool = true
  380. // 如果当前新增为0,或者完成也更新时间
  381. _ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime) //上次新增完成更新时间
  382. }
  383. // 处理留存
  384. if complete.RetainedTarget > currentRetainedCompleted {
  385. lastRetainedCompleted, _ := s.cache.GetCacheNum(ctx, lastRetainedCompletedKey)
  386. alsoRetainedTarget := complete.RetainedTarget - currentRetainedCompleted
  387. retainedRate := 0
  388. lastRetainedCompletedUpdateTime, _ := s.cache.GetCacheNum(ctx, lastRetainedCompletedUpdateTimeKey)
  389. timeRate := int(ctime) - lastRetainedCompletedUpdateTime
  390. if lastRetainedCompleted < currentRetainedCompleted {
  391. retainedRate = currentRetainedCompleted - lastRetainedCompleted
  392. _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedKey, currentRetainedCompleted)
  393. _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime) //上次留存完成更新时间
  394. }
  395. RateMp["retainedRate"] = CompletedInfo{
  396. AlsoTarget: alsoRetainedTarget,
  397. Rate: retainedRate,
  398. TimeRate: timeRate,
  399. TaskId: complete.TaskId,
  400. }
  401. } else {
  402. retainedBoll = true
  403. // 如果当前留存为0,或者完成也更新时间
  404. _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime) //上次留存完成更新时间
  405. }
  406. if !newBool || !retainedBoll {
  407. mps[complete.TaskId] = RateMp
  408. }
  409. }
  410. var taskStatistics = "%s:taskStatistics"
  411. var retained = "# 活跃播报 "
  412. if len(mps) == 0 {
  413. global.GVA_LOG.Warn(retained)
  414. }
  415. retained += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
  416. var errMsg = "**以下游戏目标效率为零:**"
  417. var errMsgZ = ""
  418. var sendMsg = map[string]string{}
  419. var errSendMsg = map[string]string{}
  420. var m int // 时间内
  421. m = (int(ctime) - lastMsgSendTime) / 60
  422. for taskId, data := range mps {
  423. key := fmt.Sprintf(taskStatistics, date)
  424. gameIdStr := strconv.Itoa(taskId)
  425. gameTask, err := global.GVA_REDIS.HGet(ctx, key, gameIdStr).Result()
  426. if err != nil {
  427. if err == redis.Nil {
  428. continue
  429. } else {
  430. global.GVA_LOG.Error("TaskMsgSendRetainedData获取缓存任务数据失败", zap.Error(err))
  431. continue
  432. }
  433. }
  434. var taskStatistics request.TaskStatistics
  435. _ = json.Unmarshal([]byte(gameTask), &taskStatistics)
  436. var eMsg = "" //单条异常数据
  437. var isNew = false
  438. var nm int //新增时间内
  439. var rm int //存时间内
  440. var rate string //效率
  441. var newErr = false
  442. var retainedErr = false
  443. var name = taskStatistics.Remark
  444. if info, ok := data["newRate"]; ok {
  445. sendMsg[name] += "\n"
  446. sendMsg[name] += taskStatistics.GameName
  447. sendMsg[name] += ",新增差"
  448. //sendMsg[name] += strconv.Itoa(info.AlsoTarget)
  449. sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", info.AlsoTarget)
  450. isNew = true
  451. if info.TimeRate > 60*60*24 {
  452. lastNewCompletedUpdateTimeKey := fmt.Sprintf(LastNewCompletedUpdateTimeKey, date, info.TaskId)
  453. _ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime) //上次新增完成更新时间
  454. nm = 1
  455. } else {
  456. nm = info.TimeRate / 60
  457. }
  458. rate = strconv.Itoa(info.Rate)
  459. if info.Rate == 0 {
  460. newErr = true
  461. }
  462. }
  463. if info, ok := data["retainedRate"]; ok {
  464. if !isNew {
  465. sendMsg[name] += "\n"
  466. sendMsg[name] += taskStatistics.GameName
  467. rate = strconv.Itoa(info.Rate)
  468. sendMsg[name] += "活跃差"
  469. } else {
  470. rate += "/" + strconv.Itoa(info.Rate)
  471. sendMsg[name] += ",活跃差"
  472. }
  473. if info.TimeRate > 60*60*24 {
  474. lastRetainedCompletedUpdateTimeKey := fmt.Sprintf(LastRetainedCompletedUpdateTimeKey, date, info.TaskId)
  475. _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime) //上次留存完成更新时间
  476. rm = 1
  477. } else {
  478. rm = info.TimeRate / 60
  479. }
  480. //sendMsg[name] += strconv.Itoa(info.AlsoTarget)
  481. sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", info.AlsoTarget)
  482. if info.Rate == 0 {
  483. retainedErr = true
  484. }
  485. }
  486. // 5分钟数据没动报异常数据
  487. if newErr && nm > 4 {
  488. eMsg += "\n"
  489. eMsg += taskStatistics.GameName
  490. eMsg += ",新增"
  491. if nm >= 60 {
  492. eMsg += "("
  493. eMsg += strconv.Itoa(nm / 60)
  494. eMsg += "小时内)"
  495. } else {
  496. eMsg += "("
  497. eMsg += strconv.Itoa(nm)
  498. eMsg += "分钟内)"
  499. }
  500. }
  501. if retainedErr && rm > 4 {
  502. if !newErr {
  503. eMsg += "\n"
  504. eMsg += taskStatistics.GameName
  505. }
  506. eMsg += ",活跃"
  507. if rm >= 60 {
  508. eMsg += "("
  509. eMsg += strconv.Itoa(rm / 60)
  510. eMsg += "小时内)"
  511. } else {
  512. eMsg += "("
  513. eMsg += strconv.Itoa(rm)
  514. eMsg += "分钟内)"
  515. }
  516. }
  517. if eMsg != "" {
  518. errMsgZ += eMsg
  519. errSendMsg[name] += eMsg
  520. }
  521. sendMsg[name] += ","
  522. if m >= 60 {
  523. sendMsg[name] += strconv.Itoa(m / 60)
  524. sendMsg[name] += "小时内完成"
  525. } else {
  526. sendMsg[name] += strconv.Itoa(m)
  527. sendMsg[name] += "分钟内完成"
  528. }
  529. //sendMsg[name] += rate
  530. sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%s</font>", rate)
  531. }
  532. hour := time.Now().Hour()
  533. msg := ""
  534. mpsPerson, _ := s.Person.GetUserInfo()
  535. //b1 ,_ := json.Marshal(mpsPerson)
  536. //global.GVA_LOG.Warn(string(b1))
  537. var mobile []string
  538. if hour >= 16 {
  539. if len(sendMsg) == 0 {
  540. return
  541. }
  542. if len(mps) != 0 && len(errSendMsg) != 0 {
  543. for name, _ := range errSendMsg {
  544. mobile = append(mobile, mpsPerson[name])
  545. }
  546. }
  547. for name, msg := range sendMsg {
  548. retained += "\n"
  549. retained += "**" + name + "**"
  550. retained += msg
  551. }
  552. msg = retained
  553. if errMsgZ != "" {
  554. msg += "\n"
  555. //msg += errMsg + errMsgZ
  556. msg += fmt.Sprintf("<font color=\"warning\">%s</font>", errMsg+errMsgZ)
  557. }
  558. } else {
  559. if errMsgZ != "" {
  560. //msg += errMsg + errMsgZ
  561. }
  562. if len(mps) != 0 && len(errSendMsg) != 0 {
  563. msg += "# 活跃播报 "
  564. msg += errMsg
  565. for name, m := range errSendMsg {
  566. mobile = append(mobile, mpsPerson[name])
  567. msg += "\n"
  568. msg += "**" + name + "**"
  569. msg += fmt.Sprintf("<font color=\"warning\">%s</font>", m)
  570. }
  571. }
  572. }
  573. //global.GVA_LOG.Warn(msg)
  574. _ = s.cache.SetCacheStr(ctx, lastMsgSendTimeKey, time.Now().Unix())
  575. if msg == "" {
  576. return
  577. }
  578. url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
  579. var sendData SendMsg
  580. sendData.MsgType = "markdown"
  581. sendData.Markdown.Content = msg
  582. s.SendMsgData(url, sendData)
  583. if len(mobile) != 0 {
  584. var sendTextData SendTextMsg
  585. sendTextData.MsgType = "text"
  586. sendTextData.Text.MentionedMobileList = mobile
  587. //b ,_ := json.Marshal(sendTextData)
  588. //global.GVA_LOG.Warn(string(b))
  589. s.SendMsgData(url, sendTextData)
  590. }
  591. }
  592. func (s *SyncData) TaskMsgSendFreeData(ctx context.Context, completesInfo []task.GameTargetComplete, ctime int64, date, lastFreeMsgSendTimeKey string, isOne bool) {
  593. var RateMp = make(map[int]CompletedInfo)
  594. lastFreeMsgSendTime, _ := s.cache.GetCacheNum(ctx, lastFreeMsgSendTimeKey)
  595. for _, complete := range completesInfo {
  596. lastPayCompletedKey := fmt.Sprintf(LastPayCompletedKey, date, complete.TaskId)
  597. lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, complete.TaskId)
  598. lastPayAddUpdateTimeKey := fmt.Sprintf(LastPayAddUpdateTimeKey, date, complete.TaskId)
  599. currentPayCompleted := complete.PayComplete + complete.HandPayComplete
  600. // 付费处理
  601. if complete.PayTarget != 0 && complete.PayTarget > currentPayCompleted {
  602. lastPayCompleted, _ := s.cache.GetCacheNum(ctx, lastPayCompletedKey)
  603. alsoPayTarget := complete.PayTarget - currentPayCompleted
  604. payRate := 0
  605. lastPayCompletedUpdateTime, _ := s.cache.GetCacheNum(ctx, lastPayCompletedUpdateTimeKey)
  606. lastPayAddUpdateTime, _ := s.cache.GetCacheNum(ctx, lastPayAddUpdateTimeKey)
  607. timeRate := int(ctime) - lastPayCompletedUpdateTime
  608. if lastPayCompleted < currentPayCompleted {
  609. payRate = currentPayCompleted - lastPayCompleted
  610. _ = s.cache.SetCacheStr(ctx, lastPayCompletedKey, currentPayCompleted)
  611. _ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime) //上次付费更新时间
  612. }
  613. RateMp[complete.TaskId] = CompletedInfo{
  614. AlsoTarget: alsoPayTarget,
  615. Rate: payRate,
  616. TimeRate: timeRate,
  617. TaskId: complete.TaskId,
  618. AddPayUpdateTime: lastPayAddUpdateTime,
  619. }
  620. } else {
  621. // 如果当前付费为0,或者完成也更新时间
  622. _ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime) //上次付费更新时间
  623. }
  624. }
  625. if isOne {
  626. _ = s.cache.SetCacheStr(ctx, lastFreeMsgSendTimeKey, time.Now().Unix())
  627. return
  628. }
  629. if len(RateMp) == 0 {
  630. global.GVA_LOG.Info("TaskMsgSendFreeData没有查询到未完成付费数据")
  631. return
  632. }
  633. var taskStatistics = "%s:taskStatistics"
  634. var retained = "付费播报 "
  635. retained += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
  636. var errMsg = "**以下游戏付费效率为零:**"
  637. var errMsgZ = ""
  638. var sendMsg = map[string]string{}
  639. var m int //时间内
  640. m = (int(ctime) - lastFreeMsgSendTime) / 60
  641. mpsPerson, _ := s.Person.GetUserInfo()
  642. var mobile []string
  643. for taskId, data := range RateMp {
  644. if data.AlsoTarget <= 0 {
  645. continue
  646. }
  647. key := fmt.Sprintf(taskStatistics, date)
  648. gameIdStr := strconv.Itoa(taskId)
  649. gameTask, err := global.GVA_REDIS.HGet(ctx, key, gameIdStr).Result()
  650. if err != nil {
  651. if err == redis.Nil {
  652. continue
  653. } else {
  654. global.GVA_LOG.Error("TaskMsgSendRetainedData获取缓存任务数据失败", zap.Error(err))
  655. continue
  656. }
  657. }
  658. var taskStatistics request.TaskStatistics
  659. _ = json.Unmarshal([]byte(gameTask), &taskStatistics)
  660. var name = taskStatistics.Remark
  661. sendMsg[name] += "\n"
  662. sendMsg[name] += taskStatistics.GameName
  663. sendMsg[name] += ",付费差"
  664. //sendMsg[name] += strconv.Itoa(data.AlsoTarget)
  665. sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", data.AlsoTarget)
  666. if data.TimeRate > 60*60*24 {
  667. lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, data.TaskId)
  668. _ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime) //上次付费更新时间
  669. data.TimeRate = 60 * 60 * 2
  670. }
  671. // 5分钟数据没动报异常数据
  672. if data.TimeRate/60 >= 2 {
  673. if data.Rate == 0 {
  674. lastPayAddNumKey := fmt.Sprintf(LastPayAddNumKey, date, data.TaskId)
  675. payErrAddNumKey := fmt.Sprintf(PayErrAddNumKey, date, data.TaskId)
  676. numErr, _ := s.cache.GetCacheNum(context.Background(), payErrAddNumKey)
  677. lastAddFeeNumErr, _ := s.cache.GetCacheNum(context.Background(), lastPayAddNumKey)
  678. errMsgZ += "\n"
  679. errMsgZ += taskStatistics.GameName
  680. errMsgZ += "("
  681. if data.TimeRate/60 >= 60 {
  682. errMsgZ += strconv.Itoa(data.TimeRate / 60 / 60)
  683. errMsgZ += "小时内(+" + strconv.Itoa(numErr) + "))"
  684. } else {
  685. errMsgZ += strconv.Itoa(data.TimeRate / 60)
  686. errMsgZ += "分钟内(+" + strconv.Itoa(numErr) + "))"
  687. }
  688. errMsgZ += ","
  689. errMsgZ += "最后加付费时间 "
  690. t := time.Unix(int64(data.AddPayUpdateTime), 0)
  691. errMsgZ += t.Format("15:04:05")
  692. errMsgZ += "(+" + strconv.Itoa(lastAddFeeNumErr) + ")"
  693. if _, ok := mpsPerson[name]; ok {
  694. mobile = append(mobile, mpsPerson[name])
  695. }
  696. }
  697. }
  698. sendMsg[name] += ","
  699. if m >= 60 {
  700. sendMsg[name] += strconv.Itoa(m / 60)
  701. sendMsg[name] += "分钟内完成"
  702. } else {
  703. sendMsg[name] += strconv.Itoa(m)
  704. sendMsg[name] += "分钟内完成"
  705. }
  706. //sendMsg[name] += strconv.Itoa(data.Rate)
  707. sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", data.Rate)
  708. }
  709. if len(sendMsg) == 0 {
  710. return
  711. }
  712. for name, msg := range sendMsg {
  713. retained += "\n"
  714. retained += name
  715. retained += msg
  716. }
  717. msg := retained
  718. if errMsgZ != "" {
  719. msg += "\n"
  720. //msg += errMsg + errMsgZ
  721. msg += fmt.Sprintf("<font color=\"warning\">%s</font>", errMsg+errMsgZ)
  722. }
  723. _ = s.cache.SetCacheStr(ctx, lastFreeMsgSendTimeKey, time.Now().Unix())
  724. url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
  725. var sendData SendMsg
  726. sendData.MsgType = "markdown"
  727. sendData.Markdown.Content = msg
  728. s.SendMsgData(url, sendData)
  729. if len(mobile) != 0 {
  730. var sendTextData SendTextMsg
  731. sendTextData.MsgType = "text"
  732. sendTextData.Text.MentionedMobileList = mobile
  733. s.SendMsgData(url, sendTextData)
  734. }
  735. return
  736. }
  737. func (s *SyncData) SendMsgData(url string, params interface{}) {
  738. _, _ = utils.HttpPost(url, params)
  739. return
  740. }
  741. //活跃新增数据推送
  742. func (s *SyncData) TaskMsgSend() {
  743. date := time.Now().Format("2006-01-02")
  744. ctx := context.Background()
  745. taskCompletedStatusKey := fmt.Sprintf(TaskCompletedStatusKey, date)
  746. taskCompletedStatus, _ := s.cache.GetCacheNum(ctx, taskCompletedStatusKey)
  747. if taskCompletedStatus == 1 {
  748. return
  749. }
  750. completesInfo, err := s.TaskNoCompleteDate(date)
  751. if err != nil {
  752. global.GVA_LOG.Error("TaskMsgSend查询任务数据报错", zap.Error(err))
  753. }
  754. if len(completesInfo) == 0 {
  755. global.GVA_LOG.Info("TaskMsgSend没有查询到未完成数据")
  756. }
  757. lastMsgSendTimeKey := fmt.Sprintf(LastMsgSendTimeKey, date)
  758. b, err := s.cache.ExistsKey(context.Background(), lastMsgSendTimeKey)
  759. if err != nil {
  760. global.GVA_LOG.Error("TaskMsgSend查询任务数据报错", zap.Error(err))
  761. return
  762. }
  763. ctime := time.Now().Unix()
  764. if !b {
  765. s.TaskMsgSendInitData(ctx, completesInfo, ctime, date, taskCompletedStatusKey, lastMsgSendTimeKey)
  766. } else {
  767. lastMsgSendTime, _ := s.cache.GetCacheNum(ctx, lastMsgSendTimeKey)
  768. if int(ctime)-lastMsgSendTime < 60 {
  769. global.GVA_LOG.Error("TaskMsgSend上次数据发送时间还没到5分钟", zap.Error(err))
  770. return
  771. }
  772. //s.TaskMsgSendRetainedData(ctx, completesInfo, ctime, date, lastMsgSendTimeKey)
  773. s.TaskMsgSendRetainedDataUpdate(ctx, completesInfo, ctime, date, lastMsgSendTimeKey)
  774. }
  775. }
  776. //活跃新增数据推送
  777. func (s *SyncData) TaskFreeMsgSend() {
  778. date := time.Now().Format("2006-01-02")
  779. ctx := context.Background()
  780. taskCompletedStatusKey := fmt.Sprintf(TaskCompletedStatusKey, date)
  781. taskCompletedStatus, _ := s.cache.GetCacheNum(ctx, taskCompletedStatusKey)
  782. if taskCompletedStatus == 1 {
  783. return
  784. }
  785. completesInfo, err := s.TaskNoCompleteDate(date)
  786. if err != nil {
  787. global.GVA_LOG.Error("TaskMsgSend查询任务数据报错", zap.Error(err))
  788. }
  789. if len(completesInfo) == 0 {
  790. global.GVA_LOG.Info("TaskMsgSend没有查询到未完成数据")
  791. }
  792. lastFreeMsgSendTimeKey := fmt.Sprintf(LastFreeMsgSendTimeKey, date)
  793. ctime := time.Now().Unix()
  794. lastFreeMsgSendTime, _ := s.cache.GetCacheNum(ctx, lastFreeMsgSendTimeKey)
  795. if int(ctime)-lastFreeMsgSendTime < 60 {
  796. global.GVA_LOG.Error("TaskMsgSend上次数据发送时间还没到5分钟", zap.Error(err))
  797. return
  798. }
  799. var isOne = false
  800. if lastFreeMsgSendTime == 0 {
  801. isOne = true
  802. }
  803. //s.TaskMsgSendFreeData(ctx, completesInfo, ctime, date, lastFreeMsgSendTimeKey, isOne)
  804. s.TaskMsgSendFreeDataUpdate(ctx, completesInfo, ctime, date, lastFreeMsgSendTimeKey, isOne)
  805. }
  806. func (s *SyncData) CheckTaskCompletedInfo() {
  807. date := time.Now().Format("2006-01-02")
  808. ctx := context.Background()
  809. taskCompletedStatusKey := fmt.Sprintf(TaskCompletedStatusKey, date)
  810. completesInfo, err := s.TaskNoCompleteDate(date)
  811. if err != nil {
  812. global.GVA_LOG.Error("CheckTaskCompletedInfo查询任务数据报错", zap.Error(err))
  813. return
  814. }
  815. status, _ := s.cache.GetCacheNum(ctx, taskCompletedStatusKey)
  816. if status == 1 {
  817. global.GVA_LOG.Info("任务已完成")
  818. return
  819. }
  820. if len(completesInfo) == 0 {
  821. global.GVA_LOG.Info("TaskMsgSend没有查询到未完成数据")
  822. time.Sleep(time.Second * 10)
  823. _ = s.cache.SetCacheStr(ctx, taskCompletedStatusKey, 1)
  824. msg := "# 监控报警 "
  825. msg += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
  826. msg += "\n"
  827. msg += "今日任务目标已完成"
  828. url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
  829. var sendData SendMsg
  830. sendData.MsgType = "markdown"
  831. sendData.Markdown.Content = msg
  832. s.SendMsgData(url, sendData)
  833. }
  834. }
  835. func (s *SyncData) TaskMsgSendRetainedDataUpdate(ctx context.Context, completesInfo []task.GameTargetComplete, ctime int64, date, lastMsgSendTimeKey string) {
  836. var mps = make(map[int]map[string]CompletedInfo)
  837. lastMsgSendTime, _ := s.cache.GetCacheNum(ctx, lastMsgSendTimeKey)
  838. for _, complete := range completesInfo {
  839. lastNewCompletedKey := fmt.Sprintf(LastNewCompletedKey, date, complete.TaskId)
  840. lastRetainedCompletedKey := fmt.Sprintf(LastRetainedCompletedKey, date, complete.TaskId)
  841. lastNewCompletedUpdateTimeKey := fmt.Sprintf(LastNewCompletedUpdateTimeKey, date, complete.TaskId)
  842. lastRetainedCompletedUpdateTimeKey := fmt.Sprintf(LastRetainedCompletedUpdateTimeKey, date, complete.TaskId)
  843. currentNewCompleted := complete.NewComplete + complete.HandNewComplete
  844. currentRetainedCompleted := complete.RetainedComplete + complete.HandRetainedComplete
  845. var RateMp = make(map[string]CompletedInfo)
  846. var newBool = false
  847. var retainedBoll = false
  848. // 处理新增
  849. if complete.NewTarget > currentNewCompleted {
  850. lastNewCompleted, _ := s.cache.GetCacheNum(ctx, lastNewCompletedKey)
  851. alsoNewTarget := complete.NewTarget - currentNewCompleted
  852. newRate := 0
  853. lastNewCompletedUpdateTime, _ := s.cache.GetCacheNum(ctx, lastNewCompletedUpdateTimeKey)
  854. timeRate := int(ctime) - lastNewCompletedUpdateTime
  855. if lastNewCompleted < currentNewCompleted {
  856. newRate = currentNewCompleted - lastNewCompleted
  857. _ = s.cache.SetCacheStr(ctx, lastNewCompletedKey, currentNewCompleted)
  858. _ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime) //上次新增完成更新时间
  859. }
  860. RateMp["newRate"] = CompletedInfo{
  861. AlsoTarget: alsoNewTarget,
  862. Rate: newRate,
  863. TimeRate: timeRate,
  864. TaskId: complete.TaskId,
  865. }
  866. } else {
  867. newBool = true
  868. // 如果当前新增为0,或者完成也更新时间
  869. _ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime) //上次新增完成更新时间
  870. }
  871. // 处理留存
  872. if complete.RetainedTarget > currentRetainedCompleted {
  873. lastRetainedCompleted, _ := s.cache.GetCacheNum(ctx, lastRetainedCompletedKey)
  874. alsoRetainedTarget := complete.RetainedTarget - currentRetainedCompleted
  875. retainedRate := 0
  876. lastRetainedCompletedUpdateTime, _ := s.cache.GetCacheNum(ctx, lastRetainedCompletedUpdateTimeKey)
  877. timeRate := int(ctime) - lastRetainedCompletedUpdateTime
  878. if lastRetainedCompleted < currentRetainedCompleted {
  879. retainedRate = currentRetainedCompleted - lastRetainedCompleted
  880. _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedKey, currentRetainedCompleted)
  881. _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime) //上次留存完成更新时间
  882. }
  883. RateMp["retainedRate"] = CompletedInfo{
  884. AlsoTarget: alsoRetainedTarget,
  885. Rate: retainedRate,
  886. TimeRate: timeRate,
  887. TaskId: complete.TaskId,
  888. }
  889. } else {
  890. retainedBoll = true
  891. // 如果当前留存为0,或者完成也更新时间
  892. _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime) //上次留存完成更新时间
  893. }
  894. if !newBool || !retainedBoll {
  895. mps[complete.TaskId] = RateMp
  896. }
  897. }
  898. var taskStatistics = "%s:taskStatistics"
  899. var retained = "# 活跃播报 "
  900. if len(mps) == 0 {
  901. global.GVA_LOG.Warn(retained)
  902. }
  903. retained += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
  904. var errMsg = "**以下游戏目标效率为零:**"
  905. var errMsgZ = ""
  906. var sendMsg = map[string]string{}
  907. var errSendMsg = map[string]string{}
  908. var m int // 时间内
  909. m = (int(ctime) - lastMsgSendTime) / 60
  910. for taskId, data := range mps {
  911. key := fmt.Sprintf(taskStatistics, date)
  912. gameIdStr := strconv.Itoa(taskId)
  913. gameTask, err := global.GVA_REDIS.HGet(ctx, key, gameIdStr).Result()
  914. if err != nil {
  915. if err == redis.Nil {
  916. continue
  917. } else {
  918. global.GVA_LOG.Error("TaskMsgSendRetainedData获取缓存任务数据失败", zap.Error(err))
  919. continue
  920. }
  921. }
  922. var taskStatistics request.TaskStatistics
  923. _ = json.Unmarshal([]byte(gameTask), &taskStatistics)
  924. var eMsg = "" //单条异常数据
  925. var isNew = false
  926. var nm int //新增时间内
  927. var rm int //存时间内
  928. var rate string //效率
  929. var newErr = false
  930. var retainedErr = false
  931. var name = taskStatistics.Remark
  932. if info, ok := data["newRate"]; ok {
  933. sendMsg[name] += "\n"
  934. sendMsg[name] += taskStatistics.GameName
  935. sendMsg[name] += ",新增差"
  936. //sendMsg[name] += strconv.Itoa(info.AlsoTarget)
  937. sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", info.AlsoTarget)
  938. isNew = true
  939. if info.TimeRate > 60*60*24 {
  940. lastNewCompletedUpdateTimeKey := fmt.Sprintf(LastNewCompletedUpdateTimeKey, date, info.TaskId)
  941. _ = s.cache.SetCacheStr(ctx, lastNewCompletedUpdateTimeKey, ctime) //上次新增完成更新时间
  942. nm = 1
  943. } else {
  944. nm = info.TimeRate / 60
  945. }
  946. rate = strconv.Itoa(info.Rate)
  947. if info.Rate == 0 {
  948. newErr = true
  949. }
  950. }
  951. if info, ok := data["retainedRate"]; ok {
  952. if !isNew {
  953. sendMsg[name] += "\n"
  954. sendMsg[name] += taskStatistics.GameName
  955. rate = strconv.Itoa(info.Rate)
  956. sendMsg[name] += "活跃差"
  957. } else {
  958. rate += "/" + strconv.Itoa(info.Rate)
  959. sendMsg[name] += ",活跃差"
  960. }
  961. if info.TimeRate > 60*60*24 {
  962. lastRetainedCompletedUpdateTimeKey := fmt.Sprintf(LastRetainedCompletedUpdateTimeKey, date, info.TaskId)
  963. _ = s.cache.SetCacheStr(ctx, lastRetainedCompletedUpdateTimeKey, ctime) //上次留存完成更新时间
  964. rm = 1
  965. } else {
  966. rm = info.TimeRate / 60
  967. }
  968. //sendMsg[name] += strconv.Itoa(info.AlsoTarget)
  969. sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", info.AlsoTarget)
  970. if info.Rate == 0 {
  971. retainedErr = true
  972. }
  973. }
  974. // 5分钟数据没动报异常数据
  975. if newErr && nm > 4 {
  976. eMsg += "\n"
  977. eMsg += taskStatistics.GameName
  978. eMsg += ",新增"
  979. if nm >= 60 {
  980. eMsg += "("
  981. eMsg += strconv.Itoa(nm / 60)
  982. eMsg += "小时内)"
  983. } else {
  984. eMsg += "("
  985. eMsg += strconv.Itoa(nm)
  986. eMsg += "分钟内)"
  987. }
  988. }
  989. if retainedErr && rm > 4 {
  990. if !newErr {
  991. eMsg += "\n"
  992. eMsg += taskStatistics.GameName
  993. }
  994. eMsg += ",活跃"
  995. if rm >= 60 {
  996. eMsg += "("
  997. eMsg += strconv.Itoa(rm / 60)
  998. eMsg += "小时内)"
  999. } else {
  1000. eMsg += "("
  1001. eMsg += strconv.Itoa(rm)
  1002. eMsg += "分钟内)"
  1003. }
  1004. }
  1005. if eMsg != "" {
  1006. errMsgZ += eMsg
  1007. errSendMsg[name] += eMsg
  1008. }
  1009. sendMsg[name] += ","
  1010. if m >= 60 {
  1011. sendMsg[name] += strconv.Itoa(m / 60)
  1012. sendMsg[name] += "小时内完成"
  1013. } else {
  1014. sendMsg[name] += strconv.Itoa(m)
  1015. sendMsg[name] += "分钟内完成"
  1016. }
  1017. //sendMsg[name] += rate
  1018. sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%s</font>", rate)
  1019. }
  1020. hour := time.Now().Hour()
  1021. msg := ""
  1022. mpsPerson, _ := s.Person.GetUserInfoData()
  1023. //b1 ,_ := json.Marshal(mpsPerson)
  1024. //global.GVA_LOG.Warn(string(b1))
  1025. var mobile []string
  1026. if hour >= 16 {
  1027. if len(sendMsg) == 0 {
  1028. return
  1029. }
  1030. if len(mps) != 0 && len(errSendMsg) != 0 {
  1031. for name, _ := range errSendMsg {
  1032. mobile = append(mobile, mpsPerson[name].MobilePhoneNumber)
  1033. }
  1034. }
  1035. for name, msg := range sendMsg {
  1036. retained += "\n"
  1037. retained += "**" + name + "**"
  1038. retained += msg
  1039. }
  1040. msg = retained
  1041. if errMsgZ != "" {
  1042. msg += "\n"
  1043. //msg += errMsg + errMsgZ
  1044. msg += fmt.Sprintf("<font color=\"warning\">%s</font>", errMsg+errMsgZ)
  1045. }
  1046. for pName, pMsg := range sendMsg {
  1047. if hour >= mpsPerson[pName].StartTime {
  1048. personMsg := pMsg
  1049. if _, ok := errSendMsg[pName]; ok {
  1050. personMsg += fmt.Sprintf("<font color=\"warning\">%s</font>", errSendMsg[pName])
  1051. }
  1052. url := mpsPerson[pName].Url
  1053. var sendPersonData SendMsg
  1054. sendPersonData.MsgType = "markdown"
  1055. sendPersonData.Markdown.Content = personMsg
  1056. s.SendMsgData(url, sendPersonData)
  1057. if mpsPerson[pName].Custodians != "" {
  1058. if _, ok := mpsPerson[mpsPerson[pName].Custodians]; ok {
  1059. custodiansMsg := fmt.Sprintf("<font color=\"warning\">%s的任务</font>", pName)
  1060. custodiansMsg += "\n"
  1061. custodiansMsg += personMsg
  1062. var custodiansData SendMsg
  1063. custodiansData.MsgType = "markdown"
  1064. custodiansData.Markdown.Content = custodiansMsg
  1065. urlCustodians := mpsPerson[mpsPerson[pName].Custodians].Url
  1066. s.SendMsgData(urlCustodians, custodiansData)
  1067. }
  1068. }
  1069. }
  1070. }
  1071. } else {
  1072. if errMsgZ != "" {
  1073. //msg += errMsg + errMsgZ
  1074. }
  1075. if len(mps) != 0 && len(errSendMsg) != 0 {
  1076. msg += "# 活跃播报 "
  1077. msg += errMsg
  1078. for name, m := range errSendMsg {
  1079. mobile = append(mobile, mpsPerson[name].MobilePhoneNumber)
  1080. msg += "\n"
  1081. msg += "**" + name + "**"
  1082. msg += fmt.Sprintf("<font color=\"warning\">%s</font>", m)
  1083. }
  1084. }
  1085. for pName, pMsg := range sendMsg {
  1086. if hour >= mpsPerson[pName].StartTime {
  1087. var personMsg = "# 活跃播报 "
  1088. personMsg += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
  1089. personMsg = pMsg
  1090. if _, ok := errSendMsg[pName]; ok {
  1091. personMsg += fmt.Sprintf("<font color=\"warning\">%s</font>", errSendMsg[pName])
  1092. }
  1093. url := mpsPerson[pName].Url
  1094. var sendPersonData SendMsg
  1095. sendPersonData.MsgType = "markdown"
  1096. sendPersonData.Markdown.Content = personMsg
  1097. global.GVA_LOG.Warn(personMsg)
  1098. s.SendMsgData(url, sendPersonData)
  1099. if mpsPerson[pName].Custodians != "" {
  1100. custodiansMsg := fmt.Sprintf("<font color=\"warning\">%s的任务</font>", pName)
  1101. custodiansMsg += "\n"
  1102. custodiansMsg += personMsg
  1103. var custodiansData SendMsg
  1104. custodiansData.MsgType = "markdown"
  1105. custodiansData.Markdown.Content = custodiansMsg
  1106. urlCustodians := mpsPerson[mpsPerson[pName].Custodians].Url
  1107. s.SendMsgData(urlCustodians, custodiansData)
  1108. }
  1109. }
  1110. }
  1111. }
  1112. //global.GVA_LOG.Warn(msg)
  1113. _ = s.cache.SetCacheStr(ctx, lastMsgSendTimeKey, time.Now().Unix())
  1114. if msg == "" {
  1115. return
  1116. }
  1117. url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
  1118. var sendData SendMsg
  1119. sendData.MsgType = "markdown"
  1120. sendData.Markdown.Content = msg
  1121. s.SendMsgData(url, sendData)
  1122. if len(mobile) != 0 {
  1123. var sendTextData SendTextMsg
  1124. sendTextData.MsgType = "text"
  1125. sendTextData.Text.MentionedMobileList = mobile
  1126. //b ,_ := json.Marshal(sendTextData)
  1127. //global.GVA_LOG.Warn(string(b))
  1128. s.SendMsgData(url, sendTextData)
  1129. }
  1130. }
  1131. func (s *SyncData) TaskMsgSendFreeDataUpdate(ctx context.Context, completesInfo []task.GameTargetComplete, ctime int64, date, lastFreeMsgSendTimeKey string, isOne bool) {
  1132. var RateMp = make(map[int]CompletedInfo)
  1133. lastFreeMsgSendTime, _ := s.cache.GetCacheNum(ctx, lastFreeMsgSendTimeKey)
  1134. for _, complete := range completesInfo {
  1135. lastPayCompletedKey := fmt.Sprintf(LastPayCompletedKey, date, complete.TaskId)
  1136. lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, complete.TaskId)
  1137. lastPayAddUpdateTimeKey := fmt.Sprintf(LastPayAddUpdateTimeKey, date, complete.TaskId)
  1138. currentPayCompleted := complete.PayComplete + complete.HandPayComplete
  1139. // 付费处理
  1140. if complete.PayTarget != 0 && complete.PayTarget > currentPayCompleted {
  1141. lastPayCompleted, _ := s.cache.GetCacheNum(ctx, lastPayCompletedKey)
  1142. alsoPayTarget := complete.PayTarget - currentPayCompleted
  1143. payRate := 0
  1144. lastPayCompletedUpdateTime, _ := s.cache.GetCacheNum(ctx, lastPayCompletedUpdateTimeKey)
  1145. lastPayAddUpdateTime, _ := s.cache.GetCacheNum(ctx, lastPayAddUpdateTimeKey)
  1146. timeRate := int(ctime) - lastPayCompletedUpdateTime
  1147. if lastPayCompleted < currentPayCompleted {
  1148. payRate = currentPayCompleted - lastPayCompleted
  1149. _ = s.cache.SetCacheStr(ctx, lastPayCompletedKey, currentPayCompleted)
  1150. _ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime) //上次付费更新时间
  1151. }
  1152. RateMp[complete.TaskId] = CompletedInfo{
  1153. AlsoTarget: alsoPayTarget,
  1154. Rate: payRate,
  1155. TimeRate: timeRate,
  1156. TaskId: complete.TaskId,
  1157. AddPayUpdateTime: lastPayAddUpdateTime,
  1158. }
  1159. } else {
  1160. // 如果当前付费为0,或者完成也更新时间
  1161. _ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime) //上次付费更新时间
  1162. }
  1163. }
  1164. if isOne {
  1165. _ = s.cache.SetCacheStr(ctx, lastFreeMsgSendTimeKey, time.Now().Unix())
  1166. return
  1167. }
  1168. if len(RateMp) == 0 {
  1169. global.GVA_LOG.Info("TaskMsgSendFreeData没有查询到未完成付费数据")
  1170. return
  1171. }
  1172. var taskStatistics = "%s:taskStatistics"
  1173. var retained = "# 付费播报 "
  1174. retained += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
  1175. var errMsg = "**以下游戏付费效率为零:**"
  1176. var errMsgZ = ""
  1177. var sendMsg = map[string]string{}
  1178. var m int //时间内
  1179. m = (int(ctime) - lastFreeMsgSendTime) / 60
  1180. mpsPerson, _ := s.Person.GetUserInfoData()
  1181. var mobile []string
  1182. for taskId, data := range RateMp {
  1183. if data.AlsoTarget <= 0 {
  1184. continue
  1185. }
  1186. key := fmt.Sprintf(taskStatistics, date)
  1187. gameIdStr := strconv.Itoa(taskId)
  1188. gameTask, err := global.GVA_REDIS.HGet(ctx, key, gameIdStr).Result()
  1189. if err != nil {
  1190. if err == redis.Nil {
  1191. continue
  1192. } else {
  1193. global.GVA_LOG.Error("TaskMsgSendRetainedData获取缓存任务数据失败", zap.Error(err))
  1194. continue
  1195. }
  1196. }
  1197. var taskStatistics request.TaskStatistics
  1198. _ = json.Unmarshal([]byte(gameTask), &taskStatistics)
  1199. var name = taskStatistics.Remark
  1200. sendMsg[name] += "\n"
  1201. sendMsg[name] += taskStatistics.GameName
  1202. sendMsg[name] += ",付费差"
  1203. //sendMsg[name] += strconv.Itoa(data.AlsoTarget)
  1204. sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", data.AlsoTarget)
  1205. if data.TimeRate > 60*60*24 {
  1206. lastPayCompletedUpdateTimeKey := fmt.Sprintf(LastPayCompletedUpdateTimeKey, date, data.TaskId)
  1207. _ = s.cache.SetCacheStr(ctx, lastPayCompletedUpdateTimeKey, ctime) //上次付费更新时间
  1208. data.TimeRate = 60 * 60 * 2
  1209. }
  1210. // 5分钟数据没动报异常数据
  1211. if data.TimeRate/60 >= 2 {
  1212. if data.Rate == 0 {
  1213. lastPayAddNumKey := fmt.Sprintf(LastPayAddNumKey, date, data.TaskId)
  1214. payErrAddNumKey := fmt.Sprintf(PayErrAddNumKey, date, data.TaskId)
  1215. numErr, _ := s.cache.GetCacheNum(context.Background(), payErrAddNumKey)
  1216. lastAddFeeNumErr, _ := s.cache.GetCacheNum(context.Background(), lastPayAddNumKey)
  1217. errMsgZ += "\n"
  1218. errMsgZ += taskStatistics.GameName
  1219. errMsgZ += "("
  1220. if data.TimeRate/60 >= 60 {
  1221. errMsgZ += strconv.Itoa(data.TimeRate / 60 / 60)
  1222. errMsgZ += "小时内(+" + strconv.Itoa(numErr) + "))"
  1223. } else {
  1224. errMsgZ += strconv.Itoa(data.TimeRate / 60)
  1225. errMsgZ += "分钟内(+" + strconv.Itoa(numErr) + "))"
  1226. }
  1227. errMsgZ += ","
  1228. errMsgZ += "最后加付费时间 "
  1229. t := time.Unix(int64(data.AddPayUpdateTime), 0)
  1230. errMsgZ += t.Format("15:04:05")
  1231. errMsgZ += "(+" + strconv.Itoa(lastAddFeeNumErr) + ")"
  1232. if _, ok := mpsPerson[name]; ok {
  1233. mobile = append(mobile, mpsPerson[name].MobilePhoneNumber)
  1234. }
  1235. }
  1236. }
  1237. sendMsg[name] += ","
  1238. if m >= 60 {
  1239. sendMsg[name] += strconv.Itoa(m / 60)
  1240. sendMsg[name] += "分钟内完成"
  1241. } else {
  1242. sendMsg[name] += strconv.Itoa(m)
  1243. sendMsg[name] += "分钟内完成"
  1244. }
  1245. //sendMsg[name] += strconv.Itoa(data.Rate)
  1246. sendMsg[name] += fmt.Sprintf("<font color=\"warning\">%d</font>", data.Rate)
  1247. }
  1248. if len(sendMsg) == 0 {
  1249. return
  1250. }
  1251. hour := time.Now().Hour()
  1252. for name, msg := range sendMsg {
  1253. retained += "\n"
  1254. retained += name
  1255. retained += msg
  1256. if hour >= mpsPerson[name].StartTime {
  1257. var personMsg = "# 付费播报 "
  1258. personMsg += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
  1259. personMsg = msg
  1260. url := mpsPerson[name].Url
  1261. var sendPersonData SendMsg
  1262. sendPersonData.MsgType = "markdown"
  1263. sendPersonData.Markdown.Content = personMsg
  1264. s.SendMsgData(url, sendPersonData)
  1265. if mpsPerson[name].Custodians != "" {
  1266. if _, ok := mpsPerson[mpsPerson[name].Custodians]; ok {
  1267. custodiansMsg := fmt.Sprintf("<font color=\"warning\">%s的任务</font>", name)
  1268. custodiansMsg += "\n"
  1269. custodiansMsg += personMsg
  1270. var custodiansData SendMsg
  1271. custodiansData.MsgType = "markdown"
  1272. custodiansData.Markdown.Content = custodiansMsg
  1273. urlCustodians := mpsPerson[mpsPerson[name].Custodians].Url
  1274. s.SendMsgData(urlCustodians, custodiansData)
  1275. }
  1276. }
  1277. }
  1278. }
  1279. msg := retained
  1280. if errMsgZ != "" {
  1281. msg += "\n"
  1282. //msg += errMsg + errMsgZ
  1283. msg += fmt.Sprintf("<font color=\"warning\">%s</font>", errMsg+errMsgZ)
  1284. }
  1285. global.GVA_LOG.Warn(msg)
  1286. _ = s.cache.SetCacheStr(ctx, lastFreeMsgSendTimeKey, time.Now().Unix())
  1287. url := global.GVA_CONFIG.SendUrl.ComputerSendUrl
  1288. var sendData SendMsg
  1289. sendData.MsgType = "markdown"
  1290. sendData.Markdown.Content = msg
  1291. s.SendMsgData(url, sendData)
  1292. if len(mobile) != 0 {
  1293. var sendTextData SendTextMsg
  1294. sendTextData.MsgType = "text"
  1295. sendTextData.Text.MentionedMobileList = mobile
  1296. s.SendMsgData(url, sendTextData)
  1297. }
  1298. return
  1299. }
  1300. // 加付费通知
  1301. func (s *SyncData) FreeSendMsg(num, target int, taskName, director string) {
  1302. hour := time.Now().Hour()
  1303. if hour < 8 {
  1304. return
  1305. }
  1306. person, err := s.Person.GetUserInfoByName(director)
  1307. if err != nil {
  1308. global.GVA_LOG.Error("FreeSendMsg获取用户数据失败"+director, zap.Error(err))
  1309. }
  1310. if person.PushStatus != 1 {
  1311. return
  1312. }
  1313. personMsg := "# 加付费"
  1314. personMsg += fmt.Sprintf("<font color=\"warning\">%s</font>", time.Now().Format("2006-01-02 15:04:05"))
  1315. personMsg += "\n"
  1316. personMsg += taskName
  1317. personMsg += fmt.Sprintf("<font color=\"warning\"> 加付费 %d, 当前付费目标 %d</font>", num, target)
  1318. url := person.Url
  1319. var sendData SendMsg
  1320. sendData.MsgType = "markdown"
  1321. sendData.Markdown.Content = personMsg
  1322. s.SendMsgData(url, sendData)
  1323. }