achievement_chance.go
1.6 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
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type AchievementChance struct {
Id int64 `orm:"column(id);pk"`
AchievementId int64 `orm:"column(achievement_id);null" description:"成果编号 表achievement.id"`
ChanceId int64 `orm:"column(chance_id);null" description:"机会编号 表chance.id"`
ChanceCode string `orm:"column(chance_code);size(255);null" description:"机会编号 表chance.code"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
}
func (t *AchievementChance) TableName() string {
return "achievement_chance"
}
func init() {
orm.RegisterModel(new(AchievementChance))
}
// GetAchievementChanceById retrieves AchievementChance by Id. Returns error if
// Id doesn't exist
func GetAchievementChanceById(id int64) (v *AchievementChance, err error) {
o := orm.NewOrm()
v = &AchievementChance{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
//查询成果提供者列表
func GetAchievementChances(achievementId int64, v interface{}) (err error) {
o := orm.NewOrm()
sql := `select a.*,b.images,speechs,videos
from (
select chance_id,b.user_id chance_user_id,approve_time create_at,source_content,enable_status,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,publish_status,status
from achievement_chance a inner join chance b on a.chance_id=b.id where achievement_id=? and b.review_status=3
) a left JOIN chance_data b on a.chance_id =b.chance_id
order by a.create_at desc
`
if _, err = o.Raw(sql, achievementId).QueryRows(v); err == nil {
return nil
}
return err
}