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

763 lines
24 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. nowStr := now.Format("2006-01-02 15:04:05")
  469. signInDb := implement.NewEggSignInDb(db.Db)
  470. exit, signIn, err := signInDb.EggSignInGetOne(nowStr, nowStr, user.Id)
  471. if err != nil {
  472. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  473. return
  474. }
  475. var signPersonEggEnergy = "0.00"
  476. var signTeamEggEnergy = "0.00"
  477. if exit && utils.TimeParseStd(signIn.EndTime).After(now) {
  478. //获取预估每秒获得蛋蛋能量数
  479. estimatePerSecondPersonEggEnergyValue, err1 := decimal.NewFromString(signIn.EstimatePerSecondPersonEggEnergyValue)
  480. if err1 != nil {
  481. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  482. return
  483. }
  484. signPersonEggEnergy = estimatePerSecondPersonEggEnergyValue.String()
  485. estimatePerSecondTeamEggEnergyValue, err2 := decimal.NewFromString(signIn.EstimatePerSecondTeamEggEnergyValue)
  486. if err2 != nil {
  487. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  488. return
  489. }
  490. signTeamEggEnergy = estimatePerSecondTeamEggEnergyValue.String()
  491. }
  492. nowBasalRate := utils.StrToFloat64(signPersonEggEnergy) * 60 * 60 //每小时基础速率
  493. nowTeamRate := utils.StrToFloat64(signTeamEggEnergy) * 60 * 60 // 每小时团队速率
  494. resp := md.TotalRateResp{
  495. NowBasalRate: utils.Float64ToStr(nowBasalRate),
  496. NowTeamRate: utils.Float64ToStr(nowTeamRate),
  497. ConsumedPersonalEggPoint: signIn.TotalPersonEggPoints,
  498. ConsumedTeamEggPoint: signIn.TotalTeamEggPoints,
  499. NowTotalRate: utils.Float64ToStr(nowTeamRate + nowBasalRate),
  500. }
  501. e.OutSuc(c, resp, nil)
  502. }
  503. // MyFans
  504. // @Summary 蛋蛋星球-添加好友-粉丝团队-我的粉丝-团队加速速率(获取)
  505. // @Tags 添加好友
  506. // @Description 团队加速速率(获取)
  507. // @Accept json
  508. // @Produce json
  509. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  510. // @Success 200 {object} md.MyFansResp "具体数据"
  511. // @Failure 400 {object} md.Response "具体错误"
  512. // @Router /api/v1/addFriend/myFans [GET]
  513. func MyFans(c *gin.Context) {
  514. val, exists := c.Get("user")
  515. if !exists {
  516. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  517. return
  518. }
  519. user, ok := val.(*model.User)
  520. if !ok {
  521. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  522. return
  523. }
  524. // 找出公排中所有关联用户
  525. userRelateDb := implement.NewUserRelateDb(db.Db)
  526. total, err := userRelateDb.UserRelatesCountByParentUid(user.Id, 0)
  527. if err != nil {
  528. e.OutErr(c, e.ERR_DB_ORM, err)
  529. return
  530. }
  531. session := db.Db.NewSession()
  532. defer session.Close()
  533. now := time.Now()
  534. assistanceDb := implement.NewEggEnergyTeamAssistanceDb(db.Db)
  535. assistance, err := assistanceDb.EggEnergyTeamAssistanceGetOneBySession(session, user.Id, now.Format("2006-01-02"))
  536. if err != nil {
  537. e.OutErr(c, e.ERR_DB_ORM, err)
  538. return
  539. }
  540. var nowTeamAssistanceNum int
  541. var nowTeamAssistanceReward string
  542. if assistance != nil {
  543. nowTeamAssistanceNum = assistance.AssistedNum
  544. nowTeamAssistanceReward = assistance.RewardScore
  545. }
  546. resp := md.MyFansResp{
  547. NowTeamUser: total,
  548. NowTeamAssistanceNum: nowTeamAssistanceNum,
  549. NowTeamAssistanceReward: nowTeamAssistanceReward,
  550. }
  551. e.OutSuc(c, resp, nil)
  552. return
  553. }
  554. // MyFansUserList
  555. // @Summary 蛋蛋星球-添加好友-粉丝团队-我的粉丝-在线好友列表(获取)
  556. // @Tags 添加好友
  557. // @Description 在线好友列表(获取)
  558. // @Accept json
  559. // @Produce json
  560. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  561. // @Param limit query int true "每页大小"
  562. // @Param page query int true "页数"
  563. // @Success 200 {object} md.MyFansUserListResp "具体数据"
  564. // @Failure 400 {object} md.Response "具体错误"
  565. // @Router /api/v1/addFriend/myFansUserList [GET]
  566. func MyFansUserList(c *gin.Context) {
  567. page := c.DefaultQuery("page", "")
  568. limit := c.DefaultQuery("limit", "20")
  569. now := time.Now()
  570. val, exists := c.Get("user")
  571. if !exists {
  572. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  573. return
  574. }
  575. user, ok := val.(*model.User)
  576. if !ok {
  577. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  578. return
  579. }
  580. energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  581. eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  582. "key": "is_open",
  583. "value": 1,
  584. })
  585. if err != nil {
  586. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  587. return
  588. }
  589. var teamRewardSetting *md2.TeamRewardSettingStruct
  590. err = json.Unmarshal([]byte(eggEnergyBasicSetting.DirectPushReward), &teamRewardSetting)
  591. if err != nil {
  592. e.OutErr(c, e.ERR, err.Error())
  593. return
  594. }
  595. var oneRoundDuration = utils.StrToInt(teamRewardSetting.OneRoundDuration)
  596. startTime := now.Add(-time.Hour * time.Duration(oneRoundDuration)).Format("2006-01-02 15:04:05")
  597. relateDb := implement.NewUserRelateDb(db.Db)
  598. userRelates, err := relateDb.FindUserRelateByParentUid(user.Id, 1)
  599. if err != nil {
  600. e.OutErr(c, e.ERR, err.Error())
  601. return
  602. }
  603. var userRelatesUids []string
  604. var userSignInMap = map[int64]interface{}{}
  605. var results []map[string]string
  606. if userRelates != nil {
  607. for _, userRelate := range *userRelates {
  608. userRelatesUids = append(userRelatesUids, utils.Int64ToStr(userRelate.Uid))
  609. }
  610. signInDb := implement.NewEggSignInDb(db.Db)
  611. eggSignIns, err1 := signInDb.EggSignInFindByTimeAndParams(startTime, "", 0, map[string]interface{}{
  612. "key": "uid",
  613. "value": userRelatesUids,
  614. })
  615. if err1 != nil {
  616. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  617. return
  618. }
  619. for _, eggSignIn := range eggSignIns {
  620. userSignInMap[eggSignIn.Uid] = *eggSignIn
  621. }
  622. var sql string
  623. sql = "SELECT user.id AS uid, user.avatar AS avatar, user.nickname AS nickname, user_relate.invite_time AS invite_time " +
  624. "FROM `user_relate` " +
  625. "LEFT JOIN `user` ON user_relate.uid = user.uid " +
  626. "where user_relate.uid IN(%s)"
  627. sql += " ORDER BY user_relate.invite_time DESC LIMIT %d, %d;"
  628. sql = fmt.Sprintf(sql, strings.Join(userRelatesUids, ","), (utils.StrToInt64(page)-1)*utils.StrToInt64(limit), utils.StrToInt64(limit))
  629. results, err = db.QueryNativeString(db.Db, sql)
  630. if err != nil {
  631. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  632. return
  633. }
  634. }
  635. redisConn := cache.GetPool().Get()
  636. scheme, domain := svc.ImageBucket(db.Db, redisConn)
  637. var data []md.OneLineUserNode
  638. for _, v := range results {
  639. isOnline := false
  640. if userSignInMap[utils.AnyToInt64(v["uid"])] != nil {
  641. isOnline = true
  642. }
  643. tempUrl := svc.ImageFormatWithBucket(scheme, domain, v["avatar_url"])
  644. data = append(data, md.OneLineUserNode{
  645. IsOnline: isOnline,
  646. AvatarURL: tempUrl,
  647. Nickname: v["nickname"],
  648. InviteTime: v["invite_time"],
  649. })
  650. }
  651. resp := md.MyFansUserListResp{
  652. List: data,
  653. }
  654. e.OutSuc(c, resp, nil)
  655. return
  656. }
  657. // NineDimensionalSpace
  658. // @Summary 蛋蛋星球-添加好友-粉丝团队-九维空间(获取)
  659. // @Tags 添加好友
  660. // @Description 九维空间(获取)
  661. // @Accept json
  662. // @Produce json
  663. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  664. // @Success 200 {object} md.NineDimensionalSpaceResp "具体数据"
  665. // @Failure 400 {object} md.Response "具体错误"
  666. // @Router /api/v1/addFriend/nineDimensionalSpace [GET]
  667. func NineDimensionalSpace(c *gin.Context) {
  668. //1、 查找 `one_circles_public_platoon_basic_setting` 基础设置
  669. settingDb := implement.NewPublicPlatoonBasicSettingDb(db.Db)
  670. setting, err := settingDb.PublicPlatoonBasicSettingGetOneByParams(map[string]interface{}{
  671. "key": "is_open",
  672. "value": 1,
  673. })
  674. if err != nil {
  675. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  676. return
  677. }
  678. if setting == nil {
  679. e.OutErr(c, e.ERR_NO_DATA, nil)
  680. return
  681. }
  682. val, exists := c.Get("user")
  683. if !exists {
  684. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  685. return
  686. }
  687. user, ok := val.(*model.User)
  688. if !ok {
  689. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  690. return
  691. }
  692. uid := user.Id
  693. row := setting.SeveralRows
  694. times := setting.SeveralTimes
  695. var spaceTotalNums float64
  696. var list []md.SpaceListNode
  697. for i := 1; i <= setting.SeveralRows; i++ {
  698. var tmpSql = fmt.Sprintf("SELECT COUNT(*)AS total FROM `public_platoon_user_relation` WHERE father_uid%d = %d", i, uid)
  699. tmpNativeString, _ := db.QueryNativeString(db.Db, tmpSql)
  700. nowUserCount := utils.StrToInt64(tmpNativeString[0]["total"])
  701. maxCount := math.Pow(float64(setting.SeveralTimes), float64(i))
  702. if nowUserCount > int64(maxCount) {
  703. nowUserCount = int64(maxCount)
  704. }
  705. list = append(list, md.SpaceListNode{
  706. Name: utils.IntToStr(i) + "维",
  707. MaxCount: utils.Float64ToStr(maxCount),
  708. NowCount: utils.Int64ToStr(nowUserCount),
  709. })
  710. spaceTotalNums += maxCount
  711. }
  712. //2、统计当前用户下多少人数
  713. 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)
  714. nativeString1, _ := db.QueryNativeString(db.Db, sql)
  715. hasUserCount := utils.StrToInt64(nativeString1[0]["total"])
  716. resp := md.NineDimensionalSpaceResp{
  717. Rows: utils.IntToStr(row),
  718. Times: utils.IntToStr(times),
  719. SpaceTotalNums: utils.Float64ToStr(spaceTotalNums),
  720. SpaceNums: utils.Int64ToStr(hasUserCount),
  721. SpaceList: list,
  722. ALotOfNums: utils.Float64ToStr(spaceTotalNums),
  723. DayNum: utils.IntToStr(setting.SystemPunishReplaceValue),
  724. }
  725. e.OutSuc(c, resp, nil)
  726. return
  727. }