蛋蛋星球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.

add_public_platoon_user_relation_commission.go 3.3 KiB

1 week ago
3 days ago
1 week ago
3 days ago
1 week ago
3 days ago
1 week ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package consume
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/db"
  5. "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. )
  20. func AddPublicPlatoonUserRelationCommissionConsume(queue md.MqQueue) {
  21. fmt.Println(">>>>>>>>>>>>AddPublicPlatoonUserRelationCommissionConsume>>>>>>>>>>>>")
  22. ch, err := rabbit.Cfg.Pool.GetChannel()
  23. if err != nil {
  24. logx.Error(err)
  25. return
  26. }
  27. defer ch.Release()
  28. //1、将自己绑定到交换机上
  29. ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
  30. //2、取出数据进行消费
  31. ch.Qos(1)
  32. delivery := ch.Consume(queue.Name, false)
  33. egg_system_rules.Init(cfg.RedisAddr)
  34. var res amqp.Delivery
  35. var ok bool
  36. for {
  37. res, ok = <-delivery
  38. if ok == true {
  39. err = handleAddPublicPlatoonUserRelationCommissionConsume(res.Body)
  40. if err != nil {
  41. fmt.Println("err ::: ", err)
  42. utils.FilePutContents("AddPublicPlatoonUserRelationCommissionConsume_ERR", "[err]:"+err.Error())
  43. _ = res.Reject(false)
  44. //TODO::重新推回队列末尾,避免造成队列堵塞
  45. var msg *md2.AddPublicPlatoonUserRelationCommissionReq
  46. json.Unmarshal(res.Body, &msg)
  47. ch.Publish(queue.ExchangeName, msg, queue.RoutKey)
  48. } else {
  49. _ = res.Ack(true)
  50. }
  51. } else {
  52. panic(errors.New("error getting message"))
  53. }
  54. }
  55. fmt.Println("get msg done")
  56. }
  57. func handleAddPublicPlatoonUserRelationCommissionConsume(msgData []byte) error {
  58. //1、解析mq中queue的数据结构体
  59. var msg *md2.AddPublicPlatoonUserRelationCommissionReq
  60. err := json.Unmarshal(msgData, &msg)
  61. if err != nil {
  62. return err
  63. }
  64. //2、给到直推奖励
  65. eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  66. eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  67. "key": "is_open",
  68. "value": 1,
  69. })
  70. if err != nil {
  71. return err
  72. }
  73. if eggEnergyBasicSetting != nil {
  74. var newUserRewardRules *md2.NewUserRewardRules
  75. err = json.Unmarshal([]byte(eggEnergyBasicSetting.NewUserIncentiveRules), &newUserRewardRules)
  76. if err != nil {
  77. fmt.Println("handleAddPublicPlatoonUserRelationCommissionConsume___ERR>>>>", err.Error())
  78. }
  79. rewardValue := newUserRewardRules.InviteUserRewardValue
  80. session := db.Db.NewSession()
  81. err = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{
  82. Kind: "add",
  83. Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyRecruitNewUsersReward),
  84. TransferType: int(enum.EggEnergyRecruitNewUsersReward),
  85. CoinId: eggEnergyBasicSetting.PersonEggPointsCoinId,
  86. Uid: utils.StrToInt64(msg.RecommendUid),
  87. Amount: float64(rewardValue),
  88. })
  89. if err != nil {
  90. return err
  91. }
  92. session.Commit()
  93. }
  94. //3、加入公排
  95. var req []*md2.AddPublicPlatoonUserRelationCommissionReq
  96. req = append(req, msg)
  97. _, err = rule.AddPublicPlatoonUserRelationCommission(db.Db, req)
  98. fmt.Println("err::::", err)
  99. if err != nil {
  100. return err
  101. }
  102. return nil
  103. }