蛋蛋星球-客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

hdl_add_friend.go 26 KiB

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