12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package model
- import (
- "trading-go/common"
- )
- type Order struct {
- Id uint `db:"id"`
- GoodsId uint `db:"goods_id"`
- BuyerId uint `db:"buyer_id"`
- Time uint `db:"time"`
- Place string `db:"place"`
- Phone string `db:"phone"`
- State int `db:"state"`
- }
- type OrderJson struct {
- GoodsId uint `json:"goodsId"`
- BuyerId uint `json:"buyerId"`
- Time uint `json:"time"`
- Place string `json:"place"`
- Phone string `json:"phone"`
- State int `json:"state"`
- }
- func (o OrderJson) Change() Order {
- return Order{
- GoodsId: o.GoodsId,
- BuyerId: o.BuyerId,
- Time: o.Time,
- Place: o.Place,
- Phone: o.Phone,
- State: o.State,
- }
- }
- func (o Order) GetAll() (orders []Order, err error) {
- db := common.DB
- sqlStr := "SELECT * FROM orders"
- err = db.Select(&orders, sqlStr)
- return
- }
- func (o Order) GetOwner(ownerId uint) (orders []Order, err error) {
- db := common.DB
- sqlStr := "SELECT * FROM orders WHERE buyer_id = ?"
- err = db.Select(&orders, sqlStr, ownerId)
- return
- }
- func (o Order) Revise() error {
- db := common.DB
- sqlStr := "UPDATE orders SET state = ? WHERE id = ?"
- _, err := db.Exec(sqlStr, o.State, o.Id)
- return err
- }
- func (o Order) Create() error {
- db := common.DB
- sqlStr := "INSERT INTO orders(goods_id, buyer_id, time, place, phone, state) VALUES(:goods_id, :buyer_id, :time, :place, :phone , :state)"
- _, err := db.NamedExec(sqlStr, o)
- return err
- }
- func (o Order) Delete() error {
- db := common.DB
- sqlStr := "DELETE FROM orders WHERE id = ?"
- _, err := db.Exec(sqlStr, o.Id)
- return err
- }
|