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

hdl_add_friend.go 24 KiB

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