rank_type.go
1.9 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
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type RankType struct {
Id int64 `orm:"column(id);pk"`
CompanyId int64 `orm:"column(company_id)"`
Name string `orm:"column(name)"`
EnableStatus int8 `orm:"column(enable_status)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
Type int8 `orm:"column(type)"`
AutoCreate int8 `orm:"column(auto_create)"` //是否自动创建赛季 【0:否】【1:是】
AutoPeriod int `orm:"column(auto_period)"`
}
func (t *RankType) TableName() string {
return "rank_type"
}
func init() {
orm.RegisterModel(new(RankType))
}
//榜单类型
const (
RANK_TYPE_SEASON int8 = 1 //季赛榜
RANK_TYPE_YEAR int8 = 2 //年榜
)
//榜单状态
const (
RANK_STATUS_YES int8 = 1 //启用
RANK_STATUS_NO int8 = 2 //禁用
)
// AddRank insert a new Rank into database and returns
// last inserted Id on success.
func AddRank(m *RankType) (id int64, err error) {
o := orm.NewOrm()
nowTime := time.Now()
m.CreateAt = nowTime
m.UpdateAt = nowTime
id, err = o.Insert(m)
return
}
// GetRankById retrieves Rank by Id. Returns error if
// Id doesn't exist
func GetRankById(id int64) (v *RankType, err error) {
o := orm.NewOrm()
v = &RankType{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateRank updates Rank by Id and returns error if
// the record to be updated doesn't exist
func UpdateRankById(m *RankType, cols []string, om ...orm.Ormer) (err error) {
var o orm.Ormer
if len(om) > 0 {
o = om[0]
} else {
o = orm.NewOrm()
}
m.UpdateAt = time.Now()
if len(cols) > 0 {
cols = append(cols, "UpdateAt")
}
var num int64
if num, err = o.Update(m, cols...); err == nil {
fmt.Println("Number of records updated in database:", num)
}
return
}