123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- package company_contract
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_task/utils"
- "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:"状态"`
- PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
- RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
- }
- // GetStartContractListByStartDate 通过开始日期获取当天开始的合同列表
- func GetStartContractListByStartDate(startDate string) (total int64, list []*CompanyContract, err error) {
- o := orm.NewOrm()
- sql := "SELECT * FROM company_contract where start_date = ? AND status = 1 "
- total, err = o.Raw(sql, startDate).QueryRows(&list)
- return
- }
- 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:"修改时间"`
- ContractType string `description:"签约合同时,当前行业类型:枚举值:'行业新签','行业续约'"`
- PermissionName string `description:"权限名称"`
- }
- // GetContractListByEndDate 通过结束日期获取当天结束的合同列表
- func GetContractListByEndDate(endDate string) (total int64, list []*CompanyContract, err error) {
- o := orm.NewOrm()
- sql := "SELECT * FROM company_contract where end_date = ? AND product_id = 1 AND status = 1 "
- total, err = o.Raw(sql, endDate).QueryRows(&list)
- return
- }
- // GetContractListByEndDateAndModifyTime 通过结束日期获取之前已经续约了的合同列表
- func GetContractListByEndDateAndModifyTime(endDate, modifyTime string, companyIdList []int) (total int64, list []*CompanyContract, err error) {
- num := len(companyIdList)
- if num <= 0 {
- return
- }
- o := orm.NewOrm()
- sql := "SELECT * FROM company_contract where end_date > ? AND product_id = 1 AND status = 1 AND modify_time <= ? AND company_id in (" + utils.GetOrmInReplace(num) + ")"
- total, err = o.Raw(sql, endDate, modifyTime, companyIdList).QueryRows(&list)
- return
- }
- // GetAfterCompanyContractListByCompanyIdListAndEndDate 通过结束日期和客户id列表获取合同列表
- func GetAfterCompanyContractListByCompanyIdListAndEndDate(endDate string, companyIdList []int) (total int64, list []*CompanyContract, err error) {
- num := len(companyIdList)
- if num <= 0 {
- return
- }
- o := orm.NewOrm()
- sql := "SELECT * FROM company_contract where end_date > ? AND product_id = 1 AND status = 1 AND company_id in (" + utils.GetOrmInReplace(num) + ")"
- total, err = o.Raw(sql, endDate, companyIdList).QueryRows(&list)
- 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
- }
- // 获取合同对应的权限列表
- func GetCompanyContractPermissionList(condition string, pars []interface{}) (items []*CompanyContractPermission, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM company_contract_permission WHERE 1 = 1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- type CompanyContractResp 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:小套餐"`
- RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
- PermissionName string `description:"权限名"`
- }
- // 通过ID获取详情
- func GetCompanyContracDetail(condition string, pars []interface{}) (item *CompanyContractResp, 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
- }
- // UpdateCompanyContractPermissionMulti 批量修改
- func UpdateCompanyContractPermissionMulti(items []*CompanyContractPermission) (err error) {
- o, err := orm.NewOrm().Begin()
- if err != nil {
- return
- }
- defer func() {
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- //批量修改公司
- p, err := o.Raw("UPDATE company_contract_permission SET permission_name = ? ,contract_type = ? WHERE id = ?").Prepare()
- if err != nil {
- return
- }
- defer func() {
- _ = p.Close() // 别忘记关闭 statement
- }()
- for _, v := range items {
- _, err = p.Exec(v.PermissionName, v.ContractType, v.Id)
- if err != nil {
- return
- }
- }
- return
- }
|