yanxuan_special.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/services"
  7. "hongze/hongze_clpt/utils"
  8. "path"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type YanxuanSpecialController struct {
  14. BaseAuthController
  15. }
  16. type YanxuanSpecialNoLoginController struct {
  17. BaseAuthMobileController
  18. }
  19. // @Title 专栏列表
  20. // @Description 专栏列表
  21. // @Param SpecialColumnId query int true "作者专栏ID"
  22. // @Param PageSize query int true "每页数据条数"
  23. // @Param CurrentIndex query int true "当前页页码,从1开始"
  24. // @Success 200 {object} models.AddEnglishReportResp
  25. // @router /list [get]
  26. func (this *YanxuanSpecialNoLoginController) List() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. sysUser := this.User
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. specialColumnId, _ := this.GetInt("SpecialColumnId", 0)
  40. pageSize, _ := this.GetInt("PageSize")
  41. currentIndex, _ := this.GetInt("CurrentIndex")
  42. var startSize int
  43. if pageSize <= 0 {
  44. pageSize = utils.PageSize20
  45. }
  46. if currentIndex <= 0 {
  47. currentIndex = 1
  48. }
  49. startSize = utils.StartIndex(currentIndex, pageSize)
  50. resp := new(models.SpecialListResp)
  51. var condition string
  52. var pars []interface{}
  53. if specialColumnId > 0 {
  54. authorItem, err := models.GetYanxuanSpecialAuthorById(specialColumnId)
  55. if err != nil {
  56. br.Msg = "查询栏目详情失败!"
  57. br.ErrMsg = "查询栏目详情失败,Err:" + err.Error()
  58. return
  59. }
  60. condition += ` AND a.user_id = ? `
  61. pars = append(pars, authorItem.UserId)
  62. }
  63. condition += ` AND a.status = 3 `
  64. total, err := models.GetCygxYanxuanSpecialCount(condition, pars)
  65. if err != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取失败, Err:" + err.Error()
  68. return
  69. }
  70. list, err := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, startSize, pageSize)
  71. if err != nil {
  72. br.Msg = "获取失败"
  73. br.ErrMsg = "获取失败, Err:" + err.Error()
  74. return
  75. }
  76. var yanxuanSpecialIds []int
  77. for _, v := range list {
  78. yanxuanSpecialIds = append(yanxuanSpecialIds, v.Id)
  79. }
  80. yanxuanSpecialPv := services.GetYanxuanSpecialRecordByYanxuanSpecialId(yanxuanSpecialIds)
  81. for _, v := range list {
  82. hasImg, err := utils.ArticleHasImgUrl(v.Content)
  83. if err != nil {
  84. return
  85. }
  86. if hasImg {
  87. v.ContentHasImg = 1
  88. }
  89. v.ImgUrl = strings.TrimRight(v.ImgUrl, ",")
  90. //去除图片标签
  91. v.Content = utils.ArticleRemoveImgUrl(v.Content)
  92. //v.Content, err = utils.ExtractText(v.Content)
  93. if v.DocUrl != "" {
  94. var docs []models.Doc
  95. err := json.Unmarshal([]byte(v.DocUrl), &docs)
  96. if err != nil {
  97. br.Msg = "参数解析异常!"
  98. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  99. return
  100. }
  101. v.Docs = docs
  102. }
  103. if v.MyCollectNum > 0 {
  104. v.IsCollect = 1
  105. }
  106. if v.ImgUrl != "" {
  107. imgList := strings.Split(v.ImgUrl, ",")
  108. for _, s := range imgList {
  109. v.ImgUrlList = append(v.ImgUrlList, s)
  110. }
  111. } else {
  112. v.ImgUrlList = []string{}
  113. }
  114. if v.CompanyTags != "" {
  115. tagList := strings.Split(v.CompanyTags, ",")
  116. for _, s := range tagList {
  117. v.TagList = append(v.TagList, s)
  118. }
  119. }
  120. if v.IndustryTags != "" {
  121. tagList := strings.Split(v.IndustryTags, ",")
  122. for _, s := range tagList {
  123. v.TagList = append(v.TagList, s)
  124. }
  125. }
  126. if len(v.TagList) == 0 {
  127. v.TagList = []string{}
  128. }
  129. v.Pv = yanxuanSpecialPv[v.Id]
  130. }
  131. specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
  132. resp.IsAuthor = specialAuthorCheck.IsAuthor
  133. resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
  134. resp.List = list
  135. page := paging.GetPaging(currentIndex, pageSize, total)
  136. resp.Paging = page
  137. br.Data = resp
  138. br.Ret = 200
  139. br.Success = true
  140. br.Msg = "获取成功"
  141. }
  142. // @Title 专栏详情
  143. // @Description 专栏详情
  144. // @Param request body help_doc.AddHelpDocReq true "type json string"
  145. // @Success 200 {object} models.AddEnglishReportResp
  146. // @router /detail [get]
  147. func (this *YanxuanSpecialNoLoginController) Detail() {
  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.ErrMsg = "请登录,SysUser Is Empty"
  157. br.Ret = 408
  158. return
  159. }
  160. specialId, _ := this.GetInt("Id", 0)
  161. if specialId <= 0 {
  162. br.Msg = "参数错误"
  163. br.ErrMsg = "参数错误"
  164. return
  165. }
  166. item, tmpErr := models.GetYanxuanSpecialById(specialId, user.UserId)
  167. if tmpErr != nil {
  168. br.Msg = "获取失败"
  169. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  170. return
  171. }
  172. if item.MyCollectNum > 0 {
  173. item.IsCollect = 1
  174. }
  175. var resp models.CygxYanxuanSpecialResp
  176. resp.HasPermission = 1
  177. resp.CygxYanxuanSpecialItem = *item
  178. if item.DocUrl != "" {
  179. var docs []models.Doc
  180. err := json.Unmarshal([]byte(item.DocUrl), &docs)
  181. if err != nil {
  182. br.Msg = "参数解析异常!"
  183. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  184. return
  185. }
  186. resp.Docs = docs
  187. }
  188. if item.ImgUrl != "" {
  189. imgList := strings.Split(item.ImgUrl, ",")
  190. for _, s := range imgList {
  191. resp.ImgUrlList = append(resp.ImgUrlList, s)
  192. }
  193. } else {
  194. resp.ImgUrlList = []string{}
  195. }
  196. if item.CompanyTags != "" {
  197. cTagList := strings.Split(item.CompanyTags, ",")
  198. for _, s := range cTagList {
  199. resp.CompanyTags = append(resp.CompanyTags, s)
  200. }
  201. } else {
  202. resp.CompanyTags = []string{}
  203. }
  204. if item.IndustryTags != "" {
  205. iTagList := strings.Split(item.IndustryTags, ",")
  206. for _, s := range iTagList {
  207. resp.IndustryTags = append(resp.IndustryTags, s)
  208. }
  209. } else {
  210. resp.IndustryTags = []string{}
  211. }
  212. var configCode string
  213. //如果是研选的就推送给汪洋跟王芳,否则就推送给王芳
  214. configCode = utils.TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL
  215. cnf, err := models.GetConfigByCode(configCode)
  216. if err != nil {
  217. br.Msg = "获取失败"
  218. br.ErrMsg = "获取失败, Err:" + err.Error()
  219. return
  220. }
  221. if item.UserId != user.UserId && item.Status != 3 && !strings.Contains(cnf.ConfigValue, user.Mobile) {
  222. resp.CygxYanxuanSpecialItem = *new(models.CygxYanxuanSpecialItem) // 如果内容不可见,就把内容置空
  223. resp.CygxYanxuanSpecialItem.Status = item.Status
  224. //resp.HasPermission = 2
  225. }
  226. //如果是用户本人写的专栏,那么就不做校验
  227. //if item.UserId == sysUser.UserId || sysUser.UserId == 0 {
  228. // resp.HasPermission = 1
  229. //} else {
  230. // hasPermission, err := services.GetUserRaiPermissionYanXuanInfo(sysUser)
  231. // if err != nil {
  232. // br.Msg = "获取失败"
  233. // br.ErrMsg = "获取失败, Err:" + err.Error()
  234. // return
  235. // }
  236. // resp.HasPermission = hasPermission
  237. //}
  238. //判断是否属于审核人员
  239. mobileSlice := strings.Split(cnf.ConfigValue, ",")
  240. for _, v := range mobileSlice {
  241. if v == user.Mobile {
  242. resp.IsApprovalAdmin = true
  243. }
  244. }
  245. if user.UserId > 0 {
  246. followCount, err := models.GetCygxYanxuanSpecialFollowCountByUser(user.UserId, item.UserId)
  247. if err != nil {
  248. br.Msg = "获取失败"
  249. br.ErrMsg = "获取失败, Err:" + err.Error()
  250. return
  251. }
  252. if followCount == 1 {
  253. resp.IsFollowAuthor = true
  254. }
  255. }
  256. //校验研选专栏权限,以及无权限的时候的对应状态码
  257. havePower, err := services.GetYanxuanSpecialDetailUserPower(user)
  258. if err != nil {
  259. br.Msg = "获取信息失败"
  260. br.ErrMsg = "校验用户权限失败,Err:" + err.Error()
  261. return
  262. }
  263. //看自己的文章时不设权限限制,不需要判断是否有研选订阅权限,都可以看。
  264. if user.UserId == item.UserId {
  265. havePower = true
  266. }
  267. var hasPermission int
  268. if havePower {
  269. hasPermission = 1
  270. } else {
  271. hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
  272. if err != nil {
  273. br.Msg = "获取信息失败"
  274. br.ErrMsg = "获取用户权限状态失败,Err:" + err.Error()
  275. return
  276. }
  277. }
  278. resp.HasPermission = hasPermission
  279. //if resp.HasPermission != 1 || sysUser.UserId == 0 {
  280. // resp.Content = utils.InterceptHtmlLength(resp.Content, 240)
  281. //}
  282. resp.ShareImg = utils.YANXUAN_SPECIAL_SHARE_IMG
  283. br.Data = resp
  284. br.Ret = 200
  285. br.Success = true
  286. br.Msg = "获取成功"
  287. }
  288. // @Title 新增保存专栏作者详情
  289. // @Description 新增保存专栏作者详情
  290. // @Param request body help_doc.AddHelpDocReq true "type json string"
  291. // @Success 200 {object} models.AddEnglishReportResp
  292. // @router /author/save [post]
  293. func (this *YanxuanSpecialController) AuthorSave() {
  294. br := new(models.BaseResponse).Init()
  295. defer func() {
  296. this.Data["json"] = br
  297. this.ServeJSON()
  298. }()
  299. sysUser := this.User
  300. if sysUser == nil {
  301. br.Msg = "请登录"
  302. br.ErrMsg = "请登录,SysUser Is Empty"
  303. br.Ret = 408
  304. return
  305. }
  306. var req models.SaveCygxYanxuanSpecialAuthorReq
  307. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  308. if err != nil {
  309. br.Msg = "参数解析异常!"
  310. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  311. return
  312. }
  313. if req.SpecialColumnId <= 0 {
  314. br.Msg = "栏目id有误"
  315. return
  316. }
  317. if req.SpecialName == "" {
  318. br.Msg = "请输入专栏名称"
  319. return
  320. }
  321. if req.NickName == "" {
  322. br.Msg = "请输入昵称"
  323. return
  324. }
  325. item := models.CygxYanxuanSpecialAuthor{
  326. Id: req.SpecialColumnId,
  327. UserId: sysUser.UserId,
  328. SpecialName: req.SpecialName,
  329. Introduction: req.Introduction,
  330. Label: req.Label,
  331. NickName: req.NickName,
  332. CreateTime: time.Now(),
  333. ModifyTime: time.Now(),
  334. BgImg: "",
  335. Status: 1,
  336. }
  337. //if req.Id == 0{
  338. // _, err = models.AddCygxYanxuanSpecialAuthor(&item)
  339. // if err != nil {
  340. // br.Msg = "新增失败"
  341. // br.ErrMsg = "新增失败,Err:" + err.Error()
  342. // return
  343. // }
  344. //} else {
  345. // err = models.UpdateYanxuanSpecialAuthor(&item)
  346. // if err != nil {
  347. // br.Msg = "保存失败"
  348. // br.ErrMsg = "保存失败,Err:" + err.Error()
  349. // return
  350. // }
  351. //}
  352. err = models.UpdateYanxuanSpecialAuthor(&item)
  353. if err != nil {
  354. br.Msg = "保存失败"
  355. br.ErrMsg = "保存失败,Err:" + err.Error()
  356. return
  357. }
  358. br.Ret = 200
  359. br.Success = true
  360. br.Msg = "保存成功"
  361. }
  362. // @Title 新增保存专栏
  363. // @Description 新增保存专栏
  364. // @Param request body help_doc.AddHelpDocReq true "type json string"
  365. // @Success 200 {object} models.AddEnglishReportResp
  366. // @router /save [post]
  367. func (this *YanxuanSpecialController) Save() {
  368. br := new(models.BaseResponse).Init()
  369. defer func() {
  370. this.Data["json"] = br
  371. this.ServeJSON()
  372. }()
  373. sysUser := this.User
  374. if sysUser == nil {
  375. br.Msg = "请登录"
  376. br.ErrMsg = "请登录,SysUser Is Empty"
  377. br.Ret = 408
  378. return
  379. }
  380. var req models.CygxYanxuanSpecialReq
  381. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  382. if err != nil {
  383. br.Msg = "参数解析异常!"
  384. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  385. return
  386. }
  387. if req.Content == "" && req.DoType == 2 {
  388. br.Msg = "请输入内容"
  389. return
  390. }
  391. if len(req.CompanyTags) == 0 && len(req.IndustryTags) == 0 && req.DoType == 2 {
  392. br.Msg = "请至少输入一个标签"
  393. return
  394. }
  395. if len(req.Docs) > 0 {
  396. for i, doc := range req.Docs {
  397. extMap := services.GetCloudDiskResourceFileTypeExtMap()
  398. ext := path.Ext(doc.DocName)
  399. req.Docs[i].DocIcon = extMap[ext]
  400. }
  401. }
  402. docUrl, err := json.Marshal(req.Docs)
  403. if err != nil {
  404. return
  405. }
  406. imgUrls := strings.Join(req.ImgUrl, ",")
  407. cTags := strings.Join(req.CompanyTags, ",")
  408. iTags := strings.Join(req.IndustryTags, ",")
  409. isApprovalPersonnel := req.IsApprovalPersonnel
  410. item := models.CygxYanxuanSpecial{
  411. Id: req.Id,
  412. UserId: sysUser.UserId,
  413. CreateTime: time.Now(),
  414. ModifyTime: time.Now(),
  415. PublishTime: time.Now(),
  416. Content: req.Content,
  417. CompanyTags: cTags,
  418. IndustryTags: iTags,
  419. ImgUrl: imgUrls,
  420. DocUrl: string(docUrl),
  421. Title: req.Title,
  422. Type: req.Type,
  423. }
  424. if req.DoType == 1 {
  425. item.Status = 1
  426. br.Msg = "保存成功"
  427. } else {
  428. item.Status = 2
  429. br.Msg = "已提交审核"
  430. }
  431. var authorUserId int
  432. // 如果是审批人员操作的那么就是修改内容,加审批通过
  433. if isApprovalPersonnel {
  434. item.Status = 3
  435. //校验是否属于审核人员
  436. if !services.CheckYxSpecialIsApprovalPersonnel(sysUser.Mobile) {
  437. br.Msg = "操作失败"
  438. br.ErrMsg = "操作失败,该账号不属于审核人员:" + sysUser.Mobile
  439. return
  440. }
  441. specialItem, err := models.GetYanxuanSpecialItemById(req.Id)
  442. if err != nil {
  443. br.Msg = "保存失败"
  444. br.ErrMsg = "保存失败,Err:" + err.Error()
  445. return
  446. }
  447. item.UserId = specialItem.UserId // 专栏userid还是原有userId
  448. authorUserId = specialItem.UserId
  449. item.AdminName = sysUser.RealName //审核人员姓名
  450. br.Msg = "审批成功"
  451. }
  452. specialId := 0
  453. if req.Id == 0 {
  454. id, err := models.AddCygxYanxuanSpecial(&item)
  455. if err != nil {
  456. br.Msg = "新增失败"
  457. br.ErrMsg = "新增失败,Err:" + err.Error()
  458. return
  459. }
  460. specialId = int(id)
  461. } else {
  462. detail, tmpErr := models.GetYanxuanSpecialById(req.Id, sysUser.UserId)
  463. if tmpErr != nil {
  464. br.Msg = "获取失败"
  465. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  466. return
  467. }
  468. if detail.Status == 2 && !isApprovalPersonnel {
  469. br.Msg = "请勿重复提交"
  470. br.ErrMsg = "保存失败,专栏内容正在审核"
  471. return
  472. }
  473. err = models.UpdateYanxuanSpecial(&item)
  474. if err != nil {
  475. br.Msg = "保存失败"
  476. br.ErrMsg = "保存失败,Err:" + err.Error()
  477. return
  478. }
  479. specialId = req.Id
  480. }
  481. if isApprovalPersonnel {
  482. go services.UpdateYanxuanSpecialResourceData(specialId) // 写入首页最新 cygx_resource_data 表
  483. go services.EsAddYanxuanSpecial(specialId) // 写入es 综合搜索
  484. go services.SendWxMsgSpecialFollow(req.Id) //研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
  485. go services.SendWxMsgSpecialAuthor(req.Id, 1) //研选专栏审核完成时,给提交人发送模板消息
  486. go services.UdpateYanxuanSpecialauthorArticleNum(authorUserId) // 更新作者发布文章的数量
  487. go services.MakeYanxuanSpecialMomentsImg(specialId) // 生成研选专栏分享到朋友圈的图片
  488. go services.SendWxCategoryMsgSpecialAuthor(req.Id, 1) //研选专栏审核完成时,给提交人发送类目模板消息
  489. go services.SendWxCategoryMsgSpecialFollow(req.Id) // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
  490. } else {
  491. if req.DoType == 2 {
  492. go services.SendReviewTemplateMsgAdmin(specialId)
  493. go services.SendReviewCategoryTemplateMsgAdmin(specialId)
  494. go services.UpdateYanxuanSpecialResourceData(specialId) // 写入首页最新 cygx_resource_data 表
  495. go services.EsAddYanxuanSpecial(specialId) // 写入es 综合搜索
  496. }
  497. }
  498. br.Ret = 200
  499. br.Success = true
  500. br.Data = specialId
  501. }
  502. // @Title 专栏作者详情
  503. // @Description 专栏作者详情
  504. // @Param request body help_doc.AddHelpDocReq true "type json string"
  505. // @Success 200 {object} models.AddEnglishReportResp
  506. // @router /author/detail [get]
  507. func (this *YanxuanSpecialNoLoginController) AuthorDetail() {
  508. br := new(models.BaseResponse).Init()
  509. defer func() {
  510. this.Data["json"] = br
  511. this.ServeJSON()
  512. }()
  513. sysUser := this.User
  514. if sysUser == nil {
  515. br.Msg = "请登录"
  516. br.ErrMsg = "请登录,SysUser Is Empty"
  517. br.Ret = 408
  518. return
  519. }
  520. specialColumnId, _ := this.GetInt("SpecialColumnId", 0)
  521. item, tmpErr := models.GetYanxuanSpecialAuthorBySpecialColumnId(specialColumnId, sysUser.UserId)
  522. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  523. br.Msg = "获取失败"
  524. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  525. return
  526. }
  527. if item.IsFollow > 0 {
  528. item.IsFollow = 1
  529. }
  530. br.Data = item
  531. br.Ret = 200
  532. br.Success = true
  533. br.Msg = "获取成功"
  534. }
  535. // @Title 审批研选专栏
  536. // @Description 审批研选专栏
  537. // @Param request body help_doc.AddHelpDocReq true "type json string"
  538. // @Success 200 {object} models.AddEnglishReportResp
  539. // @router /enable [post]
  540. func (this *YanxuanSpecialController) Enable() {
  541. br := new(models.BaseResponse).Init()
  542. defer func() {
  543. this.Data["json"] = br
  544. this.ServeJSON()
  545. }()
  546. user := this.User
  547. if user == nil {
  548. br.Msg = "请登录"
  549. br.ErrMsg = "请登录,SysUser Is Empty"
  550. br.Ret = 408
  551. return
  552. }
  553. var req models.EnableCygxYanxuanSpecialReq
  554. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  555. if err != nil {
  556. br.Msg = "参数解析异常!"
  557. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  558. return
  559. }
  560. if req.Id <= 0 {
  561. br.Msg = "文章id错误"
  562. return
  563. }
  564. if req.Status <= 0 {
  565. br.Msg = "参数错误"
  566. return
  567. }
  568. status := 0
  569. if req.Status == 1 {
  570. status = 3
  571. } else {
  572. status = 4
  573. }
  574. detail, err := models.GetYanxuanSpecialItemById(req.Id)
  575. if err != nil {
  576. br.Msg = "审批失败"
  577. br.ErrMsg = "审批失败, Err:" + err.Error()
  578. return
  579. }
  580. if tmpErr := models.EnableYanxuanSpecial(req.Id, status, req.Reason, user.RealName); tmpErr != nil {
  581. br.Msg = "审批失败"
  582. br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
  583. return
  584. }
  585. if req.Status == 1 {
  586. go services.SendWxMsgSpecialFollow(req.Id)
  587. go services.SendWxCategoryMsgSpecialAuthor(req.Id, 1) //研选专栏审核完成时,给提交人发送类目模板消息
  588. go services.SendWxCategoryMsgSpecialFollow(req.Id) // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
  589. } else {
  590. go services.SendWxCategoryMsgSpecialAuthor(req.Id, 2)
  591. }
  592. go services.SendWxMsgSpecialAuthor(req.Id, req.Status)
  593. go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  594. go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  595. go services.AddAddCygxYanxuanSpecialApprovalLog(user, req.Id, req.Status, req.Reason) // 写入es 综合搜索
  596. go services.UdpateYanxuanSpecialauthorArticleNum(detail.UserId) // 更新作者发布文章的数量
  597. go services.MakeYanxuanSpecialMomentsImg(req.Id) // 生成研选专栏分享到朋友圈的图片
  598. br.Msg = "审批成功"
  599. br.Ret = 200
  600. br.Success = true
  601. }
  602. // @Title 研选专栏收藏
  603. // @Description 研选专栏收藏
  604. // @Param request body help_doc.AddHelpDocReq true "type json string"
  605. // @Success 200 {object} models.AddEnglishReportResp
  606. // @router /collect [post]
  607. func (this *YanxuanSpecialController) Collect() {
  608. br := new(models.BaseResponse).Init()
  609. defer func() {
  610. this.Data["json"] = br
  611. this.ServeJSON()
  612. }()
  613. user := this.User
  614. if user == nil {
  615. br.Msg = "请登录"
  616. br.ErrMsg = "请登录,SysUser Is Empty"
  617. br.Ret = 408
  618. return
  619. }
  620. var req models.CollectCygxYanxuanSpecialReq
  621. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  622. if err != nil {
  623. br.Msg = "参数解析异常!"
  624. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  625. return
  626. }
  627. if req.Id <= 0 {
  628. br.Msg = "文章id错误"
  629. return
  630. }
  631. if req.Status <= 0 {
  632. br.Msg = "参数错误"
  633. return
  634. }
  635. var sellerName string
  636. if req.Status == 1 {
  637. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  638. if err != nil && err.Error() != utils.ErrNoRow() {
  639. br.Msg = "查询栏目详情失败!"
  640. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  641. return
  642. }
  643. if sellerItemQy != nil {
  644. sellerName = sellerItemQy.RealName
  645. }
  646. item := models.CygxYanxuanSpecialCollect{
  647. UserId: user.UserId,
  648. Mobile: user.Mobile,
  649. Email: user.Email,
  650. CompanyId: user.CompanyId,
  651. CompanyName: user.CompanyName,
  652. RealName: user.RealName,
  653. SellerName: sellerName,
  654. CreateTime: time.Now(),
  655. ModifyTime: time.Now(),
  656. RegisterPlatform: utils.REGISTER_PLATFORM,
  657. YanxuanSpecialId: req.Id,
  658. }
  659. _, err = models.AddCygxYanxuanSpecialCollect(&item)
  660. if err != nil {
  661. br.Msg = "新增失败"
  662. br.ErrMsg = "新增失败,Err:" + err.Error()
  663. return
  664. }
  665. br.Msg = "收藏成功"
  666. } else {
  667. err = models.DelCygxYanxuanSpecialCollect(user.UserId, req.Id)
  668. if err != nil {
  669. br.Msg = "删除失败"
  670. br.ErrMsg = "删除失败,Err:" + err.Error()
  671. return
  672. }
  673. br.Msg = "取消收藏成功"
  674. }
  675. go services.UdpateYanxuanSpecialCollect(req.Id)
  676. br.Ret = 200
  677. br.Success = true
  678. }
  679. // @Title 专栏内容中心
  680. // @Description 专栏内容中心
  681. // @Param request body help_doc.AddHelpDocReq true "type json string"
  682. // @Success 200 {object} models.AddEnglishReportResp
  683. // @router /center [get]
  684. func (this *YanxuanSpecialController) Center() {
  685. br := new(models.BaseResponse).Init()
  686. defer func() {
  687. this.Data["json"] = br
  688. this.ServeJSON()
  689. }()
  690. sysUser := this.User
  691. if sysUser == nil {
  692. br.Msg = "请登录"
  693. br.ErrMsg = "请登录,SysUser Is Empty"
  694. br.Ret = 408
  695. return
  696. }
  697. // 1:未发布,2:审核中 3:已发布 4:驳回
  698. status, _ := this.GetInt("Status", 0)
  699. if status <= 0 {
  700. br.Msg = "参数错误"
  701. br.ErrMsg = "参数错误"
  702. return
  703. }
  704. var condition string
  705. var pars []interface{}
  706. condition += ` AND a.user_id = ? `
  707. pars = append(pars, sysUser.UserId)
  708. condition += ` AND a.status = ? `
  709. pars = append(pars, status)
  710. list, tmpErr := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, 0, 0)
  711. if tmpErr != nil {
  712. br.Msg = "获取失败"
  713. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  714. return
  715. }
  716. br.Data = list
  717. br.Ret = 200
  718. br.Success = true
  719. br.Msg = "获取成功"
  720. }
  721. // @Title 专栏点击记录
  722. // @Description 专栏点击记录
  723. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  724. // @router /record [post]
  725. func (this *YanxuanSpecialController) Record() {
  726. br := new(models.BaseResponse).Init()
  727. defer func() {
  728. this.Data["json"] = br
  729. this.ServeJSON()
  730. }()
  731. user := this.User
  732. if user == nil {
  733. br.Msg = "请重新登录"
  734. br.Ret = 408
  735. return
  736. }
  737. var req models.AddCygxYanxuanSpecialRecordReq
  738. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  739. if err != nil {
  740. br.Msg = "参数解析异常!"
  741. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  742. return
  743. }
  744. if req.SpecialId <= 0 {
  745. br.Msg = "文章不存在"
  746. br.ErrMsg = "文章不存在,文章ID错误"
  747. return
  748. }
  749. specialId := req.SpecialId
  750. stopTime := req.StopTime
  751. if req.SpecialId <= 0 {
  752. br.Msg = "文章不存在"
  753. br.ErrMsg = "文章不存在,文章ID错误"
  754. return
  755. }
  756. err = services.AddSpecialRecord(this.User, specialId, stopTime)
  757. if err != nil {
  758. br.Msg = "记录失败"
  759. br.ErrMsg = "记录失败,Err:" + err.Error()
  760. return
  761. }
  762. br.Ret = 200
  763. br.Success = true
  764. br.Msg = "记录成功"
  765. }
  766. // @Title 研选专栏关注
  767. // @Description 研选专栏关注
  768. // @Param request body help_doc.AddHelpDocReq true "type json string"
  769. // @Success 200 {object} models.AddEnglishReportResp
  770. // @router /follow [post]
  771. func (this *YanxuanSpecialController) Follow() {
  772. br := new(models.BaseResponse).Init()
  773. defer func() {
  774. this.Data["json"] = br
  775. this.ServeJSON()
  776. }()
  777. user := this.User
  778. if user == nil {
  779. br.Msg = "请登录"
  780. br.ErrMsg = "请登录,SysUser Is Empty"
  781. br.Ret = 408
  782. return
  783. }
  784. var req models.FollowCygxYanxuanSpecialReq
  785. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  786. if err != nil {
  787. br.Msg = "参数解析异常!"
  788. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  789. return
  790. }
  791. if req.FollowSpecialColumnId <= 0 {
  792. br.Msg = "被关注的专栏栏目id错误"
  793. return
  794. }
  795. if req.Status <= 0 {
  796. br.Msg = "参数错误"
  797. return
  798. }
  799. var sellerName string
  800. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  801. if err != nil && err.Error() != utils.ErrNoRow() {
  802. br.Msg = "查询栏目详情失败!"
  803. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  804. return
  805. }
  806. if sellerItemQy != nil {
  807. sellerName = sellerItemQy.RealName
  808. }
  809. authorItem, err := models.GetYanxuanSpecialAuthorById(req.FollowSpecialColumnId)
  810. if err != nil {
  811. br.Msg = "查询栏目详情失败!"
  812. br.ErrMsg = "查询栏目详情失败,Err:" + err.Error()
  813. return
  814. }
  815. if req.Status == 1 {
  816. followCount, err := models.GetCygxYanxuanSpecialFollowCountByUser(user.UserId, authorItem.UserId)
  817. if err != nil {
  818. br.Msg = "获取失败"
  819. br.ErrMsg = "获取失败, Err:" + err.Error()
  820. return
  821. }
  822. if followCount == 0 {
  823. item := models.CygxYanxuanSpecialFollow{
  824. UserId: user.UserId,
  825. FollowUserId: authorItem.UserId,
  826. Mobile: user.Mobile,
  827. Email: user.Email,
  828. CompanyId: user.CompanyId,
  829. CompanyName: user.CompanyName,
  830. RealName: user.RealName,
  831. SellerName: sellerName,
  832. CreateTime: time.Now(),
  833. ModifyTime: time.Now(),
  834. RegisterPlatform: utils.REGISTER_PLATFORM,
  835. YanxuanSpecialId: req.SpecialId,
  836. }
  837. err = models.AddCygxYanxuanSpecialFollow(&item)
  838. if err != nil {
  839. br.Msg = "新增失败"
  840. br.ErrMsg = "新增失败,Err:" + err.Error()
  841. return
  842. }
  843. }
  844. br.Msg = "关注成功"
  845. } else {
  846. err = models.DelCygxYanxuanSpecialFollow(user.UserId, authorItem.UserId)
  847. if err != nil {
  848. br.Msg = "删除失败"
  849. br.ErrMsg = "删除失败,Err:" + err.Error()
  850. return
  851. }
  852. br.Msg = "取消关注成功"
  853. }
  854. go services.UdpateYanxuanSpecialFansNum(authorItem.UserId)
  855. br.Ret = 200
  856. br.Success = true
  857. }
  858. // @Title 行业标签搜索
  859. // @Description 行业标签搜索
  860. // @Param request body help_doc.AddHelpDocReq true "type json string"
  861. // @Success 200 {object} models.AddEnglishReportResp
  862. // @router /industrySearch [get]
  863. func (this *YanxuanSpecialController) IndustrySearch() {
  864. br := new(models.BaseResponse).Init()
  865. defer func() {
  866. this.Data["json"] = br
  867. this.ServeJSON()
  868. }()
  869. sysUser := this.User
  870. if sysUser == nil {
  871. br.Msg = "请登录"
  872. br.ErrMsg = "请登录,SysUser Is Empty"
  873. br.Ret = 408
  874. return
  875. }
  876. keyword := this.GetString("Keyword")
  877. list, tmpErr := models.GetYanxuanSpecialIndustry(keyword)
  878. if tmpErr != nil {
  879. br.Msg = "获取失败"
  880. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  881. return
  882. }
  883. br.Data = list
  884. br.Ret = 200
  885. br.Success = true
  886. br.Msg = "获取成功"
  887. }
  888. // @Title 公司标签搜索
  889. // @Description 公司标签搜索
  890. // @Param request body help_doc.AddHelpDocReq true "type json string"
  891. // @Success 200 {object} models.AddEnglishReportResp
  892. // @router /companySearch [get]
  893. func (this *YanxuanSpecialController) CompanySearch() {
  894. br := new(models.BaseResponse).Init()
  895. defer func() {
  896. this.Data["json"] = br
  897. this.ServeJSON()
  898. }()
  899. sysUser := this.User
  900. if sysUser == nil {
  901. br.Msg = "请登录"
  902. br.ErrMsg = "请登录,SysUser Is Empty"
  903. br.Ret = 408
  904. return
  905. }
  906. keyword := this.GetString("Keyword")
  907. if keyword == "" {
  908. br.Ret = 200
  909. return
  910. }
  911. list, tmpErr := models.GetYanxuanSpecialCompany(keyword)
  912. if tmpErr != nil {
  913. br.Msg = "获取失败"
  914. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  915. return
  916. }
  917. br.Data = list
  918. br.Ret = 200
  919. br.Success = true
  920. br.Msg = "获取成功"
  921. }
  922. // @Title 专栏取消发布
  923. // @Description 专栏取消发布
  924. // @Param request body help_doc.AddHelpDocReq true "type json string"
  925. // @Success 200 {object} models.AddEnglishReportResp
  926. // @router /cancel [post]
  927. func (this *YanxuanSpecialController) Cancel() {
  928. br := new(models.BaseResponse).Init()
  929. defer func() {
  930. this.Data["json"] = br
  931. this.ServeJSON()
  932. }()
  933. sysUser := this.User
  934. if sysUser == nil {
  935. br.Msg = "请登录"
  936. br.ErrMsg = "请登录,SysUser Is Empty"
  937. br.Ret = 408
  938. return
  939. }
  940. var req models.CancelPublishCygxYanxuanSpecialReq
  941. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  942. if err != nil {
  943. br.Msg = "参数解析异常!"
  944. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  945. return
  946. }
  947. if req.Id <= 0 {
  948. br.Msg = "文章id错误"
  949. return
  950. }
  951. specialItem, err := models.GetYanxuanSpecialItemById(req.Id)
  952. if err != nil {
  953. br.Msg = "专栏取消发布失败"
  954. br.ErrMsg = "专栏取消发布失败,Err:" + err.Error()
  955. return
  956. }
  957. if tmpErr := models.CancelPublishYanxuanSpecial(req.Id); tmpErr != nil {
  958. br.Msg = "取消发布失败"
  959. br.ErrMsg = "取消发布失败, Err:" + tmpErr.Error()
  960. return
  961. }
  962. go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  963. go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  964. go services.UdpateYanxuanSpecialauthorArticleNum(specialItem.UserId) // 更新作者发布文章的数量
  965. br.Msg = "取消发布成功"
  966. br.Ret = 200
  967. br.Success = true
  968. }
  969. // @Title 作者列表
  970. // @Description 作者列表
  971. // @Param PageSize query int true "每页数据条数"
  972. // @Param CurrentIndex query int true "当前页页码,从1开始"
  973. // @Success 200 {object} models.AddEnglishReportResp
  974. // @router /author/list [get]
  975. func (this *YanxuanSpecialNoLoginController) AuthorList() {
  976. br := new(models.BaseResponse).Init()
  977. defer func() {
  978. this.Data["json"] = br
  979. this.ServeJSON()
  980. }()
  981. sysUser := this.User
  982. if sysUser == nil {
  983. br.Msg = "请登录"
  984. br.ErrMsg = "请登录,SysUser Is Empty"
  985. br.Ret = 408
  986. return
  987. }
  988. pageSize, _ := this.GetInt("PageSize")
  989. currentIndex, _ := this.GetInt("CurrentIndex")
  990. var startSize int
  991. if pageSize <= 0 {
  992. pageSize = utils.PageSize20
  993. }
  994. if currentIndex <= 0 {
  995. currentIndex = 1
  996. }
  997. startSize = utils.StartIndex(currentIndex, pageSize)
  998. resp := new(models.SpecialAuthorListResp)
  999. specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
  1000. resp.IsAuthor = specialAuthorCheck.IsAuthor
  1001. resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
  1002. resp.SpecialColumnId = specialAuthorCheck.SpecialColumnId
  1003. resp.HeadImg = specialAuthorCheck.HeadImg
  1004. var condition string
  1005. var conditionUserSort string
  1006. var pars []interface{}
  1007. condition += ` AND a.nick_name <> '' `
  1008. conditionUserSort += ` ( IF ( a.user_id = ` + strconv.Itoa(sysUser.UserId) + `, 1 = 1, user_id = 1 ) ) AS user_sort , ` // 用户本人如果开通了专栏,就放在最前面
  1009. total, err := models.GetCygxYanxuanSpecialAuthorCount(condition, pars)
  1010. if err != nil {
  1011. br.Msg = "获取失败"
  1012. br.ErrMsg = "获取失败,Err:" + err.Error()
  1013. return
  1014. }
  1015. condition += ` ORDER BY user_sort DESC, latest_publish_time DESC`
  1016. list, tmpErr := models.GetYanxuanSpecialAuthorList(conditionUserSort, condition, pars, startSize, pageSize)
  1017. if tmpErr != nil {
  1018. br.Msg = "获取失败"
  1019. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  1020. return
  1021. }
  1022. //var userIds []int
  1023. for _, v := range list {
  1024. v.LatestPublishDate = v.LatestPublishTime.Format(utils.FormatDate) + "更新"
  1025. //userIds = append(userIds, v.UserId)
  1026. }
  1027. page := paging.GetPaging(currentIndex, pageSize, total)
  1028. resp.List = list
  1029. resp.Paging = page
  1030. br.Data = resp
  1031. br.Ret = 200
  1032. br.Success = true
  1033. br.Msg = "获取成功"
  1034. }
  1035. // @Title 更新作者头像
  1036. // @Description 更新作者头像
  1037. // @Param request body help_doc.AddHelpDocReq true "type json string"
  1038. // @Success 200 {object} models.AddEnglishReportResp
  1039. // @router /author/head_img [post]
  1040. func (this *YanxuanSpecialController) AuthorHeadImg() {
  1041. br := new(models.BaseResponse).Init()
  1042. defer func() {
  1043. this.Data["json"] = br
  1044. this.ServeJSON()
  1045. }()
  1046. sysUser := this.User
  1047. if sysUser == nil {
  1048. br.Msg = "请登录"
  1049. br.ErrMsg = "请登录,SysUser Is Empty"
  1050. br.Ret = 408
  1051. return
  1052. }
  1053. var req models.SaveCygxYanxuanSpecialAuthoHeadImgrReq
  1054. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1055. if err != nil {
  1056. br.Msg = "参数解析异常!"
  1057. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1058. return
  1059. }
  1060. if req.SpecialColumnId <= 0 {
  1061. br.Msg = "专栏栏目id错误"
  1062. return
  1063. }
  1064. if req.HeadImg == "" {
  1065. br.Msg = "头像图片错误"
  1066. return
  1067. }
  1068. item := models.CygxYanxuanSpecialAuthor{
  1069. Id: req.SpecialColumnId,
  1070. HeadImg: req.HeadImg,
  1071. }
  1072. err = models.UpdateYanxuanSpecialAuthorHeadImg(&item)
  1073. if err != nil {
  1074. br.Msg = "保存失败"
  1075. br.ErrMsg = "保存失败,Err:" + err.Error()
  1076. return
  1077. }
  1078. br.Ret = 200
  1079. br.Success = true
  1080. br.Msg = "保存成功"
  1081. }
  1082. // @Title 删除专栏
  1083. // @Description 删除专栏
  1084. // @Param request body help_doc.AddHelpDocReq true "type json string"
  1085. // @Success 200 {object} models.AddEnglishReportResp
  1086. // @router /del [post]
  1087. func (this *YanxuanSpecialController) Delete() {
  1088. br := new(models.BaseResponse).Init()
  1089. defer func() {
  1090. this.Data["json"] = br
  1091. this.ServeJSON()
  1092. }()
  1093. sysUser := this.User
  1094. if sysUser == nil {
  1095. br.Msg = "请登录"
  1096. br.ErrMsg = "请登录,SysUser Is Empty"
  1097. br.Ret = 408
  1098. return
  1099. }
  1100. var req models.DelCygxYanxuanSpecialReq
  1101. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1102. if err != nil {
  1103. br.Msg = "参数解析异常!"
  1104. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1105. return
  1106. }
  1107. if req.Id <= 0 {
  1108. br.Msg = "文章id错误"
  1109. return
  1110. }
  1111. if tmpErr := models.DelYanxuanSpecial(req.Id); tmpErr != nil {
  1112. br.Msg = "删除失败"
  1113. br.ErrMsg = "删除失败, Err:" + tmpErr.Error()
  1114. return
  1115. }
  1116. br.Msg = "删除成功"
  1117. br.Ret = 200
  1118. br.Success = true
  1119. }
  1120. // @Title 专栏文章敏感词检测
  1121. // @Description 专栏文章敏感词检测
  1122. // @Param request body help_doc.AddHelpDocReq true "type json string"
  1123. // @Success 200 {object} models.AddEnglishReportResp
  1124. // @router /check [post]
  1125. func (this *YanxuanSpecialController) Check() {
  1126. br := new(models.BaseResponse).Init()
  1127. defer func() {
  1128. this.Data["json"] = br
  1129. this.ServeJSON()
  1130. }()
  1131. sysUser := this.User
  1132. if sysUser == nil {
  1133. br.Msg = "请登录"
  1134. br.ErrMsg = "请登录,SysUser Is Empty"
  1135. br.Ret = 408
  1136. return
  1137. }
  1138. var req models.CygxYanxuanSpecialCheckReq
  1139. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1140. if err != nil {
  1141. br.Msg = "参数解析异常!"
  1142. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1143. return
  1144. }
  1145. if req.Content == "" {
  1146. br.Ret = 200
  1147. br.Success = true
  1148. br.Msg = "校验成功"
  1149. }
  1150. accessToken, err := services.GetWxAccessTokenByXzs()
  1151. if err != nil {
  1152. br.Msg = "GetWxAccessToken Err:" + err.Error()
  1153. return
  1154. }
  1155. if accessToken == "" {
  1156. br.Msg = "accessToken is empty"
  1157. return
  1158. }
  1159. suggest := models.WxCheckContent(accessToken, sysUser.OpenId, req.Content)
  1160. if suggest == "risky" {
  1161. br.Msg = "文章内容含有违法违规内容"
  1162. br.ErrMsg = "文章内容含有违法违规内容"
  1163. return
  1164. }
  1165. if len(req.ImgUrl) > 0 {
  1166. //for _, imgUrl := range req.ImgUrl {
  1167. // imgBody, err := http.Get(imgUrl)
  1168. // if err != nil {
  1169. // br.Msg = "图片链接有误"
  1170. // br.ErrMsg = "图片链接有误"
  1171. // return
  1172. // }
  1173. // rnStr := utils.GetRandStringNoSpecialChar(5)
  1174. // savePath := time.Now().Format(utils.FormatDateTimeUnSpace) + rnStr + ".jpg"
  1175. // err = file.SaveFile(imgBody, savePath)
  1176. // if err != nil {
  1177. // br.Msg = "保存图片错误"
  1178. // br.ErrMsg = "保存图片错误"
  1179. // return
  1180. // }
  1181. // res, err := weapp.IMGSecCheck(itemToken.AccessToken, savePath)
  1182. // if err != nil {
  1183. // // 处理一般错误信息
  1184. // br.Msg = "图片内容含有违法违规内容"
  1185. // br.ErrMsg = "图片内容含有违法违规内容"
  1186. // return
  1187. // }
  1188. // if err := res.GetResponseError(); err != nil {
  1189. // // 处理微信返回错误信息
  1190. // br.Msg = "GetResponseError Err:" + err.Error()
  1191. // return
  1192. // }
  1193. // err = os.RemoveAll(savePath)
  1194. // if err != nil {
  1195. // br.Msg = "RemoveAll Err:" + err.Error()
  1196. // return
  1197. // }
  1198. //}
  1199. }
  1200. br.Ret = 200
  1201. br.Success = true
  1202. br.Msg = "校验成功"
  1203. }