company_contract.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. }
  26. // 增量客户统计报表返回类
  27. type CompanyContractListResp struct {
  28. List []*CompanyContractResp
  29. Paging *paging.PagingItem `description:"分页数据"`
  30. }
  31. // 获取存量客户未续约报表列表统计数据(根据合同来展示)
  32. func GetCompanyContractCountJoinCompany(condition string, pars []interface{}) (total int, err error) {
  33. o := orm.NewOrm()
  34. sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
  35. JOIN company b ON a.company_id = b.company_id
  36. JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE a.status = 1 `
  37. if condition != "" {
  38. sql += condition
  39. }
  40. //sql += " order by a.start_date desc "
  41. sql = `select count(1) count from (` + sql + ` group by company_id) f`
  42. err = o.Raw(sql, pars).QueryRow(&total)
  43. return
  44. }
  45. // 获取存量客户未续约报表列表数据(根据合同来展示)
  46. func GetCompanyContractListJoinCompany(condition string, pars []interface{}, startSize, pageSize int) (items []*CompanyContractResp, err error) {
  47. o := orm.NewOrm()
  48. sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
  49. JOIN company b ON a.company_id = b.company_id
  50. JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE a.status = 1 `
  51. if condition != "" {
  52. sql += condition
  53. }
  54. sql += " order by a.start_date desc "
  55. sql = `select *,count(*) count from (` + sql + `) b group by company_id order by end_date asc,company_id desc limit ?,?`
  56. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  57. return
  58. }