yanxuan_special.go 42 KB

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