chance_reserve_type.go
1.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
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type ChanceReserveType struct {
Id int `orm:"column(id);auto"`
Name string `orm:"column(name);size(50)" description:"储备类型名称"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`
SortNum int `orm:"column(sort_num);null" description:"序号 "`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间 "`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间 "`
}
func (t *ChanceReserveType) TableName() string {
return "chance_reserve_type"
}
func init() {
orm.RegisterModel(new(ChanceReserveType))
}
// AddChanceReserveType insert a new ChanceReserveType into database and returns
// last inserted Id on success.
func AddChanceReserveType(m *ChanceReserveType) (id int64, err error) {
m.CreateAt = time.Now()
m.UpdateAt = time.Now()
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
func UpdateChanceReserveType(m *ChanceReserveType, cols []string) (err error) {
m.UpdateAt = time.Now()
cols = append(cols, "UpdateAt")
o := orm.NewOrm()
_, err = o.Update(m, cols...)
return
}
func DeleteChanceReserveType(id int) (err error) {
o := orm.NewOrm()
m := &ChanceReserveType{Id: id}
_, err = o.Delete(m)
return err
}
func GetChanceReserveTypeById(id int) (m *ChanceReserveType, err error) {
o := orm.NewOrm()
m = &ChanceReserveType{Id: id}
err = o.Read(m)
return m, err
}
func HasChanceReserveTypeName(name string, companyid int64, notId int) bool {
var bl bool
o := orm.NewOrm()
bl = o.QueryTable(&ChanceReserveType{}).
Filter("name", name).
Filter("company_id", companyid).
Exclude("id", notId).
Exist()
return bl
}