company_contract.go 3.0 KB

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