| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package account
- import (
- "time"
- "mtp2_if/db"
- "mtp2_if/token"
- "net/http"
- "github.com/gin-gonic/gin"
- )
- // AccountQueryReq 账户查询请求
- type AccountQueryReq struct {
- Token string `json:"token" binding:"required"`
- AccountID int `json:"accountid" binding:"required"`
- }
- // AccountQueryRsp 账户查询响应
- type AccountQueryRsp struct {
- Accountid int `json:"accountid" binding:"required"`
- Userid int `json:"userid" binding:"required"`
- Currencyid int `json:"currencyid" binding:"required"`
- Changeflag int `json:"changeflag" binding:"required"`
- Changetime time.Time `json:"changetime" binding:"required"`
- }
- // Taaccount 账户表结构定义
- type Taaccount struct {
- Accountid int `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"`
- Userid int `json:"userid" xorm:"'USERID'" binding:"required"`
- Currencyid int `json:"currencyid" xorm:"'CURRENCYID'" binding:"required"`
- Changeflag int `json:"changeflag" xorm:"'CHANGEFLAG'" binding:"required"`
- Changetime time.Time `json:"changetime" xorm:"'CHANGETIME'" binding:"required"`
- }
- // Reckondaytaaccount 账户结算日照表结构定义
- type Reckondaytaaccount struct {
- Accountid int `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"`
- Userid int `json:"userid" xorm:"'USERID'" binding:"required"`
- Currencyid int `json:"currencyid" xorm:"'CURRENCYID'" binding:"required"`
- Changeflag int `json:"changeflag" xorm:"'CHANGEFLAG'" binding:"required"`
- Reckondate string `json:"reckondate" xorm:"'RECKONDATE'" binding:"required"`
- }
- // TableName 返回表名接口
- func (Taaccount) TableName() string {
- return "TAACCOUNT"
- }
- // TableName 返回表名接口
- func (Reckondaytaaccount) TableName() string {
- return "RECKON_DAYTAACCOUNT"
- }
- // GetAccount 获取账户接口
- func GetAccount(c *gin.Context) {
- var account AccountQueryReq
- err := c.ShouldBind(&account)
- if err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- }
- var ok bool
- ok, err = token.CheckToken(account.AccountID, account.Token)
- if err != nil || !ok {
- c.JSON(http.StatusBadRequest, gin.H{"token check failed": err.Error()})
- return
- }
- engine := db.GetEngine()
- accountinfo := new(Taaccount)
- has, err := engine.Where("accountid=?", account.AccountID).Get(accountinfo)
- if err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- return
- }
- if !has {
- c.JSON(http.StatusBadRequest, gin.H{"error": "not find"})
- return
- }
- ret := AccountQueryRsp{
- Accountid: accountinfo.Accountid,
- Userid: accountinfo.Userid,
- Currencyid: accountinfo.Currencyid,
- Changeflag: accountinfo.Changeflag,
- Changetime: accountinfo.Changetime,
- }
- c.SecureJSON(http.StatusOK, ret)
- }
- // GetReckonAccount 获取日照账户接口
- func GetReckonAccount(c *gin.Context) {
- var account AccountQueryReq
- err := c.ShouldBind(&account)
- if err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- }
- engine := db.GetEngine()
- accountinfo := new(Reckondaytaaccount)
- has, err := engine.Where("accountid=?", account.AccountID).And("reckondate=?", "20200314").Get(accountinfo)
- if err != nil {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- return
- }
- if !has {
- c.JSON(http.StatusBadRequest, gin.H{"error": "not find"})
- return
- }
- ret := AccountQueryRsp{
- Accountid: accountinfo.Accountid,
- Userid: accountinfo.Userid,
- Currencyid: accountinfo.Currencyid,
- Changeflag: accountinfo.Changeflag,
- }
- c.SecureJSON(http.StatusOK, ret)
- }
|