|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755 |
- 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、获取当前用户 蛋蛋能量(可用+结算)、 预估总价值
- 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)
- }
- 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.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空格拼接"
- // @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
- }
|