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