package hdl import ( "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" "encoding/json" "fmt" "github.com/gin-gonic/gin" "github.com/shopspring/decimal" "math" "strconv" "strings" "time" ) // EggEnergyDetails // @Summary 蛋蛋星球-添加好友-蛋蛋能量明细(获取) // @Tags 添加好友 // @Description 蛋蛋能量明细(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param req body md.EggEnergyDetailReq true "分页类型必填" // @Success 200 {object} md.EggEnergyDetailResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/addFriend/eggEnergyDetails [POST] func EggEnergyDetails(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 } var req *md.EggEnergyDetailReq if err1 := c.ShouldBindJSON(&req); err1 != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) return } //1、查找 `OneCirclesPublicPlatoonBasicSetting` 基础设置 energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ "key": "is_open", "value": 1, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var coinID int isAsc := false if req.Kind == "1" { // 待结 coinID = eggEnergyBasicSetting.PersonEggEnergyCoinId } else { // 可用 coinID = eggEnergyBasicSetting.TeamEggEnergyCoinId } if req.Asc == "1" { isAsc = true } direction := 0 switch req.Direction { case "1": direction = 1 case "2": direction = 2 default: direction = 0 } transferType := 0 switch req.Type { case "1": transferType = 1 case "2": transferType = 2 default: transferType = 0 } flowDb := implement.NewUserVirtualCoinFlowDb(db.Db) flows, total, err := flowDb.UserVirtualCoinFlowFindByCoinAndUser(req.Page, req.Limit, coinID, user.Id, "", "", direction, isAsc, transferType) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var list = make([]map[string]string, 0) for _, flow := range flows { var tmp = map[string]string{ "title": flow.Title, "time": flow.CreateAt, "type": utils.IntToStr(flow.Direction), "value": flow.Amount, "transfer_type": utils.IntToStr(flow.TransferType), } list = append(list, tmp) } //3、获取当前用户 蛋蛋能量(可用+结算)、 预估总价值 var teamRewardSetting *md2.TeamRewardSettingStruct err = json.Unmarshal([]byte(eggEnergyBasicSetting.DirectPushReward), &teamRewardSetting) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db) personEggEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggEnergyBasicSetting.PersonEggEnergyCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } teamEggEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggEnergyBasicSetting.TeamEggEnergyCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db) coreData, err := coreDataDb.EggEnergyCoreDataGet() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } totalEggEnergy := utils.StrToFloat64(personEggEnergy.Amount) + utils.StrToFloat64(teamEggEnergy.Amount) totalEggEnergyPrice := totalEggEnergy * utils.StrToFloat64(coreData.NowPrice) transferTypeList := md.TransferTypeList{ AvailableIntegralList: md.IntegralList{ IncomeList: []md.TransferTypeNode{ { Value: strconv.Itoa(md3.EggPlantEggEnergySignInSettlementPersonalRewardForUserVirtualCoinFlow), Name: md3.EggPlantEggEnergySignInSettlementPersonalReward, }, { Value: strconv.Itoa(md3.EggPlantBalanceExchangeForEggEnergyForUserVirtualCoinFlow), Name: md3.EggPlantBalanceExchangeForEggEnergy, }, { Value: strconv.Itoa(md3.EggPlantPersonalActiveCoinExchangeEggEnergyForUserVirtualCoinFlow), Name: md3.EggPlantPersonalActiveCoinExchangeEggEnergy, }, { Value: strconv.Itoa(md3.EggPlantSettlementEggEnergyExchangeEggEnergyForUserVirtualCoinFlow), Name: md3.EggPlantSettlementEggEnergyExchangeEggEnergy, }, }, ExpendList: []md.TransferTypeNode{ { Value: strconv.Itoa(md3.EggPlantEggEnergyExchangeForBalanceForUserVirtualCoinFlow), Name: md3.EggPlantEggEnergyExchangeForBalance, }, }, }, SettlementIntegralList: md.IntegralList{ IncomeList: []md.TransferTypeNode{ { Value: strconv.Itoa(md3.EggPlantEggEnergySignInSettlementTeamRewardForUserVirtualCoinFlow), Name: md3.EggPlantEggEnergySignInSettlementTeamReward, }, { Value: strconv.Itoa(md3.EggPlantTeamActiveCoinExchangeEggEnergyForUserVirtualCoinFlow), Name: md3.EggPlantTeamActiveCoinExchangeEggEnergy, }, { Value: strconv.Itoa(md3.EggPlantSettlementStarLevelDividendsForUserVirtualCoinFlow), Name: md3.EggPlantSettlementStarLevelDividends, }, }, ExpendList: []md.TransferTypeNode{ { Value: strconv.Itoa(md3.EggPlantSettlementEggEnergyExchangeTobeEggEnergyForUserVirtualCoinFlow), Name: md3.EggPlantSettlementEggEnergyExchangeEggEnergy, }, }, }, } resp := md.EggEnergyDetailResp{ PersonEggEnergy: personEggEnergy.Amount, TeamEggEnergy: teamEggEnergy.Amount, TotalEggEnergy: utils.Float64ToStr(totalEggEnergy), TotalEggEnergyPrice: utils.Float64ToStr(totalEggEnergyPrice), List: list, TransferTypeList: transferTypeList, Paginate: md.Paginate{ Limit: req.Limit, Page: req.Page, Total: total, }, } e.OutSuc(c, resp, nil) } // EggPointDetails // @Summary 蛋蛋星球-添加好友-蛋蛋积分明细(获取) // @Tags 添加好友 // @Description 蛋蛋积分明细(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param req body md.EggPointDetailsReq true "分页类型必填" // @Success 200 {object} md.EggPointDetailsResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/addFriend/eggPointDetails [POST] func EggPointDetails(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 } var req *md.EggPointDetailsReq if err1 := c.ShouldBindJSON(&req); err1 != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) return } //1、查找 `OneCirclesPublicPlatoonBasicSetting` 基础设置 energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ "key": "is_open", "value": 1, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var coinID int isAsc := false if req.Kind == "1" { // 待结 coinID = eggEnergyBasicSetting.PersonEggPointsCoinId } else { // 可用 coinID = eggEnergyBasicSetting.TeamEggPointsCoinId } if req.Asc == "1" { isAsc = true } direction := 0 switch req.Direction { case "1": direction = 1 case "2": direction = 2 default: direction = 0 } transferType := 0 switch req.Type { case "1": transferType = 1 case "2": transferType = 2 default: transferType = 0 } flowDb := implement.NewUserVirtualCoinFlowDb(db.Db) flows, total, err := flowDb.UserVirtualCoinFlowFindByCoinAndUser(req.Page, req.Limit, coinID, user.Id, "", "", direction, isAsc, transferType) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var list = make([]map[string]string, 0) for _, flow := range flows { var tmp = map[string]string{ "title": flow.Title, "time": flow.CreateAt, "type": utils.IntToStr(flow.Direction), "value": flow.Amount, "transfer_type": utils.IntToStr(flow.TransferType), } list = append(list, tmp) } var teamRewardSetting *md2.TeamRewardSettingStruct err = json.Unmarshal([]byte(eggEnergyBasicSetting.DirectPushReward), &teamRewardSetting) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db) var totalEggPoints float64 personEggPoints, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggEnergyBasicSetting.PersonEggEnergyCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } teamEggPoints, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggEnergyBasicSetting.TeamEggEnergyCoinId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } totalEggPoints = utils.StrToFloat64(personEggPoints.Amount) + utils.StrToFloat64(teamEggPoints.Amount) coinDb := implement.NewVirtualCoinDb(db.Db) coin, err := coinDb.VirtualCoinGetOneByParams(map[string]interface{}{ "key": "id", "value": eggEnergyBasicSetting.PersonEggPointsCoinId, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } exchangeRatio, _ := decimal.NewFromString(coin.ExchangeRatio) totalEggPointsValue := decimal.NewFromFloat(totalEggPoints) totalEggPointsAmount := totalEggPointsValue.Div(exchangeRatio).String() transferTypeList := md.TransferTypeList{ AvailableIntegralList: md.IntegralList{ IncomeList: []md.TransferTypeNode{ { Value: strconv.Itoa(md3.EggPlantWatchAdRewardPersonalActiveCoinForUserVirtualCoinFlow), Name: md3.EggPlantWatchAdRewardPersonalActiveCoin, }, { Value: strconv.Itoa(md3.EggPlantConsumeOrdersGiveEggEnergyToPersonForUserVirtualCoinFlow), Name: md3.EggPlantConsumeOrdersGiveEggEnergyForPerson, }, }, ExpendList: []md.TransferTypeNode{ { Value: strconv.Itoa(md3.EggPlantPersonalActiveCoinExchangeToBeEggEnergyForUserVirtualCoinFlow), Name: md3.EggPlantPersonalActiveCoinExchangeToBeEggEnergy, }, }, }, SettlementIntegralList: md.IntegralList{ IncomeList: []md.TransferTypeNode{ { Value: strconv.Itoa(md3.EggPlantWatchAdRewardTeamActiveCoinForUserVirtualCoinFlow), Name: md3.EggPlantWatchAdRewardTeamActiveCoin, }, { Value: strconv.Itoa(md3.EggPlantConsumeOrdersGiveEggEnergyToTeamForUserVirtualCoinFlow), Name: md3.EggPlantConsumeOrdersGiveEggEnergyForTeam, }, }, ExpendList: []md.TransferTypeNode{ { Value: strconv.Itoa(md3.EggPlantTeamActiveCoinExchangeToBeEggEnergyForUserVirtualCoinFlow), Name: md3.EggPlantTeamActiveCoinExchangeToBeEggEnergy, }, }, }, } resp := md.EggPointDetailsResp{ PersonEggPoints: personEggPoints.Amount, TeamEggPoints: teamEggPoints.Amount, TotalEggPoints: utils.Float64ToStr(totalEggPoints), TotalEggPointsAmount: totalEggPointsAmount, List: list, TransferTypeList: transferTypeList, Paginate: md.Paginate{ Limit: req.Limit, Page: req.Page, Total: total, }, } e.OutSuc(c, resp, nil) } // BasalRate // @Summary 蛋蛋星球-添加好友-基础速率(获取) // @Tags 添加好友 // @Description 基础速率(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.BasalRateResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/addFriend/basalRate [GET] func BasalRate(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 } energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ "key": "is_open", "value": 1, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } coinID := eggEnergyBasicSetting.PersonEggEnergyCoinId coinDb := implement.NewVirtualCoinDb(db.Db) coin, err := coinDb.VirtualCoinGetOneByParams(map[string]interface{}{ "key": "id", "value": coinID, }) now := time.Now() nowStr := now.Format("2006-01-02 15:04:05") signInDb := implement.NewEggSignInDb(db.Db) has, eggSignIn, err := signInDb.EggSignINGetOneByTimeAndUid(nowStr, nowStr, user.Id, 0) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if !has { resp := md.BasalRateResp{ ConsumedTime: "", ConsumedEggEnergy: "", RemainingTime: "", RemainingEggEnergy: "", BasalRate: "", ConsumedEggPoint: "", EstimatedRevenue: "", SignCountdown: "0000:00:00", } e.OutSuc(c, resp, nil) return } ratio, err := decimal.NewFromString(coin.ExchangeRatio) if err != nil { e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) return } estimatePerSecondEggEnergyValue, err := decimal.NewFromString(eggSignIn.EstimatePerSecondEggEnergyValue) if err != nil { e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) return } // 消耗时间、已获得收益 consumedTimeSec := now.Unix() - utils.TimeParseStd(eggSignIn.StartTime).Unix() consumedTime := decimal.NewFromInt(consumedTimeSec).Div(decimal.NewFromInt(60 * 60)) consumedEggEnergy := decimal.NewFromInt(consumedTimeSec).Mul(estimatePerSecondEggEnergyValue) consumedAmount := consumedEggEnergy.Div(ratio) // 剩余时间、待收益 remainingTimeSec := utils.TimeParseStd(eggSignIn.EndTime).Unix() - now.Unix() remainingTime := decimal.NewFromInt(remainingTimeSec).Div(decimal.NewFromInt(60 * 60)) remainingEggEnergy := decimal.NewFromInt(remainingTimeSec).Mul(estimatePerSecondEggEnergyValue) remainingAmount := remainingEggEnergy.Div(ratio) // 预估收益 estimatedRevenue := consumedAmount.Add(remainingAmount) // 基础速率 / 每小时 basalRateDecimal, err := decimal.NewFromString(eggSignIn.EstimatePerSecondEggEnergyValue) if err != nil { e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) return } basalRate := basalRateDecimal.Mul(decimal.NewFromInt(60 * 60)) // 收益倒计时 duration := utils.TimeParseStd(eggSignIn.EndTime).Sub(now) // 计算时间差值 hours := duration / time.Hour // 获取小时部分 minutes := duration % time.Hour / time.Minute // 获取分钟部分(先除去小时后再乘以60) seconds := int64(duration/time.Second) % 60 signCountdown := fmt.Sprintf("%d:%d:%d", hours, minutes, seconds) //收益倒计时 resp := md.BasalRateResp{ ConsumedTime: consumedTime.StringFixed(2), ConsumedEggEnergy: consumedEggEnergy.StringFixed(2), RemainingTime: remainingTime.StringFixed(2), RemainingEggEnergy: remainingEggEnergy.StringFixed(2), BasalRate: basalRate.StringFixed(2), ConsumedEggPoint: eggSignIn.TotalPersonEggPoints, EstimatedRevenue: estimatedRevenue.StringFixed(2), SignCountdown: signCountdown, } e.OutSuc(c, resp, nil) } // TotalRate // @Summary 蛋蛋星球-添加好友-总速率(获取) // @Tags 添加好友 // @Description 总速率(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.TotalRateResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/addFriend/totalRate [GET] func TotalRate(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 } energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ "key": "is_open", "value": 1, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var teamRewardSetting *md2.TeamRewardSettingStruct err = json.Unmarshal([]byte(eggEnergyBasicSetting.DirectPushReward), &teamRewardSetting) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } now := time.Now() signInDb := implement.NewEggSignInDb(db.Db) // 计算用户是否在团队收益时间段内签到 var oneRoundDuration = utils.StrToInt(teamRewardSetting.OneRoundDuration) startTime := now.Add(-time.Hour * time.Duration(oneRoundDuration)).Format("2006-01-02 15:04:05") exit, signIn, err := signInDb.EggSignInGetOne(startTime, now.Format("2006-01-02 15:04:05"), user.Id) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var signEggEnergy = "0.00" if exit && utils.TimeParseStd(signIn.EndTime).After(now) { //获取预估每秒获得蛋蛋能量数 estimatePerSecondEggEnergyValue, err1 := decimal.NewFromString(signIn.EstimatePerSecondEggEnergyValue) if err1 != nil { e.OutErr(c, e.ERR, err1.Error()) return } signEggEnergy = estimatePerSecondEggEnergyValue.String() } nowBasalRate := utils.StrToFloat64(signEggEnergy) * 60 * 60 //每小时基础速率 var estimateLevel int nowBasalRateValue := decimal.NewFromFloat(nowBasalRate) for { estimateLevel++ rewardDecrementValue := utils.StrToFloat64(teamRewardSetting.RewardDecrementValue) / 100 tmpRewardBase := decimal.NewFromFloat(math.Pow(rewardDecrementValue, float64(estimateLevel))) tmpReward := nowBasalRateValue.Mul(tmpRewardBase) rewardEndValue, _ := decimal.NewFromString(teamRewardSetting.RewardEndValue) if !tmpReward.GreaterThanOrEqual(rewardEndValue) { estimateLevel-- break } if estimateLevel == 99 { e.OutErr(c, e.ERR, "奖励结束值设置有误") return } } relateDb := implement.NewUserRelateDb(db.Db) userRelates, err := relateDb.FindUserRelateByParentUid(user.Id, estimateLevel) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } var userRelatesUids []string var userRelatesMap = map[int64]model.UserRelate{} if userRelates != nil { for _, userRelate := range *userRelates { userRelatesUids = append(userRelatesUids, utils.Int64ToStr(userRelate.Uid)) userRelatesMap[userRelate.Uid] = userRelate } } var eggSignIns []*model.EggSignIn if len(userRelatesUids) > 0 { eggSignIns, err = signInDb.EggSignInFindByParams(map[string]interface{}{ "key": "uid", "value": userRelatesUids, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } } var nowTeamRate float64 //每小时基础速率 for _, vv := range eggSignIns { rewardDecrementValue := utils.StrToFloat64(teamRewardSetting.RewardDecrementValue) / 100 tmpRewardBase := decimal.NewFromFloat(math.Pow(rewardDecrementValue, float64(userRelatesMap[vv.Uid].Level))) tmpReward := nowBasalRateValue.Mul(tmpRewardBase) rewardEndValue, _ := decimal.NewFromString(teamRewardSetting.RewardEndValue) if tmpReward.GreaterThanOrEqual(rewardEndValue) { tmpRewardValue, _ := tmpReward.Float64() nowTeamRate += tmpRewardValue } } resp := md.TotalRateResp{ NowBasalRate: utils.Float64ToStr(nowBasalRate), NowTeamRate: utils.Float64ToStr(nowTeamRate), ConsumedPersonalEggPoint: signIn.TotalPersonEggPoints, ConsumedTeamEggPoint: signIn.TotalTeamEggPoints, NowTotalRate: utils.Float64ToStr(nowTeamRate + nowBasalRate), } e.OutSuc(c, resp, nil) } // MyFans // @Summary 蛋蛋星球-添加好友-粉丝团队-我的粉丝-团队加速速率(获取) // @Tags 添加好友 // @Description 团队加速速率(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.MyFansResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/addFriend/myFans [GET] func MyFans(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 } // 找出公排中所有关联用户 userRelateDb := implement.NewUserRelateDb(db.Db) total, err := userRelateDb.UserRelatesCountByParentUid(user.Id, 0) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err) return } session := db.Db.NewSession() defer session.Close() now := time.Now() assistanceDb := implement.NewEggEnergyTeamAssistanceDb(db.Db) assistance, err := assistanceDb.EggEnergyTeamAssistanceGetOneBySession(session, user.Id, now.Format("2006-01-02")) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err) return } var nowTeamAssistanceNum int var nowTeamAssistanceReward string if assistance != nil { nowTeamAssistanceNum = assistance.AssistedNum nowTeamAssistanceReward = assistance.RewardScore } resp := md.MyFansResp{ NowTeamUser: total, NowTeamAssistanceNum: nowTeamAssistanceNum, NowTeamAssistanceReward: nowTeamAssistanceReward, } e.OutSuc(c, resp, nil) return } // MyFansUserList // @Summary 蛋蛋星球-添加好友-粉丝团队-我的粉丝-在线好友列表(获取) // @Tags 添加好友 // @Description 在线好友列表(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.MyFansUserListResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/addFriend/myFansUserList [GET] func MyFansUserList(c *gin.Context) { page := c.DefaultQuery("page", "") limit := c.DefaultQuery("page_size", "20") now := time.Now() 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 } energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ "key": "is_open", "value": 1, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var teamRewardSetting *md2.TeamRewardSettingStruct err = json.Unmarshal([]byte(eggEnergyBasicSetting.DirectPushReward), &teamRewardSetting) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } var oneRoundDuration = utils.StrToInt(teamRewardSetting.OneRoundDuration) startTime := now.Add(-time.Hour * time.Duration(oneRoundDuration)).Format("2006-01-02 15:04:05") relateDb := implement.NewUserRelateDb(db.Db) userRelates, err := relateDb.FindUserRelateByParentUid(user.Id, 1) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } var userRelatesUids []string var userSignInMap = map[int64]interface{}{} var results []map[string]string if userRelates != nil { for _, userRelate := range *userRelates { userRelatesUids = append(userRelatesUids, utils.Int64ToStr(userRelate.Uid)) } signInDb := implement.NewEggSignInDb(db.Db) eggSignIns, err1 := signInDb.EggSignInFindByTimeAndParams(startTime, "", 0, map[string]interface{}{ "key": "uid", "value": userRelatesUids, }) if err1 != nil { e.OutErr(c, e.ERR_DB_ORM, err1.Error()) return } for _, eggSignIn := range eggSignIns { userSignInMap[eggSignIn.Uid] = *eggSignIn } var sql string sql = "SELECT user.id AS uid, user.avatar AS avatar, user.nickname AS nickname, user_relate.invite_time AS invite_time " + "FROM `user_relate` " + "LEFT JOIN `user` ON user_relate.uid = user.uid " + "where user_relate.uid IN(%s)" sql += " ORDER BY user_relate.invite_time DESC LIMIT %d, %d;" sql = fmt.Sprintf(sql, strings.Join(userRelatesUids, ","), (utils.StrToInt64(page)-1)*utils.StrToInt64(limit), utils.StrToInt64(limit)) results, err = db.QueryNativeString(db.Db, sql) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } } var data []md.OneLineUserNode for _, v := range results { isOnline := false if userSignInMap[utils.AnyToInt64(v["uid"])] != nil { isOnline = true } data = append(data, md.OneLineUserNode{ IsOnline: isOnline, AvatarURL: v["avatar_url"], Nickname: v["nickname"], InviteTime: v["invite_time"], }) } resp := md.MyFansUserListResp{ List: data, } e.OutSuc(c, resp, nil) return } // NineDimensionalSpace // @Summary 蛋蛋星球-添加好友-粉丝团队-九维空间(获取) // @Tags 添加好友 // @Description 九维空间(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.NineDimensionalSpaceResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/addFriend/nineDimensionalSpace [GET] func NineDimensionalSpace(c *gin.Context) { //1、 查找 `one_circles_public_platoon_basic_setting` 基础设置 settingDb := implement.NewPublicPlatoonBasicSettingDb(db.Db) setting, err := settingDb.PublicPlatoonBasicSettingGetOneByParams(map[string]interface{}{ "key": "is_open", "value": 1, }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if setting == nil { e.OutErr(c, e.ERR_NO_DATA, nil) return } 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 } uid := user.Id var list []md.SpaceListNode for i := 1; i <= setting.SeveralRows; i++ { var tmpSql = fmt.Sprintf("SELECT COUNT(*)AS total FROM `public_platoon_user_relation` WHERE father_uid%d = %d", i, uid) tmpNativeString, _ := db.QueryNativeString(db.Db, tmpSql) nowUserCount := utils.StrToInt64(tmpNativeString[0]["total"]) maxCount := math.Pow(float64(setting.SeveralTimes), float64(i)) if nowUserCount > int64(maxCount) { nowUserCount = int64(maxCount) } list = append(list, md.SpaceListNode{ Name: utils.IntToStr(i) + "维", MaxCount: utils.Float64ToStr(maxCount), NowCount: utils.Int64ToStr(nowUserCount), }) } //2、统计当前用户下多少人数 sql := fmt.Sprintf("SELECT COUNT(*)AS total FROM `public_platoon_user_relation` WHERE father_uid1 = %d OR father_uid2= %d OR father_uid3= %d OR father_uid4= %d OR father_uid5= %d OR father_uid6= %d OR father_uid7= %d OR father_uid8= %d OR father_uid9= %d", uid, uid, uid, uid, uid, uid, uid, uid, uid) nativeString1, _ := db.QueryNativeString(db.Db, sql) hasUserCount := utils.StrToInt64(nativeString1[0]["total"]) resp := md.NineDimensionalSpaceResp{ SpaceTotalNums: "29523", SpaceNums: utils.Int64ToStr(hasUserCount), SpaceList: list, ALotOfNums: "29523", } e.OutSuc(c, resp, nil) return }