achevement_score.go
2.1 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
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type AchevementScore struct {
Id int64 `orm:"column(id);auto"`
GraspScoreRemain float64 `orm:"column(grasp_score_remain);null;digits(10);decimals(1)" description:"福利池总分 ,来源achievement中的评分"`
CompanyId int64 `orm:"column(company_id)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null"`
}
func (t *AchevementScore) TableName() string {
return "achevement_score"
}
func init() {
orm.RegisterModel(new(AchevementScore))
}
// AddAchevementScore insert a new AchevementScore into database and returns
// last inserted Id on success.
func AddAchevementScore(m *AchevementScore, o orm.Ormer) (id int64, err error) {
id, err = o.Insert(m)
return
}
// GetAchevementScoreById retrieves AchevementScore by Id. Returns error if
// Id doesn't exist
func GetAchevementScoreById(id int64) (v *AchevementScore, err error) {
o := orm.NewOrm()
v = &AchevementScore{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
func GetAchevementScoreByCompanyId(companyid int64) (v *AchevementScore, err error) {
o := orm.NewOrm()
v = &AchevementScore{}
ok := o.QueryTable(&AchevementScore{}).
Filter("company_id", companyid).
Exist()
if !ok {
return v, nil
}
err = o.QueryTable(&AchevementScore{}).
Filter("company_id", companyid).
One(v)
return v, err
}
func IncreaseAchevementScore(companyid int64, addScore float64, o orm.Ormer) error {
v := &AchevementScore{}
ok := o.QueryTable(&AchevementScore{}).
Filter("company_id", companyid).
Exist()
if ok {
nowTime := time.Now().Format("2006-01-02 15:04:05")
sql := `update achevement_score set grasp_score_remain=grasp_score_remain+?,update_at=? where company_id=?`
//存在,更新
_, err := o.Raw(sql, addScore, nowTime, companyid).Exec()
return err
}
//不存在
v.CompanyId = companyid
v.GraspScoreRemain = addScore
v.CreateAt = time.Now()
_, err := o.Insert(v)
return err
}