package company

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

type CompanyApproval struct {
	CompanyApprovalId   int `orm:"column(company_approval_id);pk"`
	CompanyId           int
	ProductId           int
	ApproveStatus       string    `description:"'待审批','已审批','驳回','已撤回'"`
	ApproveUserId       int       `description:"审批人"`
	ApproveRoleTypeCode string    `description:"审批人角色类型"`
	ApproveRealName     string    `description:"审批人姓名"`
	ApproveTime         time.Time `description:"审批时间"`
	ApproveContent      string    `description:"待审内容"`
	ApplyMethod         int       `description:"申请类型：1:试用->正式,2:冻结—>试用,3:试用延期,4:原销售申请领取流失客户，5:正式客户申请服务更新，6：正式客户补充协议"`
	ApplyReasons        string    `description:"申请原因"`
	ApplyUserId         int       `description:"申请人"`
	ApplyRealName       string    `description:"申请人姓名"`
	CreateTime          time.Time `description:"申请时间"`
	ModifyTime          time.Time `description:"修改时间"`
	CompanyContractId   int       `description:"合同id"`
	IsFormal            int       `description:"是否已经转正式，0是没有转正式，1是已经转过正式"`
}

func GetCompanyApprovalById(companyId int) (item *CompanyApproval, err error) {
	sql := `SELECT * FROM company_approval WHERE company_id=? AND product_id=2 AND approve_status='已审批' order by company_approval_id desc LIMIT 1 `
	o := orm.NewOrmUsingDB("weekly_report")
	err = o.Raw(sql, companyId).QueryRow(&item)
	return
}
