|
- 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"
- enum "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
- 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"
- "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、获取当前用户 蛋蛋能量(可用+结算)、 预估总价值
- 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{
- PersonalTransferTypeList: md.IntegralList{
- IncomeList: []md.TransferTypeNode{
- {
- // 浏览视频
- Value: utils.AnyToString(enum.EggEnergyWatchAdRewardPersonalActiveCoin),
- Name: enum.EggEnergyWatchAdRewardPersonalActiveCoin.String(),
- },
- {
- // 圈层奖励
- Value: utils.AnyToString(enum.EggEnergyWatchAdRewardTeamActiveCoin),
- Name: enum.EggEnergyWatchAdRewardTeamActiveCoin.String(),
- },
- {
- // 兑换到个人蛋蛋能量
- Value: utils.AnyToString(enum.PersonEggGetByEnergyEggPointCoin),
- Name: enum.PersonEggGetByEnergyEggPointCoin.String(),
- },
- {
- // 释放到个人蛋蛋能量
- Value: utils.AnyToString(enum.TeamEggEnergyReleaseToPersonEggEnergy),
- Name: enum.TeamEggEnergyReleaseToPersonEggEnergy.String(),
- },
- {
- // 蛋蛋能量-社区分红
- Value: utils.AnyToString(enum.EggEnergyCommunityDividends),
- Name: enum.EggEnergyCommunityDividends.String(),
- },
- {
- // 星级分红
- Value: utils.AnyToString(enum.SettlementStarLevelDividends),
- Name: enum.SettlementStarLevelDividends.String(),
- },
- },
- ExpendList: []md.TransferTypeNode{
- {
- // 个人蛋蛋能量兑换余额
- Value: utils.AnyToString(enum.EggEnergyToExchangeToAmount),
- Name: enum.EggEnergyToExchangeToAmount.String(),
- },
- },
- },
- TeamTransferTypeList: md.IntegralList{
- IncomeList: []md.TransferTypeNode{
- {
- // 兑换到团队蛋蛋能量
- Value: utils.AnyToString(enum.TeamEggGetByEnergyEggPointCoin),
- Name: enum.TeamEggGetByEnergyEggPointCoin.String(),
- },
- },
- ExpendList: []md.TransferTypeNode{
-
- {
- // 团队蛋蛋能量释放
- Value: utils.AnyToString(enum.TeamEggEnergyReleaseToPersonEggEnergy),
- Name: enum.TeamEggEnergyReleaseToPersonEggEnergy.String(),
- },
- },
- },
- }
-
- 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)
- }
- 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{
- PersonalTransferTypeList: md.IntegralList{
- IncomeList: []md.TransferTypeNode{},
- ExpendList: []md.TransferTypeNode{
- {
- // 个人蛋蛋积分兑换
- Value: utils.AnyToString(enum.EggPointCoinToExchangeToPersonEggEnergy),
- Name: enum.EggPointCoinToExchangeToPersonEggEnergy.String(),
- },
- },
- },
- TeamTransferTypeList: md.IntegralList{
- IncomeList: []md.TransferTypeNode{},
- ExpendList: []md.TransferTypeNode{
- {
- // 团队蛋蛋积分兑换
- Value: utils.AnyToString(enum.EggPointCoinToExchangeToTeamEggEnergy),
- Name: enum.EggPointCoinToExchangeToTeamEggEnergy.String(),
- },
- },
- },
- }
-
- 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.EstimatePerSecondPersonEggEnergyValue)
- 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.EstimatePerSecondPersonEggEnergyValue)
- 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.String(),
- ConsumedEggEnergy: consumedEggEnergy.String(),
- RemainingTime: remainingTime.String(),
- RemainingEggEnergy: remainingEggEnergy.String(),
- BasalRate: basalRate.String(),
- ConsumedEggPoint: eggSignIn.TotalPersonEggPoints,
- EstimatedRevenue: estimatedRevenue.String(),
- 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
- }
- now := time.Now()
- nowStr := now.Format("2006-01-02 15:04:05")
- signInDb := implement.NewEggSignInDb(db.Db)
- exit, signIn, err := signInDb.EggSignInGetOne(nowStr, nowStr, user.Id)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- var signPersonEggEnergy = "0.00"
- var signTeamEggEnergy = "0.00"
- if exit && utils.TimeParseStd(signIn.EndTime).After(now) {
- //获取预估每秒获得蛋蛋能量数
- estimatePerSecondPersonEggEnergyValue, err1 := decimal.NewFromString(signIn.EstimatePerSecondPersonEggEnergyValue)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- signPersonEggEnergy = estimatePerSecondPersonEggEnergyValue.String()
- estimatePerSecondTeamEggEnergyValue, err2 := decimal.NewFromString(signIn.EstimatePerSecondTeamEggEnergyValue)
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- signTeamEggEnergy = estimatePerSecondTeamEggEnergyValue.String()
- }
-
- nowBasalRate := utils.StrToFloat64(signPersonEggEnergy) * 60 * 60 //每小时基础速率
- nowTeamRate := utils.StrToFloat64(signTeamEggEnergy) * 60 * 60 // 每小时团队速率
- 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空格拼接"
- // @Param limit query int true "每页大小"
- // @Param page query int true "页数"
- // @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("limit", "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
-
- row := setting.SeveralRows
- times := setting.SeveralTimes
- var spaceTotalNums float64
- 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),
- })
- spaceTotalNums += maxCount
- }
-
- //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{
- Rows: utils.IntToStr(row),
- Times: utils.IntToStr(times),
- SpaceTotalNums: utils.Float64ToStr(spaceTotalNums),
- SpaceNums: utils.Int64ToStr(hasUserCount),
- SpaceList: list,
- ALotOfNums: utils.Float64ToStr(spaceTotalNums),
- DayNum: utils.IntToStr(setting.SystemPunishReplaceValue),
- }
-
- e.OutSuc(c, resp, nil)
- return
- }
|