蛋蛋星球-客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

svc_no_sign_send.go 2.8 KiB

před 3 týdny
před 2 týdny
před 1 týdnem
před 3 týdny
před 1 týdnem
před 3 týdny
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/md"
  5. "applet/app/utils"
  6. "applet/app/utils/cache"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  9. "fmt"
  10. "strings"
  11. "time"
  12. "xorm.io/xorm"
  13. )
  14. func NoSignSend(eg *xorm.Engine) {
  15. PessimismLockValue := "NoSignSend"
  16. ch, err := rabbit.Cfg.Pool.GetChannel()
  17. if err != nil {
  18. return
  19. }
  20. defer ch.Release()
  21. key := fmt.Sprintf("NoSignSend")
  22. //TODO::增加“悲观锁”防止串行
  23. getString, _ := cache.GetString(key)
  24. if getString == PessimismLockValue {
  25. fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "上一次未执行完")
  26. return
  27. }
  28. cache.SetEx(key, PessimismLockValue, 3600*8) //8小时
  29. notice := make([]model.JpushNotice, 0)
  30. eg.Where("type='sign' and (jpush_open=1 or sms_open=1)").Desc("day").Find(&notice)
  31. for _, v := range notice {
  32. commNoSignSend(eg, ch, 1, v)
  33. }
  34. cache.Del(key)
  35. }
  36. func commNoSignSend(eg *xorm.Engine, ch *rabbit.Channel, p int, data model.JpushNotice) {
  37. now := time.Now().Unix()
  38. lastLoginAt := now - int64(data.Day)*3600
  39. loginNoticeTime := now - int64(data.NoticeDay)*3600
  40. sql := `
  41. SELECT u.id,u.phone,u.nickname,unt.id as unt_id,unt.sign_time,unt.sign_notice_time FROM user_notice_time unt
  42. LEFT JOIN user u on u.id=unt.uid
  43. WHERE unt.sign_time<'%d' and unt.sign_notice_time<'%d' and unt.sign_time>0 %s
  44. `
  45. sql = fmt.Sprintf(sql, lastLoginAt, loginNoticeTime, "limit "+utils.IntToStr((p-1)*1000)+",1000")
  46. userList, _ := db.QueryNativeString(eg, sql)
  47. if len(userList) == 0 {
  48. return
  49. }
  50. extra := ""
  51. for _, v := range userList {
  52. hour := (now - utils.StrToInt64(v["sign_time"])) / 3600
  53. data.Content = strings.ReplaceAll(data.Content, "{昵称}", v["nickname"])
  54. data.Content = strings.ReplaceAll(data.Content, "{手机号}", v["phone"])
  55. data.Content = strings.ReplaceAll(data.Content, "{小时}", utils.Int64ToStr(hour))
  56. extra = "{\"hour\":\"" + utils.Int64ToStr(hour) + "\"}"
  57. if data.JpushOpen == 1 {
  58. arg := md.JpushRecordFundData{UserId: v["id"], Target: "1", Platform: "all", Title: data.Title, Content: data.Content}
  59. err := ch.PublishV2(md.EggJpushRecordQueueExchange, arg, md.EggJpushRecordQueue)
  60. if err != nil {
  61. ch.PublishV2(md.EggJpushRecordQueueExchange, arg, md.EggJpushRecordQueue)
  62. }
  63. }
  64. if data.SmsOpen == 1 {
  65. arg1 := md.AliyunSmsRecordFundData{Phone: v["phone"], Title: data.Title, Content: data.Content, Code: data.SmsCode, Extra: extra}
  66. err := ch.PublishV2(md.EggAliyunSmsRecordQueueExchange, arg1, md.EggAliyunSmsRecordQueue)
  67. if err != nil {
  68. ch.PublishV2(md.EggAliyunSmsRecordQueueExchange, arg1, md.EggAliyunSmsRecordQueue)
  69. }
  70. }
  71. eg.Where("id=?", v["unt_id"]).Cols("sign_notice_time").Update(&model.UserNoticeTime{SignNoticeTime: int(time.Now().Unix())})
  72. }
  73. if len(userList) == 1000 {
  74. p++
  75. commNoSignSend(eg, ch, p, data)
  76. return
  77. }
  78. return
  79. }