yanxuan_special.go 36 KB

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