package models
|
|
import (
|
"fmt"
|
"github.com/astaxie/beego/orm"
|
)
|
|
//cid和别名绑定记录
|
type UserClient struct {
|
Id string `orm:"pk;size(50);column(id)" json:"id"`
|
PhoneNum string `orm:"column(phoneNum)" json:"phoneNum"` //手机号
|
ClientId string `orm:"column(clientId)" json:"clientId"` //手机客户端id
|
BindTime string `orm:"column(bindTime)" json:"bindTime"`
|
}
|
|
func (uc *UserClient) TableName() string {
|
return "user_client"
|
}
|
|
func (uc *UserClient) Insert() (int64,error) {
|
o := orm.NewOrm()
|
return o.Insert(uc)
|
}
|
|
func (uc *UserClient) Exist(phoneNum string) bool {
|
var list []UserClient
|
o := orm.NewOrm()
|
o.QueryTable(uc.TableName()).Filter("phoneNum", phoneNum).All(&list)
|
if len(list) >0 {
|
return true
|
}
|
return false
|
}
|
|
func (uc *UserClient) ExistByCid(phoneNum string, cid string) bool {
|
var list []UserClient
|
o := orm.NewOrm()
|
o.QueryTable(uc.TableName()).Filter("phoneNum", phoneNum).Filter("clientId", cid).All(&list)
|
if len(list) >0 {
|
return true
|
}
|
return false
|
}
|
|
func (uc *UserClient) GetByCid(cid string) []UserClient {
|
var list []UserClient
|
o := orm.NewOrm()
|
_, err := o.QueryTable(uc.TableName()).Filter("clientId", cid).All(&list)
|
if err != nil {
|
return nil
|
}
|
return list
|
}
|
|
|
func (uc *UserClient) DeleteByCid(clientId string) (int64, error) {
|
o := orm.NewOrm()
|
sql := fmt.Sprintf("delete from "+uc.TableName()+" where clientId='%s'", clientId)
|
result, err := o.Raw(sql).Exec()
|
if err != nil {
|
return 0, err
|
}
|
return result.RowsAffected()
|
}
|