company_contract.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. )
  6. // 增量客户统计报表列表数据结构
  7. type CompanyContractResp struct {
  8. CompanyContractId int `description:"合同id"`
  9. ContractType string `description:"合同类型"`
  10. CompanyId int `description:"企业客户id"`
  11. CompanyName string `description:"企业客户名称"`
  12. ContractCode string `description:"合同编码"`
  13. StartDate string `description:"合同开始日期"`
  14. EndDate string `description:"合同结束日期"`
  15. Money float64 `description:"合同金额"`
  16. CreateTime string `description:"合同创建时间"`
  17. ModifyTime string `description:"合同修改时间"`
  18. SellerId int `description:"归属销售id"`
  19. SellerName string `description:"归属销售名称"`
  20. IsAllocation int `description:"是否派点: 0-未派点; 1-已派点"`
  21. Source string `description:"合同来源,枚举值:上传附件、系统合同,默认上传附件"`
  22. FormalType string `description:"转正类型,枚举值: 标准、非标"`
  23. IsGray bool `description:"是否置灰"`
  24. ContractId int `description:"合同唯一id"`
  25. MoneyPoint float64 `description:"派点金额"`
  26. PermissionName string `description:"权限名"`
  27. Quarter string `description:"季度(X类试用客户使用)"`
  28. }
  29. // 增量客户统计报表返回类
  30. type CompanyContractListResp struct {
  31. Paging *paging.PagingItem `description:"分页数据"`
  32. List []*CompanyContractResp
  33. }
  34. // 获取存量客户未续约报表列表统计数据(根据合同来展示)
  35. func GetCompanyContractCountJoinCompany(condition string, pars []interface{}) (total int, err error) {
  36. o := orm.NewOrm()
  37. sql := ` SELECT
  38. count(*) AS count
  39. FROM
  40. (
  41. SELECT
  42. COUNT(*)
  43. FROM
  44. company_contract a
  45. JOIN company b ON a.company_id = b.company_id
  46. JOIN company_product c ON a.company_id = c.company_id
  47. AND a.product_id = c.product_id
  48. WHERE
  49. a.STATUS = 1
  50. ` + condition + `
  51. GROUP BY
  52. a.company_contract_id
  53. ) b`
  54. err = o.Raw(sql, pars).QueryRow(&total)
  55. return
  56. }
  57. // 获取存量客户未续约报表列表数据(根据合同来展示)
  58. func GetCompanyContractListJoinCompany(condition string, pars []interface{}, startSize, pageSize int) (items []*CompanyContractResp, err error) {
  59. o := orm.NewOrm()
  60. //
  61. //sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
  62. // JOIN company b ON a.company_id = b.company_id
  63. // JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE a.status = 1 `
  64. //
  65. //if condition != "" {
  66. // sql += condition
  67. //}
  68. //sql += " order by a.start_date desc "
  69. //sql = `select *,count(*) count from (` + sql + `) b group by company_id order by end_date asc,company_id desc limit ?,?`
  70. sql := ` SELECT
  71. a.*,
  72. b.region_type,
  73. c.seller_id,
  74. c.seller_name,
  75. b.company_name
  76. FROM
  77. company_contract a
  78. JOIN company b ON a.company_id = b.company_id
  79. JOIN company_product c ON a.company_id = c.company_id
  80. AND a.product_id = c.product_id
  81. WHERE
  82. a.STATUS = 1`
  83. sql += condition
  84. sql += `GROUP BY a.company_contract_id ORDER BY a.start_date DESC , a.company_contract_id DESC LIMIT ?,? `
  85. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  86. return
  87. }