article.go 25 KB

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