achievement_chance.go 1.6 KB
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
}