liuxiaolong
2020-08-12 8849dda9c4fd92467e2c05c15ea483abae6af8e5
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
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) 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()
}