company.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. // @Success 200 {object} roadshow.CompanyDetailView
  60. // @router /company/detail [get]
  61. func (this *CalendarController) CompanyDetail() {
  62. br := new(models.BaseResponse).Init()
  63. defer func() {
  64. if br.ErrMsg == "" {
  65. br.IsSendEmail = false
  66. }
  67. this.Data["json"] = br
  68. this.ServeJSON()
  69. }()
  70. sysUser := this.SysUser
  71. if sysUser == nil {
  72. br.Msg = "请登录"
  73. br.ErrMsg = "请登录,SysUser Is Empty"
  74. br.Ret = 408
  75. return
  76. }
  77. companyId, _ := this.GetInt("CompanyId")
  78. if companyId <= 0 {
  79. br.Msg = "参数错误!"
  80. return
  81. }
  82. englishCompany, _ := this.GetInt("EnglishCompany")
  83. productId := services.GetProductId(sysUser.RoleTypeCode)
  84. if productId == 0 {
  85. productId = 1
  86. }
  87. detailView := new(roadshow.CompanyDetailView)
  88. if englishCompany == 0 {
  89. companyProductItem, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  90. if err != nil {
  91. if err.Error() == utils.ErrNoRow() {
  92. br.Msg = "该客户已被删除"
  93. return
  94. }
  95. br.Msg = "搜索客户失败!"
  96. br.ErrMsg = "搜索客户失败!Err:" + err.Error()
  97. return
  98. }
  99. permissionList, err := company.GetCompanyProductReportPermissionList(companyId, productId)
  100. if err != nil {
  101. br.Msg = "搜索客户权限失败!"
  102. br.ErrMsg = "搜索客户权限失败!Err:" + err.Error()
  103. return
  104. }
  105. var permissionArr []string
  106. for _, v := range permissionList {
  107. permissionArr = append(permissionArr, v.PermissionName)
  108. }
  109. detailView.CompanyId = companyProductItem.CompanyId
  110. detailView.CompanyName = companyProductItem.CompanyName
  111. detailView.Status = companyProductItem.Status
  112. detailView.IndustryId = companyProductItem.IndustryId
  113. detailView.IndustryName = companyProductItem.IndustryName
  114. detailView.PermissionName = strings.Join(permissionArr, "/")
  115. detailView.ReportReadTotal = companyProductItem.ViewTotal //ficc报告-累计阅读次数
  116. br.Ret = 200
  117. br.Success = true
  118. br.Msg = "获取成功"
  119. br.Data = detailView
  120. return
  121. }
  122. // 英文客户
  123. enItem, e := models.GetEnglishCompanyById(companyId)
  124. if e != nil {
  125. br.Msg = "搜索英文客户失败!"
  126. br.ErrMsg = "获取英文客户详情失败!Err:" + e.Error()
  127. return
  128. }
  129. detailView.CompanyId = enItem.CompanyId
  130. detailView.CompanyName = enItem.CompanyName
  131. detailView.Status = "正常"
  132. detailView.EnglishCompany = 1
  133. detailView.EnglishCountry = enItem.Country
  134. detailView.EnglishViewTotal = enItem.ViewTotal
  135. br.Ret = 200
  136. br.Success = true
  137. br.Msg = "获取成功"
  138. br.Data = detailView
  139. }