company.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. package roadshow
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/models/company"
  6. "hongze/hz_crm_api/models/roadshow"
  7. "hongze/hz_crm_api/models/system"
  8. "hongze/hz_crm_api/services"
  9. "hongze/hz_crm_api/utils"
  10. "strings"
  11. )
  12. // @Title 我的日历列表
  13. // @Description 我的日历列表接口
  14. // @Param KeyWord query string true "搜索关键词"
  15. // @Success 200 {object} roadshow.CalendarListResp
  16. // @router /company/search [get]
  17. func (this *CalendarController) CompanySearch() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. sysUser := this.SysUser
  24. if sysUser == nil {
  25. br.Msg = "请登录"
  26. br.ErrMsg = "请登录,SysUser Is Empty"
  27. br.Ret = 408
  28. return
  29. }
  30. KeyWord := this.GetString("KeyWord")
  31. if KeyWord == "" {
  32. br.Msg = "请输入搜索词!"
  33. return
  34. }
  35. KeyWord = "%" + KeyWord + "%"
  36. var groupId int
  37. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  38. groupId = sysUser.GroupId
  39. } else {
  40. groupId = -1
  41. }
  42. list, err := roadshow.CompanySearchV2(sysUser.AdminId, groupId, KeyWord, sysUser.RoleTypeCode)
  43. if err != nil && err.Error() != utils.ErrNoRow() {
  44. br.Msg = "搜索客户失败!"
  45. br.ErrMsg = "搜索客户失败!Err:" + err.Error()
  46. return
  47. }
  48. if list == nil {
  49. list = make([]*roadshow.CompanySearchView, 0)
  50. }
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. br.Data = list
  55. }
  56. // CompanyDetail
  57. // @Title 我的日历列表
  58. // @Description 我的日历列表接口
  59. // @Param CompanyId query int true "公司id"
  60. // @Param EnglishCompany query int true "是否为英文客户"
  61. // @Param CompanyType query string true "客户类型:'ficc','权益',传空默认为ficc,"
  62. // @Param RsReportRecordId query int true "路演统计Id"
  63. // @Success 200 {object} roadshow.CompanyDetailView
  64. // @router /company/detail [get]
  65. func (this *CalendarController) CompanyDetail() {
  66. br := new(models.BaseResponse).Init()
  67. defer func() {
  68. if br.ErrMsg == "" {
  69. br.IsSendEmail = false
  70. }
  71. this.Data["json"] = br
  72. this.ServeJSON()
  73. }()
  74. sysUser := this.SysUser
  75. if sysUser == nil {
  76. br.Msg = "请登录"
  77. br.ErrMsg = "请登录,SysUser Is Empty"
  78. br.Ret = 408
  79. return
  80. }
  81. companyId, _ := this.GetInt("CompanyId")
  82. if companyId <= 0 {
  83. br.Msg = "参数错误!"
  84. return
  85. }
  86. englishCompany, _ := this.GetInt("EnglishCompany")
  87. companyType := this.GetString("CompanyType")
  88. rsReportRecordId, _ := this.GetInt("RsReportRecordId")
  89. productId := services.GetProductId(sysUser.RoleTypeCode)
  90. if productId == 0 {
  91. productId = 1
  92. }
  93. if companyType == utils.COMPANY_CLASSIFY_RAI {
  94. productId = 2
  95. }
  96. detailView := new(roadshow.CompanyDetailView)
  97. if englishCompany == 0 {
  98. var companyStatus string
  99. var permissionName string
  100. companyProductItem, err := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  101. if err != nil {
  102. if err.Error() == utils.ErrNoRow() {
  103. br.Msg = "该客户已被删除"
  104. return
  105. }
  106. br.Msg = "搜索客户失败!"
  107. br.ErrMsg = "搜索客户失败!Err:" + err.Error()
  108. return
  109. }
  110. if rsReportRecordId > 0 {
  111. rsReportRecordItem, err := roadshow.GetRsReportRecordDetailByRsReportRecordId(rsReportRecordId)
  112. if err != nil {
  113. br.Msg = "路演信息不存在!"
  114. br.ErrMsg = "路演信息不存在!Err:" + err.Error()
  115. return
  116. }
  117. companyStatus = rsReportRecordItem.CompanyStatus
  118. permissionName = rsReportRecordItem.PermissionName
  119. } else {
  120. permissionList, err := company.GetCompanyProductReportPermissionList(companyId, productId)
  121. if err != nil {
  122. br.Msg = "搜索客户权限失败!"
  123. br.ErrMsg = "搜索客户权限失败!Err:" + err.Error()
  124. return
  125. }
  126. var permissionArr []string
  127. for _, v := range permissionList {
  128. permissionArr = append(permissionArr, v.PermissionName)
  129. }
  130. companyStatus = companyProductItem.Status
  131. permissionName = strings.Join(permissionArr, "/")
  132. }
  133. detailView.CompanyId = companyProductItem.CompanyId
  134. detailView.CompanyName = companyProductItem.CompanyName
  135. detailView.Status = companyStatus
  136. detailView.IndustryId = companyProductItem.IndustryId
  137. detailView.IndustryName = companyProductItem.IndustryName
  138. //detailView.PermissionName = strings.Join(permissionArr, "/")
  139. detailView.PermissionName = permissionName
  140. detailView.ReportReadTotal = companyProductItem.ViewTotal //ficc报告-累计阅读次数
  141. if companyType == utils.COMPANY_CLASSIFY_RAI { //权益互动统计
  142. companyItem, err := company.GetCompanyById(companyId)
  143. if err != nil {
  144. br.Msg = "查找客户失败"
  145. br.ErrMsg = "查找客户失败,Err:" + err.Error()
  146. return
  147. }
  148. detailView.ReportReadTotal = companyItem.InteractionNum
  149. }
  150. br.Ret = 200
  151. br.Success = true
  152. br.Msg = "获取成功"
  153. br.Data = detailView
  154. return
  155. }
  156. // 英文客户
  157. enItem, e := models.GetEnglishCompanyById(companyId)
  158. if e != nil {
  159. br.Msg = "搜索英文客户失败!"
  160. br.ErrMsg = "获取英文客户详情失败!Err:" + e.Error()
  161. return
  162. }
  163. detailView.CompanyId = enItem.CompanyId
  164. detailView.CompanyName = enItem.CompanyName
  165. detailView.Status = "正常"
  166. detailView.EnglishCompany = 1
  167. detailView.EnglishCountry = enItem.Country
  168. detailView.EnglishViewTotal = enItem.ViewTotal
  169. br.Ret = 200
  170. br.Success = true
  171. br.Msg = "获取成功"
  172. br.Data = detailView
  173. }
  174. //func init() {
  175. // init16_0()
  176. //}
  177. func init16_0() {
  178. var condition string
  179. var pars []interface{}
  180. condition = ` AND a.company_id > 0 `
  181. list, err := roadshow.GetRsReportRecordList(condition, pars)
  182. if err != nil {
  183. fmt.Println(err)
  184. return
  185. }
  186. var companyIds []int
  187. mapcompanyIds := make(map[int]bool)
  188. for _, v := range list {
  189. if mapcompanyIds[v.CompanyId] {
  190. continue
  191. }
  192. companyIds = append(companyIds, v.CompanyId)
  193. mapcompanyIds[v.CompanyId] = true
  194. }
  195. mapPermissionNameFicc := make(map[int][]string)
  196. mapPermissionNameRai := make(map[int][]string)
  197. listPermissionNameFicc, errFicc := company.GetCompanyProductReportPermissionListInit16_0(companyIds, 1) // FICC权限信息
  198. if errFicc != nil {
  199. err = errFicc
  200. return
  201. }
  202. mapPermissionArrFicc := make(map[string]bool)
  203. for _, v := range listPermissionNameFicc {
  204. if mapPermissionArrFicc[fmt.Sprint(v.CompanyId, v.PermissionName)] || v.PermissionName == "" {
  205. continue
  206. }
  207. mapPermissionNameFicc[v.CompanyId] = append(mapPermissionNameFicc[v.CompanyId], v.PermissionName)
  208. mapPermissionArrFicc[fmt.Sprint(v.CompanyId, v.PermissionName)] = true
  209. }
  210. listPermissionNameRai, errRai := company.GetCompanyProductReportPermissionListInit16_0(companyIds, 2) // 权益权限信息
  211. if errRai != nil {
  212. err = errRai
  213. return
  214. }
  215. mapPermissionArrRai := make(map[string]bool)
  216. for _, v := range listPermissionNameRai {
  217. if mapPermissionArrRai[fmt.Sprint(v.CompanyId, v.PermissionName)] || v.PermissionName == "" {
  218. continue
  219. }
  220. mapPermissionNameRai[v.CompanyId] = append(mapPermissionNameRai[v.CompanyId], v.PermissionName)
  221. mapPermissionArrRai[fmt.Sprint(v.CompanyId, v.PermissionName)] = true
  222. }
  223. adminAll, err := system.GetAdminList()
  224. if err != nil {
  225. return
  226. }
  227. //adminMap := make(map[int]*system.AdminView)
  228. mapRaiSllerId := make(map[int]bool) // 是否为权益销售
  229. for _, v := range adminAll {
  230. //adminMap[v.AdminId] = v
  231. if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  232. mapRaiSllerId[v.AdminId] = true
  233. }
  234. }
  235. var updateItems []*roadshow.RsReportRecord
  236. for _, v := range list {
  237. item := new(roadshow.RsReportRecord)
  238. item.RsReportRecordId = v.RsReportRecordId
  239. if mapRaiSllerId[v.SellerId] {
  240. if len(mapPermissionNameRai[v.CompanyId]) > 0 {
  241. item.PermissionName = strings.Join(mapPermissionNameRai[v.CompanyId], "/")
  242. }
  243. } else {
  244. if len(mapPermissionNameFicc[v.CompanyId]) > 0 {
  245. item.PermissionName = strings.Join(mapPermissionNameFicc[v.CompanyId], "/")
  246. }
  247. }
  248. updateItems = append(updateItems, item)
  249. }
  250. fmt.Println(len(updateItems))
  251. err = roadshow.UpdateRsReportRecordPermissionMulti(updateItems)
  252. fmt.Println(err)
  253. return
  254. }