yanxuan_special.go 35 KB

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