liuxiaolong
2020-08-18 d517b08bf4a526b696f6cdf391df64c7f6d43607
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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()
}