report.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/medivhzhan/weapp/v2"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/services"
  7. "hongze/hongze_mfyx/utils"
  8. "strconv"
  9. "time"
  10. )
  11. // 报告
  12. type ReportController struct {
  13. BaseAuthController
  14. }
  15. type ReportCommonController struct {
  16. BaseCommonController
  17. }
  18. // @Title 相关按钮是否展示接口
  19. // @Description 相关按钮是否展示接口
  20. // @Param request body models.IsShow true "type json string"
  21. // @Success 200
  22. // @router /isShow [get]
  23. func (this *ReportController) IsShow() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. user := this.User
  30. if user == nil {
  31. br.Msg = "请重新登录"
  32. br.Ret = 408
  33. return
  34. }
  35. var resp models.IsShow
  36. var condition string
  37. var pars []interface{}
  38. condition += ` AND a.user_id = ? `
  39. pars = append(pars, user.UserId)
  40. total, err := models.GetCygxYanxuanSpecialAuthorCount(condition, pars)
  41. if err != nil {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取失败,Err:" + err.Error()
  44. return
  45. }
  46. if total > 0 {
  47. resp.IsYanxuanSpecialAuthor = true
  48. }
  49. resp.IsShow = true
  50. br.Ret = 200
  51. br.Success = true
  52. br.Data = resp
  53. }
  54. // @Title 关注/取消关注产业
  55. // @Description 关注/取消关注 接口
  56. // @Param request body models.CygxIndustryFllowRep true "type json string"
  57. // @Success 200
  58. // @router /fllow [post]
  59. func (this *ReportController) Fllow() {
  60. br := new(models.BaseResponse).Init()
  61. defer func() {
  62. this.Data["json"] = br
  63. this.ServeJSON()
  64. }()
  65. user := this.User
  66. if user == nil {
  67. br.Msg = "请重新登录"
  68. br.Ret = 408
  69. return
  70. }
  71. uid := user.UserId
  72. var req models.CygxIndustryFllowRep
  73. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  74. if err != nil {
  75. br.Msg = "参数解析异常!"
  76. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  77. return
  78. }
  79. industrialManagementId := req.IndustrialManagementId
  80. var condition string
  81. countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
  82. if err != nil {
  83. br.Msg = "获取数据失败!"
  84. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  85. return
  86. }
  87. if countIndustrial == 0 {
  88. br.Msg = "产业不存在!"
  89. br.ErrMsg = "产业ID不存在:" + strconv.Itoa(industrialManagementId)
  90. return
  91. }
  92. count, err := models.GetCountCygxIndustryFllow(uid, industrialManagementId, condition)
  93. if err != nil {
  94. br.Msg = "获取数据失败!"
  95. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  96. return
  97. }
  98. resp := new(models.CygxIndustryFllowResp)
  99. countUser, err := models.GetCountCygxIndustryFllowByUid(uid)
  100. if countUser == 0 {
  101. resp.GoFollow = true
  102. }
  103. item := new(models.CygxIndustryFllow)
  104. item.IndustrialManagementId = industrialManagementId
  105. item.UserId = uid
  106. item.Email = user.Email
  107. item.Mobile = user.Mobile
  108. item.RealName = user.RealName
  109. item.Source = utils.REGISTER_PLATFORM
  110. item.CompanyId = user.CompanyId
  111. item.CompanyName = user.CompanyName
  112. if count == 0 {
  113. item.Type = 1
  114. item.CreateTime = time.Now()
  115. item.ModifyTime = time.Now()
  116. _, err = models.AddCygxIndustryFllow(item)
  117. if err != nil {
  118. br.Msg = "操作失败"
  119. br.ErrMsg = "操作失败,Err:" + err.Error()
  120. return
  121. }
  122. resp.Status = 1
  123. } else {
  124. item.Type = 2
  125. err = models.RemoveCygxIndustryFllow(uid, industrialManagementId)
  126. if err != nil {
  127. br.Msg = "操作失败"
  128. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  129. return
  130. }
  131. }
  132. go services.IndustryFllowWithTrack(industrialManagementId, count, uid) //处理是否关注全部赛道字段
  133. go services.IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid) //处理用户标签
  134. go services.AddCygxIndustryFllowLog(item) //添加操作日志记录
  135. br.Msg = "操作成功"
  136. br.Ret = 200
  137. br.Success = true
  138. br.Data = resp
  139. }
  140. // @Title 关注作者/取消关注作者
  141. // @Description 关注作者/取消关注作者 接口
  142. // @Param request body models.CygxArticleDepartmentId true "type json string"
  143. // @Success 200
  144. // @router /fllowDepartment [post]
  145. func (this *ReportController) FllowDepartment() {
  146. br := new(models.BaseResponse).Init()
  147. defer func() {
  148. this.Data["json"] = br
  149. this.ServeJSON()
  150. }()
  151. user := this.User
  152. if user == nil {
  153. br.Msg = "请重新登录"
  154. br.Ret = 408
  155. return
  156. }
  157. uid := user.UserId
  158. var req models.CygxArticleDepartmentId
  159. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  160. if err != nil {
  161. br.Msg = "参数解析异常!"
  162. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  163. return
  164. }
  165. departmentId := req.DepartmentId
  166. var condition string
  167. countDepartment, err := models.GetDepartmentCount(departmentId)
  168. if err != nil {
  169. br.Msg = "获取数据失败!"
  170. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  171. return
  172. }
  173. if countDepartment == 0 {
  174. br.Msg = "作者不存在!"
  175. br.ErrMsg = "作者ID不存在:" + strconv.Itoa(departmentId)
  176. return
  177. }
  178. countUser, err := models.GetArticleDepartmentFollowByUid(uid)
  179. count, err := models.GetArticleDepartmentFollow(uid, departmentId, condition)
  180. if err != nil {
  181. br.Msg = "获取数据失败!"
  182. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  183. return
  184. }
  185. resp := new(models.CygxArticleDepartmentFollowResp)
  186. if countUser == 0 {
  187. resp.GoFollow = true
  188. }
  189. if count == 0 {
  190. item := new(models.CygxArticleDepartmentFollow)
  191. item.DepartmentId = departmentId
  192. item.UserId = uid
  193. item.Email = user.Email
  194. item.Mobile = user.Mobile
  195. item.RealName = user.RealName
  196. item.CompanyId = user.CompanyId
  197. item.CompanyName = user.CompanyName
  198. item.Type = 1
  199. item.CreateTime = time.Now()
  200. item.ModifyTime = time.Now()
  201. _, err = models.AddArticleDepartmentFollow(item)
  202. if err != nil {
  203. br.Msg = "操作失败"
  204. br.ErrMsg = "操作失败,Err:" + err.Error()
  205. return
  206. }
  207. resp.Status = 1
  208. } else {
  209. var doType int
  210. condition = ` AND type = 1`
  211. count, err = models.GetArticleDepartmentFollow(uid, departmentId, condition)
  212. if err != nil {
  213. br.Msg = "操作失败!"
  214. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  215. return
  216. }
  217. if count == 1 {
  218. resp.Status = 2
  219. doType = 2
  220. } else {
  221. resp.Status = 1
  222. doType = 1
  223. }
  224. err = models.RemoveArticleDepartmentFollow(uid, departmentId, doType)
  225. if err != nil {
  226. br.Msg = "操作失败"
  227. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  228. return
  229. }
  230. }
  231. br.Msg = "操作成功"
  232. br.Ret = 200
  233. br.Success = true
  234. br.Data = resp
  235. }
  236. // @Title 文章留言接口
  237. // @Description 文章留言接口
  238. // @Param request body models.AddCygxActivityHelpAsk true "type json string"
  239. // @Success 200 {object} models.TacticsListResp
  240. // @router /commentAdd [post]
  241. func (this *ReportController) CommentAdd() {
  242. br := new(models.BaseResponse).Init()
  243. defer func() {
  244. this.Data["json"] = br
  245. this.ServeJSON()
  246. }()
  247. user := this.User
  248. if user == nil {
  249. br.Msg = "请重新登录"
  250. br.Ret = 408
  251. return
  252. }
  253. var req models.AddCygxArticleCommentReq
  254. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  255. if err != nil {
  256. br.Msg = "参数解析异常!"
  257. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  258. return
  259. }
  260. if req.ArticleId <= 0 {
  261. br.Msg = "文章不存在"
  262. br.ErrMsg = "文章不存在,文章ID错误"
  263. return
  264. }
  265. if req.Content == "" {
  266. br.Msg = "建议内容不可为空"
  267. return
  268. }
  269. content := req.Content
  270. itemToken, err := services.WxGetToken()
  271. if err != nil {
  272. br.Msg = "GetWxAccessToken Err:" + err.Error()
  273. return
  274. }
  275. if itemToken.AccessToken == "" {
  276. br.Msg = "accessToken is empty"
  277. return
  278. }
  279. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  280. if err != nil {
  281. br.Msg = "内容校验失败!"
  282. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  283. return
  284. }
  285. if commerr.ErrCode != 0 {
  286. br.Msg = "内容违规,请重新提交!"
  287. br.ErrMsg = "内容违规,Err:" + commerr.ErrMSG
  288. return
  289. }
  290. articleId := req.ArticleId
  291. articleInfo, errInfo := models.GetArticleDetailById(articleId)
  292. if articleInfo == nil {
  293. br.Msg = "操作失败"
  294. br.ErrMsg = "文章ID错误,不存在articleId:" + strconv.Itoa(articleId)
  295. return
  296. }
  297. if errInfo != nil {
  298. br.Msg = "操作失败"
  299. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  300. return
  301. }
  302. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  303. if err != nil {
  304. br.Msg = "提交失败!"
  305. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  306. return
  307. }
  308. if companyDetail == nil {
  309. br.Msg = "提交失败!"
  310. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  311. return
  312. }
  313. item := models.CygxArticleComment{
  314. UserId: user.UserId,
  315. ArticleId: req.ArticleId,
  316. CreateTime: time.Now(),
  317. Mobile: user.Mobile,
  318. Email: user.Email,
  319. CompanyId: user.CompanyId,
  320. CompanyName: companyDetail.CompanyName,
  321. Content: content,
  322. Title: articleInfo.Title,
  323. }
  324. msgId, err := models.AddArticleComment(&item)
  325. if err != nil {
  326. br.Msg = "提交失败"
  327. br.ErrMsg = "提交留言失败,Err:" + err.Error()
  328. return
  329. }
  330. services.SendCommentWxTemplateMsg(req, user, articleInfo, int(msgId))
  331. br.Ret = 200
  332. br.Success = true
  333. br.Msg = "提交成功"
  334. }