appraise.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package model
  2. import "trading-go/common"
  3. type Appraise struct {
  4. Id uint `db:"id"`
  5. GoodsId uint `db:"goods_id"`
  6. BuyerId uint `db:"buyer_id"`
  7. Time uint `db:"time"`
  8. Content string `db:"content"`
  9. Star int `db:"star"`
  10. }
  11. type AppraiseJson struct {
  12. GoodsId uint `json:"goodsId"`
  13. BuyerId uint `json:"buyerId"`
  14. Time uint `json:"time"`
  15. Content string `json:"content"`
  16. Star int `json:"star"`
  17. }
  18. func (j AppraiseJson) Change() Appraise {
  19. return Appraise{
  20. GoodsId: j.GoodsId,
  21. BuyerId: j.BuyerId,
  22. Time: j.Time,
  23. Content: j.Content,
  24. Star: j.Star,
  25. }
  26. }
  27. func (a Appraise) Create() error {
  28. db := common.DB
  29. sqlStr := "INSERT INTO appraises(goods_id, buyer_id, time, content, star) VALUES(:goods_id, :buyer_id, :time, :content, :star)"
  30. _, err := db.NamedExec(sqlStr, a)
  31. return err
  32. }
  33. func (a Appraise) Delete() error {
  34. db := common.DB
  35. sqlStr := "DELETE FROM appraises WHERE id = ?"
  36. _, err := db.Exec(sqlStr, a.Id)
  37. return err
  38. }
  39. func (a Appraise) Revise() error {
  40. db := common.DB
  41. sqlStr := "UPDATE appraises SET time = ?, content = ?, star = ? WHERE id = ?"
  42. _, err := db.Exec(sqlStr, a.Time, a.Content, a.Star, a.Id)
  43. return err
  44. }
  45. func (a Appraise) GetOwn() (appraises []Appraise, err error) {
  46. db := common.DB
  47. sqlStr := "SELECT * FROM appraises WHERE buyer_id = ?"
  48. err = db.Select(&appraises, sqlStr, a.BuyerId)
  49. return
  50. }