golang 的 rabbitmq 消费项目
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

zhios_withdraw_reward.go 4.1 KiB

pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package consume
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "applet/consume/md"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  9. "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule"
  10. "encoding/json"
  11. "errors"
  12. "fmt"
  13. "github.com/streadway/amqp"
  14. "github.com/tidwall/gjson"
  15. "time"
  16. "xorm.io/xorm"
  17. )
  18. func ZhiosWithdrawReward(queue md.MqQueue) {
  19. fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
  20. ch, err := rabbit.Cfg.Pool.GetChannel()
  21. if err != nil {
  22. logx.Error(err)
  23. return
  24. }
  25. defer ch.Release()
  26. //1、将自己绑定到交换机上
  27. ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
  28. //2、取出数据进行消费
  29. ch.Qos(20)
  30. delivery := ch.Consume(queue.Name, false)
  31. var res amqp.Delivery
  32. var ok bool
  33. for {
  34. res, ok = <-delivery
  35. if ok == true {
  36. //fmt.Println(string(res.Body))
  37. fmt.Println(">>>>>>>>>>>>>>>>CanalOrderConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
  38. err = handleZhiosWithdrawReward(res.Body)
  39. //_ = res.Reject(false)
  40. if err == nil {
  41. _ = res.Ack(true)
  42. }
  43. } else {
  44. panic(errors.New("error getting message"))
  45. }
  46. }
  47. fmt.Println("get msg done")
  48. }
  49. func handleZhiosWithdrawReward(msg []byte) error {
  50. //1、解析canal采集至mq中queue的数据结构体
  51. var canalMsg *md.ZhiosWithdraw
  52. fmt.Println(string(msg))
  53. var tmpString string
  54. err := json.Unmarshal(msg, &tmpString)
  55. if err != nil {
  56. fmt.Println("===with", err.Error())
  57. return err
  58. }
  59. fmt.Println(tmpString)
  60. err = json.Unmarshal([]byte(tmpString), &canalMsg)
  61. if err != nil {
  62. fmt.Println("===with", err.Error())
  63. return err
  64. }
  65. mid := canalMsg.Mid
  66. eg := db.DBs[mid]
  67. if eg == nil {
  68. return nil
  69. }
  70. //判断用户是什么等级
  71. var apply model.FinWithdrawApply
  72. get, err := eg.Where("id=?", canalMsg.Id).Get(&apply)
  73. if get == false || err != nil {
  74. return nil
  75. }
  76. if apply.Uid == 0 {
  77. return nil
  78. }
  79. //
  80. withdrawSetting := db.SysCfgGetWithDb(eg, mid, "withdraw_setting")
  81. withdrawFirstBili := gjson.Get(withdrawSetting, "withdrawFirstBili").String()
  82. publicWithdrawTeamBili := db.SysCfgGetWithDb(eg, mid, "public_withdraw_team_bili")
  83. publicWithdrawTeamCount := db.SysCfgGetWithDb(eg, mid, "public_withdraw_team_count")
  84. if utils.StrToFloat64(withdrawFirstBili) > 0 {
  85. level := 0
  86. all, _ := db.UserLevlEgAll(eg)
  87. for k, v := range all {
  88. if k == 0 {
  89. level = v.Id
  90. }
  91. }
  92. //分给粉丝
  93. levelUser := db.UserFindByLevel(eg, level)
  94. if len(levelUser) == 0 {
  95. return nil
  96. }
  97. ids := make([]int64, 0)
  98. for _, v := range levelUser {
  99. ids = append(ids, int64(v.Uid))
  100. }
  101. money := utils.FloatFormat(utils.StrToFloat64(apply.Amount)*(utils.StrToFloat64(withdrawFirstBili)/100)/float64(len(levelUser)), 6)
  102. comm(eg, canalMsg.Id, ids, money, "全网提现分红", "withdraw_reward", "92")
  103. }
  104. if utils.StrToFloat64(publicWithdrawTeamBili) > 0 && utils.StrToFloat64(publicWithdrawTeamCount) > 0 {
  105. //分给粉丝
  106. user, _ := rule.FindRandUser(eg, utils.StrToInt(publicWithdrawTeamCount))
  107. fmt.Println("=zhe", utils.SerializeStr(user))
  108. money := utils.FloatFormat(utils.StrToFloat64(apply.Amount)*(utils.StrToFloat64(publicWithdrawTeamBili)/100)/float64(len(user)), 6)
  109. comm(eg, canalMsg.Id, user, money, "公排团队提现分红", "withdraw_team_reward", "93")
  110. }
  111. return nil
  112. }
  113. func comm(eg *xorm.Engine, id string, levelUser []int64, money float64, title, types, ordAction string) {
  114. for _, v := range levelUser {
  115. profile, err := db.UserProfileFindByID(eg, v)
  116. if err != nil || profile == nil {
  117. continue
  118. }
  119. oldAmount := profile.FinValid
  120. profile.FinValid = utils.Float64ToStrByPrec(utils.StrToFloat64(profile.FinValid)+money, 6)
  121. eg.Where("uid=?", profile.Uid).Update(profile)
  122. var flow = model.FinUserFlow{
  123. Uid: int(v),
  124. Type: 0,
  125. Amount: utils.Float64ToStrByPrec(money, 6),
  126. BeforeAmount: oldAmount,
  127. AfterAmount: profile.FinValid,
  128. OrdType: types,
  129. OrdId: id,
  130. OrdTitle: title,
  131. OrdAction: utils.StrToInt(ordAction),
  132. OrdTime: int(time.Now().Unix()),
  133. State: 2,
  134. CreateAt: time.Now(),
  135. UpdateAt: time.Now(),
  136. }
  137. eg.Insert(&flow)
  138. }
  139. }