蛋蛋星球-客户端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

758 líneas
24 KiB

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