yanxuan_special.go 36 KB

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