12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package model
- import "trading-go/common"
- type Appraise struct {
- Id uint `db:"id"`
- GoodsId uint `db:"goods_id"`
- BuyerId uint `db:"buyer_id"`
- Time uint `db:"time"`
- Content string `db:"content"`
- Star int `db:"star"`
- }
- type AppraiseJson struct {
- GoodsId uint `json:"goodsId"`
- BuyerId uint `json:"buyerId"`
- Time uint `json:"time"`
- Content string `json:"content"`
- Star int `json:"star"`
- }
- func (j AppraiseJson) Change() Appraise {
- return Appraise{
- GoodsId: j.GoodsId,
- BuyerId: j.BuyerId,
- Time: j.Time,
- Content: j.Content,
- Star: j.Star,
- }
- }
- func (a Appraise) Create() error {
- db := common.DB
- sqlStr := "INSERT INTO appraises(goods_id, buyer_id, time, content, star) VALUES(:goods_id, :buyer_id, :time, :content, :star)"
- _, err := db.NamedExec(sqlStr, a)
- return err
- }
- func (a Appraise) Delete() error {
- db := common.DB
- sqlStr := "DELETE FROM appraises WHERE id = ?"
- _, err := db.Exec(sqlStr, a.Id)
- return err
- }
- func (a Appraise) Revise() error {
- db := common.DB
- sqlStr := "UPDATE appraises SET time = ?, content = ?, star = ? WHERE id = ?"
- _, err := db.Exec(sqlStr, a.Time, a.Content, a.Star, a.Id)
- return err
- }
- func (a Appraise) GetOwn() (appraises []Appraise, err error) {
- db := common.DB
- sqlStr := "SELECT * FROM appraises WHERE buyer_id = ?"
- err = db.Select(&appraises, sqlStr, a.BuyerId)
- return
- }
|