user.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. permissionList[k].CheckList = make([]int, 0)
  107. } else {
  108. permissionList[k].AllTracks = "全部赛道"
  109. if len(mapIndustrial[v.ChartPermissionId]) == 0 {
  110. permissionList[k].List = make([]*models.IndustrialManagementRep, 0)
  111. } else {
  112. permissionList[k].List = mapIndustrial[v.ChartPermissionId]
  113. }
  114. if len(ampCheckList[v.ChartPermissionId]) == 0 {
  115. permissionList[k].CheckList = make([]int, 0)
  116. } else {
  117. permissionList[k].CheckList = ampCheckList[v.ChartPermissionId]
  118. }
  119. }
  120. }
  121. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  122. if err != nil {
  123. br.Msg = "获取信息失败"
  124. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  125. return
  126. }
  127. if count == 0 {
  128. resp.IsObjective = 1
  129. resp.IsSubjective = 1
  130. } else {
  131. detail, err := models.GetCygxXzsChooseSendByMobile(mobile)
  132. if err != nil {
  133. br.Msg = "获取信息失败"
  134. br.ErrMsg = "GetCygxXzsChooseSendByMobile,Err:" + err.Error()
  135. return
  136. }
  137. resp.IsObjective = detail.IsObjective
  138. resp.IsSubjective = detail.IsSubjective
  139. resp.IsRefuse = detail.IsRefuse
  140. }
  141. resp.List = permissionList
  142. br.Ret = 200
  143. br.Success = true
  144. br.Msg = "获取成功"
  145. br.Data = resp
  146. }
  147. // @Title 提交用户的选择详情
  148. // @Description 提交用户的选择详情接口
  149. // @Param request body models.SubmitChooseSendResp true "type json string"
  150. // @Success 200 {object} models.CygxXzsChooseSendResp
  151. // @router /choose/submit [post]
  152. func (this *UserController) ChooseSubmit() {
  153. br := new(models.BaseResponse).Init()
  154. defer func() {
  155. this.Data["json"] = br
  156. this.ServeJSON()
  157. }()
  158. user := this.User
  159. if user == nil {
  160. br.Msg = "请登录"
  161. br.ErrMsg = "请登录,用户信息为空"
  162. br.Ret = 408
  163. return
  164. }
  165. if user.Mobile == "" {
  166. br.Msg = "提交失败!"
  167. br.ErrMsg = "提交失败,手机号不能为空"
  168. return
  169. }
  170. var req models.SubmitChooseSendResp
  171. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  172. if err != nil {
  173. br.Msg = "参数解析异常!"
  174. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  175. return
  176. }
  177. var industrialManagementIds string
  178. industrialManagementList := req.List
  179. for _, v := range industrialManagementList {
  180. if v.ChartPermissionId != 23 {
  181. industrialManagementIds += v.IndustrialManagementIds + ","
  182. }
  183. }
  184. industrialManagementIds = strings.TrimRight(industrialManagementIds, ",")
  185. sliceIndustrial := strings.Split(industrialManagementIds, ",")
  186. var itemsFllow []*models.CygxIndustryFllow
  187. for _, v := range sliceIndustrial {
  188. item := new(models.CygxIndustryFllow)
  189. industrialManagementId, _ := strconv.Atoi(v)
  190. item.IndustrialManagementId = industrialManagementId
  191. item.UserId = user.UserId
  192. item.Mobile = user.Mobile
  193. item.Email = user.Email
  194. item.CompanyId = user.CompanyId
  195. item.CompanyName = user.CompanyName
  196. item.RealName = user.RealName
  197. item.Type = 1
  198. item.CreateTime = time.Now()
  199. item.ModifyTime = time.Now()
  200. item.Source = 2
  201. itemsFllow = append(itemsFllow, item)
  202. }
  203. mobile := user.Mobile
  204. item := new(models.CygxXzsChooseSend)
  205. item.UserId = user.UserId
  206. item.Mobile = user.Mobile
  207. item.Email = user.Email
  208. item.CompanyId = user.CompanyId
  209. item.CompanyName = user.CompanyName
  210. item.RealName = user.RealName
  211. item.CreateTime = time.Now()
  212. item.ModifyTime = time.Now()
  213. item.IsRefuse = req.IsRefuse
  214. item.IsSubjective = req.IsSubjective
  215. item.IsObjective = req.IsObjective
  216. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  217. if err != nil {
  218. br.Msg = "获取信息失败"
  219. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  220. return
  221. }
  222. //如果有记录就新增,没有记录就修改
  223. if count == 0 {
  224. err = models.AddCygxXzsChooseSend(item, itemsFllow)
  225. } else {
  226. err = models.UpdateCygxXzsChooseSend(item, itemsFllow)
  227. }
  228. if err != nil {
  229. br.Msg = "保存失败!"
  230. br.ErrMsg = "保存失败!,Err:" + err.Error()
  231. return
  232. }
  233. br.Ret = 200
  234. br.Success = true
  235. br.Msg = "保存成功"
  236. }