蛋蛋星球-客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

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