chance_favorite.go
3.7 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package models
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceFavorite struct {
Id int64 `orm:"column(id);pk" description:"点赞编号"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
CompanyId int64 `orm:"column(company_id)" description:"company.id 公司编号"`
ObjectType int `orm:"column(object_type)" description:"类型 1:点赞 2:收藏"`
SourceType int `orm:"column(source_type)" description:"来源类型 1:机会 2:评论"`
SourceId int64 `orm:"column(source_id)" description:"来源id 机会编号/评论编号"`
ChanceType int `orm:"column(chance_type)" description:"机会类型编号 - 附加 "`
EnableStatus int `orm:"column(enable_status)" description:"1:有效 0:无效"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp);null" description:"删除时间"`
}
func (t *ChanceFavorite) TableName() string {
return "chance_favorite"
}
func init() {
orm.RegisterModel(new(ChanceFavorite))
}
// AddChanceFavorite insert a new ChanceFavorite into database and returns
// last inserted Id on success.
func AddChanceFavorite(m *ChanceFavorite) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceFavoriteById retrieves ChanceFavorite by Id. Returns error if
// Id doesn't exist
func GetChanceFavoriteById(id int64) (v *ChanceFavorite, err error) {
o := orm.NewOrm()
v = &ChanceFavorite{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceFavorite updates ChanceFavorite by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceFavoriteById(m *ChanceFavorite) (err error) {
o := orm.NewOrm()
v := ChanceFavorite{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceFavorite deletes ChanceFavorite by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceFavorite(id int64) (err error) {
o := orm.NewOrm()
v := ChanceFavorite{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceFavorite{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) {
sql := mybeego.NewSqlExutor().Table("chance_favorite").Order("create_at desc")
sql.Where(fmt.Sprintf("user_id=%d", userId))
sql.Where(fmt.Sprintf("company_id=%d", companyId))
if chanceType > 0 {
sql.Where(fmt.Sprintf("chance_type=%d", chanceType))
}
if objectType > 0 {
sql.Where(fmt.Sprintf("object_type&%d>0", objectType))
}
if pageSize > 0 {
sql.Limit(0, pageSize)
}
if lastId > 0 {
sql.Where(fmt.Sprintf("id>%d", lastId))
}
if total, err = sql.Querys(&v); err == nil {
return
}
log.Error(sql.Strings())
return
}
func ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error) {
sql := mybeego.NewSqlExutor().Table("chance_favorite")
sql.Where(fmt.Sprintf("source_id=%d", sourceId)).
Where(fmt.Sprintf("user_id=%d", userId)).
Where(fmt.Sprintf("company_id=%d", companyId)).
Where(fmt.Sprintf("(object_type&%d)>0", objectType)).
Where(fmt.Sprintf("enable_status=1"))
return sql.QueryExists()
}