蛋蛋星球-客户端
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_wallet.go 3.4 KiB

5 dagen geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. "github.com/gin-gonic/gin"
  10. )
  11. // GetAmountFlow
  12. // @Summary 蛋蛋星球-钱包-余额明细(获取)
  13. // @Tags 钱包
  14. // @Description 余额明细(获取)
  15. // @Accept json
  16. // @Produce json
  17. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  18. // @Param limit query string true "每页大小"
  19. // @Param page query string true "页数"
  20. // @Param startAt query string false "开始时间"
  21. // @Param endAt query string false "结束时间"
  22. // @Param direction query string false "流水方向(1.收入 2.支出 0.全部)"
  23. // @Success 200 {object} md.GetAmountFlowResp "具体数据"
  24. // @Failure 400 {object} md.Response "具体错误"
  25. // @Router /api/v1/wallet/amountFlow [GET]
  26. func GetAmountFlow(c *gin.Context) {
  27. pageStr := c.DefaultQuery("page", "1")
  28. limitStr := c.DefaultQuery("limit", "10")
  29. startAt := c.Query("startAt")
  30. endAt := c.Query("endAt")
  31. directionStr := c.Query("direction")
  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. direction := 0
  43. switch directionStr {
  44. case "1":
  45. direction = 1
  46. case "2":
  47. direction = 2
  48. }
  49. page := utils.StrToInt(pageStr)
  50. limit := utils.StrToInt(limitStr)
  51. flowDb := implement.NewUserWalletFlowDb(db.Db)
  52. flows, total, err := flowDb.UserWalletFlowFindByCoinAndUser(page, limit, user.Id, startAt, endAt, direction, false, 0, 0)
  53. if err != nil {
  54. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  55. return
  56. }
  57. list := make([]md.WalletFlowNode, 0, len(flows))
  58. for _, flow := range flows {
  59. temp := md.WalletFlowNode{
  60. Id: flow.Id,
  61. Uid: flow.Uid,
  62. Direction: flow.Direction,
  63. Amount: flow.Amount,
  64. BeforeAmount: flow.BeforeAmount,
  65. AfterAmount: flow.AfterAmount,
  66. SysFee: flow.SysFee,
  67. OrdId: flow.OrdId,
  68. Title: flow.Title,
  69. Kind: flow.Kind,
  70. State: flow.State,
  71. Memo: flow.Memo,
  72. CreateTime: flow.CreateAt,
  73. UpdateTime: flow.UpdateAt,
  74. }
  75. list = append(list, temp)
  76. }
  77. resp := md.GetAmountFlowResp{
  78. List: list,
  79. Paginate: md.Paginate{
  80. Limit: limit,
  81. Page: page,
  82. Total: total,
  83. },
  84. }
  85. e.OutSuc(c, resp, nil)
  86. }
  87. // WithdrawGetAmount
  88. // @Summary 蛋蛋星球-钱包-提现余额(获取)
  89. // @Tags 钱包
  90. // @Description 提现余额(获取)
  91. // @Accept json
  92. // @Produce json
  93. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  94. // @Success 200 {object} md.WithdrawGetAmountResp "具体数据"
  95. // @Failure 400 {object} md.Response "具体错误"
  96. // @Router /api/v1/wallet/withdraw/index [GET]
  97. func WithdrawGetAmount(c *gin.Context) {
  98. val, exists := c.Get("user")
  99. if !exists {
  100. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  101. return
  102. }
  103. user, ok := val.(*model.User)
  104. if !ok {
  105. e.OutErr(c, e.ERR_USER_CHECK_ERR, nil)
  106. return
  107. }
  108. walletDb := implement.NewUserWalletDb(db.Db)
  109. wallet, err := walletDb.GetUserVirtualWallet(user.Id)
  110. if err != nil {
  111. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  112. return
  113. }
  114. resp := md.WithdrawGetAmountResp{
  115. Amount: wallet.Amount,
  116. }
  117. e.OutSuc(c, resp, nil)
  118. }