company_contract.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package company_contract
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_task/utils"
  5. "time"
  6. )
  7. type CompanyContract struct {
  8. CompanyContractId int `orm:"column(company_contract_id);pk" description:"客户合同id"`
  9. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  10. ProductId int `description:"产品id"`
  11. ProductName string `description:"产品名称"`
  12. CompanyId int `description:"客户id"`
  13. CompanyProductId int `description:"客户产品id"`
  14. ContractCode string `description:"合同编码"`
  15. StartDate string `description:"合同开始时间"`
  16. EndDate string `description:"合同结束时间"`
  17. Money float64 `description:"合同金额"`
  18. PayMethod string `description:"支付方式"`
  19. PayChannel string `description:"支付渠道"`
  20. ImgUrl string `description:"合同图片,多个用#隔开"`
  21. CreateTime time.Time `description:"合同创建时间"`
  22. ModifyTime time.Time `description:"合同修改时间"`
  23. Status int `description:"状态"`
  24. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  25. RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
  26. }
  27. // GetStartContractListByStartDate 通过开始日期获取当天开始的合同列表
  28. func GetStartContractListByStartDate(startDate string) (total int64, list []*CompanyContract, err error) {
  29. o := orm.NewOrm()
  30. sql := "SELECT * FROM company_contract where start_date = ? AND status = 1 "
  31. total, err = o.Raw(sql, startDate).QueryRows(&list)
  32. return
  33. }
  34. type CompanyContractPermission struct {
  35. Id int `orm:"column(id);pk" description:"客户合同id"`
  36. CompanyId int `description:"客户id"`
  37. CompanyContractId int `description:"合同id"`
  38. ChartPermissionId int `description:"权限id"`
  39. IsUpgrade int `description:"是否升级,1是,0否"`
  40. ExpensiveYx int `description:"权益研选: 0-3w; 1-5w"`
  41. StartDate string `description:"开始日期"`
  42. EndDate string `description:"结束日期"`
  43. CreateTime time.Time `description:"创建时间"`
  44. ModifyTime time.Time `description:"修改时间"`
  45. ContractType string `description:"签约合同时,当前行业类型:枚举值:'行业新签','行业续约'"`
  46. PermissionName string `description:"权限名称"`
  47. }
  48. // GetContractListByEndDate 通过结束日期获取当天结束的合同列表
  49. func GetContractListByEndDate(endDate string) (total int64, list []*CompanyContract, err error) {
  50. o := orm.NewOrm()
  51. sql := "SELECT * FROM company_contract where end_date = ? AND product_id = 1 AND status = 1 "
  52. total, err = o.Raw(sql, endDate).QueryRows(&list)
  53. return
  54. }
  55. // GetContractListByEndDateAndModifyTime 通过结束日期获取之前已经续约了的合同列表
  56. func GetContractListByEndDateAndModifyTime(endDate, modifyTime string, companyIdList []int) (total int64, list []*CompanyContract, err error) {
  57. num := len(companyIdList)
  58. if num <= 0 {
  59. return
  60. }
  61. o := orm.NewOrm()
  62. 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) + ")"
  63. total, err = o.Raw(sql, endDate, modifyTime, companyIdList).QueryRows(&list)
  64. return
  65. }
  66. // GetAfterCompanyContractListByCompanyIdListAndEndDate 通过结束日期和客户id列表获取合同列表
  67. func GetAfterCompanyContractListByCompanyIdListAndEndDate(endDate string, companyIdList []int) (total int64, list []*CompanyContract, err error) {
  68. num := len(companyIdList)
  69. if num <= 0 {
  70. return
  71. }
  72. o := orm.NewOrm()
  73. sql := "SELECT * FROM company_contract where end_date > ? AND product_id = 1 AND status = 1 AND company_id in (" + utils.GetOrmInReplace(num) + ")"
  74. total, err = o.Raw(sql, endDate, companyIdList).QueryRows(&list)
  75. return
  76. }
  77. // GetLastContractListByEndDate 通过最近一份合同的日期获取早于该合同的最晚一份合同
  78. func GetLastContractListByEndDate(companyId, productId int, endDate string) (item *CompanyContract, err error) {
  79. o := orm.NewOrm()
  80. sql := "SELECT * FROM company_contract where company_id = ? AND product_id= ? end_date < ? AND status = 1 ORDER BY end_date desc"
  81. err = o.Raw(sql, companyId, productId, endDate).QueryRow(&item)
  82. return
  83. }
  84. // 获取合同对应的权限列表
  85. func GetCompanyContractPermissionList(condition string, pars []interface{}) (items []*CompanyContractPermission, err error) {
  86. o := orm.NewOrm()
  87. sql := `SELECT * FROM company_contract_permission WHERE 1 = 1 `
  88. if condition != "" {
  89. sql += condition
  90. }
  91. _, err = o.Raw(sql, pars).QueryRows(&items)
  92. return
  93. }
  94. type CompanyContractResp struct {
  95. CompanyContractId int `orm:"column(company_contract_id);pk" description:"客户合同id"`
  96. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  97. ProductId int `description:"产品id"`
  98. ProductName string `description:"产品名称"`
  99. CompanyId int `description:"客户id"`
  100. CompanyProductId int `description:"客户产品id"`
  101. ContractCode string `description:"合同编码"`
  102. StartDate string `description:"合同开始时间"`
  103. EndDate string `description:"合同结束时间"`
  104. Money float64 `description:"合同金额"`
  105. PayMethod string `description:"支付方式"`
  106. PayChannel string `description:"支付渠道"`
  107. ImgUrl string `description:"合同图片,多个用#隔开"`
  108. CreateTime time.Time `description:"合同创建时间"`
  109. ModifyTime time.Time `description:"合同修改时间"`
  110. Status int `description:"状态"`
  111. Source string `description:"合同来源,枚举值:上传附件、系统合同,默认上传附件"`
  112. PackageType int `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
  113. RaiPackageType int `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
  114. PermissionName string `description:"权限名"`
  115. }
  116. // 通过ID获取详情
  117. func GetCompanyContracDetail(condition string, pars []interface{}) (item *CompanyContractResp, err error) {
  118. o := orm.NewOrm()
  119. sql := `SELECT * FROM company_contract WHERE 1= 1 ` + condition
  120. err = o.Raw(sql, pars).QueryRow(&item)
  121. return
  122. }
  123. // UpdateCompanyContractPackageDifference 更改合同与上一份合同金额对比信息
  124. func UpdateCompanyContractPackageDifference(packageDifference string, companyContractId int) (err error) {
  125. o := orm.NewOrm()
  126. sql := `UPDATE company_contract SET package_difference = ? WHERE company_contract_id=? `
  127. _, err = o.Raw(sql, packageDifference, companyContractId).Exec()
  128. return
  129. }
  130. // UpdateCompanyContractPermissionMulti 批量修改
  131. func UpdateCompanyContractPermissionMulti(items []*CompanyContractPermission) (err error) {
  132. o, err := orm.NewOrm().Begin()
  133. if err != nil {
  134. return
  135. }
  136. defer func() {
  137. if err == nil {
  138. o.Commit()
  139. } else {
  140. o.Rollback()
  141. }
  142. }()
  143. //批量修改公司
  144. p, err := o.Raw("UPDATE company_contract_permission SET permission_name = ? ,contract_type = ? WHERE id = ?").Prepare()
  145. if err != nil {
  146. return
  147. }
  148. defer func() {
  149. _ = p.Close() // 别忘记关闭 statement
  150. }()
  151. for _, v := range items {
  152. _, err = p.Exec(v.PermissionName, v.ContractType, v.Id)
  153. if err != nil {
  154. return
  155. }
  156. }
  157. return
  158. }