From 7eda9be6f0021f2df46a9cb66d87fe23d5d3f904 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期三, 12 八月 2020 10:19:01 +0800 Subject: [PATCH] push to users those who bind clientId --- models/userClient.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/models/userClient.go b/models/userClient.go index 2640e7f..fafebeb 100644 --- a/models/userClient.go +++ b/models/userClient.go @@ -1 +1,54 @@ 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"` //鎵嬫満瀹㈡埛绔痠d + 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.Raw("select * from ? where phoneNum=?", uc.TableName(), phoneNum).QueryRows(&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.Raw("select * from ? where phoneNum=? and clientId=?", uc.TableName(), phoneNum, cid).QueryRows(&list) + if len(list) >0 { + return true + } + return false +} + + +func (uc *UserClient) Delete(phoneNum string, clientId string) (int64, error) { + o := orm.NewOrm() + sql := fmt.Sprintf("delete from "+uc.TableName()+" where phoneNum='%s' and clientId='%s'", phoneNum, clientId) + result, err := o.Raw(sql).Exec() + if err != nil { + return 0, err + } + return result.RowsAffected() +} \ No newline at end of file -- Gitblit v1.8.0