user_rai_label.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/models/roadshow"
  8. cygxService "hongze/hz_crm_api/services/cygx"
  9. "hongze/hz_crm_api/utils"
  10. "strconv"
  11. "time"
  12. )
  13. // 权益用户标签
  14. type UserRaiLabelController struct {
  15. controllers.BaseAuthController
  16. }
  17. // @Title 销售输入标签
  18. // @Description 销售输入标签接口
  19. // @Param request body cygx.WxUserRaiLabelAddReq true "type json string"
  20. // @Success 200 {object} "保存成功"
  21. // @router /use_rai_label/add [post]
  22. func (this *UserRaiLabelController) Add() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. AdminUser := this.SysUser
  29. if AdminUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. var req cygx.WxUserRaiLabelAddReq
  36. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  37. if err != nil {
  38. br.Msg = "参数解析异常!"
  39. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  40. return
  41. }
  42. userId := req.UserId
  43. label := req.Label
  44. wxUser, err := models.GetWxUserItemByUserId(userId)
  45. if err != nil {
  46. br.Msg = "获取失败"
  47. br.ErrMsg = "获取失败, GetWxUserItemByUserId Err:" + err.Error()
  48. return
  49. }
  50. item := new(cygx.WxUserRaiLabel)
  51. item.UserId = wxUser.UserId
  52. item.RealName = wxUser.RealName
  53. item.Mobile = wxUser.Mobile
  54. item.Email = wxUser.Email
  55. item.CompanyId = wxUser.CompanyId
  56. item.CompanyName = wxUser.CompanyName
  57. item.Label = label
  58. item.SysUserId = AdminUser.AdminId
  59. item.SysUserRealName = AdminUser.RealName
  60. item.SourceType = 6
  61. item.CreateTime = time.Now()
  62. item.ModifyTime = time.Now()
  63. err = cygx.AddWxUserRaiLabel(item)
  64. if err != nil {
  65. br.Msg = "保存失败"
  66. br.ErrMsg = "保存失败,Err:" + err.Error()
  67. return
  68. }
  69. br.Ret = 200
  70. br.Success = true
  71. br.IsAddLog = true
  72. br.Msg = "操作成功"
  73. }
  74. // @Title 删除销售输入标签
  75. // @Description 删除销售输入标签接口
  76. // @Param request body cygx.WxUserRaiLabelAddReq true "type json string"
  77. // @Success 200 {object} "保存成功"
  78. // @router /use_rai_label/delte [post]
  79. func (this *UserRaiLabelController) Delte() {
  80. br := new(models.BaseResponse).Init()
  81. defer func() {
  82. this.Data["json"] = br
  83. this.ServeJSON()
  84. }()
  85. AdminUser := this.SysUser
  86. if AdminUser == nil {
  87. br.Msg = "请登录"
  88. br.ErrMsg = "请登录,SysUser Is Empty"
  89. br.Ret = 408
  90. return
  91. }
  92. var req cygx.WxUserRaiLabelIdReq
  93. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  94. if err != nil {
  95. br.Msg = "参数解析异常!"
  96. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  97. return
  98. }
  99. raiLabelId := req.RaiLabelId
  100. err = cygx.DeleteWxUserRaiLabel(raiLabelId)
  101. if err != nil {
  102. br.Msg = "删除失败"
  103. br.ErrMsg = "删除失败,Err:" + err.Error()
  104. return
  105. }
  106. br.Ret = 200
  107. br.Success = true
  108. br.IsAddLog = true
  109. br.Msg = "操作成功"
  110. }
  111. // @Title 标签详情
  112. // @Description 获取标签详情接口
  113. // @Param RaiLabelId query int true "标签ID"
  114. // @Success Ret=200 {object} cygx.ActivityDetail
  115. // @router /use_rai_label/detail [get]
  116. func (this *UserRaiLabelController) Detail() {
  117. br := new(models.BaseResponse).Init()
  118. defer func() {
  119. this.Data["json"] = br
  120. this.ServeJSON()
  121. }()
  122. AdminUser := this.SysUser
  123. if AdminUser == nil {
  124. br.Msg = "请登录"
  125. br.ErrMsg = "请登录,用户信息为空"
  126. br.Ret = 408
  127. return
  128. }
  129. raiLabelId, _ := this.GetInt("RaiLabelId")
  130. detail, err := cygx.GetWxUserRaiLabelDetailById(raiLabelId)
  131. if err != nil {
  132. br.Msg = "获取失败"
  133. br.ErrMsg = "获取失败,标签不存在Err:" + err.Error() + "RaiLabelId:" + strconv.Itoa(raiLabelId)
  134. return
  135. }
  136. resp := new(cygx.WxUserRaiLabelDetailResp)
  137. sourceType := detail.SourceType
  138. sourceId := detail.SourceId
  139. //来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签
  140. switch sourceType {
  141. case 1:
  142. item := new(cygx.WxUserRaiLabelKeyWordResp)
  143. item.Label = detail.Label
  144. item.CreateTime = detail.CreateTime.Format(utils.FormatDateTime)
  145. resp.KeyWord = item
  146. case 2, 4:
  147. item := new(cygx.WxUserRaiLabelActivityResp)
  148. activityInfo, errInfo := cygx.GetAddActivityInfoById(sourceId)
  149. if activityInfo == nil {
  150. br.Msg = "操作失败"
  151. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(sourceId)
  152. return
  153. }
  154. if errInfo != nil {
  155. br.Msg = "操作失败"
  156. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  157. return
  158. }
  159. activitySignupDetai, _ := cygx.GetCygxActivitySignupDetailDetailLast(sourceId, detail.Mobile)
  160. item.ActivityName = activityInfo.ActivityName
  161. item.ActivityTypeName = activityInfo.ActivityTypeName
  162. item.ActivityTime = activityInfo.ActivityTime
  163. if activitySignupDetai != nil {
  164. item.Duration = activitySignupDetai.Duration
  165. }
  166. item.Label = detail.Label
  167. resp.Activity = item
  168. case 3, 5:
  169. item := new(cygx.WxUserRaiLabelRoadShowResp)
  170. rsCalendarItem, err := roadshow.GetRsCalendarById(sourceId)
  171. if err != nil {
  172. br.Msg = "获取数据失败!"
  173. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  174. return
  175. }
  176. if rsCalendarItem == nil {
  177. br.Msg = "保存失败!"
  178. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  179. return
  180. }
  181. rsCalendarResearcherList, tmpErr := roadshow.GetRsCalendarResearcherListByRsCalendarId(sourceId)
  182. if tmpErr != nil {
  183. br.Msg = "获取数据失败!"
  184. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherListByRsCalendarId:" + tmpErr.Error()
  185. return
  186. }
  187. for _, v := range rsCalendarResearcherList {
  188. item.ResearcherName = v.ResearcherName
  189. item.RoadShowTime = v.StartDate + " " + v.StartTime
  190. }
  191. item.Theme = rsCalendarItem.Theme
  192. item.Label = detail.Label
  193. resp.RoadShow = item
  194. case 6:
  195. item := new(cygx.WxUserRaiLabelSellerResp)
  196. item.Label = detail.Label
  197. item.SysUserRealName = detail.SysUserRealName
  198. item.CreateTime = detail.CreateTime.Format(utils.FormatDateTime)
  199. resp.Seller = item
  200. case 7, 8:
  201. item := new(cygx.WxUserRaiLabelArticleResp)
  202. switch detail.TableName {
  203. case "cygx_article":
  204. //文章
  205. detailArticle, err := cygx.GetArticleIdInfoByArticleId(sourceId)
  206. if err != nil {
  207. br.Msg = "内容不存在"
  208. br.ErrMsg = "操作失败,Err:" + err.Error()
  209. return
  210. }
  211. historyDetail := new(cygx.CygxArticleHistoryRecordAll)
  212. if detail.Mobile != "" {
  213. historyDetail, err = cygx.GetCygxArticleHistoryRecordAllDetailLastByMobile(sourceId, detail.Mobile)
  214. } else {
  215. historyDetail, err = cygx.GetCygxArticleHistoryRecordAllDetailLast(sourceId, detail.UserId)
  216. }
  217. item.Title = detailArticle.Title
  218. item.PublishDate = detailArticle.PublishDate.Format(utils.FormatDateTime)
  219. item.CreateTime = detail.CreateTime.Format(utils.FormatDateTime)
  220. item.SourceText = cygxService.GetArticleSourcePlatformText(historyDetail.RegisterPlatform)
  221. item.StopTime = strconv.Itoa(historyDetail.StopTime)
  222. case "cygx_report_selection":
  223. //报告精选
  224. detailReportSelection, err := cygx.GetCygxReportSelectionInfoById(sourceId)
  225. if err != nil {
  226. br.Msg = "内容不存在"
  227. br.ErrMsg = "操作失败,Err:" + err.Error()
  228. return
  229. }
  230. historyDetail, err := cygx.GetCygxReportHistoryRecordDetailLast(sourceId, detail.Mobile, "bgjx")
  231. if err != nil {
  232. br.Msg = "内容不存在"
  233. br.ErrMsg = "操作失败,Err:" + err.Error()
  234. return
  235. }
  236. item.Title = detailReportSelection.Title
  237. item.PublishDate = detailReportSelection.PublishDate
  238. item.CreateTime = detail.CreateTime.Format(utils.FormatDateTime)
  239. item.SourceText = cygxService.GetArticleSourcePlatformText(historyDetail.RegisterPlatform)
  240. item.StopTime = strconv.Itoa(historyDetail.StopTime)
  241. case "cygx_research_summary":
  242. //本周研究汇总
  243. detailResearchSummary, err := cygx.GetCygxResearchSummaryInfoById(sourceId)
  244. if err != nil {
  245. br.Msg = "内容不存在"
  246. br.ErrMsg = "操作失败,Err:" + err.Error()
  247. return
  248. }
  249. historyDetail, err := cygx.GetCygxReportHistoryRecordDetailLast(sourceId, detail.Mobile, "bzyjhz")
  250. if err != nil {
  251. br.Msg = "内容不存在"
  252. br.ErrMsg = "操作失败,Err:" + err.Error()
  253. return
  254. }
  255. item.Title = detailResearchSummary.Title
  256. item.PublishDate = detailResearchSummary.PublishDate
  257. item.CreateTime = detail.CreateTime.Format(utils.FormatDateTime)
  258. item.SourceText = cygxService.GetArticleSourcePlatformText(historyDetail.RegisterPlatform)
  259. item.StopTime = strconv.Itoa(historyDetail.StopTime)
  260. }
  261. item.Label = detail.Label
  262. resp.Article = item
  263. }
  264. resp.SourceType = detail.SourceType
  265. br.Ret = 200
  266. br.Success = true
  267. br.Msg = "获取成功"
  268. br.Data = resp
  269. }
  270. // @Title 标签详情
  271. // @Description 获取标签详情接口
  272. // @Param UserId query int true "用户ID"
  273. // @Success Ret=200 {object} cygx.ActivityDetail
  274. // @router /use_rai_label/list [get]
  275. func (this *UserRaiLabelController) List() {
  276. br := new(models.BaseResponse).Init()
  277. defer func() {
  278. this.Data["json"] = br
  279. this.ServeJSON()
  280. }()
  281. AdminUser := this.SysUser
  282. if AdminUser == nil {
  283. br.Msg = "请登录"
  284. br.ErrMsg = "请登录,用户信息为空"
  285. br.Ret = 408
  286. return
  287. }
  288. userId, _ := this.GetInt("UserId")
  289. resp := new(cygx.WxUserRaiLabelList)
  290. list, err := cygx.GetWxUserRaiLabelListByUserId(userId)
  291. if err != nil {
  292. br.Msg = "获取失败"
  293. br.ErrMsg = "获取失败,Err:" + err.Error() + "userId:" + strconv.Itoa(userId)
  294. return
  295. }
  296. if len(list) == 0 {
  297. list = make([]*cygx.WxUserRaiLabelListResp, 0)
  298. }
  299. resp.List = list
  300. br.Ret = 200
  301. br.Success = true
  302. br.Msg = "获取成功"
  303. br.Data = resp
  304. }