company.go 7.7 KB

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