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

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