report.go 9.1 KB

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