package company

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

type CompanyContractPermission struct {
	Id                int       `orm:"column(id);pk" description:"客户合同id"`
	CompanyId         int       `description:"客户id"`
	CompanyContractId int       `description:"合同id"`
	ChartPermissionId int       `description:"权限id"`
	IsUpgrade         int       `description:"是否升级，1是，0否"`
	ExpensiveYx       int       `description:"权益研选: 0-3w; 1-5w"`
	StartDate         string    `description:"开始日期"`
	EndDate           string    `description:"结束日期"`
	CreateTime        time.Time `description:"创建时间"`
	ModifyTime        time.Time `description:"修改时间"`
	Points            float64   `description:"研选扣点包点数"`
}

func GetCompanyContractPermissionCheck(companyContractId, permissionId int) (count int, err error) {
	o := orm.NewOrmUsingDB("weekly_report")
	sql := `SELECT COUNT(1) AS count FROM company_contract_permission AS a WHERE a.company_contract_id=? AND a.chart_permission_id=? `
	err = o.Raw(sql, companyContractId, permissionId).QueryRow(&count)
	return
}

// 通过查询条件获取详情
func GetCompanyContractPermissionDetail(condition string, pars []interface{}) (item *CompanyContractPermission, err error) {
	if condition == "" {
		return
	}
	o := orm.NewOrmUsingDB("weekly_report")
	sql := `SELECT * FROM company_contract_permission  WHERE 1 = 1  ` + condition
	err = o.Raw(sql, pars).QueryRow(&item)
	return
}
