yanxuan_special.go 35 KB

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