zwl 5 lat temu
rodzic
commit
6e2cffa70c
2 zmienionych plików z 28 dodań i 17 usunięć
  1. 22 15
      account/account.go
  2. 6 2
      goods/goods.go

+ 22 - 15
account/account.go

@@ -10,12 +10,13 @@ import (
 	"github.com/gin-gonic/gin"
 )
 
-// GoodsQueryReq 商品查询请求
+// 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"`
@@ -24,6 +25,7 @@ type AccountQueryRsp struct {
 	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"`
@@ -32,6 +34,7 @@ type Taaccount struct {
 	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"`
@@ -40,25 +43,35 @@ type Reckondaytaaccount struct {
 	Reckondate string `json:"reckondate" xorm:"'RECKONDATE'"  binding:"required"`
 }
 
+// TableName 返回表名接口
 func (Taaccount) TableName() string {
 	return "TAACCOUNT"
 }
 
+// TableName 返回表名接口
 func (Reckondaytaaccount) TableName() string {
 	return "RECKON_DAYTAACCOUNT"
 }
 
-func GetReckonAccount(c *gin.Context) {
+// 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(Reckondaytaaccount)
-	has, err := engine.Where("accountid=?", account.AccountID).And("reckondate=?", "20200314").Get(accountinfo)
+	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
@@ -74,28 +87,23 @@ func GetReckonAccount(c *gin.Context) {
 		Userid:     accountinfo.Userid,
 		Currencyid: accountinfo.Currencyid,
 		Changeflag: accountinfo.Changeflag,
+		Changetime: accountinfo.Changetime,
 	}
 	c.SecureJSON(http.StatusOK, ret)
 }
 
-func GetAccount(c *gin.Context) {
+// 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()})
 	}
 
-	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)
+	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
@@ -111,7 +119,6 @@ func GetAccount(c *gin.Context) {
 		Userid:     accountinfo.Userid,
 		Currencyid: accountinfo.Currencyid,
 		Changeflag: accountinfo.Changeflag,
-		Changetime: accountinfo.Changetime,
 	}
 	c.SecureJSON(http.StatusOK, ret)
 }

+ 6 - 2
goods/goods.go

@@ -9,6 +9,7 @@ import (
 	"github.com/gin-gonic/gin"
 )
 
+// Goods 商品表结构定义
 type Goods struct {
 	Goodsid   int    `json:"goodsid" xorm:"'GOODSID'"`
 	Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"`
@@ -16,6 +17,7 @@ type Goods struct {
 	Marketid  int    `json:"marketid" xorm:"'MARKETID'"`
 }
 
+// TableName 返回表名接口
 func (Goods) TableName() string {
 	return "GOODS"
 }
@@ -34,13 +36,13 @@ type GoodsQueryRsp struct {
 	MarketID  int    `json:"marketid" binding:"required"`
 }
 
-// GoodsQueryAllReq 商品查询请求
+// GoodsQueryAllReq 所有商品查询请求
 type GoodsQueryAllReq struct {
 	Token string `json:"token" binding:"required"`
 	//MarketID int `json:"marketid" binding:"required"`
 }
 
-// GoodsQueryRsp 商品查询结果
+// GoodsQueryAllRsp 所有商品查询结果
 type GoodsQueryAllRsp struct {
 	Goodss []Goods `json:"goodss"`
 }
@@ -77,6 +79,7 @@ func QueryGoods(c *gin.Context) {
 	c.SecureJSON(http.StatusOK, ret)
 }
 
+// GetGoods 商品信息查询
 func GetGoods(c *gin.Context) {
 	var goods GoodsQueryReq
 	err := c.ShouldBind(&goods)
@@ -107,6 +110,7 @@ func GetGoods(c *gin.Context) {
 	c.SecureJSON(http.StatusOK, ret)
 }
 
+// GetAllGoods 所有商品信息查询
 func GetAllGoods(c *gin.Context) {
 	var goods GoodsQueryAllReq
 	err := c.ShouldBind(&goods)