蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

745 lines
24 KiB

  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. enum "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  11. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  12. "encoding/json"
  13. "fmt"
  14. "github.com/gin-gonic/gin"
  15. "github.com/shopspring/decimal"
  16. "math"
  17. "strings"
  18. "time"
  19. )
  20. // EggEnergyDetails
  21. // @Summary 蛋蛋星球-添加好友-蛋蛋能量明细(获取)
  22. // @Tags 添加好友
  23. // @Description 蛋蛋能量明细(获取)
  24. // @Accept json
  25. // @Produce json
  26. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  27. // @Param req body md.EggEnergyDetailReq true "分页类型必填"
  28. // @Success 200 {object} md.EggEnergyDetailResp "具体数据"
  29. // @Failure 400 {object} md.Response "具体错误"
  30. // @Router /api/v1/addFriend/eggEnergyDetails [POST]
  31. func EggEnergyDetails(c *gin.Context) {
  32. val, exists := c.Get("user")
  33. if !exists {
  34. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  35. return
  36. }
  37. user, ok := val.(*model.User)
  38. if !ok {
  39. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  40. return
  41. }
  42. var req *md.EggEnergyDetailReq
  43. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  44. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  45. return
  46. }
  47. //1、查找 `OneCirclesPublicPlatoonBasicSetting` 基础设置
  48. energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  49. eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  50. "key": "is_open",
  51. "value": 1,
  52. })
  53. if err != nil {
  54. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  55. return
  56. }
  57. var coinID int
  58. isAsc := false
  59. if req.Kind == "1" { // 待结
  60. coinID = eggEnergyBasicSetting.PersonEggEnergyCoinId
  61. } else if req.Kind == "2" { // 可用
  62. coinID = eggEnergyBasicSetting.TeamEggEnergyCoinId
  63. } else {
  64. coinID = 0
  65. }
  66. if req.Asc == "1" {
  67. isAsc = true
  68. }
  69. direction := 0
  70. switch req.Direction {
  71. case "1":
  72. direction = 1
  73. case "2":
  74. direction = 2
  75. default:
  76. direction = 0
  77. }
  78. transferType := 0
  79. switch req.Type {
  80. case "1":
  81. transferType = 1
  82. case "2":
  83. transferType = 2
  84. default:
  85. transferType = 0
  86. }
  87. flowDb := implement.NewUserVirtualCoinFlowDb(db.Db)
  88. flows, total, err := flowDb.UserVirtualCoinFlowFindByCoinAndUser(req.Page, req.Limit, coinID, user.Id, "", "", direction, isAsc, transferType)
  89. if err != nil {
  90. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  91. return
  92. }
  93. var list = make([]map[string]string, 0)
  94. for _, flow := range flows {
  95. var tmp = map[string]string{
  96. "title": flow.Title,
  97. "time": flow.CreateAt,
  98. "type": utils.IntToStr(flow.Direction),
  99. "value": flow.Amount,
  100. "transfer_type": utils.IntToStr(flow.TransferType),
  101. }
  102. list = append(list, tmp)
  103. }
  104. //3、获取当前用户 蛋蛋能量(可用+结算)、 预估总价值
  105. virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db)
  106. personEggEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggEnergyBasicSetting.PersonEggEnergyCoinId)
  107. if err != nil {
  108. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  109. return
  110. }
  111. teamEggEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggEnergyBasicSetting.TeamEggEnergyCoinId)
  112. if err != nil {
  113. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  114. return
  115. }
  116. coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db)
  117. coreData, err := coreDataDb.EggEnergyCoreDataGet()
  118. if err != nil {
  119. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  120. return
  121. }
  122. totalEggEnergy := utils.StrToFloat64(personEggEnergy.Amount) + utils.StrToFloat64(teamEggEnergy.Amount)
  123. totalEggEnergyPrice := totalEggEnergy * utils.StrToFloat64(coreData.NowPrice)
  124. transferTypeList := md.TransferTypeList{
  125. PersonalTransferTypeList: md.IntegralList{
  126. IncomeList: []md.TransferTypeNode{
  127. {
  128. // 浏览视频
  129. Value: utils.AnyToString(enum.EggEnergyWatchAdRewardPersonalActiveCoin),
  130. Name: enum.EggEnergyWatchAdRewardPersonalActiveCoin.String(),
  131. },
  132. {
  133. // 圈层奖励
  134. Value: utils.AnyToString(enum.EggEnergyWatchAdRewardTeamActiveCoin),
  135. Name: enum.EggEnergyWatchAdRewardTeamActiveCoin.String(),
  136. },
  137. {
  138. // 兑换到个人蛋蛋能量
  139. Value: utils.AnyToString(enum.PersonEggGetByEnergyEggPointCoin),
  140. Name: enum.PersonEggGetByEnergyEggPointCoin.String(),
  141. },
  142. {
  143. // 释放到个人蛋蛋能量
  144. Value: utils.AnyToString(enum.TeamEggEnergyReleaseToPersonEggEnergy),
  145. Name: enum.TeamEggEnergyReleaseToPersonEggEnergy.String(),
  146. },
  147. {
  148. // 蛋蛋能量-社区分红
  149. Value: utils.AnyToString(enum.EggEnergyCommunityDividends),
  150. Name: enum.EggEnergyCommunityDividends.String(),
  151. },
  152. {
  153. // 星级分红
  154. Value: utils.AnyToString(enum.SettlementStarLevelDividends),
  155. Name: enum.SettlementStarLevelDividends.String(),
  156. },
  157. },
  158. ExpendList: []md.TransferTypeNode{
  159. {
  160. // 个人蛋蛋能量兑换余额
  161. Value: utils.AnyToString(enum.EggEnergyToExchangeToAmount),
  162. Name: enum.EggEnergyToExchangeToAmount.String(),
  163. },
  164. },
  165. },
  166. TeamTransferTypeList: md.IntegralList{
  167. IncomeList: []md.TransferTypeNode{
  168. {
  169. // 兑换到团队蛋蛋能量
  170. Value: utils.AnyToString(enum.TeamEggGetByEnergyEggPointCoin),
  171. Name: enum.TeamEggGetByEnergyEggPointCoin.String(),
  172. },
  173. },
  174. ExpendList: []md.TransferTypeNode{
  175. {
  176. // 团队蛋蛋能量释放
  177. Value: utils.AnyToString(enum.TeamEggEnergyReleaseToPersonEggEnergy),
  178. Name: enum.TeamEggEnergyReleaseToPersonEggEnergy.String(),
  179. },
  180. },
  181. },
  182. }
  183. resp := md.EggEnergyDetailResp{
  184. PersonEggEnergy: personEggEnergy.Amount,
  185. TeamEggEnergy: teamEggEnergy.Amount,
  186. TotalEggEnergy: utils.Float64ToStr(totalEggEnergy),
  187. TotalEggEnergyPrice: utils.Float64ToStr(totalEggEnergyPrice),
  188. List: list,
  189. TransferTypeList: transferTypeList,
  190. Paginate: md.Paginate{
  191. Limit: req.Limit,
  192. Page: req.Page,
  193. Total: total,
  194. },
  195. }
  196. e.OutSuc(c, resp, nil)
  197. }
  198. // EggPointDetails
  199. // @Summary 蛋蛋星球-添加好友-蛋蛋积分明细(获取)
  200. // @Tags 添加好友
  201. // @Description 蛋蛋积分明细(获取)
  202. // @Accept json
  203. // @Produce json
  204. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  205. // @Param req body md.EggPointDetailsReq true "分页类型必填"
  206. // @Success 200 {object} md.EggPointDetailsResp "具体数据"
  207. // @Failure 400 {object} md.Response "具体错误"
  208. // @Router /api/v1/addFriend/eggPointDetails [POST]
  209. func EggPointDetails(c *gin.Context) {
  210. val, exists := c.Get("user")
  211. if !exists {
  212. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  213. return
  214. }
  215. user, ok := val.(*model.User)
  216. if !ok {
  217. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  218. return
  219. }
  220. var req *md.EggPointDetailsReq
  221. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  222. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  223. return
  224. }
  225. //1、查找 `OneCirclesPublicPlatoonBasicSetting` 基础设置
  226. energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  227. eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  228. "key": "is_open",
  229. "value": 1,
  230. })
  231. if err != nil {
  232. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  233. return
  234. }
  235. var coinID int
  236. isAsc := false
  237. if req.Kind == "1" { // 待结
  238. coinID = eggEnergyBasicSetting.PersonEggPointsCoinId
  239. } else if req.Kind == "2" { // 可用
  240. coinID = eggEnergyBasicSetting.TeamEggPointsCoinId
  241. } else {
  242. coinID = 0
  243. }
  244. if req.Asc == "1" {
  245. isAsc = true
  246. }
  247. direction := 0
  248. switch req.Direction {
  249. case "1":
  250. direction = 1
  251. case "2":
  252. direction = 2
  253. default:
  254. direction = 0
  255. }
  256. transferType := 0
  257. switch req.Type {
  258. case "1":
  259. transferType = 1
  260. case "2":
  261. transferType = 2
  262. default:
  263. transferType = 0
  264. }
  265. flowDb := implement.NewUserVirtualCoinFlowDb(db.Db)
  266. flows, total, err := flowDb.UserVirtualCoinFlowFindByCoinAndUser(req.Page, req.Limit, coinID, user.Id, "", "", direction, isAsc, transferType)
  267. if err != nil {
  268. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  269. return
  270. }
  271. var list = make([]map[string]string, 0)
  272. for _, flow := range flows {
  273. var tmp = map[string]string{
  274. "title": flow.Title,
  275. "time": flow.CreateAt,
  276. "type": utils.IntToStr(flow.Direction),
  277. "value": flow.Amount,
  278. "transfer_type": utils.IntToStr(flow.TransferType),
  279. }
  280. list = append(list, tmp)
  281. }
  282. virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db)
  283. var totalEggPoints float64
  284. personEggPoints, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggEnergyBasicSetting.PersonEggPointsCoinId)
  285. if err != nil {
  286. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  287. return
  288. }
  289. teamEggPoints, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggEnergyBasicSetting.TeamEggPointsCoinId)
  290. if err != nil {
  291. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  292. return
  293. }
  294. totalEggPoints = utils.StrToFloat64(personEggPoints.Amount) + utils.StrToFloat64(teamEggPoints.Amount)
  295. coinDb := implement.NewVirtualCoinDb(db.Db)
  296. coin, err := coinDb.VirtualCoinGetOneByParams(map[string]interface{}{
  297. "key": "id",
  298. "value": eggEnergyBasicSetting.PersonEggPointsCoinId,
  299. })
  300. if err != nil {
  301. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  302. return
  303. }
  304. exchangeRatio, _ := decimal.NewFromString(coin.ExchangeRatio)
  305. totalEggPointsValue := decimal.NewFromFloat(totalEggPoints)
  306. totalEggPointsAmount := totalEggPointsValue.Div(exchangeRatio).String()
  307. transferTypeList := md.TransferTypeList{
  308. PersonalTransferTypeList: md.IntegralList{
  309. IncomeList: []md.TransferTypeNode{},
  310. ExpendList: []md.TransferTypeNode{
  311. {
  312. // 个人蛋蛋积分兑换
  313. Value: utils.AnyToString(enum.EggPointCoinToExchangeToPersonEggEnergy),
  314. Name: enum.EggPointCoinToExchangeToPersonEggEnergy.String(),
  315. },
  316. },
  317. },
  318. TeamTransferTypeList: md.IntegralList{
  319. IncomeList: []md.TransferTypeNode{},
  320. ExpendList: []md.TransferTypeNode{
  321. {
  322. // 团队蛋蛋积分兑换
  323. Value: utils.AnyToString(enum.EggPointCoinToExchangeToTeamEggEnergy),
  324. Name: enum.EggPointCoinToExchangeToTeamEggEnergy.String(),
  325. },
  326. },
  327. },
  328. }
  329. resp := md.EggPointDetailsResp{
  330. PersonEggPoints: personEggPoints.Amount,
  331. TeamEggPoints: teamEggPoints.Amount,
  332. TotalEggPoints: utils.Float64ToStr(totalEggPoints),
  333. TotalEggPointsAmount: totalEggPointsAmount,
  334. List: list,
  335. TransferTypeList: transferTypeList,
  336. Paginate: md.Paginate{
  337. Limit: req.Limit,
  338. Page: req.Page,
  339. Total: total,
  340. },
  341. }
  342. e.OutSuc(c, resp, nil)
  343. }
  344. // BasalRate
  345. // @Summary 蛋蛋星球-添加好友-基础速率(获取)
  346. // @Tags 添加好友
  347. // @Description 基础速率(获取)
  348. // @Accept json
  349. // @Produce json
  350. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  351. // @Success 200 {object} md.BasalRateResp "具体数据"
  352. // @Failure 400 {object} md.Response "具体错误"
  353. // @Router /api/v1/addFriend/basalRate [GET]
  354. func BasalRate(c *gin.Context) {
  355. val, exists := c.Get("user")
  356. if !exists {
  357. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  358. return
  359. }
  360. user, ok := val.(*model.User)
  361. if !ok {
  362. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  363. return
  364. }
  365. now := time.Now()
  366. nowStr := now.Format("2006-01-02 15:04:05")
  367. signInDb := implement.NewEggSignInDb(db.Db)
  368. has, eggSignIn, err := signInDb.EggSignINGetOneByTimeAndUid("", nowStr, user.Id, 0)
  369. if err != nil {
  370. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  371. return
  372. }
  373. if !has {
  374. resp := md.BasalRateResp{
  375. ConsumedTime: "0",
  376. ConsumedEggEnergy: "0",
  377. RemainingTime: "0",
  378. RemainingEggEnergy: "0",
  379. BasalRate: "0",
  380. ConsumedEggPoint: "0",
  381. EstimatedRevenue: "0",
  382. SignCountdown: "00:00:00",
  383. SignTimeSecs: 0,
  384. }
  385. e.OutSuc(c, resp, nil)
  386. return
  387. }
  388. estimatePerSecondEggEnergyValue, err := decimal.NewFromString(eggSignIn.EstimatePerSecondPersonEggEnergyValue)
  389. if err != nil {
  390. e.OutErr(c, e.ERR_UNMARSHAL, err.Error())
  391. return
  392. }
  393. // 消耗时间、已获得收益
  394. consumedTimeSec := now.Unix() - utils.TimeParseStd(eggSignIn.StartTime).Unix()
  395. consumedTime := decimal.NewFromInt(consumedTimeSec).Div(decimal.NewFromInt(60 * 60))
  396. consumedEggEnergy := decimal.NewFromInt(consumedTimeSec).Mul(estimatePerSecondEggEnergyValue)
  397. // 剩余时间、待收益
  398. remainingTimeSec := utils.TimeParseStd(eggSignIn.EndTime).Unix() - now.Unix()
  399. remainingTime := decimal.NewFromInt(remainingTimeSec).Div(decimal.NewFromInt(60 * 60))
  400. remainingEggEnergy := decimal.NewFromInt(remainingTimeSec).Mul(estimatePerSecondEggEnergyValue)
  401. // 预估收益
  402. estimatedRevenue := consumedEggEnergy.Add(remainingEggEnergy)
  403. // 基础速率 / 每小时
  404. basalRateDecimal, err := decimal.NewFromString(eggSignIn.EstimatePerSecondPersonEggEnergyValue)
  405. if err != nil {
  406. e.OutErr(c, e.ERR_UNMARSHAL, err.Error())
  407. return
  408. }
  409. basalRate := basalRateDecimal.Mul(decimal.NewFromInt(60 * 60))
  410. // 收益倒计时
  411. var signCountdown string
  412. var signTimeSecs int
  413. duration := utils.TimeParseStd(eggSignIn.EndTime).Sub(now) // 计算时间差值
  414. if duration > 0 {
  415. hours := duration / time.Hour // 获取小时部分
  416. minutes := duration % time.Hour / time.Minute // 获取分钟部分(先除去小时后再乘以60)
  417. seconds := int64(duration/time.Second) % 60
  418. signCountdown = fmt.Sprintf("%d:%d:%d", hours, minutes, seconds) //收益倒计时
  419. signTimeSecs = int(duration.Seconds())
  420. } else {
  421. signCountdown = fmt.Sprintf("00:00:00")
  422. }
  423. resp := md.BasalRateResp{
  424. ConsumedTime: consumedTime.StringFixed(2),
  425. ConsumedEggEnergy: consumedEggEnergy.String(),
  426. RemainingTime: remainingTime.StringFixed(2),
  427. RemainingEggEnergy: remainingEggEnergy.String(),
  428. BasalRate: basalRate.String(),
  429. ConsumedEggPoint: eggSignIn.TotalPersonEggPoints,
  430. EstimatedRevenue: estimatedRevenue.String(),
  431. SignCountdown: signCountdown,
  432. SignTimeSecs: signTimeSecs,
  433. }
  434. e.OutSuc(c, resp, nil)
  435. }
  436. // TotalRate
  437. // @Summary 蛋蛋星球-添加好友-总速率(获取)
  438. // @Tags 添加好友
  439. // @Description 总速率(获取)
  440. // @Accept json
  441. // @Produce json
  442. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  443. // @Success 200 {object} md.TotalRateResp "具体数据"
  444. // @Failure 400 {object} md.Response "具体错误"
  445. // @Router /api/v1/addFriend/totalRate [GET]
  446. func TotalRate(c *gin.Context) {
  447. val, exists := c.Get("user")
  448. if !exists {
  449. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  450. return
  451. }
  452. user, ok := val.(*model.User)
  453. if !ok {
  454. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  455. return
  456. }
  457. now := time.Now()
  458. signInDb := implement.NewEggSignInDb(db.Db)
  459. nowStr := now.Format("2006-01-02 15:04:05")
  460. exit, signIn, err := signInDb.EggSignINGetOneByTimeAndUid("", nowStr, user.Id, 0)
  461. if err != nil {
  462. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  463. return
  464. }
  465. var signPersonEggEnergy = "0.00"
  466. var signTeamEggEnergy = "0.00"
  467. if exit && utils.TimeParseStd(signIn.EndTime).After(now) {
  468. //获取预估每秒获得蛋蛋能量数
  469. estimatePerSecondPersonEggEnergyValue, err1 := decimal.NewFromString(signIn.EstimatePerSecondPersonEggEnergyValue)
  470. if err1 != nil {
  471. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  472. return
  473. }
  474. signPersonEggEnergy = estimatePerSecondPersonEggEnergyValue.String()
  475. estimatePerSecondTeamEggEnergyValue, err2 := decimal.NewFromString(signIn.EstimatePerSecondTeamEggEnergyValue)
  476. if err2 != nil {
  477. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  478. return
  479. }
  480. signTeamEggEnergy = estimatePerSecondTeamEggEnergyValue.String()
  481. }
  482. nowBasalRate := utils.StrToFloat64(signPersonEggEnergy) * 60 * 60 //每小时基础速率
  483. nowTeamRate := utils.StrToFloat64(signTeamEggEnergy) * 60 * 60 // 每小时团队速率
  484. resp := md.TotalRateResp{
  485. NowBasalRate: utils.Float64ToStr(nowBasalRate),
  486. NowTeamRate: utils.Float64ToStr(nowTeamRate),
  487. ConsumedPersonalEggPoint: signIn.TotalPersonEggPoints,
  488. ConsumedTeamEggPoint: signIn.TotalTeamEggPoints,
  489. NowTotalRate: utils.Float64ToStr(nowTeamRate + nowBasalRate),
  490. }
  491. e.OutSuc(c, resp, nil)
  492. }
  493. // MyFans
  494. // @Summary 蛋蛋星球-添加好友-粉丝团队-我的粉丝-团队加速速率(获取)
  495. // @Tags 添加好友
  496. // @Description 团队加速速率(获取)
  497. // @Accept json
  498. // @Produce json
  499. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  500. // @Success 200 {object} md.MyFansResp "具体数据"
  501. // @Failure 400 {object} md.Response "具体错误"
  502. // @Router /api/v1/addFriend/myFans [GET]
  503. func MyFans(c *gin.Context) {
  504. val, exists := c.Get("user")
  505. if !exists {
  506. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  507. return
  508. }
  509. user, ok := val.(*model.User)
  510. if !ok {
  511. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  512. return
  513. }
  514. // 找出公排中所有关联用户
  515. userRelateDb := implement.NewUserRelateDb(db.Db)
  516. total, err := userRelateDb.UserRelatesCountByParentUid(user.Id, 0)
  517. if err != nil {
  518. e.OutErr(c, e.ERR_DB_ORM, err)
  519. return
  520. }
  521. session := db.Db.NewSession()
  522. defer session.Close()
  523. now := time.Now()
  524. assistanceDb := implement.NewEggEnergyTeamAssistanceDb(db.Db)
  525. assistance, err := assistanceDb.EggEnergyTeamAssistanceGetOneBySession(session, user.Id, now.Format("2006-01-02"))
  526. if err != nil {
  527. e.OutErr(c, e.ERR_DB_ORM, err)
  528. return
  529. }
  530. var nowTeamAssistanceNum int
  531. var nowTeamAssistanceReward string
  532. if assistance != nil {
  533. nowTeamAssistanceNum = assistance.AssistedNum
  534. nowTeamAssistanceReward = assistance.RewardScore
  535. }
  536. resp := md.MyFansResp{
  537. NowTeamUser: total,
  538. NowTeamAssistanceNum: nowTeamAssistanceNum,
  539. NowTeamAssistanceReward: nowTeamAssistanceReward,
  540. }
  541. e.OutSuc(c, resp, nil)
  542. return
  543. }
  544. // MyFansUserList
  545. // @Summary 蛋蛋星球-添加好友-粉丝团队-我的粉丝-在线好友列表(获取)
  546. // @Tags 添加好友
  547. // @Description 在线好友列表(获取)
  548. // @Accept json
  549. // @Produce json
  550. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  551. // @Param limit query int true "每页大小"
  552. // @Param page query int true "页数"
  553. // @Success 200 {object} md.MyFansUserListResp "具体数据"
  554. // @Failure 400 {object} md.Response "具体错误"
  555. // @Router /api/v1/addFriend/myFansUserList [GET]
  556. func MyFansUserList(c *gin.Context) {
  557. page := c.DefaultQuery("page", "1")
  558. limit := c.DefaultQuery("limit", "20")
  559. now := time.Now()
  560. user := svc.GetUser(c)
  561. energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  562. eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  563. "key": "is_open",
  564. "value": 1,
  565. })
  566. if err != nil {
  567. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  568. return
  569. }
  570. var videoRewardSystem *md2.VideoRewardSystemStruct
  571. err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem)
  572. if err != nil {
  573. e.OutErr(c, e.ERR, err.Error())
  574. return
  575. }
  576. var oneRoundDuration = utils.StrToInt(videoRewardSystem.EachRoundHour)
  577. startTime := now.Add(-time.Hour * time.Duration(oneRoundDuration)).Format("2006-01-02 15:04:05")
  578. relateDb := implement.NewUserRelateDb(db.Db)
  579. userRelates, err := relateDb.FindUserRelateByParentUid(user.Id, 1)
  580. if err != nil {
  581. e.OutErr(c, e.ERR, err.Error())
  582. return
  583. }
  584. var userRelatesUids []string
  585. var userSignInMap = map[int64]interface{}{}
  586. var results []map[string]string
  587. if userRelates != nil {
  588. for _, userRelate := range *userRelates {
  589. userRelatesUids = append(userRelatesUids, utils.Int64ToStr(userRelate.Uid))
  590. }
  591. signInDb := implement.NewEggSignInDb(db.Db)
  592. eggSignIns, err1 := signInDb.EggSignInFindByTimeAndParams(startTime, "", 0, map[string]interface{}{
  593. "key": "uid",
  594. "value": userRelatesUids,
  595. })
  596. if err1 != nil {
  597. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  598. return
  599. }
  600. for _, eggSignIn := range eggSignIns {
  601. userSignInMap[eggSignIn.Uid] = *eggSignIn
  602. }
  603. var sql string
  604. sql = "SELECT user.id AS uid, user.avatar AS avatar, user.nickname AS nickname, user_relate.invite_time AS invite_time " +
  605. "FROM `user_relate` " +
  606. "LEFT JOIN `user` ON user_relate.uid = user.id " +
  607. "where user_relate.uid IN(%s) and user_relate.parent_uid = %d"
  608. sql += " ORDER BY user_relate.invite_time DESC LIMIT %d, %d;"
  609. sql = fmt.Sprintf(sql, strings.Join(userRelatesUids, ","), user.Id, (utils.StrToInt64(page)-1)*utils.StrToInt64(limit), utils.StrToInt64(limit))
  610. results, err = db.QueryNativeString(db.Db, sql)
  611. if err != nil {
  612. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  613. return
  614. }
  615. }
  616. scheme, domain := svc.ImageBucket(db.Db)
  617. var data []md.OneLineUserNode
  618. for _, v := range results {
  619. isOnline := false
  620. if userSignInMap[utils.AnyToInt64(v["uid"])] != nil {
  621. isOnline = true
  622. }
  623. tempUrl := svc.ImageFormatWithBucket(scheme, domain, v["avatar"])
  624. data = append(data, md.OneLineUserNode{
  625. IsOnline: isOnline,
  626. AvatarURL: tempUrl,
  627. Nickname: v["nickname"],
  628. InviteTime: v["invite_time"],
  629. })
  630. }
  631. resp := md.MyFansUserListResp{
  632. List: data,
  633. }
  634. e.OutSuc(c, resp, nil)
  635. return
  636. }
  637. // NineDimensionalSpace
  638. // @Summary 蛋蛋星球-添加好友-粉丝团队-九维空间(获取)
  639. // @Tags 添加好友
  640. // @Description 九维空间(获取)
  641. // @Accept json
  642. // @Produce json
  643. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  644. // @Success 200 {object} md.NineDimensionalSpaceResp "具体数据"
  645. // @Failure 400 {object} md.Response "具体错误"
  646. // @Router /api/v1/addFriend/nineDimensionalSpace [GET]
  647. func NineDimensionalSpace(c *gin.Context) {
  648. //1、 查找 `one_circles_public_platoon_basic_setting` 基础设置
  649. settingDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  650. setting, err := settingDb.PublicPlatoonBasicSettingGetOneByParams(map[string]interface{}{
  651. "key": "is_open",
  652. "value": 1,
  653. })
  654. if err != nil {
  655. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  656. return
  657. }
  658. if setting == nil {
  659. e.OutErr(c, e.ERR_NO_DATA, nil)
  660. return
  661. }
  662. val, exists := c.Get("user")
  663. if !exists {
  664. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  665. return
  666. }
  667. user, ok := val.(*model.User)
  668. if !ok {
  669. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  670. return
  671. }
  672. uid := user.Id
  673. row := setting.SeveralRows
  674. times := setting.SeveralTimes
  675. var spaceTotalNums float64
  676. var list []md.SpaceListNode
  677. for i := 1; i <= setting.SeveralRows; i++ {
  678. var tmpSql = fmt.Sprintf("SELECT COUNT(*)AS total FROM `public_platoon_user_relation` WHERE father_uid%d = %d", i, uid)
  679. tmpNativeString, _ := db.QueryNativeString(db.Db, tmpSql)
  680. nowUserCount := utils.StrToInt64(tmpNativeString[0]["total"])
  681. maxCount := math.Pow(float64(setting.SeveralTimes), float64(i))
  682. if nowUserCount > int64(maxCount) {
  683. nowUserCount = int64(maxCount)
  684. }
  685. list = append(list, md.SpaceListNode{
  686. Name: utils.IntToStr(i) + "维",
  687. MaxCount: int(maxCount),
  688. NowCount: int(nowUserCount),
  689. })
  690. spaceTotalNums += maxCount
  691. }
  692. //2、统计当前用户下多少人数
  693. 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)
  694. nativeString1, _ := db.QueryNativeString(db.Db, sql)
  695. hasUserCount := utils.StrToInt64(nativeString1[0]["total"])
  696. resp := md.NineDimensionalSpaceResp{
  697. Rows: utils.IntToStr(row),
  698. Times: utils.IntToStr(times),
  699. SpaceTotalNums: int(spaceTotalNums),
  700. SpaceNums: int(hasUserCount),
  701. SpaceList: list,
  702. ALotOfNums: int(spaceTotalNums),
  703. DayNum: setting.SystemPunishReplaceValue,
  704. }
  705. e.OutSuc(c, resp, nil)
  706. return
  707. }