article.go 21 KB

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