yanxuan_special.go 41 KB

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