yanxuan_special.go 36 KB

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