company_contract.go 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. }
  28. // 增量客户统计报表返回类
  29. type CompanyContractListResp struct {
  30. Paging *paging.PagingItem `description:"分页数据"`
  31. List []*CompanyContractResp
  32. }
  33. // 获取存量客户未续约报表列表统计数据(根据合同来展示)
  34. func GetCompanyContractCountJoinCompany(condition string, pars []interface{}) (total int, err error) {
  35. o := orm.NewOrm()
  36. sql := ` SELECT
  37. count(*) AS count
  38. FROM
  39. (
  40. SELECT
  41. COUNT(*)
  42. FROM
  43. 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
  46. AND a.product_id = c.product_id
  47. WHERE
  48. a.STATUS = 1
  49. ` + condition + `
  50. GROUP BY
  51. a.company_contract_id
  52. ) b`
  53. err = o.Raw(sql, pars).QueryRow(&total)
  54. return
  55. }
  56. // 获取存量客户未续约报表列表数据(根据合同来展示)
  57. func GetCompanyContractListJoinCompany(condition string, pars []interface{}, startSize, pageSize int) (items []*CompanyContractResp, err error) {
  58. o := orm.NewOrm()
  59. //
  60. //sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
  61. // JOIN company b ON a.company_id = b.company_id
  62. // JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE a.status = 1 `
  63. //
  64. //if condition != "" {
  65. // sql += condition
  66. //}
  67. //sql += " order by a.start_date desc "
  68. //sql = `select *,count(*) count from (` + sql + `) b group by company_id order by end_date asc,company_id desc limit ?,?`
  69. sql := ` SELECT
  70. a.*,
  71. b.region_type,
  72. c.seller_id,
  73. c.seller_name,
  74. b.company_name
  75. FROM
  76. company_contract a
  77. JOIN company b ON a.company_id = b.company_id
  78. JOIN company_product c ON a.company_id = c.company_id
  79. AND a.product_id = c.product_id
  80. WHERE
  81. a.STATUS = 1`
  82. sql += condition
  83. sql += `GROUP BY a.company_contract_id ORDER BY a.start_date DESC , a.company_contract_id DESC LIMIT ?,? `
  84. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  85. return
  86. }