chance_reserve_type.go 1.7 KB
package models

import (
	"time"

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

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

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

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

// AddChanceReserveType insert a new ChanceReserveType into database and returns
// last inserted Id on success.
func AddChanceReserveType(m *ChanceReserveType) (id int64, err error) {
	m.CreateAt = time.Now()
	m.UpdateAt = time.Now()
	o := orm.NewOrm()
	id, err = o.Insert(m)
	return
}

func UpdateChanceReserveType(m *ChanceReserveType, cols []string) (err error) {
	m.UpdateAt = time.Now()
	cols = append(cols, "UpdateAt")
	o := orm.NewOrm()
	_, err = o.Update(m, cols...)
	return
}

func DeleteChanceReserveType(id int) (err error) {
	o := orm.NewOrm()
	m := &ChanceReserveType{Id: id}
	_, err = o.Delete(m)
	return err
}

func GetChanceReserveTypeById(id int) (m *ChanceReserveType, err error) {
	o := orm.NewOrm()
	m = &ChanceReserveType{Id: id}
	err = o.Read(m)
	return m, err
}
func HasChanceReserveTypeName(name string, companyid int64, notId int) bool {
	var bl bool
	o := orm.NewOrm()
	bl = o.QueryTable(&ChanceReserveType{}).
		Filter("name", name).
		Filter("company_id", companyid).
		Exclude("id", notId).
		Exist()
	return bl
}