stack_company_statistic.go 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "time"
  5. )
  6. //存量客户数据表
  7. type StackCompanyStatistic struct {
  8. StatisticId int `orm:"column(statistic_id);pk"`
  9. Type string `description:"数据类型,取值范围:新签客户,续约客户,未续约客户"`
  10. CompanyId int `description:"企业客户id"`
  11. CompanyName string `description:"企业客户名称"`
  12. ProductId int `description:"客户产品id"`
  13. ProductName string `description:"客户产品名称"`
  14. ContractNum int `description:"第几份合同,默认是:1"`
  15. SellerId int `description:"所属销售id"`
  16. SellerName string `description:"所属销售名称"`
  17. GroupId int `description:"所属销售分组id"`
  18. DepartmentId int `description:"所属销售部门id"`
  19. Date string `description:"记录日期"`
  20. StartDate string `description:"服务起始时间"`
  21. EndDate string `description:"服务截止时间"`
  22. RegionType string `description:"所属区域,国内,海外"`
  23. CreateTime time.Time `description:"记录添加时间"`
  24. }
  25. //添加存量客户记录
  26. func AddStackCompanyStatistic(item *StackCompanyStatistic) (err error) {
  27. o := orm.NewOrm()
  28. _, err = o.Insert(item)
  29. return
  30. }
  31. //待签约用户列表
  32. type WillExpireCompanyList struct {
  33. CompanyContractId int `description:"合同id"`
  34. ContractType string `description:"合同类型"`
  35. CompanyId int `description:"企业客户id"`
  36. CompanyName string `description:"企业客户名称"`
  37. ProductId int `description:"产品id"`
  38. ProductName string `description:"产品名称"`
  39. CompanyProductId int `description:"客户购买产品授权id"`
  40. ContractCode string `description:"合同编码"`
  41. StartDate string `description:"合同开始日期"`
  42. EndDate string `description:"合同结束日期"`
  43. Money float64 `description:"合同金额"`
  44. PayMethod string `description:"付款方式"`
  45. PayChannel string `description:"付款渠道"`
  46. ImgUrl string `description:"合同图片"`
  47. CreateTime string `description:"合同创建时间"`
  48. ModifyTime string `description:"合同修改时间"`
  49. Status string `description:"合同审批状态,0:待审批,1:已审批;默认:1"`
  50. RegionType string `description:"企业客户所属区域;可选范围:国内,海外"`
  51. SellerId int `description:"归属销售id"`
  52. GroupId int `description:"归属销售分组id"`
  53. DepartmentId int `description:"所属销售部门id"`
  54. SellerName string `description:"归属销售名称"`
  55. ProductStatus string `description:"产品状态"`
  56. Count int `description:"合同数量"`
  57. }
  58. //新签客户数(存量客户)
  59. func GetStackCompanyListV1() (total int64, items []*WillExpireCompanyList, err error) {
  60. o := orm.NewOrm()
  61. //产品权限
  62. sql := `SELECT *,count(1) count FROM (
  63. SELECT a.*,b.region_type,c.seller_id,c.seller_name,c.company_name,c.group_id,c.department_id,c.status as product_status FROM company_contract a
  64. LEFT JOIN company b ON a.company_id = b.company_id
  65. LEFT JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id where a.status = 1
  66. order by a.end_date desc ) d
  67. GROUP BY company_id,product_id `
  68. total, err = o.Raw(sql).QueryRows(&items)
  69. return
  70. }