yanxuan_special.go 37 KB

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