yanxuan_special.go 42 KB

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