|
@@ -9,70 +9,65 @@ import (
|
|
|
)
|
|
|
|
|
|
type Goods struct {
|
|
|
- Id uint `db:"id"`
|
|
|
- Pic string `db:"pic"`
|
|
|
- OwnerId uint `db:"owner_id"`
|
|
|
- Desc string `db:"desc"`
|
|
|
- Title string `db:"title"`
|
|
|
- Price uint `db:"price"`
|
|
|
- Integrity int `db:"integrity"`
|
|
|
- Place string `db:"place"`
|
|
|
- State int `db:"state"`
|
|
|
+ Id uint `db:"id"`
|
|
|
+ OwnerId uint `db:"owner_id"`
|
|
|
+ Desc string `db:"desc"`
|
|
|
+ Title string `db:"title"`
|
|
|
+ Price uint `db:"price"`
|
|
|
+ Place string `db:"place"`
|
|
|
+ State int `db:"state"`
|
|
|
+ Pic []string
|
|
|
}
|
|
|
|
|
|
type GoodsJson struct {
|
|
|
- Pic string `json:"pic"`
|
|
|
- OwnerId uint `json:"ownerId"`
|
|
|
- Desc string `json:"desc"`
|
|
|
- Title string `json:"title"`
|
|
|
- Price uint `json:"price"`
|
|
|
- Integrity int `json:"integrity"`
|
|
|
- Place string `json:"place"`
|
|
|
- Categories []uint `json:"categories"`
|
|
|
- State int `json:"state"`
|
|
|
+ OwnerId uint `json:"ownerId"`
|
|
|
+ Desc string `json:"desc"`
|
|
|
+ Title string `json:"title"`
|
|
|
+ Price uint `json:"price"`
|
|
|
+ Place string `json:"place"`
|
|
|
+ Categories []uint `json:"categories"`
|
|
|
+ State int `json:"state"`
|
|
|
+ Pic []string `json:"pic"`
|
|
|
}
|
|
|
|
|
|
type GoodsSurfaceJson struct {
|
|
|
- Pic string `json:"pic"`
|
|
|
- OwnerId uint `json:"ownerId"`
|
|
|
- Title string `json:"title"`
|
|
|
- Price uint `json:"price"`
|
|
|
- Integrity int `json:"integrity"`
|
|
|
- State int `json:"state"`
|
|
|
+ Pic string `json:"pic"`
|
|
|
+ OwnerId uint `json:"ownerId"`
|
|
|
+ Title string `json:"title"`
|
|
|
+ Price uint `json:"price"`
|
|
|
+ State int `json:"state"`
|
|
|
}
|
|
|
|
|
|
type GoodsSurface struct {
|
|
|
- Id uint `db:"id"`
|
|
|
- Pic string `db:"pic"`
|
|
|
- OwnerId uint `db:"owner_id"`
|
|
|
- Title string `db:"title"`
|
|
|
- Price uint `db:"price"`
|
|
|
- Integrity int `db:"integrity"`
|
|
|
- State int `db:"state"`
|
|
|
+ Id uint `db:"id"`
|
|
|
+ Pic string `db:"pic"`
|
|
|
+ OwnerId uint `db:"owner_id"`
|
|
|
+ Title string `db:"title"`
|
|
|
+ Price uint `db:"price"`
|
|
|
+ State int `db:"state"`
|
|
|
}
|
|
|
|
|
|
func (g *GoodsJson) Change() Goods {
|
|
|
return Goods{
|
|
|
- Pic: g.Pic,
|
|
|
- OwnerId: g.OwnerId,
|
|
|
- Desc: g.Desc,
|
|
|
- Title: g.Title,
|
|
|
- Price: g.Price,
|
|
|
- Integrity: g.Integrity,
|
|
|
- Place: g.Place,
|
|
|
- State: g.State,
|
|
|
+ Pic: g.Pic,
|
|
|
+ OwnerId: g.OwnerId,
|
|
|
+ Desc: g.Desc,
|
|
|
+ Title: g.Title,
|
|
|
+ Price: g.Price,
|
|
|
+ Place: g.Place,
|
|
|
+ State: g.State,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (g *Goods) Create() (id uint, err error) {
|
|
|
db := common.DB
|
|
|
- sqlStr := "INSERT INTO goods(pic, owner_id, `desc`, title, price, integrity, place, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
|
|
|
- _, err = db.Exec(sqlStr, g.Pic, g.OwnerId, g.Desc, g.Title, g.Price, g.Integrity, g.Place, g.State)
|
|
|
+ sqlStr := "INSERT INTO goods(owner_id, `desc`, title, price, place, state) VALUES (?, ?, ?, ?, ?, ?)"
|
|
|
+ _, err = db.Exec(sqlStr, g.OwnerId, g.Desc, g.Title, g.Price, g.Place, g.State)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- sqlStr = "INSERT INTO goods_surfaces(pic, owner_id, title, price, integrity, state) VALUES (?, ?, ?, ?, ?, ?)"
|
|
|
- exec, err := db.Exec(sqlStr, g.Pic, g.OwnerId, g.Title, g.Price, g.Integrity, g.State)
|
|
|
+ sqlStr = "INSERT INTO goods_surfaces(pic, owner_id, title, price, state) VALUES (?, ?, ?, ?, ?)"
|
|
|
+ exec, err := db.Exec(sqlStr, g.Pic[0], g.OwnerId, g.Title, g.Price, g.State)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -119,13 +114,13 @@ func (g *GoodsSurface) GetCnt() (cnt int, err error) {
|
|
|
|
|
|
func (g *Goods) Revise() error {
|
|
|
db := common.DB
|
|
|
- sqlStr := "UPDATE goods SET pic = ?, owner_id = ?, `desc` = ?, title = ?, price = ?, integrity = ?, place = ?, state = ? WHERE id = ?"
|
|
|
- _, err := db.Exec(sqlStr, g.Pic, g.OwnerId, g.Desc, g.Title, g.Price, g.Integrity, g.Place, g.State, g.Id)
|
|
|
+ sqlStr := "UPDATE goods SET pic = ?, owner_id = ?, `desc` = ?, title = ?, price = ?, place = ?, state = ? WHERE id = ?"
|
|
|
+ _, err := db.Exec(sqlStr, g.Pic, g.OwnerId, g.Desc, g.Title, g.Price, g.Place, g.State, g.Id)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- sqlStr = "UPDATE goods_surfaces SET pic = ?, owner_id = ?, title = ?, price = ?, integrity = ?, state = ? WHERE id = ?"
|
|
|
- _, err = db.Exec(sqlStr, g.Pic, g.OwnerId, g.Title, g.Price, g.Integrity, g.State, g.Id)
|
|
|
+ sqlStr = "UPDATE goods_surfaces SET pic = ?, owner_id = ?, title = ?, price = ?, state = ? WHERE id = ?"
|
|
|
+ _, err = db.Exec(sqlStr, g.Pic, g.OwnerId, g.Title, g.Price, g.State, g.Id)
|
|
|
return err
|
|
|
}
|
|
|
|
|
@@ -152,6 +147,7 @@ func (g *GoodsSurface) GetCategoryPaged(page, pageSize int, category uint) (rsp
|
|
|
rsp.PageSize = pageSize
|
|
|
sqlStr := "SELECT goods_id FROM category_of_goods WHERE category_id = ?"
|
|
|
err = db.Select(&goodsIds, sqlStr, category)
|
|
|
+ fmt.Println(goodsIds)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -214,3 +210,14 @@ func (g *GoodsSurface) GetRecommend(id uint, size int) (goods []GoodsSurface, er
|
|
|
err = db.Select(&goods, query, args...)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+func (g *GoodsSurface) GetGoodsList(id []uint) (goods []GoodsSurface, err error) {
|
|
|
+ db := common.DB
|
|
|
+ sqlStr := "SELECT * FROM goods_surfaces WHERE id IN (?)"
|
|
|
+ query, args, err := sqlx.In(sqlStr, id)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ err = db.Select(&goods, query, args...)
|
|
|
+ return
|
|
|
+}
|