yanxuan_special.go 32 KB

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