user.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygxzs/models"
  5. "hongze/hongze_cygxzs/utils"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. type UserController struct {
  11. BaseAuthController
  12. }
  13. type UserCommonController struct {
  14. BaseCommonController
  15. }
  16. // @Title 获取用户的选择详情
  17. // @Description 获取用户的选择详情接口
  18. // @Success 200 {object} models.CygxXzsChooseSendResp
  19. // @router /choose/detail [get]
  20. func (this *UserController) ChooseDetail() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. user := this.User
  27. if user == nil {
  28. br.Msg = "请登录"
  29. br.ErrMsg = "请登录,用户信息为空"
  30. br.Ret = 408
  31. return
  32. }
  33. resp := new(models.CygxXzsChooseSendResp)
  34. var condition string
  35. var pars []interface{}
  36. mobile := user.Mobile
  37. if mobile == "" {
  38. br.Ret = 200
  39. br.Success = true
  40. br.Msg = "获取成功"
  41. br.Data = resp
  42. }
  43. permissionId, err := models.GetCompanyPermissionId(user.CompanyId)
  44. if err != nil {
  45. br.Msg = "获取信息失败"
  46. br.ErrMsg = "GetCompanyPermissionId,Err:" + err.Error()
  47. return
  48. }
  49. if permissionId == "" {
  50. br.Ret = 200
  51. br.Success = true
  52. br.Msg = "获取成功"
  53. br.Data = resp
  54. }
  55. mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
  56. mapFllow := make(map[int]int)
  57. ampCheckList := make(map[int][]int, 0)
  58. permissionIdList := make([]string, 0)
  59. fllowList, err := models.GetCygxIndustryFllowList(mobile)
  60. if err != nil && err.Error() != utils.ErrNoRow() {
  61. br.Msg = "获取信息失败"
  62. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  63. return
  64. }
  65. for _, v := range fllowList {
  66. mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
  67. }
  68. industrialList, err := models.GetindustrialManagement()
  69. if err != nil {
  70. br.Msg = "获取信息失败"
  71. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  72. return
  73. }
  74. celueList, err := models.GetReportMappingStrategyAll()
  75. if err != nil {
  76. br.Msg = "获取信息失败"
  77. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  78. return
  79. }
  80. for _, v := range industrialList {
  81. if mapFllow[v.IndustrialManagementId] > 0 {
  82. v.IsFllow = true
  83. //添加所关注的行业赛道
  84. ampCheckList[v.ChartPermissionId] = append(ampCheckList[v.ChartPermissionId], v.IndustrialManagementId)
  85. }
  86. mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
  87. }
  88. slicepermissionId := strings.Split(permissionId, ",")
  89. if len(slicepermissionId) > 0 {
  90. for _, v := range slicepermissionId {
  91. permissionIdList = append(permissionIdList, v)
  92. }
  93. condition += ` AND chart_permission_id IN (` + utils.GetOrmInReplace(len(slicepermissionId)) + ` ) `
  94. pars = append(pars, permissionIdList)
  95. }
  96. permissionList, err := models.GetChartPermissionAll(condition, pars)
  97. if err != nil {
  98. br.Msg = "获取信息失败"
  99. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  100. return
  101. }
  102. for k, v := range permissionList {
  103. if v.PermissionName == utils.CE_LUE_NAME {
  104. permissionList[k].List = celueList
  105. permissionList[k].AllTracks = "全系列报告"
  106. } else {
  107. permissionList[k].AllTracks = "全部赛道"
  108. if len(mapIndustrial[v.ChartPermissionId]) == 0 {
  109. permissionList[k].List = make([]*models.IndustrialManagementRep, 0)
  110. } else {
  111. permissionList[k].List = mapIndustrial[v.ChartPermissionId]
  112. }
  113. if len(ampCheckList[v.ChartPermissionId]) == 0 {
  114. permissionList[k].CheckList = make([]int, 0)
  115. } else {
  116. permissionList[k].CheckList = ampCheckList[v.ChartPermissionId]
  117. }
  118. }
  119. }
  120. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  121. if err != nil {
  122. br.Msg = "获取信息失败"
  123. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  124. return
  125. }
  126. if count == 0 {
  127. resp.IsObjective = 1
  128. resp.IsSubjective = 1
  129. } else {
  130. detail, err := models.GetCygxXzsChooseSendByMobile(mobile)
  131. if err != nil {
  132. br.Msg = "获取信息失败"
  133. br.ErrMsg = "GetCygxXzsChooseSendByMobile,Err:" + err.Error()
  134. return
  135. }
  136. resp.IsObjective = detail.IsObjective
  137. resp.IsSubjective = detail.IsSubjective
  138. resp.IsRefuse = detail.IsRefuse
  139. }
  140. resp.List = permissionList
  141. br.Ret = 200
  142. br.Success = true
  143. br.Msg = "获取成功"
  144. br.Data = resp
  145. }
  146. // @Title 提交用户的选择详情
  147. // @Description 提交用户的选择详情接口
  148. // @Param request body models.SubmitChooseSendResp true "type json string"
  149. // @Success 200 {object} models.CygxXzsChooseSendResp
  150. // @router /choose/submit [post]
  151. func (this *UserController) ChooseSubmit() {
  152. br := new(models.BaseResponse).Init()
  153. defer func() {
  154. this.Data["json"] = br
  155. this.ServeJSON()
  156. }()
  157. user := this.User
  158. if user == nil {
  159. br.Msg = "请登录"
  160. br.ErrMsg = "请登录,用户信息为空"
  161. br.Ret = 408
  162. return
  163. }
  164. if user.Mobile == "" {
  165. br.Msg = "提交失败!"
  166. br.ErrMsg = "提交失败,手机号不能为空"
  167. return
  168. }
  169. var req models.SubmitChooseSendResp
  170. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  171. if err != nil {
  172. br.Msg = "参数解析异常!"
  173. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  174. return
  175. }
  176. var industrialManagementIds string
  177. industrialManagementList := req.List
  178. for _, v := range industrialManagementList {
  179. if v.ChartPermissionId != 23 {
  180. industrialManagementIds += v.IndustrialManagementIds + ","
  181. }
  182. }
  183. industrialManagementIds = strings.TrimRight(industrialManagementIds, ",")
  184. sliceIndustrial := strings.Split(industrialManagementIds, ",")
  185. var itemsFllow []*models.CygxIndustryFllow
  186. for _, v := range sliceIndustrial {
  187. item := new(models.CygxIndustryFllow)
  188. industrialManagementId, _ := strconv.Atoi(v)
  189. item.IndustrialManagementId = industrialManagementId
  190. item.UserId = user.UserId
  191. item.Mobile = user.Mobile
  192. item.Email = user.Email
  193. item.CompanyId = user.CompanyId
  194. item.CompanyName = user.CompanyName
  195. item.RealName = user.RealName
  196. item.Type = 1
  197. item.CreateTime = time.Now()
  198. item.ModifyTime = time.Now()
  199. item.Source = 2
  200. itemsFllow = append(itemsFllow, item)
  201. }
  202. mobile := user.Mobile
  203. item := new(models.CygxXzsChooseSend)
  204. item.UserId = user.UserId
  205. item.Mobile = user.Mobile
  206. item.Email = user.Email
  207. item.CompanyId = user.CompanyId
  208. item.CompanyName = user.CompanyName
  209. item.RealName = user.RealName
  210. item.CreateTime = time.Now()
  211. item.ModifyTime = time.Now()
  212. item.IsRefuse = req.IsRefuse
  213. item.IsSubjective = req.IsSubjective
  214. item.IsObjective = req.IsObjective
  215. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  216. if err != nil {
  217. br.Msg = "获取信息失败"
  218. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  219. return
  220. }
  221. //如果有记录就新增,没有记录就修改
  222. if count == 0 {
  223. err = models.AddCygxXzsChooseSend(item, itemsFllow)
  224. } else {
  225. err = models.UpdateCygxXzsChooseSend(item, itemsFllow)
  226. }
  227. if err != nil {
  228. br.Msg = "保存失败!"
  229. br.ErrMsg = "保存失败!,Err:" + err.Error()
  230. return
  231. }
  232. br.Ret = 200
  233. br.Success = true
  234. br.Msg = "保存成功"
  235. }