yanxuan_special.go 43 KB

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