yanxuan_special.go 36 KB

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