蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

79 lines
2.7 KiB

  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. arg := md.JpushRecordFundData{UserId: v["id"], Target: "1", Platform: "all", Title: data.Title, Content: data.Content}
  58. err := ch.PublishV2(md.EggJpushRecordQueueExchange, arg, md.EggJpushRecordQueue)
  59. if err != nil {
  60. ch.PublishV2(md.EggJpushRecordQueueExchange, arg, md.EggJpushRecordQueue)
  61. }
  62. arg1 := md.AliyunSmsRecordFundData{Phone: v["phone"], Title: data.Title, Content: data.Content, Code: data.SmsCode, Extra: extra}
  63. err = ch.PublishV2(md.EggAliyunSmsRecordQueueExchange, arg1, md.EggAliyunSmsRecordQueue)
  64. if err != nil {
  65. ch.PublishV2(md.EggAliyunSmsRecordQueueExchange, arg1, md.EggAliyunSmsRecordQueue)
  66. }
  67. eg.Where("id=?", v["unt_id"]).Cols("sign_notice_time").Update(&model.UserNoticeTime{SignNoticeTime: int(time.Now().Unix())})
  68. }
  69. if len(userList) == 1000 {
  70. p++
  71. commNoSignSend(eg, ch, p, data)
  72. return
  73. }
  74. return
  75. }