蛋蛋星球-客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

172 行
4.9 KiB

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