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

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