user.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygxzs/models"
  5. "hongze/hongze_cygxzs/services"
  6. "hongze/hongze_cygxzs/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. type UserController struct {
  12. BaseAuthController
  13. }
  14. type UserCommonController struct {
  15. BaseCommonController
  16. }
  17. // @Title 获取用户的选择详情
  18. // @Description 获取用户的选择详情接口
  19. // @Success 200 {object} models.CygxXzsChooseSendResp
  20. // @router /choose/detail [get]
  21. func (this *UserController) ChooseDetail() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. user := this.User
  28. if user == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,用户信息为空"
  31. br.Ret = 408
  32. return
  33. }
  34. resp := new(models.CygxXzsChooseSendResp)
  35. var condition string
  36. var pars []interface{}
  37. mobile := user.Mobile
  38. if mobile == "" {
  39. br.Ret = 200
  40. br.Success = true
  41. br.Msg = "获取成功"
  42. br.Data = resp
  43. }
  44. permissionId, err := models.GetCompanyPermissionId(user.CompanyId)
  45. if err != nil {
  46. br.Msg = "获取信息失败"
  47. br.ErrMsg = "GetCompanyPermissionId,Err:" + err.Error()
  48. return
  49. }
  50. if permissionId == "" {
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. br.Data = resp
  55. }
  56. //mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
  57. mapIndustrialFollow := make(map[int][]*models.IndustrialManagementRep) // 重点关注的行业下的数组结构
  58. mapIndustrialPush := make(map[int][]*models.IndustrialManagementRep) // 接受推送的行业下的数组结构
  59. mapIndustrialUninterested := make(map[int][]*models.IndustrialManagementRep) // 不感兴趣的行业下的数组结构
  60. //mapFllow := make(map[int]int)
  61. checkListFollow := make(map[int]int) // 重点关注的ID
  62. checkListPush := make(map[int]int) // 接受推送的ID
  63. checkListUninterested := make(map[int]int) // 不感兴趣的ID
  64. mapCategory := make(map[int]int)
  65. //ampCheckList := make(map[int][]int, 0)
  66. ampCheckListFollow := make(map[int][]int, 0) // 重点关注的ID
  67. ampCheckListPush := make(map[int][]int, 0) // 接受推送的ID
  68. ampCheckListUninterested := make(map[int][]int, 0) // 不感兴趣的ID
  69. //permissionIdList := make([]string, 0)
  70. fllowList, err := models.GetCygxIndustryFllowList(mobile)
  71. if err != nil && err.Error() != utils.ErrNoRow() {
  72. br.Msg = "获取信息失败"
  73. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  74. return
  75. }
  76. for _, v := range fllowList {
  77. //mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
  78. switch v.FollowType {
  79. case 1:
  80. checkListFollow[v.IndustrialManagementId] = v.IndustrialManagementId
  81. case 0:
  82. checkListPush[v.IndustrialManagementId] = v.IndustrialManagementId
  83. case 3:
  84. checkListUninterested[v.IndustrialManagementId] = v.IndustrialManagementId
  85. }
  86. }
  87. industrialList, err := models.GetindustrialManagement()
  88. if err != nil {
  89. br.Msg = "获取信息失败"
  90. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  91. return
  92. }
  93. for _, v := range industrialList {
  94. if v.ChartPermissionId == utils.ZHOU_QI_ID {
  95. continue
  96. }
  97. //if mapFllow[v.IndustrialManagementId] > 0 {
  98. // v.IsFllow = true
  99. // //添加所关注的行业赛道
  100. // ampCheckList[v.ChartPermissionId] = append(ampCheckList[v.ChartPermissionId], v.IndustrialManagementId)
  101. //}
  102. //mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
  103. v.IsFllow = true
  104. if checkListFollow[v.IndustrialManagementId] > 0 {
  105. //添加重点关注的行业赛道
  106. ampCheckListFollow[v.ChartPermissionId] = append(ampCheckListFollow[v.ChartPermissionId], v.IndustrialManagementId)
  107. mapIndustrialFollow[v.ChartPermissionId] = append(mapIndustrialFollow[v.ChartPermissionId], v)
  108. } else if checkListUninterested[v.IndustrialManagementId] > 0 {
  109. //添加不感兴趣的行业赛道
  110. ampCheckListUninterested[v.ChartPermissionId] = append(ampCheckListUninterested[v.ChartPermissionId], v.IndustrialManagementId)
  111. mapIndustrialUninterested[v.ChartPermissionId] = append(mapIndustrialUninterested[v.ChartPermissionId], v)
  112. } else {
  113. //添加接受推送的行业赛道
  114. mapIndustrialPush[v.ChartPermissionId] = append(mapIndustrialPush[v.ChartPermissionId], v)
  115. ampCheckListPush[v.ChartPermissionId] = append(ampCheckListPush[v.ChartPermissionId], v.IndustrialManagementId)
  116. }
  117. }
  118. slicepermissionId := strings.Split(permissionId, ",")
  119. //if len(slicepermissionId) > 0 {
  120. // for _, v := range slicepermissionId {
  121. // permissionIdList = append(permissionIdList, v)
  122. // }
  123. // //condition += ` AND chart_permission_id IN (` + utils.GetOrmInReplace(len(slicepermissionId)) + ` ) `
  124. // //pars = append(pars, permissionIdList)
  125. //}
  126. permissionList, err := models.GetChartPermissionAll(condition, pars)
  127. if err != nil {
  128. br.Msg = "获取信息失败"
  129. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  130. return
  131. }
  132. //策略固收的处理
  133. categoryListFollow, err := models.GetCygxXzsChooseCategoryList(mobile)
  134. if err != nil && err.Error() != utils.ErrNoRow() {
  135. br.Msg = "获取信息失败"
  136. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  137. return
  138. }
  139. checkListCelueFollow := make(map[int]int) // 重点关注的ID
  140. checkListCeluePush := make(map[int]int) // 接受推送的ID
  141. checkListCelueUninterested := make(map[int]int) // 不感兴趣的ID
  142. for _, v := range categoryListFollow {
  143. //mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
  144. switch v.FollowType {
  145. case 1:
  146. checkListCelueFollow[v.CategoryId] = v.CategoryId
  147. case 0:
  148. checkListCeluePush[v.CategoryId] = v.CategoryId
  149. case 3:
  150. checkListCelueUninterested[v.CategoryId] = v.CategoryId
  151. }
  152. }
  153. for _, v := range categoryListFollow {
  154. mapCategory[v.CategoryId] = v.CategoryId
  155. }
  156. celueList, err := models.GetReportMappingStrategyAll()
  157. if err != nil {
  158. br.Msg = "获取信息失败"
  159. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  160. return
  161. }
  162. for _, v := range celueList {
  163. v.IsFllow = true
  164. if checkListCelueFollow[v.IndustrialManagementId] > 0 {
  165. //添加重点关注的行业赛道
  166. ampCheckListFollow[v.ChartPermissionId] = append(ampCheckListFollow[v.ChartPermissionId], v.IndustrialManagementId)
  167. mapIndustrialFollow[v.ChartPermissionId] = append(mapIndustrialFollow[v.ChartPermissionId], v)
  168. } else if checkListCelueUninterested[v.IndustrialManagementId] > 0 {
  169. //添加不感兴趣的行业赛道
  170. ampCheckListUninterested[v.ChartPermissionId] = append(ampCheckListUninterested[v.ChartPermissionId], v.IndustrialManagementId)
  171. mapIndustrialUninterested[v.ChartPermissionId] = append(mapIndustrialUninterested[v.ChartPermissionId], v)
  172. } else {
  173. //添加接受推送的行业赛道
  174. mapIndustrialPush[v.ChartPermissionId] = append(mapIndustrialPush[v.ChartPermissionId], v)
  175. ampCheckListPush[v.ChartPermissionId] = append(ampCheckListPush[v.ChartPermissionId], v.IndustrialManagementId)
  176. }
  177. }
  178. //策略、固收的处理 end
  179. //周期的处理
  180. zhouqiListFollow, err := models.GetCygxXzsChooseCategoryZhouqiList(mobile)
  181. if err != nil && err.Error() != utils.ErrNoRow() {
  182. br.Msg = "获取信息失败"
  183. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  184. return
  185. }
  186. checkListZhouqiFollow := make(map[int]int) // 重点关注的ID
  187. checkListZhouqiPush := make(map[int]int) // 接受推送的ID
  188. checkListZhouqiUninterested := make(map[int]int) // 不感兴趣的ID
  189. for _, v := range zhouqiListFollow {
  190. //mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
  191. switch v.FollowType {
  192. case 1:
  193. checkListZhouqiFollow[v.CategoryId] = v.CategoryId
  194. case 0:
  195. checkListZhouqiPush[v.CategoryId] = v.CategoryId
  196. case 3:
  197. checkListZhouqiUninterested[v.CategoryId] = v.CategoryId
  198. }
  199. }
  200. zhouqiList, err := models.GetCygxZhouqiArticleMapFirst()
  201. if err != nil {
  202. br.Msg = "获取信息失败"
  203. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  204. return
  205. }
  206. for _, vZhouqi := range zhouqiList {
  207. v := new(models.IndustrialManagementRep)
  208. v.IsFllow = true
  209. v.IndustrialManagementId = vZhouqi.CategoryId
  210. v.IndustryName = vZhouqi.MatchTypeName
  211. v.ChartPermissionId = utils.ZHOU_QI_ID
  212. if checkListZhouqiFollow[v.IndustrialManagementId] > 0 {
  213. //添加重点关注的行业赛道
  214. ampCheckListFollow[v.ChartPermissionId] = append(ampCheckListFollow[v.ChartPermissionId], v.IndustrialManagementId)
  215. mapIndustrialFollow[v.ChartPermissionId] = append(mapIndustrialFollow[v.ChartPermissionId], v)
  216. } else if checkListZhouqiUninterested[v.IndustrialManagementId] > 0 {
  217. //添加不感兴趣的行业赛道
  218. ampCheckListUninterested[v.ChartPermissionId] = append(ampCheckListUninterested[v.ChartPermissionId], v.IndustrialManagementId)
  219. mapIndustrialUninterested[v.ChartPermissionId] = append(mapIndustrialUninterested[v.ChartPermissionId], v)
  220. } else {
  221. //添加接受推送的行业赛道
  222. mapIndustrialPush[v.ChartPermissionId] = append(mapIndustrialPush[v.ChartPermissionId], v)
  223. ampCheckListPush[v.ChartPermissionId] = append(ampCheckListPush[v.ChartPermissionId], v.IndustrialManagementId)
  224. }
  225. }
  226. //周期的处理end
  227. for k, v := range permissionList {
  228. //if v.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  229. // v.PermissionName = utils.MAI_FANG_YAN_XUAN_NAME
  230. //}
  231. //if v.PermissionName == utils.CE_LUE_NAME || v.PermissionName == utils.GU_SHOU_NAME {
  232. // permissionList[k].List = celueList
  233. // //permissionList[k].AllTracks = "全系列报告"
  234. //} else if v.PermissionName == utils.ZHOU_QI_NAME {
  235. //
  236. //} else {
  237. //permissionList[k].AllTracks = "全部赛道"
  238. //if len(mapIndustrial[v.ChartPermissionId]) == 0 {
  239. // permissionList[k].List = make([]*models.IndustrialManagementRep, 0)
  240. //} else {
  241. //permissionList[k].List = mapIndustrial[v.ChartPermissionId]
  242. //}
  243. if len(mapIndustrialFollow[v.ChartPermissionId]) == 0 {
  244. permissionList[k].ListFollow = make([]*models.IndustrialManagementRep, 0)
  245. } else {
  246. permissionList[k].ListFollow = mapIndustrialFollow[v.ChartPermissionId]
  247. }
  248. if len(mapIndustrialPush[v.ChartPermissionId]) == 0 {
  249. permissionList[k].ListPush = make([]*models.IndustrialManagementRep, 0)
  250. } else {
  251. permissionList[k].ListPush = mapIndustrialPush[v.ChartPermissionId]
  252. }
  253. if len(mapIndustrialUninterested[v.ChartPermissionId]) == 0 {
  254. permissionList[k].ListUninterested = make([]*models.IndustrialManagementRep, 0)
  255. } else {
  256. permissionList[k].ListUninterested = mapIndustrialUninterested[v.ChartPermissionId]
  257. }
  258. //}
  259. //if len(ampCheckList[v.ChartPermissionId]) == 0 {
  260. // permissionList[k].CheckList = make([]int, 0)
  261. //} else {
  262. // permissionList[k].CheckList = ampCheckList[v.ChartPermissionId]
  263. //}
  264. if len(ampCheckListFollow[v.ChartPermissionId]) == 0 {
  265. permissionList[k].CheckListFollow = make([]int, 0)
  266. } else {
  267. permissionList[k].CheckListFollow = ampCheckListFollow[v.ChartPermissionId]
  268. }
  269. if len(ampCheckListPush[v.ChartPermissionId]) == 0 {
  270. permissionList[k].CheckListPush = make([]int, 0)
  271. } else {
  272. permissionList[k].CheckListPush = ampCheckListPush[v.ChartPermissionId]
  273. }
  274. if len(ampCheckListUninterested[v.ChartPermissionId]) == 0 {
  275. permissionList[k].CheckListUninterested = make([]int, 0)
  276. } else {
  277. permissionList[k].CheckListUninterested = ampCheckListUninterested[v.ChartPermissionId]
  278. }
  279. v.HasCheck = utils.InArrayByStr(slicepermissionId, strconv.Itoa(v.ChartPermissionId))
  280. }
  281. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  282. if err != nil {
  283. br.Msg = "获取信息失败"
  284. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  285. return
  286. }
  287. if count == 0 {
  288. resp.IsObjective = 1
  289. resp.IsSubjective = 1
  290. } else {
  291. detail, err := models.GetCygxXzsChooseSendByMobile(mobile)
  292. if err != nil {
  293. br.Msg = "获取信息失败"
  294. br.ErrMsg = "GetCygxXzsChooseSendByMobile,Err:" + err.Error()
  295. return
  296. }
  297. resp.IsObjective = detail.IsObjective
  298. resp.IsSubjective = detail.IsSubjective
  299. resp.IsRefuse = detail.IsRefuse
  300. }
  301. resp.IsPush = 1 - resp.IsRefuse
  302. resp.List = permissionList
  303. br.Ret = 200
  304. br.Success = true
  305. br.Msg = "获取成功"
  306. br.Data = resp
  307. }
  308. // @Title 提交用户的选择详情
  309. // @Description 提交用户的选择详情接口
  310. // @Param request body models.SubmitChooseSendResp true "type json string"
  311. // @Success 200 {object} models.CygxXzsChooseSendResp
  312. // @router /choose/submit [post]
  313. func (this *UserController) ChooseSubmit() {
  314. br := new(models.BaseResponse).Init()
  315. defer func() {
  316. this.Data["json"] = br
  317. this.ServeJSON()
  318. }()
  319. user := this.User
  320. if user == nil {
  321. br.Msg = "请登录"
  322. br.ErrMsg = "请登录,用户信息为空"
  323. br.Ret = 408
  324. return
  325. }
  326. if user.Mobile == "" {
  327. br.Msg = "提交失败!"
  328. br.ErrMsg = "提交失败,手机号不能为空"
  329. return
  330. }
  331. var req models.SubmitChooseSendResp
  332. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  333. if err != nil {
  334. br.Msg = "参数解析异常!"
  335. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  336. return
  337. }
  338. var industrialManagementIds string
  339. var categoryIds string
  340. industrialManagementList := req.IndustrialManagementIds
  341. isRefuse := req.IsRefuse
  342. isSubjective := req.IsSubjective
  343. isObjective := req.IsObjective
  344. if isRefuse == 0 && isSubjective == 0 && isObjective == 0 {
  345. br.Msg = "请至少选择一项主客观内容"
  346. return
  347. }
  348. listMap, err := models.GetCygxXzsChooseCategoryMapList()
  349. if err != nil {
  350. br.Msg = "操作失败!"
  351. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  352. return
  353. }
  354. mapReport := make(map[int]int)
  355. for _, v := range listMap {
  356. mapReport[v.CategoryId] = v.Id
  357. }
  358. var itemsFllow []*models.CygxIndustryFllow
  359. var itemsCategory []*models.CygxXzsChooseCategory
  360. industrialFllowNum := make(map[int]int) // 提交过来的不同行业的下对应的产业数量
  361. //如果为1 则不做任何推送 ,主观客观默认改成0
  362. if isRefuse == 1 {
  363. isSubjective = 0
  364. isObjective = 0
  365. } else {
  366. for _, v := range industrialManagementList {
  367. //如果为空就不做拼接处理
  368. if v.IndustrialManagementIds == "" {
  369. continue
  370. }
  371. if v.ChartPermissionId != utils.CE_LUE_ID {
  372. industrialManagementIds += v.IndustrialManagementIds + ","
  373. } else {
  374. categoryIds += v.IndustrialManagementIds + ","
  375. }
  376. industrialFllowNum[v.ChartPermissionId] = strings.Count(v.IndustrialManagementIds, ",") + 1
  377. }
  378. industrialManagementIds = strings.TrimRight(industrialManagementIds, ",")
  379. if industrialManagementIds != "" {
  380. sliceIndustrial := strings.Split(industrialManagementIds, ",")
  381. for _, v := range sliceIndustrial {
  382. item := new(models.CygxIndustryFllow)
  383. industrialManagementId, _ := strconv.Atoi(v)
  384. item.IndustrialManagementId = industrialManagementId
  385. item.UserId = user.UserId
  386. item.Mobile = user.Mobile
  387. item.Email = user.Email
  388. item.CompanyId = user.CompanyId
  389. item.CompanyName = user.CompanyName
  390. item.RealName = user.RealName
  391. item.Type = 1
  392. item.CreateTime = time.Now()
  393. item.ModifyTime = time.Now()
  394. item.Source = 2
  395. itemsFllow = append(itemsFllow, item)
  396. }
  397. }
  398. //处理策略
  399. categoryIds = strings.TrimRight(categoryIds, ",")
  400. if categoryIds != "" {
  401. sliceCategoryId := strings.Split(categoryIds, ",")
  402. for _, v := range sliceCategoryId {
  403. item := new(models.CygxXzsChooseCategory)
  404. categoryId, _ := strconv.Atoi(v)
  405. item.CategoryId = categoryId
  406. item.IdCygx = mapReport[categoryId]
  407. item.UserId = user.UserId
  408. item.Mobile = user.Mobile
  409. item.Email = user.Email
  410. item.CompanyId = user.CompanyId
  411. item.CompanyName = user.CompanyName
  412. item.RealName = user.RealName
  413. item.CreateTime = time.Now()
  414. item.ModifyTime = time.Now()
  415. itemsCategory = append(itemsCategory, item)
  416. }
  417. }
  418. }
  419. //医药、消费、科技、智造、研选下的产业赛道
  420. mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
  421. industrialList, err := models.GetindustrialManagement()
  422. if err != nil {
  423. br.Msg = "获取信息失败"
  424. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  425. return
  426. }
  427. for _, v := range industrialList {
  428. mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
  429. }
  430. //策略下的产业赛道
  431. celueList, err := models.GetReportMappingStrategyAll()
  432. if err != nil {
  433. br.Msg = "获取信息失败"
  434. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  435. return
  436. }
  437. mobile := user.Mobile
  438. item := new(models.CygxXzsChooseSend)
  439. item.UserId = user.UserId
  440. item.Mobile = user.Mobile
  441. item.Email = user.Email
  442. item.CompanyId = user.CompanyId
  443. item.CompanyName = user.CompanyName
  444. item.RealName = user.RealName
  445. item.CreateTime = time.Now()
  446. item.ModifyTime = time.Now()
  447. item.IsRefuse = req.IsRefuse
  448. item.IsSubjective = isSubjective
  449. item.IsObjective = isObjective
  450. if industrialFllowNum[utils.YI_YAO_ID] == len(mapIndustrial[utils.YI_YAO_ID]) {
  451. item.AllInYiYao = 1 //如果医药全选则设为1
  452. }
  453. if industrialFllowNum[utils.XIAO_FEI_ID] == len(mapIndustrial[utils.XIAO_FEI_ID]) {
  454. item.AllInXiaoFei = 1 //如果消费全选则设为1
  455. }
  456. if industrialFllowNum[utils.KE_JI_ID] == len(mapIndustrial[utils.KE_JI_ID]) {
  457. item.AllInKeJi = 1 //如果科技全选则设为1
  458. }
  459. if industrialFllowNum[utils.ZHI_ZAO_ID] == len(mapIndustrial[utils.ZHI_ZAO_ID]) {
  460. item.AllInZhiZao = 1 //如果智造全选则设为1
  461. }
  462. if industrialFllowNum[utils.CHART_PERMISSION_ID_YANXUAN] == len(mapIndustrial[utils.CHART_PERMISSION_ID_YANXUAN]) {
  463. item.AllInYanXuan = 1 //如果研选全选则设为1
  464. }
  465. if industrialFllowNum[utils.CE_LUE_ID] == len(celueList) {
  466. item.AllInCeLue = 1 //如果策略全选则设为1
  467. }
  468. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  469. if err != nil {
  470. br.Msg = "获取信息失败"
  471. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  472. return
  473. }
  474. //如果有记录就新增,没有记录就修改
  475. if count == 0 {
  476. err = models.AddCygxXzsChooseSend(item, itemsFllow, itemsCategory)
  477. } else {
  478. err = models.UpdateCygxXzsChooseSend(item, itemsFllow, itemsCategory)
  479. }
  480. if err != nil {
  481. br.Msg = "保存失败!"
  482. br.ErrMsg = "保存失败!,Err:" + err.Error()
  483. return
  484. }
  485. go services.UserSubmit(itemsFllow, itemsCategory, user.UserId)
  486. br.Ret = 200
  487. br.Success = true
  488. br.Msg = "保存成功"
  489. }
  490. // @Title 提交用户的选择关注的类型
  491. // @Description 提交用户的选择关注的类型接口
  492. // @Param request body models.SubmitChooseSendResp true "type json string"
  493. // @Success 200 {object} models.CygxXzsChooseSendResp
  494. // @router /choose/submit_follow_type [post]
  495. func (this *UserController) ChooseSubmitFollowType() {
  496. br := new(models.BaseResponse).Init()
  497. defer func() {
  498. this.Data["json"] = br
  499. this.ServeJSON()
  500. }()
  501. user := this.User
  502. if user == nil {
  503. br.Msg = "请登录"
  504. br.ErrMsg = "请登录,用户信息为空"
  505. br.Ret = 408
  506. return
  507. }
  508. if user.Mobile == "" {
  509. br.Msg = "提交失败!"
  510. br.ErrMsg = "提交失败,手机号不能为空"
  511. return
  512. }
  513. var req models.SubmitChooseSendFollowTypeResp
  514. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  515. if err != nil {
  516. br.Msg = "参数解析异常!"
  517. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  518. return
  519. }
  520. listMap, err := models.GetCygxXzsChooseCategoryMapList()
  521. if err != nil {
  522. br.Msg = "操作失败!"
  523. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  524. return
  525. }
  526. mapReport := make(map[int]int)
  527. for _, v := range listMap {
  528. mapReport[v.CategoryId] = v.Id
  529. }
  530. followType := req.FollowType
  531. listReq := req.List
  532. var itemsFllow []*models.CygxIndustryFllow
  533. var itemsCategory []*models.CygxXzsChooseCategory
  534. var itemsZhouqi []*models.CygxXzsChooseCategoryZhouqi
  535. var zhouqiIds []int
  536. var celueIds []int
  537. var industryIds []int
  538. for _, vChartPermissionn := range listReq {
  539. if vChartPermissionn.ChartPermissionName == utils.CE_LUE_NAME || vChartPermissionn.ChartPermissionName == utils.GU_SHOU_NAME {
  540. //策略与固收
  541. for _, v := range vChartPermissionn.CheckList {
  542. item := new(models.CygxXzsChooseCategory)
  543. categoryId := v
  544. item.CategoryId = v
  545. item.IdCygx = mapReport[categoryId]
  546. item.UserId = user.UserId
  547. item.Mobile = user.Mobile
  548. item.Email = user.Email
  549. item.CompanyId = user.CompanyId
  550. item.CompanyName = user.CompanyName
  551. item.RealName = user.RealName
  552. item.FollowType = followType
  553. item.CreateTime = time.Now()
  554. item.ModifyTime = time.Now()
  555. itemsCategory = append(itemsCategory, item)
  556. celueIds = append(celueIds, v)
  557. }
  558. } else if vChartPermissionn.ChartPermissionName == utils.ZHOU_QI_NAME {
  559. //周期
  560. for _, v := range vChartPermissionn.CheckList {
  561. item := new(models.CygxXzsChooseCategoryZhouqi)
  562. item.CategoryId = v
  563. item.UserId = user.UserId
  564. item.Email = user.Email
  565. item.Mobile = user.Mobile
  566. item.RealName = user.RealName
  567. item.CompanyId = user.CompanyId
  568. item.CompanyName = user.CompanyName
  569. item.FollowType = followType
  570. item.CreateTime = time.Now()
  571. item.ModifyTime = time.Now()
  572. itemsZhouqi = append(itemsZhouqi, item)
  573. zhouqiIds = append(zhouqiIds, v)
  574. }
  575. } else {
  576. //正常带有产业的行业
  577. for _, v := range vChartPermissionn.CheckList {
  578. item := new(models.CygxIndustryFllow)
  579. item.IndustrialManagementId = v
  580. item.UserId = user.UserId
  581. item.Mobile = user.Mobile
  582. item.Email = user.Email
  583. item.CompanyId = user.CompanyId
  584. item.CompanyName = user.CompanyName
  585. item.RealName = user.RealName
  586. item.Type = 1
  587. item.FollowType = followType
  588. if followType == 3 {
  589. item.FollowTypeOrder = -1
  590. } else {
  591. item.FollowTypeOrder = followType
  592. }
  593. item.CreateTime = time.Now()
  594. item.ModifyTime = time.Now()
  595. item.Source = 2
  596. itemsFllow = append(itemsFllow, item)
  597. industryIds = append(industryIds, v)
  598. }
  599. }
  600. }
  601. err = models.AddCygxXzsChooseSendFollow(user.Mobile, itemsFllow, itemsCategory, itemsZhouqi, industryIds, celueIds, zhouqiIds)
  602. if err != nil {
  603. br.Msg = "保存失败!"
  604. br.ErrMsg = "保存失败!,Err:" + err.Error()
  605. return
  606. }
  607. br.Ret = 200
  608. br.Success = true
  609. br.Msg = "保存成功"
  610. }
  611. // @Title 推送更新内容
  612. // @Description 推送更新内容接口
  613. // @Param request body models.SubmitChooseSendResp true "type json string"
  614. // @Success 200 {object} models.CygxXzsChooseSendResp
  615. // @router /choose/submit_push [post]
  616. func (this *UserController) ChooseSubmitPush() {
  617. br := new(models.BaseResponse).Init()
  618. defer func() {
  619. this.Data["json"] = br
  620. this.ServeJSON()
  621. }()
  622. user := this.User
  623. if user == nil {
  624. br.Msg = "请登录"
  625. br.ErrMsg = "请登录,用户信息为空"
  626. br.Ret = 408
  627. return
  628. }
  629. if user.Mobile == "" {
  630. br.Msg = "提交失败!"
  631. br.ErrMsg = "提交失败,手机号不能为空"
  632. return
  633. }
  634. var req models.SubmitChooseSendResp
  635. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  636. if err != nil {
  637. br.Msg = "参数解析异常!"
  638. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  639. return
  640. }
  641. isPush := req.IsPush // 是否接受推送
  642. //isRefuse := req.IsRefuse
  643. isSubjective := req.IsSubjective
  644. isObjective := req.IsObjective
  645. req.IsRefuse = 1 - isPush // 是否拒绝推送,与是否接收推送进行取反(兼容老的数据库字段)
  646. isRefuse := req.IsRefuse
  647. if isRefuse == 0 && isSubjective == 0 && isObjective == 0 {
  648. br.Msg = "请至少选择一项主客观内容"
  649. return
  650. }
  651. //如果为1 则不做任何推送 ,主观客观默认改成0
  652. if isRefuse == 1 {
  653. isSubjective = 0
  654. isObjective = 0
  655. }
  656. mobile := user.Mobile
  657. item := new(models.CygxXzsChooseSend)
  658. item.UserId = user.UserId
  659. item.Mobile = user.Mobile
  660. item.Email = user.Email
  661. item.CompanyId = user.CompanyId
  662. item.CompanyName = user.CompanyName
  663. item.RealName = user.RealName
  664. item.CreateTime = time.Now()
  665. item.ModifyTime = time.Now()
  666. item.IsRefuse = isRefuse
  667. item.IsSubjective = isSubjective
  668. item.IsObjective = isObjective
  669. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  670. if err != nil {
  671. br.Msg = "获取信息失败"
  672. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  673. return
  674. }
  675. //如果有记录就新增,没有记录就修改
  676. if count == 0 {
  677. err = models.AddCygxXzsChooseSendPush(item)
  678. } else {
  679. err = models.UpdateCygxXzsChooseSendPush(item)
  680. }
  681. if err != nil {
  682. br.Msg = "保存失败!"
  683. br.ErrMsg = "保存失败!,Err:" + err.Error()
  684. return
  685. }
  686. br.Ret = 200
  687. br.Success = true
  688. br.Msg = "保存成功"
  689. }