yanxuan_special.go 37 KB

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