蛋蛋星球-客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

756 行
24 KiB

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