chance_reserve_type.go 1.3 KB
package models

import (
	"time"

	"github.com/astaxie/beego/orm"
)

type ChanceReserveType struct {
	Id        int       `orm:"column(id);auto" json:"id"`
	Name      string    `orm:"column(name);size(50)" description:"储备类型名称" json:"name"`
	CompanyId int       `orm:"column(company_id)" description:"表company.id 公司编号" json:"-"`
	SortNum   int       `orm:"column(sort_num);null" description:"序号 " json:"-"`
	CreateAt  time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间 " json:"-"`
	UpdateAt  time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间 " json:"-"`
}

func (t *ChanceReserveType) TableName() string {
	return "chance_reserve_type"
}

func init() {
	orm.RegisterModel(new(ChanceReserveType))
}

// GetChanceReserveTypeById retrieves ChanceReserveType by Id. Returns error if
// Id doesn't exist
func GetChanceReserveTypeById(id int) (v *ChanceReserveType, err error) {
	o := orm.NewOrm()
	v = &ChanceReserveType{Id: id}
	if err = o.Read(v); err == nil {
		return v, nil
	}
	return nil, err
}

func GetChanceReserveTypes(cid int64) (v []*ChanceReserveType, err error) {
	o := orm.NewOrm()
	sql := "select * from chance_reserve_type where company_id=? order by sort_num,id"
	if _, err = o.Raw(sql, cid).QueryRows(&v); err == nil {
		return
	}
	return
}