蛋蛋星球-客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

hdl_member_center.go 4.6 KiB

před 1 měsícem
před 1 měsícem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es"
  10. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  11. "context"
  12. "encoding/json"
  13. "github.com/gin-gonic/gin"
  14. "github.com/olivere/elastic/v7"
  15. "github.com/shopspring/decimal"
  16. "time"
  17. )
  18. // MemberCenterGetBasic
  19. // @Summary 蛋蛋星球-会员中心-基础数据(获取)
  20. // @Tags 会员中心
  21. // @Description 基础数据(获取)
  22. // @Accept json
  23. // @Produce json
  24. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  25. // @Success 200 {object} md.MemberCenterGetBasicResp "具体数据"
  26. // @Failure 400 {object} md.Response "具体错误"
  27. // @Router /api/v1/memberCenter/getBasic [GET]
  28. func MemberCenterGetBasic(c *gin.Context) {
  29. val, exists := c.Get("user")
  30. if !exists {
  31. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  32. return
  33. }
  34. user, ok := val.(*model.User)
  35. if !ok {
  36. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  37. return
  38. }
  39. // 1. 获取会员等级名称
  40. userLevelDb := implement.NewUserLevelDb(db.Db)
  41. level, err := userLevelDb.UserLevelByID(user.Level)
  42. if err != nil {
  43. e.OutErr(c, e.ERR_DB_ORM, nil)
  44. return
  45. }
  46. // 2. 获取基础设置
  47. settingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  48. setting, err := settingDb.EggEnergyBasicSettingGetOne()
  49. if err != nil {
  50. e.OutErr(c, e.ERR_DB_ORM, nil)
  51. return
  52. }
  53. // 3. 查询余额
  54. virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db)
  55. // 3.1 活跃积分(蛋蛋积分 = 团队 + 个人)
  56. eggPersonalPoint, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.PersonEggPointsCoinId)
  57. if err != nil {
  58. e.OutErr(c, e.ERR_DB_ORM, nil)
  59. return
  60. }
  61. eggTeamPoint, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.TeamEggPointsCoinId)
  62. if err != nil {
  63. e.OutErr(c, e.ERR_DB_ORM, nil)
  64. return
  65. }
  66. eggPoint := utils.StrToFloat64(eggPersonalPoint.Amount) + utils.StrToFloat64(eggTeamPoint.Amount)
  67. // 3.2 蛋蛋能量 (个人 + 团队)
  68. eggPersonalEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.PersonEggEnergyCoinId)
  69. if err != nil {
  70. e.OutErr(c, e.ERR_DB_ORM, nil)
  71. return
  72. }
  73. eggTeamEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.TeamEggEnergyCoinId)
  74. if err != nil {
  75. e.OutErr(c, e.ERR_DB_ORM, nil)
  76. return
  77. }
  78. eggEnergy := utils.StrToFloat64(eggPersonalEnergy.Amount) + utils.StrToFloat64(eggTeamEnergy.Amount)
  79. // 3.3 钱包余额
  80. walletDb := implement.NewUserWalletDb(db.Db)
  81. wallet, err := walletDb.GetUserVirtualWallet(user.Id)
  82. if err != nil {
  83. e.OutErr(c, e.ERR_DB_ORM, nil)
  84. return
  85. }
  86. // 3.4 贡献值
  87. contributionValue, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.ContributionCoinId)
  88. if err != nil {
  89. e.OutErr(c, e.ERR_DB_ORM, nil)
  90. return
  91. }
  92. coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db)
  93. coreData, err := coreDataDb.EggEnergyCoreDataGet()
  94. if err != nil {
  95. e.OutErr(c, e.ERR_DB_ORM, nil)
  96. return
  97. }
  98. // 4. 预估蛋蛋能量价值
  99. nowPrice, err := decimal.NewFromString(coreData.NowPrice)
  100. if err != nil {
  101. e.OutErr(c, e.ERR_UNMARSHAL, nil)
  102. return
  103. }
  104. eggEnergyValue := nowPrice.Mul(decimal.NewFromFloat(eggEnergy))
  105. // 5. 查询蛋蛋分
  106. now := time.Now()
  107. esIndexName := es2.GetLatestEffectiveIndexFromAlias(now)
  108. // 构建查询条件
  109. boolQuery := elastic.NewBoolQuery()
  110. boolQuery.Filter(elastic.NewTermQuery("uid", user.Id))
  111. searchResult, err := es.EsClient.Search().
  112. Index(esIndexName).
  113. Query(boolQuery).
  114. Pretty(true).
  115. Do(context.Background())
  116. if err != nil {
  117. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  118. return
  119. }
  120. var results []md.UserEggFlowReqRespList
  121. // 检查是否有结果
  122. if searchResult.Hits.TotalHits.Value != 0 {
  123. // 解析结果
  124. for _, hit := range searchResult.Hits.Hits {
  125. var doc md.UserEggFlowReqRespList
  126. err = json.Unmarshal(hit.Source, &doc)
  127. if err != nil {
  128. e.OutErr(c, e.ERR_DB_ORM, nil)
  129. return
  130. }
  131. results = append(results, doc)
  132. }
  133. }
  134. score := results[0].ScoreValue
  135. resp := md.MemberCenterGetBasicResp{
  136. Nickname: user.Nickname,
  137. LevelName: level.LevelName,
  138. ActiveNum: utils.Float64ToStr(eggPoint),
  139. EggScore: utils.Float64ToStr(score),
  140. EggEnergy: utils.Float64ToStr(eggEnergy),
  141. EggEnergyValue: eggEnergyValue.String(),
  142. ContributionValue: contributionValue.Amount,
  143. Date: "29",
  144. Ratio: "1:1000",
  145. Amount: wallet.Amount,
  146. }
  147. e.OutSuc(c, resp, nil)
  148. return
  149. }