article.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_web_mfyx/models"
  6. "hongze/hongze_web_mfyx/models/order"
  7. "hongze/hongze_web_mfyx/services"
  8. "hongze/hongze_web_mfyx/utils"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type ArticleController struct {
  14. BaseAuthController
  15. }
  16. type ArticleCommonController struct {
  17. BaseCommonController
  18. }
  19. type ArticleNoLoginController struct {
  20. BaseAuthMobileController
  21. }
  22. // @Title 获取报告详情
  23. // @Description 获取报告详情接口
  24. // @Param ArticleId query int true "报告ID"
  25. // @Param InviteShareCode query string false "销售账号邀请码"
  26. // @Success 200 {object} models.ArticleDetailResp
  27. // @router /detail [get]
  28. func (this *ArticleNoLoginController) Detail() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. user := this.User
  35. if user == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,用户信息为空"
  38. br.Ret = 408
  39. return
  40. }
  41. resp := new(models.ArticleDetailResp)
  42. uid := user.UserId
  43. articleId, err := this.GetInt("ArticleId")
  44. if articleId <= 0 {
  45. br.Msg = "文章不存在"
  46. br.ErrMsg = "文章不存在,文章ID错误"
  47. return
  48. }
  49. inviteShareCode := this.GetString("InviteShareCode")
  50. detail := new(models.ArticleDetail)
  51. hasPermission := 0
  52. //resp := new(models.ArticleDetailResp)
  53. detail, err = models.GetArticleDetailById(articleId)
  54. if err != nil {
  55. br.Msg = "获取信息失败"
  56. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  57. return
  58. }
  59. //记录分享来源
  60. if inviteShareCode != "" {
  61. go services.AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_ARTICLE, detail.Title, inviteShareCode, articleId)
  62. }
  63. resp.IsResearch = true
  64. havePower, err := services.GetArticleDetailUserPower(user)
  65. if err != nil {
  66. br.Msg = "获取信息失败"
  67. br.ErrMsg = "校验用户权限失败,Err:" + err.Error()
  68. return
  69. }
  70. // 判断是否属于研选类型的报告
  71. if strings.Contains(detail.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  72. resp.IsResearch = true
  73. }
  74. if havePower {
  75. detail.Body = services.GetReportContentTextArticleBody(detail.Body)
  76. hasPermission = 1
  77. go services.ArticleHistory(articleId, user)
  78. //30分钟之内阅读同一篇文章不错二次推送
  79. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  80. if !utils.Rc.IsExist(key) {
  81. go services.ArticleUserRemind(user, detail, 1)
  82. // 互动提醒
  83. go services.SendWxCategoryMsgInteractive(user, "阅读报告", articleId, detail.Title)
  84. utils.Rc.Put(key, 1, 30*time.Second)
  85. }
  86. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  87. if err != nil {
  88. br.Msg = "获取信息失败"
  89. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  90. return
  91. }
  92. detail.FollowNum = articleFollowdetail.DNum
  93. detail.CollectionNum = articleFollowdetail.AcNum
  94. if articleFollowdetail.MdNum > 0 {
  95. detail.IsFollow = true
  96. }
  97. resp.GoodsList = make([]*order.CygxGoodsResp, 0)
  98. } else {
  99. hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
  100. if err != nil && err.Error() != utils.ErrNoRow() {
  101. br.Msg = "获取信息失败"
  102. br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error()
  103. return
  104. }
  105. //权益客户对权益销售信息进行展示
  106. if hasPermission == 2 || hasPermission == 3 {
  107. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  108. if err != nil && err.Error() != utils.ErrNoRow() {
  109. br.Msg = "获取信息失败"
  110. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  111. return
  112. }
  113. if sellerItemQy != nil {
  114. detail.Seller.SellerMobile = sellerItemQy.Mobile
  115. detail.Seller.SellerName = sellerItemQy.RealName
  116. }
  117. }
  118. detail.Body = ""
  119. resp.IsShowWxPay = utils.IS_SHOW_WX_PAY //是否展示微信支付按钮
  120. resp.IsCompanyApply = services.GetUserApplyRecordCountByCompanyIdPay(user.CompanyId) //获取客户是否有过历史申请记录
  121. resp.IsNeedBusinessCard = services.GetCygxUserBusinessCardCount(user.UserId, user.CompanyId) //是否需要上传名片
  122. resp.GoodsList = services.GetUserGoodsCardList() //日卡月卡商品信息
  123. for _, v := range resp.GoodsList {
  124. resp.PopupPriceMsg += v.PopupPriceMsg //价格弹窗信息
  125. }
  126. }
  127. if detail.ArticleTypeId == 14 {
  128. detail.IsApplyAppointmentExpert = true //判断文章类型是否属于专家访谈 查研观向11.0
  129. }
  130. if detail.ArticleTypeId == 0 {
  131. detail.ChartPermissionName = utils.GU_SHOU_NAME
  132. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  133. detail.VmpAuthorization, _ = services.GetUserTokenByMobile(user.Mobile)
  134. } else {
  135. detail.ChartPermissionName = utils.CHART_PERMISSION_NAME_YANXUAN
  136. }
  137. detail.Disclaimers = utils.DISCLAIMERS
  138. detail.ShareImg = services.GetArticleShareImg(articleId)
  139. //作者头像
  140. if detail.DepartmentId > 0 {
  141. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  142. if err == nil {
  143. detail.ShareImg = departmentDetail.ImgUrl
  144. }
  145. }
  146. if user.UserId == 0 {
  147. hasPermission = 1
  148. }
  149. resp.HasPermission = hasPermission
  150. resp.IsSpecialArticle = detail.IsSpecialArticle
  151. resp.Detail = detail
  152. br.Ret = 200
  153. br.Success = true
  154. br.Msg = "获取成功"
  155. br.Data = resp
  156. }
  157. // @Title 收藏\取消收藏
  158. // @Description 收藏\取消收藏
  159. // @Param request body models.ArticleCollectReq true "type json string"
  160. // @Success 200 {object} models.ArticleCollectResp
  161. // @router /collect [post]
  162. func (this *ArticleController) ArticleCollect() {
  163. br := new(models.BaseResponse).Init()
  164. defer func() {
  165. this.Data["json"] = br
  166. this.ServeJSON()
  167. }()
  168. user := this.User
  169. if user == nil {
  170. br.Msg = "请重新登录"
  171. br.Ret = 408
  172. return
  173. }
  174. uid := user.UserId
  175. var req models.ArticleCollectReq
  176. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  177. if err != nil {
  178. br.Msg = "参数解析异常!"
  179. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  180. return
  181. }
  182. articleId := req.ArticleId
  183. detail, err := models.GetArticleDetailById(articleId)
  184. if err != nil {
  185. br.Msg = "获取信息失败"
  186. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  187. return
  188. }
  189. count, err := models.GetArticleCollectCount(uid, articleId)
  190. if err != nil {
  191. br.Msg = "获取数据失败!"
  192. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  193. return
  194. }
  195. resp := new(models.ArticleCollectResp)
  196. if count <= 0 {
  197. item := new(models.CygxArticleCollect)
  198. item.ArticleId = req.ArticleId
  199. item.UserId = uid
  200. item.CreateTime = time.Now()
  201. item.Mobile = user.Mobile
  202. item.Email = user.Email
  203. item.CompanyId = user.CompanyId
  204. item.CompanyName = user.CompanyName
  205. item.RealName = user.RealName
  206. _, err = models.AddCygxArticleCollect(item)
  207. if err != nil {
  208. br.Msg = "收藏失败"
  209. br.ErrMsg = "收藏失败,Err:" + err.Error()
  210. return
  211. }
  212. br.Msg = "收藏成功"
  213. resp.Status = 1
  214. // 文章收藏消息发送
  215. go services.ArticleUserRemind(user, detail, 1)
  216. // 互动提醒
  217. go services.SendWxCategoryMsgInteractive(user, "收藏报告", articleId, detail.Title)
  218. } else {
  219. err = models.RemoveArticleCollect(uid, articleId)
  220. if err != nil {
  221. br.Msg = "取消收藏失败"
  222. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  223. return
  224. }
  225. br.Msg = "已取消收藏"
  226. resp.Status = 2
  227. }
  228. collectTotal, err := models.GetArticleCollectUsersCount(articleId)
  229. if err != nil {
  230. br.Msg = "获取数据失败"
  231. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  232. return
  233. }
  234. resp.CollectCount = collectTotal
  235. br.Ret = 200
  236. br.Success = true
  237. br.Data = resp
  238. }
  239. // @Title 访谈申请\取消访谈申请
  240. // @Description 访谈申请\取消访谈申请
  241. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  242. // @Success 200 {object} models.FontsCollectResp
  243. // @router /interview/apply [post]
  244. func (this *ArticleController) InterviewApply() {
  245. br := new(models.BaseResponse).Init()
  246. defer func() {
  247. this.Data["json"] = br
  248. this.ServeJSON()
  249. }()
  250. user := this.User
  251. if user == nil {
  252. br.Msg = "请重新登录"
  253. br.Ret = 408
  254. return
  255. }
  256. uid := user.UserId
  257. var req models.ArticleInterviewApplyReq
  258. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  259. if err != nil {
  260. br.Msg = "参数解析异常!"
  261. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  262. return
  263. }
  264. article, err := models.GetArticleDetailById(req.ArticleId)
  265. if err != nil {
  266. br.Msg = "获取纪要失败!"
  267. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  268. return
  269. }
  270. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  271. if err != nil {
  272. br.Msg = "获取数据失败!"
  273. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  274. return
  275. }
  276. resp := new(models.ArticleInterviewApplyResp)
  277. if count <= 0 {
  278. item := new(models.CygxInterviewApply)
  279. item.ArticleId = req.ArticleId
  280. item.UserId = uid
  281. item.CompanyId = user.CompanyId
  282. item.Status = "待邀请"
  283. item.Sort = 1
  284. item.ArticleTitle = article.Title
  285. item.CreateTime = time.Now()
  286. item.ModifyTime = time.Now()
  287. item.ArticleIdMd5 = article.ArticleIdMd5
  288. _, err = models.AddCygxInterviewApply(item)
  289. if err != nil {
  290. br.Msg = "申请失败"
  291. br.ErrMsg = "申请失败,Err:" + err.Error()
  292. return
  293. }
  294. br.Msg = "申请成功"
  295. resp.Status = 1
  296. //发送模板消息
  297. if user.CompanyId > 1 {
  298. mobile := user.Mobile
  299. if mobile == "" {
  300. mobile = user.Email
  301. }
  302. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  303. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  304. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  305. if openIpItem != nil && openIpItem.OpenId != "" {
  306. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  307. }
  308. }
  309. }
  310. } else {
  311. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  312. if err != nil {
  313. br.Msg = "取消申请失败"
  314. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  315. return
  316. }
  317. br.Msg = "已取消申请"
  318. resp.Status = 2
  319. if user.CompanyId > 1 {
  320. mobile := user.Mobile
  321. if mobile == "" {
  322. mobile = user.Email
  323. }
  324. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  325. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  326. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  327. if openIpItem != nil && openIpItem.OpenId != "" {
  328. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  329. }
  330. }
  331. }
  332. }
  333. br.Ret = 200
  334. br.Success = true
  335. br.Data = resp
  336. }
  337. // @Title 文章带问
  338. // @Description 新增文章带问接口
  339. // @Param request body models.AddArticleAskRep true "type json string"
  340. // @Success Ret=200 新增成功
  341. // @router /askAdd [post]
  342. func (this *ArticleController) AskAdd() {
  343. br := new(models.BaseResponse).Init()
  344. defer func() {
  345. this.Data["json"] = br
  346. this.ServeJSON()
  347. }()
  348. user := this.User
  349. if user == nil {
  350. br.Msg = "请登录"
  351. br.ErrMsg = "请登录,SysUser Is Empty"
  352. br.Ret = 408
  353. return
  354. }
  355. var req models.AddArticleAskRep
  356. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  357. if err != nil {
  358. br.Msg = "参数解析异常!"
  359. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  360. return
  361. }
  362. if req.Content == "" {
  363. br.Msg = "建议内容不可为空"
  364. return
  365. }
  366. content := req.Content
  367. //accessToken, err := models.GetWxAccessTokenByXzs()
  368. //itemToken, err := services.WxGetToken()
  369. //if err != nil {
  370. // br.Msg = "GetWxAccessToken Err:" + err.Error()
  371. // return
  372. //}
  373. //if accessToken == "" {
  374. // br.Msg = "accessToken is empty"
  375. // return
  376. //}
  377. //commerr, err := weapp.MSGSecCheck(accessToken, content)
  378. //if err != nil {
  379. // br.Msg = "内容校验失败!"
  380. // br.ErrMsg = "内容校验失败,Err:" + err.Error()
  381. //
  382. // return
  383. //}
  384. //fmt.Println(commerr)
  385. //if commerr.ErrCode != 0 {
  386. // br.Msg = "内容违规,请重新提交!"
  387. // br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  388. // return
  389. //}
  390. articleId := req.ArticleId
  391. count, _ := models.GetArticleCountById(articleId)
  392. if count == 0 {
  393. br.Msg = "操作失败"
  394. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  395. return
  396. }
  397. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  398. if err != nil {
  399. br.Msg = "提交失败!"
  400. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  401. return
  402. }
  403. if companyDetail == nil {
  404. br.Msg = "提交失败!"
  405. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  406. return
  407. }
  408. item := new(models.CygxArticleAsk)
  409. item.UserId = user.UserId
  410. item.ArticleId = req.ArticleId
  411. item.CompanyId = user.CompanyId
  412. item.CompanyName = companyDetail.CompanyName
  413. item.CreateTime = time.Now()
  414. item.Mobile = user.Mobile
  415. item.Email = user.Email
  416. item.Content = content
  417. _, err = models.AddArticleAsk(item)
  418. if err != nil {
  419. br.Msg = "提交失败"
  420. br.ErrMsg = "提交失败,Err:" + err.Error()
  421. return
  422. }
  423. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  424. if err != nil {
  425. br.Msg = "获取信息失败"
  426. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  427. return
  428. }
  429. var mobile string
  430. if utils.RunMode == "release" {
  431. mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  432. } else {
  433. mobile = utils.WxMsgTemplateIdAskMsgMobile + "," + companyItem.Mobile
  434. }
  435. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  436. if err != nil {
  437. br.Msg = "提交失败"
  438. br.ErrMsg = "提交失败,Err:" + err.Error()
  439. return
  440. }
  441. detail, err := models.GetArticleDetailById(articleId)
  442. if err != nil {
  443. br.Msg = "获取信息失败"
  444. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  445. return
  446. }
  447. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  448. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  449. br.Ret = 200
  450. br.Success = true
  451. br.Msg = "提交成功"
  452. }
  453. // @Title 文章相关热门收藏
  454. // @Description 文章相关热门收藏接口
  455. // @Param ArticleId query int true "文章ID"
  456. // @Success 200 {object} models.ArticleCollectionLIstResp
  457. // @router /hotList [get]
  458. func (this *ArticleController) ArticleHotList() {
  459. br := new(models.BaseResponse).Init()
  460. defer func() {
  461. this.Data["json"] = br
  462. this.ServeJSON()
  463. }()
  464. user := this.User
  465. if user == nil {
  466. br.Msg = "请重新登录"
  467. br.Ret = 408
  468. return
  469. }
  470. articleId, _ := this.GetInt("ArticleId")
  471. if articleId < 1 {
  472. br.Msg = "请输入分类ID"
  473. return
  474. }
  475. var condition string
  476. condition = ` AND a.article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id IN (SELECT industrial_management_id FROM cygx_industrial_article_group_management WHERE article_id = ` + strconv.Itoa(articleId) + ` ) ) AND a.article_id != ` + strconv.Itoa(articleId) + ` AND a.category_name LIKE '%研选%' AND publish_status = 1 GROUP BY a.article_id ORDER BY collect_num DESC, publish_date DESC LIMIT 3 `
  477. list, err := models.GetArticleCollectionList(condition, user.UserId)
  478. if err != nil {
  479. br.Msg = "获取信息失败"
  480. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  481. return
  482. }
  483. resp := new(models.ArticleCollectionLIstResp)
  484. if len(list) == 0 {
  485. list = make([]*models.ArticleCollectionResp, 0)
  486. }
  487. resp.List = list
  488. br.Ret = 200
  489. br.Success = true
  490. br.Msg = "获取成功"
  491. br.Data = resp
  492. }
  493. // @Title 上传文章阅读时间
  494. // @Description 上传文章阅读时间接口
  495. // @Param request body models.AddStopTimeRep true "type json string"
  496. // @Success 200 {object} models.ArticleDetailResp
  497. // @router /addStopTime [post]
  498. func (this *ArticleController) AddStopTime() {
  499. br := new(models.BaseResponse).Init()
  500. defer func() {
  501. this.Data["json"] = br
  502. this.ServeJSON()
  503. }()
  504. user := this.User
  505. if user == nil {
  506. br.Msg = "请登录"
  507. br.ErrMsg = "请登录,用户信息为空"
  508. br.Ret = 408
  509. return
  510. }
  511. var req models.AddStopTimeRep
  512. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  513. if err != nil {
  514. br.Msg = "参数解析异常!"
  515. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  516. return
  517. }
  518. //uid := user.UserId
  519. articleId := req.ArticleId
  520. stopTime := req.StopTime
  521. outType := req.OutType
  522. //source := req.Source
  523. if articleId <= 0 {
  524. br.Msg = "参数错误"
  525. br.ErrMsg = "参数错误"
  526. return
  527. }
  528. if stopTime == 0 {
  529. stopTime = 1
  530. }
  531. if outType != 2 {
  532. outType = 1
  533. }
  534. //source = "WEB"
  535. //detail := new(models.ArticleDetail)
  536. hasPermission := 0
  537. hasFree := 0
  538. //
  539. //detail, err = models.GetArticleDetailById(articleId)
  540. //if err != nil {
  541. // br.Msg = "获取信息失败"
  542. // br.ErrMsg = "获取信息失败,Err:" + err.Error()
  543. // return
  544. //}
  545. havePower, err := services.GetArticleDetailUserPower(user)
  546. if err != nil {
  547. br.Msg = "获取信息失败"
  548. br.ErrMsg = "校验用户权限失败,Err:" + err.Error()
  549. return
  550. }
  551. if havePower {
  552. hasPermission = 1
  553. go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
  554. } else {
  555. hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
  556. if err != nil && err.Error() != utils.ErrNoRow() {
  557. br.Msg = "获取信息失败"
  558. br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error()
  559. return
  560. }
  561. }
  562. // //判断是否已经申请过
  563. // applyCount, err := models.GetApplyRecordCount(uid)
  564. // if err != nil && err.Error() != utils.ErrNoRow() {
  565. // br.Msg = "获取信息失败"
  566. // br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  567. // return
  568. // }
  569. // mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid)
  570. // //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  571. // if user.CompanyId > 1 || mfyxUserPermissionTotal == 1 {
  572. // companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  573. // if err != nil {
  574. // br.Msg = "获取信息失败"
  575. // br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  576. // return
  577. // }
  578. // detail, err = models.GetArticleDetailById(articleId)
  579. // if err != nil {
  580. // br.Msg = "获取信息失败"
  581. // br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  582. // return
  583. // }
  584. // if mfyxUserPermissionTotal == 1 {
  585. // companyPermission = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  586. // }
  587. // if companyPermission == "" {
  588. // if applyCount > 0 {
  589. // hasPermission = 5
  590. // } else {
  591. // hasPermission = 2
  592. // }
  593. // hasFree = 2
  594. // goto Loop
  595. // } else {
  596. // hasFree = 1
  597. // var articlePermissionPermissionName string
  598. // if detail.CategoryId > 0 {
  599. // articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  600. // if err != nil {
  601. // br.Msg = "获取信息失败"
  602. // br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  603. // return
  604. // }
  605. // if articlePermission == nil {
  606. // br.Msg = "获取信息失败"
  607. // br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  608. // return
  609. // }
  610. // articlePermissionPermissionName = articlePermission.PermissionName
  611. // } else {
  612. // articlePermissionPermissionName = detail.CategoryName
  613. // }
  614. // var hasPersion bool
  615. // slice := strings.Split(articlePermissionPermissionName, ",")
  616. // //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称
  617. //
  618. // if mfyxUserPermissionTotal == 1 {
  619. // companyPermission += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
  620. // companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
  621. // }
  622. // //如果有研选订阅的权限,那么就拼接一个 买方研选的权限做校验
  623. // if strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  624. // companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME
  625. // }
  626. // for _, v := range slice {
  627. // if strings.Contains(companyPermission, v) {
  628. // hasPersion = true
  629. // }
  630. // }
  631. // if hasPersion {
  632. // go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
  633. // } else { //无该行业权限
  634. // hasPermission = 3
  635. // }
  636. // }
  637. // } else { //潜在客户
  638. // if applyCount > 0 {
  639. // hasPermission = 5
  640. // } else {
  641. // hasPermission = 4
  642. // }
  643. // }
  644. //Loop:
  645. resp := new(models.ArticleDetailAddStopTimeRep)
  646. resp.HasPermission = hasPermission
  647. resp.HasFree = hasFree
  648. br.Ret = 200
  649. br.Success = true
  650. br.Msg = "操作成功"
  651. br.Data = resp
  652. }
  653. // @Title 约访专家
  654. // @Description 约访专家接口
  655. // @Param request body models.CygxArticleIdReq true "type json string"
  656. // @Success 200 {object}
  657. // @router /applyAppointmentExpert [post]
  658. func (this *ArticleController) ApplyAppointmentExpert() {
  659. br := new(models.BaseResponse).Init()
  660. defer func() {
  661. this.Data["json"] = br
  662. this.ServeJSON()
  663. }()
  664. user := this.User
  665. if user == nil {
  666. br.Msg = "请登录"
  667. br.ErrMsg = "请登录,用户信息为空"
  668. br.Ret = 408
  669. return
  670. }
  671. var req models.CygxArticleIdReq
  672. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  673. if err != nil {
  674. br.Msg = "参数解析异常!"
  675. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  676. return
  677. }
  678. articleId := req.ArticleId
  679. var condition string
  680. var pars []interface{}
  681. condition += ` AND article_id =? AND user_id = ? `
  682. pars = append(pars, articleId, user.UserId)
  683. total, err := models.GetCygxArticleApplyAppointmentExpertCount(condition, pars)
  684. if err != nil {
  685. br.Msg = "约访专家失败"
  686. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  687. return
  688. }
  689. if total > 0 {
  690. br.Msg = "您已提交申请,请勿重复提交。"
  691. return
  692. }
  693. err = services.AddArticleApplyAppointmentExpert(user, articleId)
  694. if err != nil {
  695. br.Msg = "约访专家失败"
  696. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  697. return
  698. }
  699. services.SendArticleApplyAppointmentExpertTemplateMsg(user, articleId)
  700. br.Ret = 200
  701. br.Success = true
  702. br.Msg = "操作成功"
  703. }
  704. // @Title 获取上海策略平台报告详情
  705. // @Description 获取上海策略平台报告详情接口
  706. // @Param ArticleId query int true "报告ID"
  707. // @Success 200 {object} models.ArticleDetailResp
  708. // @router /detail_vmp [get]
  709. func (this *ArticleController) DetailVmp() {
  710. br := new(models.BaseResponse).Init()
  711. defer func() {
  712. this.Data["json"] = br
  713. this.ServeJSON()
  714. }()
  715. user := this.User
  716. if user == nil {
  717. br.Msg = "请登录"
  718. br.ErrMsg = "请登录,用户信息为空"
  719. br.Ret = 408
  720. return
  721. }
  722. articleId, _ := this.GetInt("ArticleId")
  723. var clueApiUrl string
  724. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", articleId)
  725. authorization := utils.ApiAuthorization
  726. body, err := services.PublicGetDate(clueApiUrl, authorization)
  727. if err != nil {
  728. br.Msg = "约访专家失败"
  729. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  730. return
  731. }
  732. var articleResultDate models.ArticleDetailResultApi
  733. err = json.Unmarshal(body, &articleResultDate)
  734. if err != nil {
  735. br.Msg = "约访专家失败"
  736. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  737. return
  738. }
  739. br.Ret = 200
  740. br.Success = true
  741. br.Msg = "获取成功"
  742. br.Data = articleResultDate
  743. }