article.go 28 KB

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