zwl 5 년 전
부모
커밋
551be6f5c5
5개의 변경된 파일52개의 추가작업 그리고 7개의 파일을 삭제
  1. 3 0
      db/db.go
  2. 1 0
      go.mod
  3. 2 0
      go.sum
  4. 45 7
      goods/goods.go
  5. 1 0
      main.go

+ 3 - 0
db/db.go

@@ -3,6 +3,7 @@ package db
 import (
 	"fmt"
 
+	"github.com/xormplus/core"
 	"github.com/xormplus/xorm"
 )
 
@@ -21,6 +22,8 @@ func InitDbEngine() error {
 
 	Engine.SetMaxIdleConns(10)
 	Engine.SetMaxOpenConns(100)
+	Engine.ShowSQL(true)
+	Engine.SetTableMapper(core.SameMapper{})
 
 	return nil
 }

+ 1 - 0
go.mod

@@ -35,6 +35,7 @@ require (
 	github.com/tealeg/xlsx v1.0.5 // indirect
 	github.com/tebeka/strftime v0.1.3 // indirect
 	github.com/xormplus/builder v0.0.0-20200331055651-240ff40009be // indirect
+	github.com/xormplus/core v0.0.0-20200308074340-f3bce19d5f31
 	github.com/xormplus/xorm v0.0.0-20200514184607-0f37421d8714
 	gopkg.in/flosch/pongo2.v3 v3.0.0-20141028000813-5e81b817a0c4 // indirect
 )

+ 2 - 0
go.sum

@@ -129,6 +129,8 @@ github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs
 github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
 github.com/xormplus/builder v0.0.0-20200331055651-240ff40009be h1:HTSana2sMSKVze3XXYrF89w2tw835Fh+7xX5KPvAkuo=
 github.com/xormplus/builder v0.0.0-20200331055651-240ff40009be/go.mod h1:PgBA7NoHtnttVkWModa/qpvIWkX6MpOKgyRCWsSKSB0=
+github.com/xormplus/core v0.0.0-20200308074340-f3bce19d5f31 h1:Xc/TNcIKyvLIp1Y9K+K7a/XQ2wtBLiF6FNmyCjgmb5E=
+github.com/xormplus/core v0.0.0-20200308074340-f3bce19d5f31/go.mod h1:V3p6iAR/MaICgU6GJqxGQxspfljTyfOTv4Czz0B5atU=
 github.com/xormplus/xorm v0.0.0-20200514184607-0f37421d8714 h1:N/QKP2s2FuwXOozdAkX6upoKfxysbz0K8Ea5eZYH1D0=
 github.com/xormplus/xorm v0.0.0-20200514184607-0f37421d8714/go.mod h1:+v6b10b4x5IcQmp1/Cbo9IqaknxVeuhQng+fhya6bdI=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

+ 45 - 7
goods/goods.go

@@ -23,6 +23,17 @@ type GoodsQueryRsp struct {
 	MarketID  int    `json:"marketid" binding:"required"`
 }
 
+type Goodstest struct {
+	Goodsid   int    `json:"goodsid" xorm:"'GOODSID'"`
+	Goodscode string `json:"goodscode" xorm:"'GOODSCODE'"`
+	Goodsname string `json:"goodsname" xorm:"'GOODSNAME'"`
+	Marketid  int    `json:"marketid" xorm:"'MARKETID'"`
+}
+
+func (Goodstest) TableName() string {
+	return "GOODSTEST"
+}
+
 // GetGoodsInfo 商品信息查询
 func QueryGoods(c *gin.Context) {
 	var goods GoodsQueryReq
@@ -52,12 +63,39 @@ func QueryGoods(c *gin.Context) {
 		GoodsName: goodsname,
 		MarketID:  marketid,
 	}
-	/*
-		c.JSON(http.StatusOK, gin.H{
-			"token":   goods.Token,
-			"goodsid": goods.GoodsID,
-			"ret":     ret,
-		})
-	*/
+	c.SecureJSON(http.StatusOK, ret)
+}
+
+func GetGoods(c *gin.Context) {
+	var goods GoodsQueryReq
+	err := c.ShouldBind(&goods)
+	if err != nil {
+		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+	}
+
+	engine := db.GetEngine()
+
+	goodsinfo := new(Goodstest)
+	has, err := engine.Where("goodsid=?", goods.GoodsID).Get(goodsinfo)
+	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
+	}
+
+	goodscode := goodsinfo.Goodscode
+	goodsname := goodsinfo.Goodsname
+	marketid := goodsinfo.Marketid
+
+	ret := GoodsQueryRsp{
+		GoodsID:   goods.GoodsID,
+		GoodsCode: goodscode,
+		GoodsName: goodsname,
+		MarketID:  marketid,
+	}
 	c.SecureJSON(http.StatusOK, ret)
 }

+ 1 - 0
main.go

@@ -21,6 +21,7 @@ func main() {
 	gropt := gr.Group("/goodsopt")
 	{
 		gropt.POST("/QueryGoods", goods.QueryGoods)
+		gropt.POST("/GetGoods", goods.GetGoods)
 	}
 
 	r.Run(":8080")