yanxuan_special.go 43 KB

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