yanxuan_special.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  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. } else {
  419. if req.DoType == 2 {
  420. go services.SendReviewTemplateMsgAdmin(specialId)
  421. go services.UpdateYanxuanSpecialResourceData(specialId) // 写入首页最新 cygx_resource_data 表
  422. go services.EsAddYanxuanSpecial(specialId) // 写入es 综合搜索
  423. }
  424. }
  425. br.Ret = 200
  426. br.Success = true
  427. br.Msg = "保存成功"
  428. }
  429. // @Title 专栏作者详情
  430. // @Description 专栏作者详情
  431. // @Param request body help_doc.AddHelpDocReq true "type json string"
  432. // @Success 200 {object} models.AddEnglishReportResp
  433. // @router /author/detail [get]
  434. func (this *YanxuanSpecialController) AuthorDetail() {
  435. br := new(models.BaseResponse).Init()
  436. defer func() {
  437. this.Data["json"] = br
  438. this.ServeJSON()
  439. }()
  440. sysUser := this.User
  441. if sysUser == nil {
  442. br.Msg = "请登录"
  443. br.ErrMsg = "请登录,SysUser Is Empty"
  444. br.Ret = 408
  445. return
  446. }
  447. userId, _ := this.GetInt("UserId", 0)
  448. if userId == 0 {
  449. userId = sysUser.UserId
  450. }
  451. item, tmpErr := models.GetYanxuanSpecialAuthor(userId, sysUser.UserId, "")
  452. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  453. br.Msg = "获取失败"
  454. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  455. return
  456. }
  457. if item.IsFollow > 0 {
  458. item.IsFollow = 1
  459. }
  460. br.Data = item
  461. br.Ret = 200
  462. br.Success = true
  463. br.Msg = "获取成功"
  464. }
  465. // @Title 审批研选专栏
  466. // @Description 审批研选专栏
  467. // @Param request body help_doc.AddHelpDocReq true "type json string"
  468. // @Success 200 {object} models.AddEnglishReportResp
  469. // @router /enable [post]
  470. func (this *YanxuanSpecialController) Enable() {
  471. br := new(models.BaseResponse).Init()
  472. defer func() {
  473. this.Data["json"] = br
  474. this.ServeJSON()
  475. }()
  476. user := this.User
  477. if user == nil {
  478. br.Msg = "请登录"
  479. br.ErrMsg = "请登录,SysUser Is Empty"
  480. br.Ret = 408
  481. return
  482. }
  483. var req models.EnableCygxYanxuanSpecialReq
  484. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  485. if err != nil {
  486. br.Msg = "参数解析异常!"
  487. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  488. return
  489. }
  490. if req.Id <= 0 {
  491. br.Msg = "文章id错误"
  492. return
  493. }
  494. if req.Status <= 0 {
  495. br.Msg = "参数错误"
  496. return
  497. }
  498. status := 0
  499. if req.Status == 1 {
  500. status = 3
  501. } else {
  502. status = 4
  503. }
  504. detail, err := models.GetYanxuanSpecialItemById(req.Id)
  505. if err != nil {
  506. br.Msg = "审批失败"
  507. br.ErrMsg = "审批失败, Err:" + err.Error()
  508. return
  509. }
  510. if tmpErr := models.EnableYanxuanSpecial(req.Id, status, req.Reason, user.RealName); tmpErr != nil {
  511. br.Msg = "审批失败"
  512. br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
  513. return
  514. }
  515. if req.Status == 1 {
  516. go services.SendWxMsgSpecialFollow(req.Id)
  517. }
  518. go services.SendWxMsgSpecialAuthor(req.Id, req.Status)
  519. go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  520. go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  521. go services.AddAddCygxYanxuanSpecialApprovalLog(user, req.Id, req.Status, req.Reason) // 添加审核记录日志
  522. go services.UdpateYanxuanSpecialauthorArticleNum(detail.UserId) // 更新作者发布文章的数量
  523. go services.MakeYanxuanSpecialMomentsImg(req.Id) // 生成研选专栏分享到朋友圈的图片
  524. br.Msg = "审批成功"
  525. br.Ret = 200
  526. br.Success = true
  527. }
  528. // @Title 研选专栏收藏
  529. // @Description 研选专栏收藏
  530. // @Param request body help_doc.AddHelpDocReq true "type json string"
  531. // @Success 200 {object} models.AddEnglishReportResp
  532. // @router /collect [post]
  533. func (this *YanxuanSpecialController) Collect() {
  534. br := new(models.BaseResponse).Init()
  535. defer func() {
  536. this.Data["json"] = br
  537. this.ServeJSON()
  538. }()
  539. user := this.User
  540. if user == nil {
  541. br.Msg = "请登录"
  542. br.ErrMsg = "请登录,SysUser Is Empty"
  543. br.Ret = 408
  544. return
  545. }
  546. var req models.CollectCygxYanxuanSpecialReq
  547. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  548. if err != nil {
  549. br.Msg = "参数解析异常!"
  550. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  551. return
  552. }
  553. if req.Id <= 0 {
  554. br.Msg = "文章id错误"
  555. return
  556. }
  557. if req.Status <= 0 {
  558. br.Msg = "参数错误"
  559. return
  560. }
  561. var sellerName string
  562. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  563. if err != nil && err.Error() != utils.ErrNoRow() {
  564. br.Msg = "查询栏目详情失败!"
  565. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  566. return
  567. }
  568. if sellerItemQy != nil {
  569. sellerName = sellerItemQy.RealName
  570. }
  571. if req.Status == 1 {
  572. item := models.CygxYanxuanSpecialCollect{
  573. UserId: user.UserId,
  574. Mobile: user.Mobile,
  575. Email: user.Email,
  576. CompanyId: user.CompanyId,
  577. CompanyName: user.CompanyName,
  578. RealName: user.RealName,
  579. SellerName: sellerName,
  580. CreateTime: time.Now(),
  581. ModifyTime: time.Now(),
  582. RegisterPlatform: utils.REGISTER_PLATFORM,
  583. YanxuanSpecialId: req.Id,
  584. }
  585. _, err = models.AddCygxYanxuanSpecialCollect(&item)
  586. if err != nil {
  587. br.Msg = "新增失败"
  588. br.ErrMsg = "新增失败,Err:" + err.Error()
  589. return
  590. }
  591. br.Msg = "收藏成功"
  592. } else {
  593. err = models.DelCygxYanxuanSpecialCollect(user.UserId, req.Id)
  594. if err != nil {
  595. br.Msg = "删除失败"
  596. br.ErrMsg = "删除失败,Err:" + err.Error()
  597. return
  598. }
  599. br.Msg = "取消收藏成功"
  600. }
  601. go services.UdpateYanxuanSpecialCollect(req.Id)
  602. br.Ret = 200
  603. br.Success = true
  604. }
  605. // @Title 专栏内容中心
  606. // @Description 专栏内容中心
  607. // @Param request body help_doc.AddHelpDocReq true "type json string"
  608. // @Success 200 {object} models.AddEnglishReportResp
  609. // @router /center [get]
  610. func (this *YanxuanSpecialController) Center() {
  611. br := new(models.BaseResponse).Init()
  612. defer func() {
  613. this.Data["json"] = br
  614. this.ServeJSON()
  615. }()
  616. sysUser := this.User
  617. if sysUser == nil {
  618. br.Msg = "请登录"
  619. br.ErrMsg = "请登录,SysUser Is Empty"
  620. br.Ret = 408
  621. return
  622. }
  623. // 1:未发布,2:审核中 3:已发布 4:驳回
  624. status, _ := this.GetInt("Status", 0)
  625. if status <= 0 {
  626. br.Msg = "参数错误"
  627. br.ErrMsg = "参数错误"
  628. return
  629. }
  630. var condition string
  631. var pars []interface{}
  632. condition += ` AND a.user_id = ? `
  633. pars = append(pars, sysUser.UserId)
  634. condition += ` AND a.status = ? `
  635. pars = append(pars, status)
  636. list, tmpErr := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, 0, 0)
  637. if tmpErr != nil {
  638. br.Msg = "获取失败"
  639. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  640. return
  641. }
  642. for _, v := range list {
  643. //如果在web端有样式或者上传了文件,小程序就禁止编辑修改内容
  644. hasStyle, err := utils.ArticleHasStyle(v.Content)
  645. if err != nil {
  646. return
  647. }
  648. hasImg, err := utils.ArticleHasImgUrl(v.Content)
  649. if err != nil {
  650. return
  651. }
  652. if hasStyle || strings.Contains(v.DocUrl, "http") || hasImg {
  653. v.ContentHasStyle = true
  654. }
  655. }
  656. br.Data = list
  657. br.Ret = 200
  658. br.Success = true
  659. br.Msg = "获取成功"
  660. }
  661. // @Title 专栏点击记录
  662. // @Description 专栏点击记录
  663. // @Param request body models.AddCygxYanxuanSpecialRecordReq true "type json string"
  664. // @router /record [post]
  665. func (this *YanxuanSpecialController) Record() {
  666. br := new(models.BaseResponse).Init()
  667. defer func() {
  668. this.Data["json"] = br
  669. this.ServeJSON()
  670. }()
  671. user := this.User
  672. if user == nil {
  673. br.Msg = "请重新登录"
  674. br.Ret = 408
  675. return
  676. }
  677. var req models.AddCygxYanxuanSpecialRecordReq
  678. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  679. if err != nil {
  680. br.Msg = "参数解析异常!"
  681. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  682. return
  683. }
  684. specialId := req.SpecialId
  685. stopTime := req.StopTime
  686. if req.SpecialId <= 0 {
  687. br.Msg = "文章不存在"
  688. br.ErrMsg = "文章不存在,文章ID错误"
  689. return
  690. }
  691. err = services.AddSpecialRecord(this.User, specialId, stopTime)
  692. if err != nil {
  693. br.Msg = "记录失败"
  694. br.ErrMsg = "记录失败,Err:" + err.Error()
  695. return
  696. }
  697. br.Ret = 200
  698. br.Success = true
  699. br.Msg = "记录成功"
  700. }
  701. // @Title 研选专栏关注
  702. // @Description 研选专栏关注
  703. // @Param request body help_doc.AddHelpDocReq true "type json string"
  704. // @Success 200 {object} models.AddEnglishReportResp
  705. // @router /follow [post]
  706. func (this *YanxuanSpecialController) Follow() {
  707. br := new(models.BaseResponse).Init()
  708. defer func() {
  709. this.Data["json"] = br
  710. this.ServeJSON()
  711. }()
  712. user := this.User
  713. if user == nil {
  714. br.Msg = "请登录"
  715. br.ErrMsg = "请登录,SysUser Is Empty"
  716. br.Ret = 408
  717. return
  718. }
  719. var req models.FollowCygxYanxuanSpecialReq
  720. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  721. if err != nil {
  722. br.Msg = "参数解析异常!"
  723. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  724. return
  725. }
  726. if req.FollowUserId <= 0 {
  727. br.Msg = "被关注的用户id"
  728. return
  729. }
  730. if req.Status <= 0 {
  731. br.Msg = "参数错误"
  732. return
  733. }
  734. var sellerName string
  735. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  736. if err != nil && err.Error() != utils.ErrNoRow() {
  737. br.Msg = "查询栏目详情失败!"
  738. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  739. return
  740. }
  741. if sellerItemQy != nil {
  742. sellerName = sellerItemQy.RealName
  743. }
  744. if req.Status == 1 {
  745. followCount, err := models.GetCygxYanxuanSpecialFollowCountByUser(user.UserId, req.FollowUserId)
  746. if err != nil {
  747. br.Msg = "获取失败"
  748. br.ErrMsg = "获取失败, Err:" + err.Error()
  749. return
  750. }
  751. if followCount == 0 {
  752. item := models.CygxYanxuanSpecialFollow{
  753. UserId: user.UserId,
  754. FollowUserId: req.FollowUserId,
  755. Mobile: user.Mobile,
  756. Email: user.Email,
  757. CompanyId: user.CompanyId,
  758. CompanyName: user.CompanyName,
  759. RealName: user.RealName,
  760. SellerName: sellerName,
  761. CreateTime: time.Now(),
  762. ModifyTime: time.Now(),
  763. RegisterPlatform: utils.REGISTER_PLATFORM,
  764. YanxuanSpecialId: req.SpecialId,
  765. }
  766. err = models.AddCygxYanxuanSpecialFollow(&item)
  767. if err != nil {
  768. br.Msg = "新增失败"
  769. br.ErrMsg = "新增失败,Err:" + err.Error()
  770. return
  771. }
  772. }
  773. br.Msg = "关注成功"
  774. } else {
  775. err = models.DelCygxYanxuanSpecialFollow(user.UserId, req.FollowUserId)
  776. if err != nil {
  777. br.Msg = "删除失败"
  778. br.ErrMsg = "删除失败,Err:" + err.Error()
  779. return
  780. }
  781. br.Msg = "取消关注成功"
  782. }
  783. go services.UdpateYanxuanSpecialFansNum(req.FollowUserId)
  784. br.Ret = 200
  785. br.Success = true
  786. }
  787. // @Title 行业标签搜索
  788. // @Description 行业标签搜索
  789. // @Param request body help_doc.AddHelpDocReq true "type json string"
  790. // @Success 200 {object} models.AddEnglishReportResp
  791. // @router /industrySearch [get]
  792. func (this *YanxuanSpecialController) IndustrySearch() {
  793. br := new(models.BaseResponse).Init()
  794. defer func() {
  795. this.Data["json"] = br
  796. this.ServeJSON()
  797. }()
  798. sysUser := this.User
  799. if sysUser == nil {
  800. br.Msg = "请登录"
  801. br.ErrMsg = "请登录,SysUser Is Empty"
  802. br.Ret = 408
  803. return
  804. }
  805. keyword := this.GetString("Keyword")
  806. list, tmpErr := models.GetYanxuanSpecialIndustry(keyword)
  807. if tmpErr != nil {
  808. br.Msg = "获取失败"
  809. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  810. return
  811. }
  812. br.Data = list
  813. br.Ret = 200
  814. br.Success = true
  815. br.Msg = "获取成功"
  816. }
  817. // @Title 公司标签搜索
  818. // @Description 公司标签搜索
  819. // @Param request body help_doc.AddHelpDocReq true "type json string"
  820. // @Success 200 {object} models.AddEnglishReportResp
  821. // @router /companySearch [get]
  822. func (this *YanxuanSpecialController) CompanySearch() {
  823. br := new(models.BaseResponse).Init()
  824. defer func() {
  825. this.Data["json"] = br
  826. this.ServeJSON()
  827. }()
  828. sysUser := this.User
  829. if sysUser == nil {
  830. br.Msg = "请登录"
  831. br.ErrMsg = "请登录,SysUser Is Empty"
  832. br.Ret = 408
  833. return
  834. }
  835. keyword := this.GetString("Keyword")
  836. if keyword == "" {
  837. br.Ret = 200
  838. return
  839. }
  840. list, tmpErr := models.GetYanxuanSpecialCompany(keyword)
  841. if tmpErr != nil {
  842. br.Msg = "获取失败"
  843. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  844. return
  845. }
  846. br.Data = list
  847. br.Ret = 200
  848. br.Success = true
  849. br.Msg = "获取成功"
  850. }
  851. // @Title 专栏取消发布
  852. // @Description 专栏取消发布
  853. // @Param request body help_doc.AddHelpDocReq true "type json string"
  854. // @Success 200 {object} models.AddEnglishReportResp
  855. // @router /cancel [post]
  856. func (this *YanxuanSpecialController) Cancel() {
  857. br := new(models.BaseResponse).Init()
  858. defer func() {
  859. this.Data["json"] = br
  860. this.ServeJSON()
  861. }()
  862. sysUser := this.User
  863. if sysUser == nil {
  864. br.Msg = "请登录"
  865. br.ErrMsg = "请登录,SysUser Is Empty"
  866. br.Ret = 408
  867. return
  868. }
  869. var req models.CancelPublishCygxYanxuanSpecialReq
  870. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  871. if err != nil {
  872. br.Msg = "参数解析异常!"
  873. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  874. return
  875. }
  876. if req.Id <= 0 {
  877. br.Msg = "文章id错误"
  878. return
  879. }
  880. specialItem, err := models.GetYanxuanSpecialItemById(req.Id)
  881. if err != nil {
  882. br.Msg = "专栏取消发布失败"
  883. br.ErrMsg = "专栏取消发布失败,Err:" + err.Error()
  884. return
  885. }
  886. if tmpErr := models.CancelPublishYanxuanSpecial(req.Id); tmpErr != nil {
  887. br.Msg = "取消发布失败"
  888. br.ErrMsg = "取消发布失败, Err:" + tmpErr.Error()
  889. return
  890. }
  891. go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  892. go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  893. go services.UdpateYanxuanSpecialauthorArticleNum(specialItem.UserId) // 更新作者发布文章的数量
  894. br.Msg = "取消发布成功"
  895. br.Ret = 200
  896. br.Success = true
  897. }
  898. // @Title 作者列表
  899. // @Description 作者列表
  900. // @Param PageSize query int true "每页数据条数"
  901. // @Param CurrentIndex query int true "当前页页码,从1开始"
  902. // @Success 200 {object} models.AddEnglishReportResp
  903. // @router /author/list [get]
  904. func (this *YanxuanSpecialController) AuthorList() {
  905. br := new(models.BaseResponse).Init()
  906. defer func() {
  907. this.Data["json"] = br
  908. this.ServeJSON()
  909. }()
  910. sysUser := this.User
  911. if sysUser == nil {
  912. br.Msg = "请登录"
  913. br.ErrMsg = "请登录,SysUser Is Empty"
  914. br.Ret = 408
  915. return
  916. }
  917. pageSize, _ := this.GetInt("PageSize")
  918. currentIndex, _ := this.GetInt("CurrentIndex")
  919. var startSize int
  920. if pageSize <= 0 {
  921. pageSize = utils.PageSize20
  922. }
  923. if currentIndex <= 0 {
  924. currentIndex = 1
  925. }
  926. startSize = utils.StartIndex(currentIndex, pageSize)
  927. var condition string
  928. var pars []interface{}
  929. condition += ` AND a.nick_name <> '' `
  930. total, err := models.GetCygxYanxuanSpecialAuthorCount(condition, pars)
  931. if err != nil {
  932. br.Msg = "获取失败"
  933. br.ErrMsg = "获取失败,Err:" + err.Error()
  934. return
  935. }
  936. condition += ` ORDER BY latest_publish_time DESC`
  937. list, tmpErr := models.GetYanxuanSpecialAuthorList(condition, pars, startSize, pageSize)
  938. if tmpErr != nil {
  939. br.Msg = "获取失败"
  940. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  941. return
  942. }
  943. var userIds []int
  944. for _, v := range list {
  945. v.LatestPublishDate = v.LatestPublishTime.Format(utils.FormatDate) + "更新"
  946. userIds = append(userIds, v.UserId)
  947. }
  948. bestNew := services.GetBestNewYanxuanSpecialByUserId(userIds)
  949. for _, v := range list {
  950. v.YanxuanSpecialCenter = bestNew[v.UserId]
  951. }
  952. resp := new(models.SpecialAuthorListResp)
  953. isAuthor, _ := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
  954. resp.IsAuthor = isAuthor
  955. page := paging.GetPaging(currentIndex, pageSize, total)
  956. resp.List = list
  957. resp.Paging = page
  958. br.Data = resp
  959. br.Ret = 200
  960. br.Success = true
  961. br.Msg = "获取成功"
  962. }
  963. // @Title 更新作者头像
  964. // @Description 更新作者头像
  965. // @Param request body help_doc.AddHelpDocReq true "type json string"
  966. // @Success 200 {object} models.AddEnglishReportResp
  967. // @router /author/head_img [post]
  968. func (this *YanxuanSpecialController) AuthorHeadImg() {
  969. br := new(models.BaseResponse).Init()
  970. defer func() {
  971. this.Data["json"] = br
  972. this.ServeJSON()
  973. }()
  974. sysUser := this.User
  975. if sysUser == nil {
  976. br.Msg = "请登录"
  977. br.ErrMsg = "请登录,SysUser Is Empty"
  978. br.Ret = 408
  979. return
  980. }
  981. var req models.SaveCygxYanxuanSpecialAuthoHeadImgrReq
  982. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  983. if err != nil {
  984. br.Msg = "参数解析异常!"
  985. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  986. return
  987. }
  988. if req.UserId <= 0 {
  989. br.Msg = "用户id有误"
  990. return
  991. }
  992. if req.HeadImg == "" {
  993. br.Msg = "头像图片错误"
  994. return
  995. }
  996. item := models.CygxYanxuanSpecialAuthor{
  997. UserId: req.UserId,
  998. HeadImg: req.HeadImg,
  999. }
  1000. err = models.UpdateYanxuanSpecialAuthorHeadImg(&item)
  1001. if err != nil {
  1002. br.Msg = "保存失败"
  1003. br.ErrMsg = "保存失败,Err:" + err.Error()
  1004. return
  1005. }
  1006. br.Ret = 200
  1007. br.Success = true
  1008. br.Msg = "保存成功"
  1009. }
  1010. // @Title 删除专栏
  1011. // @Description 删除专栏
  1012. // @Param request body help_doc.AddHelpDocReq true "type json string"
  1013. // @Success 200 {object} models.AddEnglishReportResp
  1014. // @router /del [post]
  1015. func (this *YanxuanSpecialController) Delete() {
  1016. br := new(models.BaseResponse).Init()
  1017. defer func() {
  1018. this.Data["json"] = br
  1019. this.ServeJSON()
  1020. }()
  1021. sysUser := this.User
  1022. if sysUser == nil {
  1023. br.Msg = "请登录"
  1024. br.ErrMsg = "请登录,SysUser Is Empty"
  1025. br.Ret = 408
  1026. return
  1027. }
  1028. var req models.EnableCygxYanxuanSpecialReq
  1029. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1030. if err != nil {
  1031. br.Msg = "参数解析异常!"
  1032. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1033. return
  1034. }
  1035. if req.Id <= 0 {
  1036. br.Msg = "文章id错误"
  1037. return
  1038. }
  1039. if tmpErr := models.DelYanxuanSpecial(req.Id); tmpErr != nil {
  1040. br.Msg = "删除失败"
  1041. br.ErrMsg = "删除失败, Err:" + tmpErr.Error()
  1042. return
  1043. }
  1044. br.Msg = "删除成功"
  1045. br.Ret = 200
  1046. br.Success = true
  1047. }
  1048. // @Title 专栏文章敏感词检测
  1049. // @Description 专栏文章敏感词检测
  1050. // @Param request body help_doc.AddHelpDocReq true "type json string"
  1051. // @Success 200 {object} models.AddEnglishReportResp
  1052. // @router /check [post]
  1053. func (this *YanxuanSpecialController) Check() {
  1054. br := new(models.BaseResponse).Init()
  1055. defer func() {
  1056. this.Data["json"] = br
  1057. this.ServeJSON()
  1058. }()
  1059. sysUser := this.User
  1060. if sysUser == nil {
  1061. br.Msg = "请登录"
  1062. br.ErrMsg = "请登录,SysUser Is Empty"
  1063. br.Ret = 408
  1064. return
  1065. }
  1066. var req models.CygxYanxuanSpecialCheckReq
  1067. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1068. if err != nil {
  1069. br.Msg = "参数解析异常!"
  1070. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1071. return
  1072. }
  1073. if req.Content == "" {
  1074. br.Ret = 200
  1075. br.Success = true
  1076. br.Msg = "校验成功"
  1077. }
  1078. itemToken, err := services.WxGetToken()
  1079. if err != nil {
  1080. br.Msg = "GetWxAccessToken Err:" + err.Error()
  1081. return
  1082. }
  1083. if itemToken.AccessToken == "" {
  1084. br.Msg = "accessToken is empty"
  1085. return
  1086. }
  1087. suggest := models.WxCheckContent(itemToken.AccessToken, sysUser.OpenId, req.Content)
  1088. if suggest == "risky" {
  1089. br.Msg = "文章内容含有违法违规内容"
  1090. br.ErrMsg = "文章内容含有违法违规内容"
  1091. return
  1092. }
  1093. if len(req.ImgUrl) > 0 {
  1094. //for _, imgUrl := range req.ImgUrl {
  1095. // imgBody, err := http.Get(imgUrl)
  1096. // if err != nil {
  1097. // br.Msg = "图片链接有误"
  1098. // br.ErrMsg = "图片链接有误"
  1099. // return
  1100. // }
  1101. // rnStr := utils.GetRandStringNoSpecialChar(5)
  1102. // savePath := time.Now().Format(utils.FormatDateTimeUnSpace) + rnStr + ".jpg"
  1103. // err = file.SaveFile(imgBody, savePath)
  1104. // if err != nil {
  1105. // br.Msg = "保存图片错误"
  1106. // br.ErrMsg = "保存图片错误"
  1107. // return
  1108. // }
  1109. // res, err := weapp.IMGSecCheck(itemToken.AccessToken, savePath)
  1110. // if err != nil {
  1111. // // 处理一般错误信息
  1112. // br.Msg = "图片内容含有违法违规内容"
  1113. // br.ErrMsg = "图片内容含有违法违规内容"
  1114. // return
  1115. // }
  1116. // if err := res.GetResponseError(); err != nil {
  1117. // // 处理微信返回错误信息
  1118. // return
  1119. // }
  1120. // err = os.RemoveAll(savePath)
  1121. // if err != nil {
  1122. // return
  1123. // }
  1124. //}
  1125. }
  1126. br.Ret = 200
  1127. br.Success = true
  1128. br.Msg = "校验成功"
  1129. }
  1130. // @Title 上传文章阅读时间
  1131. // @Description 上传文章阅读时间接口
  1132. // @Param request body models.AddStopTimeRep true "type json string"
  1133. // @Success 200 {object} models.ArticleDetailResp
  1134. // @router /addStopTimedel [post]
  1135. func (this *YanxuanSpecialController) AddStopTime() {
  1136. br := new(models.BaseResponse).Init()
  1137. defer func() {
  1138. this.Data["json"] = br
  1139. this.ServeJSON()
  1140. }()
  1141. user := this.User
  1142. if user == nil {
  1143. br.Msg = "请登录"
  1144. br.ErrMsg = "请登录,用户信息为空"
  1145. br.Ret = 408
  1146. return
  1147. }
  1148. var req models.AddStopTimeRep
  1149. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1150. if err != nil {
  1151. br.Msg = "参数解析异常!"
  1152. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1153. return
  1154. }
  1155. uid := user.UserId
  1156. articleId := req.ArticleId
  1157. stopTime := req.StopTime
  1158. outType := req.OutType
  1159. source := req.Source
  1160. if articleId <= 0 {
  1161. br.Msg = "参数错误"
  1162. br.ErrMsg = "参数错误"
  1163. return
  1164. }
  1165. if stopTime == 0 {
  1166. stopTime = 1
  1167. }
  1168. if outType != 2 {
  1169. outType = 1
  1170. }
  1171. if source != "PC" {
  1172. source = "MOBILE"
  1173. }
  1174. detail := new(models.ArticleDetail)
  1175. hasPermission := 0
  1176. hasFree := 0
  1177. //判断是否已经申请过
  1178. applyCount, err := models.GetApplyRecordCount(uid)
  1179. if err != nil && err.Error() != utils.ErrNoRow() {
  1180. br.Msg = "获取信息失败"
  1181. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1182. return
  1183. }
  1184. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  1185. if user.CompanyId > 1 {
  1186. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1187. if err != nil {
  1188. br.Msg = "获取信息失败"
  1189. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1190. return
  1191. }
  1192. detail, err = models.GetArticleDetailById(articleId)
  1193. if err != nil {
  1194. br.Msg = "获取信息失败"
  1195. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1196. return
  1197. }
  1198. if companyPermission == "" {
  1199. if applyCount > 0 {
  1200. hasPermission = 5
  1201. } else {
  1202. hasPermission = 2
  1203. }
  1204. hasFree = 2
  1205. goto Loop
  1206. } else {
  1207. hasFree = 1
  1208. var articlePermissionPermissionName string
  1209. if detail.CategoryId > 0 {
  1210. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  1211. if err != nil {
  1212. br.Msg = "获取信息失败"
  1213. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1214. return
  1215. }
  1216. if articlePermission == nil {
  1217. br.Msg = "获取信息失败"
  1218. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1219. return
  1220. }
  1221. articlePermissionPermissionName = articlePermission.PermissionName
  1222. } else {
  1223. articlePermissionPermissionName = detail.CategoryName
  1224. }
  1225. var hasPersion bool
  1226. slice := strings.Split(articlePermissionPermissionName, ",")
  1227. for _, v := range slice {
  1228. if strings.Contains(companyPermission, v) {
  1229. hasPersion = true
  1230. }
  1231. }
  1232. if hasPersion {
  1233. go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
  1234. } else { //无该行业权限
  1235. hasPermission = 3
  1236. }
  1237. }
  1238. } else { //潜在客户
  1239. if applyCount > 0 {
  1240. hasPermission = 5
  1241. } else {
  1242. hasPermission = 4
  1243. }
  1244. }
  1245. Loop:
  1246. resp := new(models.ArticleDetailAddStopTimeRep)
  1247. resp.HasPermission = hasPermission
  1248. resp.HasFree = hasFree
  1249. br.Ret = 200
  1250. br.Success = true
  1251. br.Msg = "操作成功"
  1252. br.Data = resp
  1253. }