account.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package account
  2. import (
  3. "time"
  4. "mtp2_if/db"
  5. "mtp2_if/token"
  6. "net/http"
  7. "github.com/gin-gonic/gin"
  8. )
  9. // AccountQueryReq 账户查询请求
  10. type AccountQueryReq struct {
  11. Token string `json:"token" binding:"required"`
  12. AccountID int `json:"accountid" binding:"required"`
  13. }
  14. // AccountQueryRsp 账户查询响应
  15. type AccountQueryRsp struct {
  16. Accountid int `json:"accountid" binding:"required"`
  17. Userid int `json:"userid" binding:"required"`
  18. Currencyid int `json:"currencyid" binding:"required"`
  19. Changeflag int `json:"changeflag" binding:"required"`
  20. Changetime time.Time `json:"changetime" binding:"required"`
  21. }
  22. // Taaccount 账户表结构定义
  23. type Taaccount struct {
  24. Accountid int `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"`
  25. Userid int `json:"userid" xorm:"'USERID'" binding:"required"`
  26. Currencyid int `json:"currencyid" xorm:"'CURRENCYID'" binding:"required"`
  27. Changeflag int `json:"changeflag" xorm:"'CHANGEFLAG'" binding:"required"`
  28. Changetime time.Time `json:"changetime" xorm:"'CHANGETIME'" binding:"required"`
  29. }
  30. // Reckondaytaaccount 账户结算日照表结构定义
  31. type Reckondaytaaccount struct {
  32. Accountid int `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"`
  33. Userid int `json:"userid" xorm:"'USERID'" binding:"required"`
  34. Currencyid int `json:"currencyid" xorm:"'CURRENCYID'" binding:"required"`
  35. Changeflag int `json:"changeflag" xorm:"'CHANGEFLAG'" binding:"required"`
  36. Reckondate string `json:"reckondate" xorm:"'RECKONDATE'" binding:"required"`
  37. }
  38. // TableName 返回表名接口
  39. func (Taaccount) TableName() string {
  40. return "TAACCOUNT"
  41. }
  42. // TableName 返回表名接口
  43. func (Reckondaytaaccount) TableName() string {
  44. return "RECKON_DAYTAACCOUNT"
  45. }
  46. // GetAccount 获取账户接口
  47. func GetAccount(c *gin.Context) {
  48. var account AccountQueryReq
  49. err := c.ShouldBind(&account)
  50. if err != nil {
  51. c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
  52. }
  53. var ok bool
  54. ok, err = token.CheckToken(account.AccountID, account.Token)
  55. if err != nil || !ok {
  56. c.JSON(http.StatusBadRequest, gin.H{"token check failed": err.Error()})
  57. return
  58. }
  59. engine := db.GetEngine()
  60. accountinfo := new(Taaccount)
  61. has, err := engine.Where("accountid=?", account.AccountID).Get(accountinfo)
  62. if err != nil {
  63. c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
  64. return
  65. }
  66. if !has {
  67. c.JSON(http.StatusBadRequest, gin.H{"error": "not find"})
  68. return
  69. }
  70. ret := AccountQueryRsp{
  71. Accountid: accountinfo.Accountid,
  72. Userid: accountinfo.Userid,
  73. Currencyid: accountinfo.Currencyid,
  74. Changeflag: accountinfo.Changeflag,
  75. Changetime: accountinfo.Changetime,
  76. }
  77. c.SecureJSON(http.StatusOK, ret)
  78. }
  79. // GetReckonAccount 获取日照账户接口
  80. func GetReckonAccount(c *gin.Context) {
  81. var account AccountQueryReq
  82. err := c.ShouldBind(&account)
  83. if err != nil {
  84. c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
  85. }
  86. engine := db.GetEngine()
  87. accountinfo := new(Reckondaytaaccount)
  88. has, err := engine.Where("accountid=?", account.AccountID).And("reckondate=?", "20200314").Get(accountinfo)
  89. if err != nil {
  90. c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
  91. return
  92. }
  93. if !has {
  94. c.JSON(http.StatusBadRequest, gin.H{"error": "not find"})
  95. return
  96. }
  97. ret := AccountQueryRsp{
  98. Accountid: accountinfo.Accountid,
  99. Userid: accountinfo.Userid,
  100. Currencyid: accountinfo.Currencyid,
  101. Changeflag: accountinfo.Changeflag,
  102. }
  103. c.SecureJSON(http.StatusOK, ret)
  104. }