yanxuan_special.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  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. "strings"
  9. "time"
  10. )
  11. type YanxuanSpecialController struct {
  12. BaseAuthController
  13. }
  14. // @Title 专栏列表
  15. // @Description 专栏列表
  16. // @Param UserId query int true "用户ID"
  17. // @Param PageSize query int true "每页数据条数"
  18. // @Param CurrentIndex query int true "当前页页码,从1开始"
  19. // @Success 200 {object} models.SpecialListResp
  20. // @router /list [get]
  21. func (this *YanxuanSpecialController) List() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. sysUser := this.User
  28. if sysUser == nil {
  29. br.Msg = "请登录"
  30. br.ErrMsg = "请登录,SysUser Is Empty"
  31. br.Ret = 408
  32. return
  33. }
  34. userId, _ := this.GetInt("UserId", 0)
  35. pageSize, _ := this.GetInt("PageSize")
  36. currentIndex, _ := this.GetInt("CurrentIndex")
  37. var startSize int
  38. if pageSize <= 0 {
  39. pageSize = utils.PageSize20
  40. }
  41. if currentIndex <= 0 {
  42. currentIndex = 1
  43. }
  44. startSize = utils.StartIndex(currentIndex, pageSize)
  45. resp := new(models.SpecialListResp)
  46. var condition string
  47. var pars []interface{}
  48. if userId > 0 {
  49. condition += ` AND a.user_id = ? `
  50. pars = append(pars, userId)
  51. }
  52. condition += ` AND a.status = 3 `
  53. total, err := models.GetCygxYanxuanSpecialCount(condition, pars)
  54. if err != nil {
  55. br.Msg = "获取失败"
  56. br.ErrMsg = "获取失败, Err:" + err.Error()
  57. return
  58. }
  59. list, err := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, startSize, pageSize)
  60. if err != nil {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "获取失败, Err:" + err.Error()
  63. return
  64. }
  65. for _, v := range list {
  66. hasImg, err := utils.ArticleHasImgUrl(v.Content)
  67. if err != nil {
  68. return
  69. }
  70. if hasImg {
  71. v.ContentHasImg = 1
  72. }
  73. v.Content = utils.ArticleRemoveImgUrl(v.Content)
  74. //v.Content, err = utils.ExtractText(v.Content)
  75. //if err != nil {
  76. // return
  77. //}
  78. //v.Content, _ = services.GetReportContentTextSubNew(v.Content)
  79. v.Content = services.AnnotationHtml(v.Content)
  80. if v.DocUrl != "" {
  81. var docs []models.Doc
  82. err := json.Unmarshal([]byte(v.DocUrl), &docs)
  83. if err != nil {
  84. br.Msg = "参数解析异常!"
  85. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  86. return
  87. }
  88. v.Docs = docs
  89. }
  90. if v.MyCollectNum > 0 {
  91. v.IsCollect = 1
  92. }
  93. if v.CompanyTags != "" {
  94. v.Tags += v.CompanyTags
  95. }
  96. if v.IndustryTags != "" {
  97. if v.Tags != "" {
  98. v.Tags += ","
  99. }
  100. v.Tags += v.IndustryTags
  101. }
  102. }
  103. isAuthor, isImproveInformation := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
  104. resp.IsAuthor = isAuthor
  105. resp.IsImproveInformation = isImproveInformation
  106. resp.List = list
  107. page := paging.GetPaging(currentIndex, pageSize, total)
  108. resp.Paging = page
  109. br.Data = resp
  110. br.Ret = 200
  111. br.Success = true
  112. br.Msg = "获取成功"
  113. }
  114. // @Title 专栏详情
  115. // @Description 专栏详情
  116. // @Param IsSendWx query int false "是否是通过微信模版进来的 1是,其它否"
  117. // @Param Id query int true "详情ID"
  118. // @Success 200 {object} models.AddEnglishReportResp
  119. // @router /detail [get]
  120. func (this *YanxuanSpecialController) Detail() {
  121. br := new(models.BaseResponse).Init()
  122. defer func() {
  123. this.Data["json"] = br
  124. this.ServeJSON()
  125. }()
  126. sysUser := this.User
  127. if sysUser == nil {
  128. br.Msg = "请登录"
  129. br.ErrMsg = "请登录,SysUser Is Empty"
  130. br.Ret = 408
  131. return
  132. }
  133. specialId, _ := this.GetInt("Id", 0)
  134. isSendWx, _ := this.GetInt("IsSendWx", 0)
  135. if specialId <= 0 {
  136. br.Msg = "参数错误"
  137. br.ErrMsg = "参数错误"
  138. return
  139. }
  140. item, tmpErr := models.GetYanxuanSpecialById(specialId, sysUser.UserId)
  141. if tmpErr != nil {
  142. br.Msg = "获取失败"
  143. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  144. return
  145. }
  146. if item.MyCollectNum > 0 {
  147. item.IsCollect = 1
  148. }
  149. var resp models.CygxYanxuanSpecialResp
  150. resp.HasPermission = 1
  151. resp.CygxYanxuanSpecialItem = *item
  152. if item.DocUrl != "" {
  153. var docs []models.Doc
  154. err := json.Unmarshal([]byte(item.DocUrl), &docs)
  155. if err != nil {
  156. br.Msg = "参数解析异常!"
  157. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  158. return
  159. }
  160. resp.Docs = docs
  161. }
  162. if item.CompanyTags != "" {
  163. resp.Tags += item.CompanyTags
  164. resp.CompanyTags = append(resp.CompanyTags, item.CompanyTags)
  165. }
  166. if item.IndustryTags != "" {
  167. if resp.Tags != "" {
  168. resp.Tags += ","
  169. }
  170. resp.Tags += item.IndustryTags
  171. resp.IndustryTags = append(resp.IndustryTags, item.IndustryTags)
  172. }
  173. //如果状态未审核通过,而且查看的不是本人,不是审核人员,就无法查看详情
  174. var configCode string
  175. configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
  176. cnf, err := models.GetConfigByCode(configCode)
  177. if err != nil {
  178. br.Msg = "获取失败"
  179. br.ErrMsg = "获取失败, Err:" + err.Error()
  180. return
  181. }
  182. if isSendWx == 1 && strings.Contains(cnf.ConfigValue, sysUser.Mobile) {
  183. resp.IsShowExamine = true
  184. resp.ExamineStatus = item.Status
  185. }
  186. resp.ExamineStatus = item.Status
  187. if item.UserId != sysUser.UserId && item.Status != 3 && !strings.Contains(cnf.ConfigValue, sysUser.Mobile) {
  188. resp.CygxYanxuanSpecialItem = *new(models.CygxYanxuanSpecialItem) // 如果内容不可见,就把内容置空
  189. resp.HasPermission = 2
  190. }
  191. go services.AddSpecialRecord(this.User, specialId)
  192. br.Data = resp
  193. br.Ret = 200
  194. br.Success = true
  195. br.Msg = "获取成功"
  196. }
  197. // @Title 新增保存专栏作者详情
  198. // @Description 新增保存专栏作者详情
  199. // @Param request body help_doc.AddHelpDocReq true "type json string"
  200. // @Success 200 {object} models.AddEnglishReportResp
  201. // @router /author/save [post]
  202. func (this *YanxuanSpecialController) AuthorSave() {
  203. br := new(models.BaseResponse).Init()
  204. defer func() {
  205. this.Data["json"] = br
  206. this.ServeJSON()
  207. }()
  208. sysUser := this.User
  209. if sysUser == nil {
  210. br.Msg = "请登录"
  211. br.ErrMsg = "请登录,SysUser Is Empty"
  212. br.Ret = 408
  213. return
  214. }
  215. var req models.SaveCygxYanxuanSpecialAuthorReq
  216. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  217. if err != nil {
  218. br.Msg = "参数解析异常!"
  219. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  220. return
  221. }
  222. if req.UserId <= 0 {
  223. br.Msg = "用户id有误"
  224. return
  225. }
  226. if req.SpecialName == "" {
  227. br.Msg = "请输入专栏名称"
  228. return
  229. }
  230. if req.NickName == "" {
  231. br.Msg = "请输入昵称"
  232. return
  233. }
  234. item := models.CygxYanxuanSpecialAuthor{
  235. UserId: req.UserId,
  236. SpecialName: req.SpecialName,
  237. Introduction: req.Introduction,
  238. Label: req.Label,
  239. NickName: req.NickName,
  240. CreateTime: time.Now(),
  241. ModifyTime: time.Now(),
  242. BgImg: "",
  243. Status: 1,
  244. }
  245. //if req.Id == 0{
  246. // _, err = models.AddCygxYanxuanSpecialAuthor(&item)
  247. // if err != nil {
  248. // br.Msg = "新增失败"
  249. // br.ErrMsg = "新增失败,Err:" + err.Error()
  250. // return
  251. // }
  252. //} else {
  253. // err = models.UpdateYanxuanSpecialAuthor(&item)
  254. // if err != nil {
  255. // br.Msg = "保存失败"
  256. // br.ErrMsg = "保存失败,Err:" + err.Error()
  257. // return
  258. // }
  259. //}
  260. err = models.UpdateYanxuanSpecialAuthor(&item)
  261. if err != nil {
  262. br.Msg = "保存失败"
  263. br.ErrMsg = "保存失败,Err:" + err.Error()
  264. return
  265. }
  266. br.Ret = 200
  267. br.Success = true
  268. br.Msg = "保存成功"
  269. }
  270. // @Title 新增保存专栏
  271. // @Description 新增保存专栏
  272. // @Param request body help_doc.AddHelpDocReq true "type json string"
  273. // @Success 200 {object} models.AddEnglishReportResp
  274. // @router /save [post]
  275. func (this *YanxuanSpecialController) Save() {
  276. br := new(models.BaseResponse).Init()
  277. defer func() {
  278. this.Data["json"] = br
  279. this.ServeJSON()
  280. }()
  281. sysUser := this.User
  282. if sysUser == nil {
  283. br.Msg = "请登录"
  284. br.ErrMsg = "请登录,SysUser Is Empty"
  285. br.Ret = 408
  286. return
  287. }
  288. var req models.CygxYanxuanSpecialReq
  289. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  290. if err != nil {
  291. br.Msg = "参数解析异常!"
  292. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  293. return
  294. }
  295. if req.Content == "" && req.DoType == 2 {
  296. br.Msg = "请输入内容"
  297. return
  298. }
  299. if req.CompanyTags == "" && req.IndustryTags == "" && req.DoType == 2 {
  300. br.Msg = "请至少输入一个标签"
  301. return
  302. }
  303. item := models.CygxYanxuanSpecial{
  304. Id: req.Id,
  305. UserId: sysUser.UserId,
  306. CreateTime: time.Now(),
  307. ModifyTime: time.Now(),
  308. PublishTime: time.Now(),
  309. Content: req.Content,
  310. ImgUrl: req.ImgUrl,
  311. DocUrl: req.DocUrl,
  312. Title: req.Title,
  313. Type: req.Type,
  314. CompanyTags: req.CompanyTags,
  315. IndustryTags: req.IndustryTags,
  316. }
  317. if req.DoType == 1 {
  318. item.Status = 1
  319. } else {
  320. item.Status = 2
  321. }
  322. specialId := 0
  323. if req.Id == 0 {
  324. id, err := models.AddCygxYanxuanSpecial(&item)
  325. if err != nil {
  326. br.Msg = "新增失败"
  327. br.ErrMsg = "新增失败,Err:" + err.Error()
  328. return
  329. }
  330. specialId = int(id)
  331. } else {
  332. err = models.UpdateYanxuanSpecial(&item)
  333. if err != nil {
  334. br.Msg = "保存失败"
  335. br.ErrMsg = "保存失败,Err:" + err.Error()
  336. return
  337. }
  338. specialId = req.Id
  339. }
  340. if req.DoType == 2 {
  341. go services.SendReviewTemplateMsgAdmin(specialId)
  342. go services.UpdateYanxuanSpecialResourceData(specialId) // 写入首页最新 cygx_resource_data 表
  343. go services.EsAddYanxuanSpecial(specialId) // 写入es 综合搜索
  344. }
  345. br.Ret = 200
  346. br.Success = true
  347. br.Msg = "保存成功"
  348. }
  349. // @Title 专栏作者详情
  350. // @Description 专栏作者详情
  351. // @Param request body help_doc.AddHelpDocReq true "type json string"
  352. // @Success 200 {object} models.AddEnglishReportResp
  353. // @router /author/detail [get]
  354. func (this *YanxuanSpecialController) AuthorDetail() {
  355. br := new(models.BaseResponse).Init()
  356. defer func() {
  357. this.Data["json"] = br
  358. this.ServeJSON()
  359. }()
  360. sysUser := this.User
  361. if sysUser == nil {
  362. br.Msg = "请登录"
  363. br.ErrMsg = "请登录,SysUser Is Empty"
  364. br.Ret = 408
  365. return
  366. }
  367. userId, _ := this.GetInt("UserId", 0)
  368. if userId == 0 {
  369. userId = sysUser.UserId
  370. }
  371. item, tmpErr := models.GetYanxuanSpecialAuthor(userId, sysUser.UserId, "")
  372. if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
  373. br.Msg = "获取失败"
  374. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  375. return
  376. }
  377. br.Data = item
  378. br.Ret = 200
  379. br.Success = true
  380. br.Msg = "获取成功"
  381. }
  382. // @Title 审批研选专栏
  383. // @Description 审批研选专栏
  384. // @Param request body help_doc.AddHelpDocReq true "type json string"
  385. // @Success 200 {object} models.AddEnglishReportResp
  386. // @router /enable [post]
  387. func (this *YanxuanSpecialController) Enable() {
  388. br := new(models.BaseResponse).Init()
  389. defer func() {
  390. this.Data["json"] = br
  391. this.ServeJSON()
  392. }()
  393. sysUser := this.User
  394. if sysUser == nil {
  395. br.Msg = "请登录"
  396. br.ErrMsg = "请登录,SysUser Is Empty"
  397. br.Ret = 408
  398. return
  399. }
  400. var req models.EnableCygxYanxuanSpecialReq
  401. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  402. if err != nil {
  403. br.Msg = "参数解析异常!"
  404. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  405. return
  406. }
  407. if req.Id <= 0 {
  408. br.Msg = "文章id错误"
  409. return
  410. }
  411. if req.Status <= 0 {
  412. br.Msg = "参数错误"
  413. return
  414. }
  415. status := 0
  416. if req.Status == 1 {
  417. status = 3
  418. } else {
  419. status = 4
  420. }
  421. if tmpErr := models.EnableYanxuanSpecial(req.Id, status, req.Reason); tmpErr != nil {
  422. br.Msg = "审批失败"
  423. br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
  424. return
  425. }
  426. if req.Status == 1 {
  427. go services.SendWxMsgSpecialFollow(req.Id)
  428. }
  429. go services.SendWxMsgSpecialAuthor(req.Id, req.Status)
  430. go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  431. go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  432. br.Msg = "审批成功"
  433. br.Ret = 200
  434. br.Success = true
  435. }
  436. // @Title 研选专栏收藏
  437. // @Description 研选专栏收藏
  438. // @Param request body help_doc.AddHelpDocReq true "type json string"
  439. // @Success 200 {object} models.AddEnglishReportResp
  440. // @router /collect [post]
  441. func (this *YanxuanSpecialController) Collect() {
  442. br := new(models.BaseResponse).Init()
  443. defer func() {
  444. this.Data["json"] = br
  445. this.ServeJSON()
  446. }()
  447. sysUser := this.User
  448. if sysUser == nil {
  449. br.Msg = "请登录"
  450. br.ErrMsg = "请登录,SysUser Is Empty"
  451. br.Ret = 408
  452. return
  453. }
  454. var req models.CollectCygxYanxuanSpecialReq
  455. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  456. if err != nil {
  457. br.Msg = "参数解析异常!"
  458. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  459. return
  460. }
  461. if req.Id <= 0 {
  462. br.Msg = "文章id错误"
  463. return
  464. }
  465. if req.Status <= 0 {
  466. br.Msg = "参数错误"
  467. return
  468. }
  469. var sellerName string
  470. sellerName, err = models.GetCompanySellerName(sysUser.CompanyId)
  471. if err != nil {
  472. br.Msg = "报名失败!"
  473. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  474. return
  475. }
  476. if req.Status == 1 {
  477. item := models.CygxYanxuanSpecialCollect{
  478. UserId: sysUser.UserId,
  479. Mobile: sysUser.Mobile,
  480. Email: sysUser.Email,
  481. CompanyId: sysUser.CompanyId,
  482. CompanyName: sysUser.CompanyName,
  483. RealName: sysUser.RealName,
  484. SellerName: sellerName,
  485. CreateTime: time.Now(),
  486. ModifyTime: time.Now(),
  487. RegisterPlatform: utils.REGISTER_PLATFORM,
  488. YanxuanSpecialId: req.Id,
  489. }
  490. _, err = models.AddCygxYanxuanSpecialCollect(&item)
  491. if err != nil {
  492. br.Msg = "新增失败"
  493. br.ErrMsg = "新增失败,Err:" + err.Error()
  494. return
  495. }
  496. br.Msg = "收藏成功"
  497. } else {
  498. err = models.DelCygxYanxuanSpecialCollect(sysUser.UserId, req.Id)
  499. if err != nil {
  500. br.Msg = "删除失败"
  501. br.ErrMsg = "删除失败,Err:" + err.Error()
  502. return
  503. }
  504. br.Msg = "取消收藏成功"
  505. }
  506. br.Ret = 200
  507. br.Success = true
  508. }
  509. // @Title 专栏内容中心
  510. // @Description 专栏内容中心
  511. // @Param request body help_doc.AddHelpDocReq true "type json string"
  512. // @Success 200 {object} models.AddEnglishReportResp
  513. // @router /center [get]
  514. func (this *YanxuanSpecialController) Center() {
  515. br := new(models.BaseResponse).Init()
  516. defer func() {
  517. this.Data["json"] = br
  518. this.ServeJSON()
  519. }()
  520. sysUser := this.User
  521. if sysUser == nil {
  522. br.Msg = "请登录"
  523. br.ErrMsg = "请登录,SysUser Is Empty"
  524. br.Ret = 408
  525. return
  526. }
  527. // 1:未发布,2:审核中 3:已发布 4:驳回
  528. status, _ := this.GetInt("Status", 0)
  529. if status <= 0 {
  530. br.Msg = "参数错误"
  531. br.ErrMsg = "参数错误"
  532. return
  533. }
  534. var condition string
  535. var pars []interface{}
  536. condition += ` AND a.user_id = ? `
  537. pars = append(pars, sysUser.UserId)
  538. condition += ` AND a.status = ? `
  539. pars = append(pars, status)
  540. list, tmpErr := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, 0, 0)
  541. if tmpErr != nil {
  542. br.Msg = "获取失败"
  543. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  544. return
  545. }
  546. for _, v := range list {
  547. //如果在web端有样式或者上传了文件,小程序就禁止编辑修改内容
  548. hasStyle, err := utils.ArticleHasStyle(v.Content)
  549. if err != nil {
  550. return
  551. }
  552. hasImg, err := utils.ArticleHasImgUrl(v.Content)
  553. if err != nil {
  554. return
  555. }
  556. if hasStyle || strings.Contains(v.DocUrl, "http") || hasImg {
  557. v.ContentHasStyle = true
  558. }
  559. }
  560. br.Data = list
  561. br.Ret = 200
  562. br.Success = true
  563. br.Msg = "获取成功"
  564. }
  565. // @Title 专栏点击记录
  566. // @Description 专栏点击记录
  567. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  568. // @router /record [post]
  569. func (this *YanxuanSpecialController) Record() {
  570. br := new(models.BaseResponse).Init()
  571. defer func() {
  572. this.Data["json"] = br
  573. this.ServeJSON()
  574. }()
  575. user := this.User
  576. if user == nil {
  577. br.Msg = "请重新登录"
  578. br.Ret = 408
  579. return
  580. }
  581. var req models.AddCygxYanxuanSpecialRecordReq
  582. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  583. if err != nil {
  584. br.Msg = "参数解析异常!"
  585. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  586. return
  587. }
  588. if req.SpecialId <= 0 {
  589. br.Msg = "文章不存在"
  590. br.ErrMsg = "文章不存在,文章ID错误"
  591. return
  592. }
  593. var sellerName string
  594. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  595. if err != nil {
  596. br.Msg = "报名失败!"
  597. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  598. return
  599. }
  600. item := models.CygxYanxuanSpecialRecord{
  601. UserId: user.UserId,
  602. Mobile: user.Mobile,
  603. Email: user.Email,
  604. CompanyId: user.CompanyId,
  605. CompanyName: user.CompanyName,
  606. RealName: user.RealName,
  607. SellerName: sellerName,
  608. CreateTime: time.Now(),
  609. ModifyTime: time.Now(),
  610. RegisterPlatform: utils.REGISTER_PLATFORM,
  611. YanxuanSpecialId: req.SpecialId,
  612. }
  613. _, err = models.AddCygxYanxuanSpecialRecord(&item)
  614. if err != nil {
  615. br.Msg = "记录失败"
  616. br.ErrMsg = "记录失败,Err:" + err.Error()
  617. return
  618. }
  619. br.Ret = 200
  620. br.Success = true
  621. br.Msg = "记录成功"
  622. }
  623. // @Title 研选专栏关注
  624. // @Description 研选专栏关注
  625. // @Param request body help_doc.AddHelpDocReq true "type json string"
  626. // @Success 200 {object} models.AddEnglishReportResp
  627. // @router /follow [post]
  628. func (this *YanxuanSpecialController) Follow() {
  629. br := new(models.BaseResponse).Init()
  630. defer func() {
  631. this.Data["json"] = br
  632. this.ServeJSON()
  633. }()
  634. sysUser := this.User
  635. if sysUser == nil {
  636. br.Msg = "请登录"
  637. br.ErrMsg = "请登录,SysUser Is Empty"
  638. br.Ret = 408
  639. return
  640. }
  641. var req models.FollowCygxYanxuanSpecialReq
  642. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  643. if err != nil {
  644. br.Msg = "参数解析异常!"
  645. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  646. return
  647. }
  648. if req.FollowUserId <= 0 {
  649. br.Msg = "被关注的用户id"
  650. return
  651. }
  652. if req.Status <= 0 {
  653. br.Msg = "参数错误"
  654. return
  655. }
  656. var sellerName string
  657. sellerName, err = models.GetCompanySellerName(sysUser.CompanyId)
  658. if err != nil {
  659. br.Msg = "报名失败!"
  660. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  661. return
  662. }
  663. if req.Status == 1 {
  664. item := models.CygxYanxuanSpecialFollow{
  665. UserId: sysUser.UserId,
  666. FollowUserId: req.FollowUserId,
  667. Mobile: sysUser.Mobile,
  668. Email: sysUser.Email,
  669. CompanyId: sysUser.CompanyId,
  670. CompanyName: sysUser.CompanyName,
  671. RealName: sysUser.RealName,
  672. SellerName: sellerName,
  673. CreateTime: time.Now(),
  674. ModifyTime: time.Now(),
  675. RegisterPlatform: utils.REGISTER_PLATFORM,
  676. YanxuanSpecialId: req.SpecialId,
  677. }
  678. err = models.AddCygxYanxuanSpecialFollow(&item)
  679. if err != nil {
  680. br.Msg = "新增失败"
  681. br.ErrMsg = "新增失败,Err:" + err.Error()
  682. return
  683. }
  684. br.Msg = "关注成功"
  685. } else {
  686. err = models.DelCygxYanxuanSpecialFollow(sysUser.UserId, req.FollowUserId)
  687. if err != nil {
  688. br.Msg = "删除失败"
  689. br.ErrMsg = "删除失败,Err:" + err.Error()
  690. return
  691. }
  692. br.Msg = "取消关注成功"
  693. }
  694. br.Ret = 200
  695. br.Success = true
  696. }
  697. // @Title 行业标签搜索
  698. // @Description 行业标签搜索
  699. // @Param request body help_doc.AddHelpDocReq true "type json string"
  700. // @Success 200 {object} models.AddEnglishReportResp
  701. // @router /industrySearch [get]
  702. func (this *YanxuanSpecialController) IndustrySearch() {
  703. br := new(models.BaseResponse).Init()
  704. defer func() {
  705. this.Data["json"] = br
  706. this.ServeJSON()
  707. }()
  708. sysUser := this.User
  709. if sysUser == nil {
  710. br.Msg = "请登录"
  711. br.ErrMsg = "请登录,SysUser Is Empty"
  712. br.Ret = 408
  713. return
  714. }
  715. keyword := this.GetString("Keyword")
  716. list, tmpErr := models.GetYanxuanSpecialIndustry(keyword)
  717. if tmpErr != nil {
  718. br.Msg = "获取失败"
  719. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  720. return
  721. }
  722. br.Data = list
  723. br.Ret = 200
  724. br.Success = true
  725. br.Msg = "获取成功"
  726. }
  727. // @Title 公司标签搜索
  728. // @Description 公司标签搜索
  729. // @Param request body help_doc.AddHelpDocReq true "type json string"
  730. // @Success 200 {object} models.AddEnglishReportResp
  731. // @router /companySearch [get]
  732. func (this *YanxuanSpecialController) CompanySearch() {
  733. br := new(models.BaseResponse).Init()
  734. defer func() {
  735. this.Data["json"] = br
  736. this.ServeJSON()
  737. }()
  738. sysUser := this.User
  739. if sysUser == nil {
  740. br.Msg = "请登录"
  741. br.ErrMsg = "请登录,SysUser Is Empty"
  742. br.Ret = 408
  743. return
  744. }
  745. keyword := this.GetString("Keyword")
  746. if keyword == "" {
  747. br.Ret = 200
  748. return
  749. }
  750. list, tmpErr := models.GetYanxuanSpecialCompany(keyword)
  751. if tmpErr != nil {
  752. br.Msg = "获取失败"
  753. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  754. return
  755. }
  756. br.Data = list
  757. br.Ret = 200
  758. br.Success = true
  759. br.Msg = "获取成功"
  760. }
  761. // @Title 专栏取消发布
  762. // @Description 专栏取消发布
  763. // @Param request body help_doc.AddHelpDocReq true "type json string"
  764. // @Success 200 {object} models.AddEnglishReportResp
  765. // @router /cancel [post]
  766. func (this *YanxuanSpecialController) Cancel() {
  767. br := new(models.BaseResponse).Init()
  768. defer func() {
  769. this.Data["json"] = br
  770. this.ServeJSON()
  771. }()
  772. sysUser := this.User
  773. if sysUser == nil {
  774. br.Msg = "请登录"
  775. br.ErrMsg = "请登录,SysUser Is Empty"
  776. br.Ret = 408
  777. return
  778. }
  779. var req models.CancelPublishCygxYanxuanSpecialReq
  780. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  781. if err != nil {
  782. br.Msg = "参数解析异常!"
  783. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  784. return
  785. }
  786. if req.Id <= 0 {
  787. br.Msg = "文章id错误"
  788. return
  789. }
  790. if tmpErr := models.CancelPublishYanxuanSpecial(req.Id); tmpErr != nil {
  791. br.Msg = "取消发布失败"
  792. br.ErrMsg = "取消发布失败, Err:" + tmpErr.Error()
  793. return
  794. }
  795. go services.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  796. go services.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  797. br.Msg = "取消发布成功"
  798. br.Ret = 200
  799. br.Success = true
  800. }
  801. // @Title 作者列表
  802. // @Description 作者列表
  803. // @Param PageSize query int true "每页数据条数"
  804. // @Param CurrentIndex query int true "当前页页码,从1开始"
  805. // @Success 200 {object} models.AddEnglishReportResp
  806. // @router /author/list [get]
  807. func (this *YanxuanSpecialController) AuthorList() {
  808. br := new(models.BaseResponse).Init()
  809. defer func() {
  810. this.Data["json"] = br
  811. this.ServeJSON()
  812. }()
  813. sysUser := this.User
  814. if sysUser == nil {
  815. br.Msg = "请登录"
  816. br.ErrMsg = "请登录,SysUser Is Empty"
  817. br.Ret = 408
  818. return
  819. }
  820. pageSize, _ := this.GetInt("PageSize")
  821. currentIndex, _ := this.GetInt("CurrentIndex")
  822. var startSize int
  823. if pageSize <= 0 {
  824. pageSize = utils.PageSize20
  825. }
  826. if currentIndex <= 0 {
  827. currentIndex = 1
  828. }
  829. startSize = utils.StartIndex(currentIndex, pageSize)
  830. var condition string
  831. var pars []interface{}
  832. condition += ` AND a.nick_name <> '' `
  833. total, err := models.GetCygxYanxuanSpecialAuthorCount(condition, pars)
  834. if err != nil {
  835. br.Msg = "获取失败"
  836. br.ErrMsg = "获取失败,Err:" + err.Error()
  837. return
  838. }
  839. condition += ` ORDER BY latest_publish_time DESC`
  840. list, tmpErr := models.GetYanxuanSpecialAuthorList(condition, pars, startSize, pageSize)
  841. if tmpErr != nil {
  842. br.Msg = "获取失败"
  843. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  844. return
  845. }
  846. var userIds []int
  847. for _, v := range list {
  848. v.LatestPublishDate = v.LatestPublishTime.Format(utils.FormatDate) + "更新"
  849. userIds = append(userIds, v.UserId)
  850. }
  851. bestNew := services.GetBestNewYanxuanSpecialByUserId(userIds)
  852. for _, v := range list {
  853. v.YanxuanSpecialCenter = bestNew[v.UserId]
  854. }
  855. resp := new(models.SpecialAuthorListResp)
  856. isAuthor, _ := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
  857. resp.IsAuthor = isAuthor
  858. page := paging.GetPaging(currentIndex, pageSize, total)
  859. resp.List = list
  860. resp.Paging = page
  861. br.Data = resp
  862. br.Ret = 200
  863. br.Success = true
  864. br.Msg = "获取成功"
  865. }
  866. // @Title 更新作者头像
  867. // @Description 更新作者头像
  868. // @Param request body help_doc.AddHelpDocReq true "type json string"
  869. // @Success 200 {object} models.AddEnglishReportResp
  870. // @router /author/head_img [post]
  871. func (this *YanxuanSpecialController) AuthorHeadImg() {
  872. br := new(models.BaseResponse).Init()
  873. defer func() {
  874. this.Data["json"] = br
  875. this.ServeJSON()
  876. }()
  877. sysUser := this.User
  878. if sysUser == nil {
  879. br.Msg = "请登录"
  880. br.ErrMsg = "请登录,SysUser Is Empty"
  881. br.Ret = 408
  882. return
  883. }
  884. var req models.SaveCygxYanxuanSpecialAuthoHeadImgrReq
  885. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  886. if err != nil {
  887. br.Msg = "参数解析异常!"
  888. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  889. return
  890. }
  891. if req.UserId <= 0 {
  892. br.Msg = "用户id有误"
  893. return
  894. }
  895. if req.HeadImg == "" {
  896. br.Msg = "头像图片错误"
  897. return
  898. }
  899. item := models.CygxYanxuanSpecialAuthor{
  900. UserId: req.UserId,
  901. HeadImg: req.HeadImg,
  902. }
  903. err = models.UpdateYanxuanSpecialAuthorHeadImg(&item)
  904. if err != nil {
  905. br.Msg = "保存失败"
  906. br.ErrMsg = "保存失败,Err:" + err.Error()
  907. return
  908. }
  909. br.Ret = 200
  910. br.Success = true
  911. br.Msg = "保存成功"
  912. }
  913. // @Title 删除专栏
  914. // @Description 删除专栏
  915. // @Param request body help_doc.AddHelpDocReq true "type json string"
  916. // @Success 200 {object} models.AddEnglishReportResp
  917. // @router /del [post]
  918. func (this *YanxuanSpecialController) Delete() {
  919. br := new(models.BaseResponse).Init()
  920. defer func() {
  921. this.Data["json"] = br
  922. this.ServeJSON()
  923. }()
  924. sysUser := this.User
  925. if sysUser == nil {
  926. br.Msg = "请登录"
  927. br.ErrMsg = "请登录,SysUser Is Empty"
  928. br.Ret = 408
  929. return
  930. }
  931. var req models.EnableCygxYanxuanSpecialReq
  932. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  933. if err != nil {
  934. br.Msg = "参数解析异常!"
  935. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  936. return
  937. }
  938. if req.Id <= 0 {
  939. br.Msg = "文章id错误"
  940. return
  941. }
  942. if tmpErr := models.DelYanxuanSpecial(req.Id); tmpErr != nil {
  943. br.Msg = "删除失败"
  944. br.ErrMsg = "删除失败, Err:" + tmpErr.Error()
  945. return
  946. }
  947. br.Msg = "删除成功"
  948. br.Ret = 200
  949. br.Success = true
  950. }
  951. // @Title 专栏文章敏感词检测
  952. // @Description 专栏文章敏感词检测
  953. // @Param request body help_doc.AddHelpDocReq true "type json string"
  954. // @Success 200 {object} models.AddEnglishReportResp
  955. // @router /check [post]
  956. func (this *YanxuanSpecialController) Check() {
  957. br := new(models.BaseResponse).Init()
  958. defer func() {
  959. this.Data["json"] = br
  960. this.ServeJSON()
  961. }()
  962. sysUser := this.User
  963. if sysUser == nil {
  964. br.Msg = "请登录"
  965. br.ErrMsg = "请登录,SysUser Is Empty"
  966. br.Ret = 408
  967. return
  968. }
  969. var req models.CygxYanxuanSpecialCheckReq
  970. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  971. if err != nil {
  972. br.Msg = "参数解析异常!"
  973. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  974. return
  975. }
  976. if req.Content == "" {
  977. br.Ret = 200
  978. br.Success = true
  979. br.Msg = "校验成功"
  980. }
  981. itemToken, err := services.WxGetToken()
  982. if err != nil {
  983. br.Msg = "GetWxAccessToken Err:" + err.Error()
  984. return
  985. }
  986. if itemToken.AccessToken == "" {
  987. br.Msg = "accessToken is empty"
  988. return
  989. }
  990. suggest := models.WxCheckContent(itemToken.AccessToken, sysUser.OpenId, req.Content)
  991. if suggest == "risky" {
  992. br.Msg = "文章内容含有违法违规内容"
  993. br.ErrMsg = "文章内容含有违法违规内容"
  994. return
  995. }
  996. if len(req.ImgUrl) > 0 {
  997. //for _, imgUrl := range req.ImgUrl {
  998. // imgBody, err := http.Get(imgUrl)
  999. // if err != nil {
  1000. // br.Msg = "图片链接有误"
  1001. // br.ErrMsg = "图片链接有误"
  1002. // return
  1003. // }
  1004. // rnStr := utils.GetRandStringNoSpecialChar(5)
  1005. // savePath := time.Now().Format(utils.FormatDateTimeUnSpace) + rnStr + ".jpg"
  1006. // err = file.SaveFile(imgBody, savePath)
  1007. // if err != nil {
  1008. // br.Msg = "保存图片错误"
  1009. // br.ErrMsg = "保存图片错误"
  1010. // return
  1011. // }
  1012. // res, err := weapp.IMGSecCheck(itemToken.AccessToken, savePath)
  1013. // if err != nil {
  1014. // // 处理一般错误信息
  1015. // br.Msg = "图片内容含有违法违规内容"
  1016. // br.ErrMsg = "图片内容含有违法违规内容"
  1017. // return
  1018. // }
  1019. // if err := res.GetResponseError(); err != nil {
  1020. // // 处理微信返回错误信息
  1021. // return
  1022. // }
  1023. // err = os.RemoveAll(savePath)
  1024. // if err != nil {
  1025. // return
  1026. // }
  1027. //}
  1028. }
  1029. br.Ret = 200
  1030. br.Success = true
  1031. br.Msg = "校验成功"
  1032. }