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

hdl_member_center.go 5.3 KiB

6 dagen geleden
6 dagen geleden
23 uur geleden
6 dagen geleden
23 uur geleden
23 uur geleden
6 dagen geleden
23 uur geleden
6 dagen geleden
23 uur geleden
6 dagen geleden
6 dagen geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
  11. es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es"
  12. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  13. "encoding/json"
  14. "github.com/gin-gonic/gin"
  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. score := 60.00
  107. now := time.Now()
  108. esIndex := es2.GetLatestEffectiveIndexFromAlias(now)
  109. esIndexName := md2.EggEnergyUserEggScoreEsAlias + "_" + esIndex
  110. results, err := es.FirstDoc(esIndexName, esIndex+"_"+utils.Int64ToStr(user.Id))
  111. if err != nil {
  112. if err.Error() != "elastic: Error 404 (Not Found)" {
  113. e.OutErr(c, e.ERR, err.Error())
  114. return
  115. }
  116. }
  117. //// 构建查询条件
  118. //boolQuery := elastic.NewBoolQuery()
  119. //boolQuery.Filter(elastic.NewTermQuery("uid", user.Id))
  120. //searchResult, err := es.EsClient.Search().
  121. // Index(esIndexName).
  122. // Query(boolQuery).
  123. // Pretty(true).
  124. // Do(context.Background())
  125. //
  126. //if err != nil {
  127. // e.OutErr(c, e.ERR_DB_ORM, err.Error())
  128. // return
  129. //}
  130. //var results []md.UserEggFlowReqRespList
  131. //// 检查是否有结果
  132. //if searchResult.Hits.TotalHits.Value != 0 {
  133. // // 解析结果
  134. // for _, hit := range searchResult.Hits.Hits {
  135. var doc md.UserEggFlowReqRespList
  136. err = json.Unmarshal(results.Source, &doc)
  137. if err != nil {
  138. e.OutErr(c, e.ERR_DB_ORM, nil)
  139. return
  140. }
  141. // results = append(results, doc)
  142. // }
  143. //}
  144. score = doc.ScoreValue
  145. resp := md.MemberCenterGetBasicResp{
  146. Nickname: user.Nickname,
  147. LevelName: level.LevelName,
  148. ActiveNum: utils.Float64ToStr(eggPoint),
  149. EggScore: utils.Float64ToStr(score),
  150. EggEnergy: utils.Float64ToStr(eggEnergy),
  151. EggEnergyValue: eggEnergyValue.String(),
  152. ContributionValue: contributionValue.Amount,
  153. Date: "29",
  154. Ratio: "1:1000",
  155. Amount: wallet.Amount,
  156. Id: utils.Int64ToStr(user.Id),
  157. Phone: user.Phone,
  158. InviteCode: user.SystemInviteCode,
  159. IsBindExtend: "0",
  160. HeadImg: svc.GetOssUrl(user.Avatar),
  161. }
  162. if user.CustomInviteCode != "" {
  163. resp.InviteCode = user.CustomInviteCode
  164. }
  165. if user.ParentUid > 0 {
  166. resp.IsBindExtend = "1"
  167. }
  168. e.OutSuc(c, resp, nil)
  169. return
  170. }