yanxuan_special.go 38 KB

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