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