user.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygxzs/models"
  5. "hongze/hongze_cygxzs/utils"
  6. "time"
  7. )
  8. type UserController struct {
  9. BaseAuthController
  10. }
  11. type UserCommonController struct {
  12. BaseCommonController
  13. }
  14. // @Title 获取用户的选择详情
  15. // @Description 获取用户的选择详情接口
  16. // @Success 200 {object} models.CygxXzsChooseSendResp
  17. // @router /choose/detail [get]
  18. func (this *UserController) ChooseDetail() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. user := this.User
  25. if user == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,用户信息为空"
  28. br.Ret = 408
  29. return
  30. }
  31. mobile := user.Mobile
  32. mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
  33. mapFllow := make(map[int]int)
  34. fllowList, err := models.GetCygxIndustryFllowList(mobile)
  35. if err != nil && err.Error() != utils.ErrNoRow() {
  36. br.Msg = "获取信息失败"
  37. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  38. return
  39. }
  40. for _, v := range fllowList {
  41. mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
  42. }
  43. industrialList, err := models.GetindustrialManagement()
  44. if err != nil {
  45. br.Msg = "获取信息失败"
  46. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  47. return
  48. }
  49. for _, v := range industrialList {
  50. if mapFllow[v.IndustrialManagementId] > 0 {
  51. v.IsFllow = true
  52. }
  53. mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
  54. }
  55. permissionList, err := models.GetChartPermissionAll("")
  56. if err != nil {
  57. br.Msg = "获取信息失败"
  58. br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
  59. return
  60. }
  61. for k, v := range permissionList {
  62. permissionList[k].List = mapIndustrial[v.ChartPermissionId]
  63. }
  64. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  65. if err != nil {
  66. br.Msg = "获取信息失败"
  67. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  68. return
  69. }
  70. resp := new(models.CygxXzsChooseSendResp)
  71. if count == 0 {
  72. resp.IsObjective = 1
  73. resp.IsSubjective = 1
  74. }
  75. resp.List = permissionList
  76. br.Ret = 200
  77. br.Success = true
  78. br.Msg = "获取成功"
  79. br.Data = resp
  80. }
  81. // @Title 提交用户的选择详情
  82. // @Description 提交用户的选择详情接口
  83. // @Param request body models.ActivityIdRep true "type json string"
  84. // @Success 200 {object} models.CygxXzsChooseSendResp
  85. // @router /choose/submit [post]
  86. func (this *UserController) ChooseSubmit() {
  87. br := new(models.BaseResponse).Init()
  88. defer func() {
  89. this.Data["json"] = br
  90. this.ServeJSON()
  91. }()
  92. user := this.User
  93. if user == nil {
  94. br.Msg = "请登录"
  95. br.ErrMsg = "请登录,用户信息为空"
  96. br.Ret = 408
  97. return
  98. }
  99. var req models.SubmitChooseSendResp
  100. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  101. if err != nil {
  102. br.Msg = "参数解析异常!"
  103. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  104. return
  105. }
  106. mobile := user.Mobile
  107. item := new(models.CygxXzsChooseSend)
  108. item.UserId = user.UserId
  109. item.Mobile = user.Mobile
  110. item.Email = user.Email
  111. item.CompanyId = user.CompanyId
  112. item.CompanyName = user.CompanyName
  113. item.RealName = user.RealName
  114. item.CreateTime = time.Now()
  115. item.ModifyTime = time.Now()
  116. item.IsRefuse = req.IsRefuse
  117. item.IsSubjective = req.IsSubjective
  118. item.IsObjective = req.IsObjective
  119. count, err := models.GetXzsChooseSendCountByMobile(mobile)
  120. if err != nil {
  121. br.Msg = "获取信息失败"
  122. br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
  123. return
  124. }
  125. if count == 0 {
  126. err = models.AddCygxXzsChooseSend(item)
  127. } else {
  128. updateParams := make(map[string]interface{})
  129. updateParams["UserId"] = item.UserId
  130. updateParams["Mobile"] = item.Mobile
  131. updateParams["Email"] = item.Email
  132. updateParams["CompanyId"] = item.CompanyId
  133. updateParams["CompanyName"] = item.CompanyName
  134. updateParams["RealName"] = item.RealName
  135. updateParams["ModifyTime"] = time.Now()
  136. updateParams["IsRefuse"] = item.IsRefuse
  137. updateParams["IsSubjective"] = item.IsSubjective
  138. updateParams["IsObjective"] = item.IsObjective
  139. whereParam := map[string]interface{}{"mobile": item.Mobile}
  140. err = models.UpdateByExpr(models.CygxXzsChooseSend{}, whereParam, updateParams)
  141. }
  142. if err != nil {
  143. br.Msg = "保存失败!"
  144. br.ErrMsg = "保存失败!,Err:" + err.Error()
  145. return
  146. }
  147. br.Ret = 200
  148. br.Success = true
  149. br.Msg = "保存成功"
  150. }