company.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package roadshow
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CompanySearchView struct {
  7. CompanyId int `orm:"column(company_id);pk"`
  8. CompanyName string `description:"客户名称"`
  9. CreditCode string `description:"社会统一信用码"`
  10. CompanyCode string `description:"客户编码"`
  11. EnglishCompany int `description:"是否为英文客户"`
  12. }
  13. func CompanySearch(sellerId int, keyWord string) (list []*CompanySearchView, err error) {
  14. o := orm.NewOrm()
  15. sql := ` SELECT b.company_id,b.company_name FROM company AS a
  16. INNER JOIN company_product AS b ON a.company_id=b.company_id
  17. WHERE b.seller_id=?
  18. AND b.status IN('正式','试用')
  19. AND b.company_name LIKE '%` + keyWord + `%'
  20. `
  21. sql += ` GROUP BY b.company_id `
  22. _, err = o.Raw(sql, sellerId).QueryRows(&list)
  23. return
  24. }
  25. type CompanyDetailView struct {
  26. CompanyId int `orm:"column(company_id);pk"`
  27. CompanyName string `description:"客户名称"`
  28. Status string `description:"客户状态"`
  29. IndustryId int `description:"行业id"`
  30. IndustryName string `description:"行业名称"`
  31. PermissionName string `description:"开通品种"`
  32. ReportReadTotal int `description:"累计阅读次数"`
  33. EnglishCompany int `description:"是否为英文客户: 0-否; 1-是"`
  34. EnglishCountry string `description:"英文客户-国家"`
  35. EnglishViewTotal int `description:"英文客户-累计点击量"`
  36. }
  37. type CompanyProduct struct {
  38. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  39. CompanyId int `description:"客户id"`
  40. ProductId int `description:"产品id"`
  41. ProductName string `description:"产品名称"`
  42. CompanyName string `description:"客户名称"`
  43. Source string `description:"来源"`
  44. Reasons string `description:"新增理由"`
  45. Status string `description:"客户状态"`
  46. IndustryId int `description:"行业id"`
  47. IndustryName string `description:"行业名称"`
  48. SellerId int `description:"销售id"`
  49. SellerName string `description:"销售名称"`
  50. GroupId int `description:"销售分组id"`
  51. DepartmentId int `description:"销售部门id"`
  52. IsSuspend int `description:"1:暂停,0:启用"`
  53. SuspendTime time.Time `description:"暂停启用时间"`
  54. TryOutTime time.Time `description:"正式转试用时间"`
  55. RenewalReason string `description:"正式转试用后的续约情况说明"`
  56. LastDescriptionTime time.Time `description:"上次添加说明时间"`
  57. RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
  58. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  59. FreezeTime time.Time `description:"冻结时间"`
  60. FreezeReason time.Time `description:"冻结理由"`
  61. Remark string `description:"备注信息"`
  62. CreateTime time.Time `description:"创建时间"`
  63. ModifyTime time.Time `description:"修改时间"`
  64. StartDate string `description:"开始日期"`
  65. EndDate string `description:"结束日期"`
  66. ContractEndDate time.Time `description:"合同结束日期"`
  67. LoseReason string `description:"流失原因"`
  68. LossTime time.Time `description:"流失时间"`
  69. CompanyType string `description:"客户类型"`
  70. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  71. ViewTotal int `description:"总阅读次数"`
  72. LastViewTime time.Time `description:"最后一次阅读时间"`
  73. PackageType int `description:"套餐类型"`
  74. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
  75. }
  76. func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *CompanyProduct, err error) {
  77. o := orm.NewOrm()
  78. sql := `SELECT b.* FROM company AS a
  79. INNER JOIN company_product AS b ON a.company_id=b.company_id
  80. WHERE a.company_id=? AND b.product_id=? LIMIT 1 `
  81. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  82. return
  83. }
  84. // 客户授权产品结构体(包含产品名称)
  85. type CompanyReportPermissionAndName struct {
  86. CompanyReportPermissionId int `description:"客户授权产品id"`
  87. CompanyId int
  88. ReportPermissionId int
  89. CreatedTime time.Time
  90. LastUpdatedTime time.Time
  91. ChartPermissionId int
  92. StartDate string `description:"权限开始日期"`
  93. EndDate string `description:"权限结束日期"`
  94. ProductId int `description:"产品id"`
  95. ProductName string `description:"产品名称"`
  96. CompanyContractId int `description:"合同id"`
  97. PermissionName string `description:"客户授权产品的名称"`
  98. ClassifyName string `description:"客户授权产品的分类名称"`
  99. Status string `description:"'正式','试用','关闭'"`
  100. ModifyTime time.Time `description:"修改时间"`
  101. }
  102. // 根据企业用户id和产品id获取所有正式的权限
  103. func GetCompanyProductReportPermissionList(companyId, productId int) (items []*CompanyReportPermissionAndName, err error) {
  104. o := orm.NewOrm()
  105. sql := `SELECT a.*,b.permission_name,b.classify_name FROM company_report_permission a left join chart_permission b on a.chart_permission_id=b.chart_permission_id WHERE a.company_id = ? and a.product_id=? `
  106. _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
  107. return
  108. }
  109. func CompanySearchV2(sellerId int, keyWord string) (list []*CompanySearchView, err error) {
  110. list = make([]*CompanySearchView, 0)
  111. // 中文客户
  112. companies := make([]*CompanySearchView, 0)
  113. o := orm.NewOrm()
  114. sql := `SELECT
  115. b.company_id,
  116. a.company_name,
  117. 0 AS english_company
  118. FROM
  119. company AS a
  120. INNER JOIN company_product AS b ON a.company_id = b.company_id
  121. WHERE
  122. b.status IN ('正式', '试用','永续') AND (b.seller_id = ? OR b.share_seller_id = ?) AND a.company_name LIKE ?
  123. GROUP BY
  124. b.company_id`
  125. _, err = o.Raw(sql, sellerId, sellerId, keyWord).QueryRows(&companies)
  126. if err != nil {
  127. return
  128. }
  129. list = append(list, companies...)
  130. // 英文客户
  131. enCompanies := make([]*CompanySearchView, 0)
  132. o2 := orm.NewOrmUsingDB("rddp")
  133. sql = `SELECT
  134. company_id,
  135. company_name,
  136. 1 AS english_company
  137. FROM
  138. english_company
  139. WHERE
  140. is_deleted = 0 AND enabled > 0 AND company_name LIKE ?`
  141. _, err = o2.Raw(sql, keyWord).QueryRows(&enCompanies)
  142. if err != nil {
  143. return
  144. }
  145. list = append(list, enCompanies...)
  146. return
  147. }