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

120 lines
3.7 KiB

  1. package consume
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/db"
  5. md4 "applet/app/md"
  6. utils2 "applet/app/utils"
  7. "applet/app/utils/logx"
  8. "applet/consume/md"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  10. "code.fnuoos.com/EggPlanet/egg_system_rules.git"
  11. "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  12. md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
  13. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule"
  14. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  15. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  16. "encoding/json"
  17. "errors"
  18. "fmt"
  19. "github.com/streadway/amqp"
  20. )
  21. func EggEnergyRecruitNewUserRewardConsume(queue md.MqQueue) {
  22. fmt.Println(">>>>>>>>>>>>EggEnergyRecruitNewUserRewardConsume>>>>>>>>>>>>")
  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 = handleEggEnergyRecruitNewUserRewardConsume(res.Body)
  41. if err != nil {
  42. fmt.Println("EggEnergyRecruitNewUserRewardConsume_ERR:::::", err.Error())
  43. utils2.FilePutContents("EggEnergyRecruitNewUserRewardConsume_ERR", utils2.SerializeStr(map[string]interface{}{
  44. "body": res.Body,
  45. "err": err.Error(),
  46. }))
  47. _ = res.Reject(true) //TODO::拒绝
  48. } else {
  49. err = res.Ack(true)
  50. fmt.Println("err ::: ", err)
  51. }
  52. } else {
  53. panic(errors.New("error getting message"))
  54. }
  55. }
  56. fmt.Println("get msg done")
  57. }
  58. func handleEggEnergyRecruitNewUserRewardConsume(msgData []byte) error {
  59. //1、解析mq中queue的数据结构体
  60. var msg *md4.EggEnergyRecruitNewUserRewardMq
  61. err := json.Unmarshal(msgData, &msg)
  62. if err != nil {
  63. return err
  64. }
  65. engine := db.Db
  66. //2、给到直推奖励
  67. eggEnergyRecruitNewUserRewardDb := implement.NewEggEnergyRecruitNewUserRewardDb(engine)
  68. _, exist, _ := eggEnergyRecruitNewUserRewardDb.EggEnergyRecruitNewUserRewardGet(msg.Uid)
  69. if !exist { //TODO::判断是否签到过
  70. eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  71. eggEnergyBasicSetting, err1 := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  72. "key": "is_open",
  73. "value": 1,
  74. })
  75. if err1 != nil {
  76. return err1
  77. }
  78. if eggEnergyBasicSetting != nil {
  79. userDb := implement.NewUserDb(db.Db)
  80. user, err1 := userDb.GetUser(msg.Uid)
  81. if err1 != nil {
  82. return err1
  83. }
  84. if user != nil {
  85. userDeleteInfoDb := implement.NewUserDeleteInfoDb(db.Db)
  86. userDelete := userDeleteInfoDb.GetUserDeleteInfo(user.Phone)
  87. fmt.Println("userDelete>>>>>>>>>>>>>>>", userDelete)
  88. if userDelete == nil {
  89. var newUserRewardRules *md2.NewUserRewardRules
  90. err1 = json.Unmarshal([]byte(eggEnergyBasicSetting.NewUserIncentiveRules), &newUserRewardRules)
  91. if err1 != nil {
  92. fmt.Println("handleAddPublicPlatoonUserRelationCommissionConsume___ERR>>>>", err1.Error())
  93. }
  94. rewardValue := newUserRewardRules.InviteUserRewardValue
  95. session := db.Db.NewSession()
  96. err1 = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{
  97. Kind: "add",
  98. Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyRecruitNewUsersReward),
  99. TransferType: int(enum.EggEnergyRecruitNewUsersReward),
  100. CoinId: eggEnergyBasicSetting.PersonEggPointsCoinId,
  101. Uid: user.ParentUid,
  102. Amount: float64(rewardValue),
  103. })
  104. if err1 != nil {
  105. return err1
  106. }
  107. session.Commit()
  108. }
  109. }
  110. }
  111. }
  112. return nil
  113. }