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

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