蛋蛋星球-客户端
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.
 
 
 
 
 

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