yanxuan_special.go 36 KB

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