package hdl import ( "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/svc" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" "encoding/json" "fmt" "github.com/gin-gonic/gin" "github.com/olivere/elastic/v7" "github.com/shopspring/decimal" "time" ) // MemberCenterGetBasic // @Summary 蛋蛋星球-会员中心-基础数据(获取) // @Tags 会员中心 // @Description 基础数据(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.MemberCenterGetBasicResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/memberCenter/getBasic [GET] func MemberCenterGetBasic(c *gin.Context) { val, exists := c.Get("user") if !exists { e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) return } user, ok := val.(*model.User) if !ok { e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) return } // 1. 获取会员等级名称 userLevelDb := implement.NewUserLevelDb(db.Db) level, err := userLevelDb.UserLevelByID(user.Level) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } // 2. 获取基础设置 settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) setting, err := settingDb.EggEnergyBasicSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } // 3. 查询余额 virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db) // 3.1 活跃积分(蛋蛋积分 = 团队 + 个人) eggPersonalPoint, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.PersonEggPointsCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } eggTeamPoint, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.TeamEggPointsCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } eggPoint := utils.StrToFloat64(eggPersonalPoint.Amount) + utils.StrToFloat64(eggTeamPoint.Amount) // 3.2 蛋蛋能量 (个人 + 团队) eggPersonalEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.PersonEggEnergyCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } eggTeamEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.TeamEggEnergyCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } eggEnergy := utils.StrToFloat64(eggPersonalEnergy.Amount) + utils.StrToFloat64(eggTeamEnergy.Amount) // 3.3 钱包余额 walletDb := implement.NewUserWalletDb(db.Db) wallet, err := walletDb.GetUserVirtualWallet(user.Id) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } // 3.4 贡献值 contributionValue, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.ContributionCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db) coreData, err := coreDataDb.EggEnergyCoreDataGet() if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } // 4. 预估蛋蛋能量价值 nowPrice, err := decimal.NewFromString(coreData.NowPrice) if err != nil { e.OutErr(c, e.ERR_UNMARSHAL, nil) return } eggEnergyValue := nowPrice.Mul(decimal.NewFromFloat(eggEnergy)) // 5. 查询蛋蛋分 score := 60.00 now := time.Now() esIndex := es2.GetLatestEffectiveIndexFromAlias(now) esIndexName := md2.EggEnergyUserEggScoreEsAlias + "_" + esIndex results, err := es.FirstDoc(esIndexName, esIndex+"_"+utils.Int64ToStr(user.Id)) if err != nil { if !elastic.IsNotFound(err) { e.OutErr(c, e.ERR, err.Error()) return } } //// 构建查询条件 //boolQuery := elastic.NewBoolQuery() //boolQuery.Filter(elastic.NewTermQuery("uid", user.Id)) //searchResult, err := es.EsClient.Search(). // Index(esIndexName). // Query(boolQuery). // Pretty(true). // Do(context.Background()) // //if err != nil { // e.OutErr(c, e.ERR_DB_ORM, err.Error()) // return //} //var results []md.UserEggFlowReqRespList //// 检查是否有结果 //if searchResult.Hits.TotalHits.Value != 0 { // // 解析结果 // for _, hit := range searchResult.Hits.Hits { if !elastic.IsNotFound(err) { var doc md.UserEggFlowReqRespList err = json.Unmarshal(results.Source, &doc) if err != nil { e.OutErr(c, e.ERR_DB_ORM, nil) return } // results = append(results, doc) // } //} score = doc.ScoreValue } ratio := decimal.NewFromInt(1).Div(nowPrice).StringFixed(16) ratioStr := fmt.Sprintf("%s:1", ratio) resp := md.MemberCenterGetBasicResp{ Nickname: user.Nickname, LevelName: level.LevelName, ActiveNum: utils.Float64ToStr(eggPoint), EggScore: utils.Float64ToStr(score), EggEnergy: utils.Float64ToStr(eggEnergy), EggEnergyValue: eggEnergyValue.String(), ContributionValue: contributionValue.Amount, Date: "25", Ratio: ratioStr, Amount: wallet.Amount, Id: utils.Int64ToStr(user.Id), Phone: user.Phone, InviteCode: user.SystemInviteCode, IsBindExtend: "0", IsRealName: "0", HeadImg: svc.GetOssUrl(user.Avatar), } if user.CustomInviteCode != "" { resp.InviteCode = user.CustomInviteCode } if user.ParentUid > 0 { resp.IsBindExtend = "1" } resp.IsRealName = svc.CheckRealName(user.Id) e.OutSuc(c, resp, nil) return }