liuxiaolong
2020-08-06 dbc843d0b37f786fb816131bcc7ebca86dbe72e9
models/userCar.go
@@ -1,6 +1,9 @@
package models
import "github.com/astaxie/beego/orm"
import (
   "fmt"
   "github.com/astaxie/beego/orm"
)
type UserCar struct {
   Id          string       `orm:"pk;size(50);column(id)" json:"id"`
@@ -19,7 +22,7 @@
func (uc *UserCar) GetByUserId(userId string) (all []UserCar,err error) {
   o := orm.NewOrm()
   _, err = o.Raw("select * from ? where userId=?", uc.TableName(), userId).QueryRows(&all)
   _, err = o.QueryTable(uc.TableName()).Filter("userId", userId).All(&all)
   if err != nil {
      return nil, err
   }
@@ -29,16 +32,17 @@
func (uc *UserCar) Exist(userId string, plateNo string) bool {
   var list []UserCar
   o := orm.NewOrm()
   i,_ := o.Raw("select * from ? where userId=? and plateNo=?", uc.TableName(), userId, plateNo).QueryRows(&list)
   if i > 0 && len(list) >0 {
   o.Raw("select * from ? where userId=? and plateNo=?", uc.TableName(), userId, plateNo).QueryRows(&list)
   if len(list) >0 {
      return true
   }
   return false
}
func (uc *UserCar) DeleteByUserId(userId string) (int64, error) {
func (uc *UserCar) Delete(userId string, plateNo string) (int64, error) {
   o := orm.NewOrm()
   result, err := o.Raw("delete from ? where userId=?", uc.TableName(), userId).Exec()
   sql := fmt.Sprintf("delete from "+uc.TableName()+" where userId='%s' and plateNo='%s'", userId, plateNo)
   result, err := o.Raw(sql).Exec()
   if err != nil {
      return 0, err
   }