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

204 lines
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. // todo 解除注释
  138. if !elastic.IsNotFound(err) {
  139. var doc md.UserEggFlowReqRespList
  140. err = json.Unmarshal(results.Source, &doc)
  141. if err != nil {
  142. e.OutErr(c, e.ERR_DB_ORM, nil)
  143. return
  144. }
  145. // results = append(results, doc)
  146. // }
  147. //}
  148. score = doc.ScoreValue
  149. }
  150. ratio := decimal.NewFromInt(1).Div(nowPrice).StringFixed(16)
  151. ratioStr := fmt.Sprintf("%s:1", ratio)
  152. contributionValueDecimal, err := decimal.NewFromString(contributionValue.Amount)
  153. if err != nil {
  154. e.OutErr(c, e.ERR_UNMARSHAL, nil)
  155. return
  156. }
  157. resp := md.MemberCenterGetBasicResp{
  158. Nickname: user.Nickname,
  159. LevelName: level.LevelName,
  160. ActiveNum: utils.Float64ToStr(eggPoint),
  161. EggScore: utils.Float64ToStr(score),
  162. EggEnergy: utils.Float64ToStr(eggEnergy),
  163. EggEnergyValue: eggEnergyValue.String(),
  164. ContributionValue: contributionValueDecimal.StringFixed(0),
  165. Date: "25",
  166. WechatAccount: user.WechatAccount,
  167. Ratio: ratioStr,
  168. Amount: wallet.Amount,
  169. Id: utils.Int64ToStr(user.Id),
  170. Phone: user.Phone,
  171. InviteCode: user.SystemInviteCode,
  172. IsBindExtend: "0",
  173. IsRealName: "0",
  174. HeadImg: svc.GetOssUrl(user.Avatar),
  175. }
  176. if user.CustomInviteCode != "" {
  177. resp.InviteCode = user.CustomInviteCode
  178. }
  179. if user.ParentUid > 0 {
  180. resp.IsBindExtend = "1"
  181. }
  182. //创始人不用弹出绑定邀请码
  183. publicPlatoonBasicDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  184. publicPlatoonBasic, _ := publicPlatoonBasicDb.PublicPlatoonBasicSettingGetOne()
  185. if publicPlatoonBasic != nil && int(user.Id) == publicPlatoonBasic.OriginatorUid {
  186. resp.IsBindExtend = "1"
  187. }
  188. resp.IsRealName = svc.CheckRealName(user.Id)
  189. fmt.Println(utils.SerializeStr(resp))
  190. e.OutSuc(c, resp, nil)
  191. return
  192. }