yanxuan_special.go 42 KB

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