package company_contract import ( "github.com/beego/beego/v2/client/orm" "hongze/hongze_mobile_admin/models/tables/company_contract_permission" "hongze/hongze_mobile_admin/models/tables/company_report_permission" "time" ) type CompanyContract struct { CompanyContractId int `orm:"column(company_contract_id);pk" description:"客户合同id"` ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"` ProductId int `description:"产品id"` ProductName string `description:"产品名称"` CompanyId int `description:"客户id"` CompanyProductId int `description:"客户产品id"` ContractCode string `description:"合同编码"` StartDate string `description:"合同开始时间"` EndDate string `description:"合同结束时间"` Money float64 `description:"合同金额"` PayMethod string `description:"支付方式"` PayChannel string `description:"支付渠道"` ImgUrl string `description:"合同图片,多个用#隔开"` CreateTime time.Time `description:"合同创建时间"` ModifyTime time.Time `description:"合同修改时间"` Status int `description:"状态"` Source string `description:"合同来源:上传附件, 系统合同"` PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"` } type CompanyContractDetail struct { CompanyContractId int CompanyId int `description:"客户id"` ProductId int `description:"产品id" json:"-"` ContractCode string `description:"合同编码"` ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"` StartDate string `description:"合同开始时间"` EndDate string `description:"合同结束时间"` Quarter string `description:"季度(X类试用客户使用)"` Money float64 `description:"合同金额"` PayMethod string `description:"支付方式"` PayChannel string `description:"支付渠道"` ImgUrl string `description:"合同图片,多个用#隔开"` CreateTime time.Time `description:"合同创建时间"` ModifyTime time.Time `description:"合同修改时间"` Status int `description:"状态"` PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"` RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w套餐; 2-45w套餐"` Source string `description:"合同来源:上传附件, 系统合同"` PermissionList []*company_report_permission.PermissionLookList } func GetCompanyContractDetail(companyId, productId, companyContractId int) (item *CompanyContractDetail, err error) { o := orm.NewOrm() if companyContractId == 0 { sql := `SELECT * FROM company_contract WHERE company_id=? AND product_id=? AND status=0 ` err = o.Raw(sql, companyId, productId).QueryRow(&item) } else { sql := `SELECT * FROM company_contract WHERE company_contract_id=? ` err = o.Raw(sql, companyContractId).QueryRow(&item) } return } // GetCompanyContractPermissionCheckByContractId 根据合同id获取已经勾选的权限 func GetCompanyContractPermissionCheckByContractId(companyId, companyContractId, permissionId int) (count int, err error) { o := orm.NewOrm() sql := `SELECT COUNT(1) AS count FROM company_contract_permission AS a WHERE a.company_id=? AND company_contract_id=? AND a.chart_permission_id=? ` err = o.Raw(sql, companyId, companyContractId, permissionId).QueryRow(&count) return } // GetCompanyContractPermissionByCompanyContractId 根据合同ID获取开通的权限 func GetCompanyContractPermissionByCompanyContractId(companyContractId int) (items []*company_contract_permission.CompanyContractPermission, err error) { o := orm.NewOrm() sql := `SELECT * FROM company_contract_permission WHERE company_contract_id =? ORDER BY modify_time DESC ` _, err = o.Raw(sql, companyContractId).QueryRows(&items) return } func GetCompanyContractDetailByContractIds(contractIds string) (list []*CompanyContract, err error) { o := orm.NewOrm() sql := `SELECT * FROM company_contract WHERE company_contract_id in (` + contractIds + `)` _, err = o.Raw(sql).QueryRows(&list) return } // 根据合同id集合字符串获取权限列表数据 type CompanyContractPermissionName struct { Id int `orm:"column(id);pk" description:"客户合同id"` CompanyId int `description:"客户id"` CompanyContractId int `description:"合同id"` ChartPermissionId int `description:"权限id"` ChartPermissionName string `description:"权限名称"` PermissionName string `description:"权限名称"` PermissionRemark string `description:"权限备注"` ClassifyName string `description:"权限分类名称"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` CreateTime time.Time `json:"-" description:"创建时间"` ModifyTime time.Time `json:"-" description:"修改时间"` IsUpgrade int `description:"是否升级,1是,0否"` } // GetCompanyContractPermissionListByContractId 根据合同Id获取合同的权限列表 func GetCompanyContractPermissionListByContractId(companyContractId int) (list []*CompanyContractPermissionName, err error) { o := orm.NewOrm() sql := `SELECT a.*,b.chart_permission_name,b.classify_name FROM company_contract_permission AS a left join chart_permission b on a.chart_permission_id = b.chart_permission_id WHERE company_contract_id =? ` _, err = o.Raw(sql, companyContractId).QueryRows(&list) return } // 通过ID获取详情 func GetCompanyContracDetail(condition string, pars []interface{}) (item *CompanyContractDetail, err error) { o := orm.NewOrm() sql := `SELECT * FROM company_contract WHERE 1= 1 ` + condition err = o.Raw(sql, pars).QueryRow(&item) return } // UpdateCompanyContractPackageDifference 更改合同与上一份合同金额对比信息 func UpdateCompanyContractPackageDifference(packageDifference string, companyContractId int) (err error) { o := orm.NewOrm() sql := `UPDATE company_contract SET package_difference = ? WHERE company_contract_id=? ` _, err = o.Raw(sql, packageDifference, companyContractId).Exec() return } // GetLastContractListByEndDate 通过最近一份合同的日期获取早于该合同的最晚一份合同 func GetLastContractListByEndDate(companyId, productId int, endDate string) (item *CompanyContract, err error) { o := orm.NewOrm() sql := "SELECT * FROM company_contract where company_id = ? AND product_id= ? end_date < ? AND status = 1 ORDER BY end_date desc" err = o.Raw(sql, companyId, productId, endDate).QueryRow(&item) return }