yanxuan_special.go 36 KB

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