蛋蛋星球RabbitMq消费项目
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.

egg_energy_start_level_dividend_consume.go 3.0 KiB

1 month ago
2 weeks ago
1 month ago
2 weeks ago
1 month ago
2 weeks ago
1 month ago
2 weeks ago
1 month ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package consume
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/db"
  5. utils2 "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "applet/consume/md"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_system_rules.git"
  10. "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  11. md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
  12. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule"
  13. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  14. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  15. "encoding/json"
  16. "errors"
  17. "fmt"
  18. "github.com/streadway/amqp"
  19. "time"
  20. )
  21. func EggEnergyStartLevelDividendConsume(queue md.MqQueue) {
  22. fmt.Println(">>>>>>>>>>>>EggEnergyStartLevelDividendConsume>>>>>>>>>>>>")
  23. ch, err := rabbit.Cfg.Pool.GetChannel()
  24. if err != nil {
  25. logx.Error(err)
  26. return
  27. }
  28. defer ch.Release()
  29. //1、将自己绑定到交换机上
  30. ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
  31. //2、取出数据进行消费
  32. ch.Qos(1)
  33. delivery := ch.Consume(queue.Name, false)
  34. egg_system_rules.Init(cfg.RedisAddr)
  35. var res amqp.Delivery
  36. var ok bool
  37. for {
  38. res, ok = <-delivery
  39. if ok == true {
  40. err = handleEggEnergyStartLevelDividendConsume(res.Body)
  41. if err != nil {
  42. fmt.Println("EggEnergyStartLevelDividendConsume_ERR:::::", err.Error())
  43. utils2.FilePutContents("EggEnergyStartLevelDividendConsume_ERR", utils2.SerializeStr(map[string]interface{}{
  44. "body": res.Body,
  45. "err": err.Error(),
  46. }))
  47. }
  48. //_ = res.Reject(false)
  49. err = res.Ack(true)
  50. fmt.Println("err ::: ", err)
  51. } else {
  52. panic(errors.New("error getting message"))
  53. }
  54. }
  55. fmt.Println("get msg done")
  56. }
  57. func handleEggEnergyStartLevelDividendConsume(msgData []byte) error {
  58. time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒
  59. //1、解析mq中queue的数据结构体
  60. var msg *md2.EggEnergyStructForStarLevelDividends
  61. err := json.Unmarshal(msgData, &msg)
  62. if err != nil {
  63. return err
  64. }
  65. engine := db.Db
  66. //2、查找 `egg_energy_basic_setting` 基础设置
  67. eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(engine)
  68. eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  69. "key": "is_open",
  70. "value": 1,
  71. })
  72. if err != nil {
  73. return err
  74. }
  75. if eggEnergyBasicSetting == nil {
  76. return errors.New("蛋蛋能量设置未开启!")
  77. }
  78. //3、给相应的用户加上个人的团队绿色能量
  79. session := engine.NewSession()
  80. defer func() {
  81. session.Close()
  82. if err := recover(); err != nil {
  83. _ = logx.Error(err)
  84. }
  85. }()
  86. session.Begin()
  87. err = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{
  88. Kind: "add",
  89. Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyCommunityDividends),
  90. TransferType: int(enum.EggEnergyCommunityDividends),
  91. CoinId: eggEnergyBasicSetting.TeamEggEnergyCoinId,
  92. Uid: msg.Uid,
  93. Amount: msg.SignDividend,
  94. })
  95. if err != nil {
  96. session.Rollback()
  97. return err
  98. }
  99. return session.Begin()
  100. }