company.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package roadshow
  2. import (
  3. "hongze/hz_crm_api/models"
  4. "hongze/hz_crm_api/models/company"
  5. "hongze/hz_crm_api/models/roadshow"
  6. "hongze/hz_crm_api/services"
  7. "hongze/hz_crm_api/utils"
  8. "strings"
  9. )
  10. // @Title 我的日历列表
  11. // @Description 我的日历列表接口
  12. // @Param KeyWord query string true "搜索关键词"
  13. // @Success 200 {object} roadshow.CalendarListResp
  14. // @router /company/search [get]
  15. func (this *CalendarController) CompanySearch() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. sysUser := this.SysUser
  22. if sysUser == nil {
  23. br.Msg = "请登录"
  24. br.ErrMsg = "请登录,SysUser Is Empty"
  25. br.Ret = 408
  26. return
  27. }
  28. KeyWord := this.GetString("KeyWord")
  29. if KeyWord == "" {
  30. br.Msg = "请输入搜索词!"
  31. return
  32. }
  33. KeyWord = "%" + KeyWord + "%"
  34. var groupId int
  35. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  36. groupId = sysUser.GroupId
  37. } else {
  38. groupId = -1
  39. }
  40. list, err := roadshow.CompanySearchV2(sysUser.AdminId, groupId, KeyWord, sysUser.RoleTypeCode)
  41. if err != nil && err.Error() != utils.ErrNoRow() {
  42. br.Msg = "搜索客户失败!"
  43. br.ErrMsg = "搜索客户失败!Err:" + err.Error()
  44. return
  45. }
  46. if list == nil {
  47. list = make([]*roadshow.CompanySearchView, 0)
  48. }
  49. br.Ret = 200
  50. br.Success = true
  51. br.Msg = "获取成功"
  52. br.Data = list
  53. }
  54. // CompanyDetail
  55. // @Title 我的日历列表
  56. // @Description 我的日历列表接口
  57. // @Param CompanyId query int true "公司id"
  58. // @Param EnglishCompany query int true "是否为英文客户"
  59. // @Param CompanyType query string true "客户类型:'ficc','权益',传空默认为ficc,"
  60. // @Success 200 {object} roadshow.CompanyDetailView
  61. // @router /company/detail [get]
  62. func (this *CalendarController) CompanyDetail() {
  63. br := new(models.BaseResponse).Init()
  64. defer func() {
  65. if br.ErrMsg == "" {
  66. br.IsSendEmail = false
  67. }
  68. this.Data["json"] = br
  69. this.ServeJSON()
  70. }()
  71. sysUser := this.SysUser
  72. if sysUser == nil {
  73. br.Msg = "请登录"
  74. br.ErrMsg = "请登录,SysUser Is Empty"
  75. br.Ret = 408
  76. return
  77. }
  78. companyId, _ := this.GetInt("CompanyId")
  79. if companyId <= 0 {
  80. br.Msg = "参数错误!"
  81. return
  82. }
  83. englishCompany, _ := this.GetInt("EnglishCompany")
  84. companyType := this.GetString("CompanyType")
  85. productId := services.GetProductId(sysUser.RoleTypeCode)
  86. if productId == 0 {
  87. productId = 1
  88. }
  89. if companyType == utils.COMPANY_CLASSIFY_RAI {
  90. productId = 2
  91. }
  92. detailView := new(roadshow.CompanyDetailView)
  93. if englishCompany == 0 {
  94. companyProductItem, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  95. if err != nil {
  96. if err.Error() == utils.ErrNoRow() {
  97. br.Msg = "该客户已被删除"
  98. return
  99. }
  100. br.Msg = "搜索客户失败!"
  101. br.ErrMsg = "搜索客户失败!Err:" + err.Error()
  102. return
  103. }
  104. permissionList, err := company.GetCompanyProductReportPermissionList(companyId, productId)
  105. if err != nil {
  106. br.Msg = "搜索客户权限失败!"
  107. br.ErrMsg = "搜索客户权限失败!Err:" + err.Error()
  108. return
  109. }
  110. var permissionArr []string
  111. for _, v := range permissionList {
  112. permissionArr = append(permissionArr, v.PermissionName)
  113. }
  114. detailView.CompanyId = companyProductItem.CompanyId
  115. detailView.CompanyName = companyProductItem.CompanyName
  116. detailView.Status = companyProductItem.Status
  117. detailView.IndustryId = companyProductItem.IndustryId
  118. detailView.IndustryName = companyProductItem.IndustryName
  119. detailView.PermissionName = strings.Join(permissionArr, "/")
  120. detailView.ReportReadTotal = companyProductItem.ViewTotal //ficc报告-累计阅读次数
  121. br.Ret = 200
  122. br.Success = true
  123. br.Msg = "获取成功"
  124. br.Data = detailView
  125. return
  126. }
  127. // 英文客户
  128. enItem, e := models.GetEnglishCompanyById(companyId)
  129. if e != nil {
  130. br.Msg = "搜索英文客户失败!"
  131. br.ErrMsg = "获取英文客户详情失败!Err:" + e.Error()
  132. return
  133. }
  134. detailView.CompanyId = enItem.CompanyId
  135. detailView.CompanyName = enItem.CompanyName
  136. detailView.Status = "正常"
  137. detailView.EnglishCompany = 1
  138. detailView.EnglishCountry = enItem.Country
  139. detailView.EnglishViewTotal = enItem.ViewTotal
  140. br.Ret = 200
  141. br.Success = true
  142. br.Msg = "获取成功"
  143. br.Data = detailView
  144. }