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

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