蛋蛋星球-客户端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

781 righe
25 KiB

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