company_contract_merge.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package company
  2. import (
  3. //"fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CompanyContractMergeResp struct {
  8. CompanyContractMergeId int `orm:"column(company_contract_merge_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. StartDate time.Time `description:"合同开始时间"`
  15. EndDate time.Time `description:"合同结束时间"`
  16. Money float64 `description:"合同金额"`
  17. CreateTime time.Time `description:"合同创建时间"`
  18. ModifyTime time.Time `description:"合同修改时间"`
  19. CompanyContractIdGroup string `description:"表company_contract合并的 company_contract_id"`
  20. ChartPermissionName string `description:"权限类目名称"`
  21. PackageDifference string `description:"和上一份合同的区别"`
  22. }
  23. type CompanyContractMergeDetailResp struct {
  24. CompanyContractMergeId int `orm:"column(company_contract_merge_id);pk" description:"主键ID"`
  25. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  26. ProductId int `description:"产品id"`
  27. ProductName string `description:"产品名称"`
  28. CompanyId int `description:"客户id"`
  29. CompanyProductId int `description:"客户产品id"`
  30. StartDate string `description:"合同开始时间"`
  31. EndDate string `description:"合同结束时间"`
  32. Money float64 `description:"合同金额"`
  33. CreateTime time.Time `description:"合同创建时间"`
  34. ModifyTime time.Time `description:"合同修改时间"`
  35. CompanyContractIdGroup string `description:"表company_contract合并的 company_contract_id"`
  36. ChartPermissionName string `description:"权限类目名称"`
  37. PackageDifference string `description:"和上一份合同的区别"`
  38. PermissionName string `description:"权限名"`
  39. }
  40. // GetIncrementalNewCompanyProductMergeCount 获取增量客户产品报表列表统计数据(根据合同来展示)
  41. func GetIncrementalNewCompanyProductMergeCount(condition string, pars []interface{}) (total int, err error) {
  42. o := orm.NewOrm()
  43. sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
  44. JOIN company b ON a.company_id = b.company_id
  45. JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE 1 = 1 `
  46. if condition != "" {
  47. sql += condition
  48. }
  49. sql = `select count(1) count from (` + sql + ` ) f`
  50. err = o.Raw(sql, pars).QueryRow(&total)
  51. return
  52. }
  53. // GetIncrementalRenewalCompanyProductMergeCount 续约合同数量
  54. func GetIncrementalRenewalCompanyProductMergeCount(condition string, pars []interface{}) (total int, err error) {
  55. o := orm.NewOrm()
  56. sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
  57. JOIN company b ON a.company_id = b.company_id
  58. JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE 1 = 1 `
  59. if condition != "" {
  60. sql += condition
  61. }
  62. sql = `select count(1) count from (` + sql + ` ) f`
  63. err = o.Raw(sql, pars).QueryRow(&total)
  64. return
  65. }
  66. type GetCompanyContractMergeDetailResp struct {
  67. Detail *CompanyContractMergeDetailResp
  68. }
  69. // GetIncrementalNewCompanyProductMergeCount 获取增量客户产品报表列表统计数据(根据合同来展示)
  70. func GetIncrementalNewCompanyProductPermissionCount(condition string, pars []interface{}) (total int, err error) {
  71. o := orm.NewOrm()
  72. sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
  73. JOIN company b ON a.company_id = b.company_id
  74. JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id
  75. JOIN company_contract_permission d ON d.company_contract_id = a.company_contract_id
  76. WHERE 1 = 1 `
  77. if condition != "" {
  78. sql += condition
  79. }
  80. sql = `select count(1) count from (` + sql + ` GROUP BY d.company_contract_id,d.permission_name ) f`
  81. err = o.Raw(sql, pars).QueryRow(&total)
  82. return
  83. }
  84. // GetIncrementalRenewalCompanyProductMergeSumMoney 对于签约的合同金额进行求和运算
  85. func GetIncrementalRenewalCompanyProductMergeSumMoney(condition string, pars []interface{}) (total float64, err error) {
  86. o := orm.NewOrm()
  87. sql := `SELECT
  88. SUM( a.money ) AS total
  89. FROM
  90. company_contract a
  91. JOIN company b ON a.company_id = b.company_id
  92. JOIN company_product c ON a.company_id = c.company_id
  93. AND a.product_id = c.product_id
  94. WHERE
  95. 1 = 1 `
  96. if condition != "" {
  97. sql += condition
  98. }
  99. err = o.Raw(sql, pars).QueryRow(&total)
  100. return
  101. }
  102. // 权益客户统计,续约率搜索自然年的年份,返回类
  103. type SearchYearListResp struct {
  104. List []int
  105. }