company.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "time"
  5. )
  6. type Company struct {
  7. CompanyId int `orm:"column(company_id);pk"`
  8. CompanyName string `description:"客户名称"`
  9. CreditCode string `description:"社会统一信用码"`
  10. CompanyCode string `description:"客户编码"`
  11. Sort int `description:"优先级"`
  12. IsFeeCustomer int `description:"是否付费用户"`
  13. Country string `description:"国家编码"`
  14. ProvinceId int `description:"省id"`
  15. CityId int `description:"市id"`
  16. Address string `description:"详细地址"`
  17. CompanyType int `orm:"column(type)" description:"客户标签,1:付费客户,2:试用客户,3:流失客户,4:潜在客户"`
  18. Enabled int `description:"用户状态"`
  19. CreatedTime time.Time `description:"创建时间"`
  20. LastUpdatedTime time.Time `description:"最后一次阅读时间"`
  21. Seller string `description:"销售员"`
  22. SellsId int `description:"销售员id"`
  23. CompanyBelong string `description:"客户所属,ficc:ficc客户,public_offering:公募客户,partner:合作伙伴"`
  24. StartDate string `description:"合同开始日期"`
  25. EndDate string `description:"合同结束日期"`
  26. LoseReason string `description:"流失原因"`
  27. LastType int `description:"原客户标签"`
  28. IsVip int `description:"0:普通用户,1:大客户"`
  29. LossTime time.Time `description:"流失时间"`
  30. FirstStartDate string `description:"首次设置为试用客户开始时间"`
  31. FirstEndDate string `description:"首次设置为试用客户结束时间"`
  32. DateType int `description:"设置流失类型,1:1个月,2:2个月,3:3个月"`
  33. }
  34. func GetCompanyByName(companyName string) (item *Company, err error) {
  35. o := orm.NewOrm()
  36. sql := `SELECT * FROM company WHERE company_name=? `
  37. err = o.Raw(sql, companyName).QueryRow(&item)
  38. return
  39. }
  40. func GetCompanyCountByCreditCode(CreditCode string) (count int, err error) {
  41. o := orm.NewOrm()
  42. sql := `SELECT COUNT(1) AS count FROM company WHERE credit_code=? `
  43. err = o.Raw(sql, CreditCode).QueryRow(&count)
  44. return
  45. }
  46. func AddCompany(item *Company) (newId int64, err error) {
  47. o := orm.NewOrm()
  48. newId, err = o.Insert(item)
  49. return
  50. }
  51. func GetCompany() (items []*Company, err error) {
  52. sql := `SELECT * FROM company WHERE type =1 `
  53. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  54. return
  55. }
  56. //待冻结客户
  57. type CompanyNeedFreeze struct {
  58. CompanyId int
  59. CompanyProductId int
  60. ProductId int
  61. CompanyName string
  62. ProductName string
  63. Status string
  64. }
  65. func GetCompanyNeedFreeze(endDate string) (items []*CompanyNeedFreeze, err error) {
  66. o := orm.NewOrm()
  67. sql := `SELECT a.company_id,b.company_product_id,b.product_id,a.company_name,b.product_name,b.status
  68. FROM company AS a
  69. INNER JOIN company_product AS b ON a.company_id=b.company_id
  70. WHERE b.status='试用'
  71. AND b.end_date<=? `
  72. _, err = o.Raw(sql, endDate).QueryRows(&items)
  73. return
  74. }
  75. func GetCompanyNeedLoss(endDate string) (items []*CompanyNeedFreeze, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT a.company_id,b.company_product_id,b.product_id,a.company_name,b.product_name,b.status
  78. FROM company AS a
  79. INNER JOIN company_product AS b ON a.company_id=b.company_id
  80. WHERE b.status='冻结'
  81. AND b.freeze_end_date<=? `
  82. _, err = o.Raw(sql, endDate).QueryRows(&items)
  83. return
  84. }
  85. //正式
  86. func GetCompanyNeedTryOut(endDate string) (items []*CompanyNeedFreeze, err error) {
  87. o := orm.NewOrm()
  88. sql := `SELECT a.company_id,b.company_product_id,b.product_id,a.company_name,b.product_name,b.status
  89. FROM company AS a
  90. INNER JOIN company_product AS b ON a.company_id=b.company_id
  91. WHERE b.status='正式'
  92. AND b.end_date<=? `
  93. _, err = o.Raw(sql, endDate).QueryRows(&items)
  94. return
  95. }
  96. type CompanyIndustry struct {
  97. IndustryId int `description:"行业id"`
  98. IndustryName string `description:"行业名称"`
  99. ParentId int `description:"父级id"`
  100. Classify string `description:"分类"`
  101. }
  102. func GetCompanyIndustryByName(industryName string) (items *CompanyIndustry, err error) {
  103. o := orm.NewOrm()
  104. sql := `SELECT * FROM company_industry WHERE industry_name=? `
  105. err = o.Raw(sql, industryName).QueryRow(&items)
  106. return
  107. }
  108. func ModifyCompanyCreditCode(companyId int, creditCode string) (err error) {
  109. o := orm.NewOrm()
  110. sql := `UPDATE company SET credit_code=? WHERE company_id=? AND credit_code='' `
  111. _, err = o.Raw(sql, creditCode, companyId).Exec()
  112. return
  113. }
  114. func ModifyCompanyIndustry(industryId,companyId int, industryName string) (err error) {
  115. o := orm.NewOrm()
  116. sql := `UPDATE company_product SET industry_id=?,industry_name=? WHERE company_id=? AND product_id=1 AND industry_id=0 `
  117. _, err = o.Raw(sql, industryId,industryName, companyId).Exec()
  118. return
  119. }