company_contract.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package company_contract
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_mobile_admin/models/tables/company_contract_permission"
  5. "hongze/hongze_mobile_admin/models/tables/company_report_permission"
  6. "time"
  7. )
  8. type CompanyContract struct {
  9. CompanyContractId int `orm:"column(company_contract_id);pk" description:"客户合同id"`
  10. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  11. ProductId int `description:"产品id"`
  12. ProductName string `description:"产品名称"`
  13. CompanyId int `description:"客户id"`
  14. CompanyProductId int `description:"客户产品id"`
  15. ContractCode string `description:"合同编码"`
  16. StartDate string `description:"合同开始时间"`
  17. EndDate string `description:"合同结束时间"`
  18. Money float64 `description:"合同金额"`
  19. PayMethod string `description:"支付方式"`
  20. PayChannel string `description:"支付渠道"`
  21. ImgUrl string `description:"合同图片,多个用#隔开"`
  22. CreateTime time.Time `description:"合同创建时间"`
  23. ModifyTime time.Time `description:"合同修改时间"`
  24. Status int `description:"状态"`
  25. Source string `description:"合同来源:上传附件, 系统合同"`
  26. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  27. }
  28. type CompanyContractDetail struct {
  29. CompanyContractId int
  30. CompanyId int `description:"客户id"`
  31. ProductId int `description:"产品id" json:"-"`
  32. ContractCode string `description:"合同编码"`
  33. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  34. StartDate string `description:"合同开始时间"`
  35. EndDate string `description:"合同结束时间"`
  36. Quarter string `description:"季度(X类试用客户使用)"`
  37. Money float64 `description:"合同金额"`
  38. PayMethod string `description:"支付方式"`
  39. PayChannel string `description:"支付渠道"`
  40. ImgUrl string `description:"合同图片,多个用#隔开"`
  41. CreateTime time.Time `description:"合同创建时间"`
  42. ModifyTime time.Time `description:"合同修改时间"`
  43. Status int `description:"状态"`
  44. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  45. RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w套餐; 2-45w套餐"`
  46. Source string `description:"合同来源:上传附件, 系统合同"`
  47. PermissionList []*company_report_permission.PermissionLookList
  48. }
  49. func GetCompanyContractDetail(companyId, productId, companyContractId int) (item *CompanyContractDetail, err error) {
  50. o := orm.NewOrm()
  51. if companyContractId == 0 {
  52. sql := `SELECT * FROM company_contract WHERE company_id=? AND product_id=? AND status=0 `
  53. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  54. } else {
  55. sql := `SELECT * FROM company_contract WHERE company_contract_id=? `
  56. err = o.Raw(sql, companyContractId).QueryRow(&item)
  57. }
  58. return
  59. }
  60. // GetCompanyContractPermissionCheckByContractId 根据合同id获取已经勾选的权限
  61. func GetCompanyContractPermissionCheckByContractId(companyId, companyContractId, permissionId int) (count int, err error) {
  62. o := orm.NewOrm()
  63. 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=? `
  64. err = o.Raw(sql, companyId, companyContractId, permissionId).QueryRow(&count)
  65. return
  66. }
  67. // GetCompanyContractPermissionByCompanyContractId 根据合同ID获取开通的权限
  68. func GetCompanyContractPermissionByCompanyContractId(companyContractId int) (items []*company_contract_permission.CompanyContractPermission, err error) {
  69. o := orm.NewOrm()
  70. sql := `SELECT * FROM company_contract_permission WHERE company_contract_id =? ORDER BY modify_time DESC `
  71. _, err = o.Raw(sql, companyContractId).QueryRows(&items)
  72. return
  73. }
  74. func GetCompanyContractDetailByContractIds(contractIds string) (list []*CompanyContract, err error) {
  75. o := orm.NewOrm()
  76. sql := `SELECT * FROM company_contract WHERE company_contract_id in (` + contractIds + `)`
  77. _, err = o.Raw(sql).QueryRows(&list)
  78. return
  79. }
  80. // 根据合同id集合字符串获取权限列表数据
  81. type CompanyContractPermissionName struct {
  82. Id int `orm:"column(id);pk" description:"客户合同id"`
  83. CompanyId int `description:"客户id"`
  84. CompanyContractId int `description:"合同id"`
  85. ChartPermissionId int `description:"权限id"`
  86. ChartPermissionName string `description:"权限名称"`
  87. PermissionName string `description:"权限名称"`
  88. PermissionRemark string `description:"权限备注"`
  89. ClassifyName string `description:"权限分类名称"`
  90. StartDate string `description:"开始日期"`
  91. EndDate string `description:"结束日期"`
  92. CreateTime time.Time `json:"-" description:"创建时间"`
  93. ModifyTime time.Time `json:"-" description:"修改时间"`
  94. IsUpgrade int `description:"是否升级,1是,0否"`
  95. }
  96. // GetCompanyContractPermissionListByContractId 根据合同Id获取合同的权限列表
  97. func GetCompanyContractPermissionListByContractId(companyContractId int) (list []*CompanyContractPermissionName, err error) {
  98. o := orm.NewOrm()
  99. 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 =? `
  100. _, err = o.Raw(sql, companyContractId).QueryRows(&list)
  101. return
  102. }
  103. // 通过ID获取详情
  104. func GetCompanyContracDetail(condition string, pars []interface{}) (item *CompanyContractDetail, err error) {
  105. o := orm.NewOrm()
  106. sql := `SELECT * FROM company_contract WHERE 1= 1 ` + condition
  107. err = o.Raw(sql, pars).QueryRow(&item)
  108. return
  109. }
  110. // UpdateCompanyContractPackageDifference 更改合同与上一份合同金额对比信息
  111. func UpdateCompanyContractPackageDifference(packageDifference string, companyContractId int) (err error) {
  112. o := orm.NewOrm()
  113. sql := `UPDATE company_contract SET package_difference = ? WHERE company_contract_id=? `
  114. _, err = o.Raw(sql, packageDifference, companyContractId).Exec()
  115. return
  116. }
  117. // GetLastContractListByEndDate 通过最近一份合同的日期获取早于该合同的最晚一份合同
  118. func GetLastContractListByEndDate(companyId, productId int, endDate string) (item *CompanyContract, err error) {
  119. o := orm.NewOrm()
  120. sql := "SELECT * FROM company_contract where company_id = ? AND product_id= ? end_date < ? AND status = 1 ORDER BY end_date desc"
  121. err = o.Raw(sql, companyId, productId, endDate).QueryRow(&item)
  122. return
  123. }