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

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