|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799 |
- 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"
- 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 if req.Kind == "2" { // 可用
- coinID = eggEnergyBasicSetting.TeamEggEnergyCoinId
- } else {
- coinID = 0
- }
- 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
- }
-
- now := time.Now()
- signInDb := implement.NewEggSignInDb(db.Db)
- nowStr := now.Format("2006-01-02 15:04:05")
- has, signIn, err := signInDb.EggSignINGetOneByTimeAndUid("", nowStr, user.Id, 0)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- var estimatePersonEggEnergyValue decimal.Decimal
- var estimateTeamEggEnergyValue decimal.Decimal
- if has && utils.TimeParseStd(signIn.EndTime).After(now) {
- //获取预估每秒获得蛋蛋能量数
- estimatePerSecondPersonEggEnergyValue, err1 := decimal.NewFromString(signIn.EstimatePerSecondPersonEggEnergyValue)
- if err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
- estimatePerSecondTeamEggEnergyValue, err1 := decimal.NewFromString(signIn.EstimatePerSecondTeamEggEnergyValue)
- if err1 != nil {
- e.OutErr(c, e.ERR, err1.Error())
- return
- }
-
- //3.2.2 计算预估获得的蛋蛋能量数
- estimateTimeSec := now.Unix() - utils.TimeParseStd(signIn.StartTime).Unix()
- estimatePersonEggEnergyValue = decimal.NewFromInt(estimateTimeSec).Mul(estimatePerSecondPersonEggEnergyValue)
- estimateTeamEggEnergyValue = decimal.NewFromInt(estimateTimeSec).Mul(estimatePerSecondTeamEggEnergyValue)
- }
- personEggEnergyValue, _ := decimal.NewFromString(personEggEnergy.Amount)
- teamEggEnergyValue, _ := decimal.NewFromString(teamEggEnergy.Amount)
-
- totalEggEnergy, _ := personEggEnergyValue.Add(teamEggEnergyValue).Add(estimatePersonEggEnergyValue).Add(estimateTeamEggEnergyValue).Float64()
- 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 if req.Kind == "2" { // 可用
- coinID = eggEnergyBasicSetting.TeamEggPointsCoinId
- } else {
- coinID = 0
- }
- 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.PersonEggPointsCoinId)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- teamEggPoints, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggEnergyBasicSetting.TeamEggPointsCoinId)
- 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, user.Id, 0)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if !has {
- resp := md.BasalRateResp{
- ConsumedTime: "0",
- ConsumedEggEnergy: "0",
- RemainingTime: "0",
- RemainingEggEnergy: "0",
- BasalRate: "0",
- ConsumedEggPoint: "0",
- EstimatedRevenue: "0",
- SignCountdown: "00:00:00",
- SignTimeSecs: 0,
- }
- 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))
- // 收益倒计时
- var signCountdown string
- var signTimeSecs int
- duration := utils.TimeParseStd(eggSignIn.EndTime).Sub(now) // 计算时间差值
- if duration > 0 {
- 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) //收益倒计时
- signTimeSecs = int(duration.Seconds())
-
- } else {
- signCountdown = fmt.Sprintf("00:00:00")
- }
-
- resp := md.BasalRateResp{
- ConsumedTime: consumedTime.StringFixed(2),
- ConsumedEggEnergy: consumedEggEnergy.String(),
- RemainingTime: remainingTime.StringFixed(2),
- RemainingEggEnergy: remainingEggEnergy.String(),
- BasalRate: basalRate.String(),
- ConsumedEggPoint: eggSignIn.TotalPersonEggPoints,
- EstimatedRevenue: estimatedRevenue.String(),
- SignCountdown: signCountdown,
- SignTimeSecs: signTimeSecs,
- }
- 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()
- signInDb := implement.NewEggSignInDb(db.Db)
- nowStr := now.Format("2006-01-02 15:04:05")
- exit, signIn, err := signInDb.EggSignINGetOneByTimeAndUid("", nowStr, user.Id, 0)
- 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", "1")
- limit := c.DefaultQuery("limit", "20")
-
- now := time.Now()
- user := svc.GetUser(c)
-
- 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 videoRewardSystem *md2.VideoRewardSystemStruct
- err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- var oneRoundDuration = utils.StrToInt(videoRewardSystem.EachRoundHour)
- 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.id " +
- "where user_relate.uid IN(%s) and user_relate.parent_uid = %d"
- sql += " ORDER BY user_relate.invite_time DESC LIMIT %d, %d;"
- sql = fmt.Sprintf(sql, strings.Join(userRelatesUids, ","), user.Id, (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
- }
- }
-
- scheme, domain := svc.ImageBucket(db.Db)
- var data []md.OneLineUserNode
- for _, v := range results {
- isOnline := false
- if userSignInMap[utils.AnyToInt64(v["uid"])] != nil {
- isOnline = true
- }
- tempUrl := svc.ImageFormatWithBucket(scheme, domain, v["avatar"])
- data = append(data, md.OneLineUserNode{
- IsOnline: isOnline,
- AvatarURL: tempUrl,
- 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: int(maxCount),
- NowCount: int(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: int(spaceTotalNums),
- SpaceNums: int(hasUserCount),
- SpaceList: list,
- ALotOfNums: int(spaceTotalNums),
- DayNum: setting.SystemPunishReplaceValue,
- }
-
- e.OutSuc(c, resp, nil)
- return
- }
|