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