article.go 29 KB

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