article.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/medivhzhan/weapp/v2"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/services"
  8. "hongze/hongze_cygx/utils"
  9. "html"
  10. "os"
  11. "rdluck_tools/http"
  12. "regexp"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type ArticleController struct {
  18. BaseAuthController
  19. }
  20. type ArticleCommonController struct {
  21. BaseCommonController
  22. }
  23. // @Title 获取报告详情
  24. // @Description 获取报告详情接口
  25. // @Param ArticleId query int true "报告ID"
  26. // @Success 200 {object} models.ArticleDetailResp
  27. // @router /detail [get]
  28. func (this *ArticleController) Detail() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. user := this.User
  35. if user == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,用户信息为空"
  38. br.Ret = 408
  39. return
  40. }
  41. uid := user.UserId
  42. articleId, err := this.GetInt("ArticleId")
  43. if articleId <= 0 {
  44. br.Msg = "文章不存在"
  45. br.ErrMsg = "文章不存在,文章ID错误"
  46. return
  47. }
  48. detail := new(models.ArticleDetail)
  49. hasPermission := 0
  50. hasFree := 0
  51. //判断是否已经申请过
  52. applyCount, err := models.GetApplyRecordCount(uid)
  53. if err != nil && err.Error() != utils.ErrNoRow() {
  54. br.Msg = "获取信息失败"
  55. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  56. return
  57. }
  58. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  59. if user.CompanyId > 1 {
  60. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  61. if err != nil {
  62. br.Msg = "获取信息失败"
  63. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  64. return
  65. }
  66. detail, err = models.GetArticleDetailById(articleId)
  67. if err != nil {
  68. br.Msg = "获取信息失败"
  69. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  70. return
  71. }
  72. detail.Body = html.UnescapeString(detail.Body)
  73. //detail.Abstract = html.UnescapeString(detail.Abstract)
  74. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  75. if companyPermission == "" {
  76. if applyCount > 0 {
  77. hasPermission = 5
  78. } else {
  79. hasPermission = 2
  80. }
  81. hasFree = 2
  82. goto Loop
  83. } else {
  84. hasFree = 1
  85. var articlePermissionPermissionName string
  86. if detail.CategoryId > 0 {
  87. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  88. if err != nil {
  89. br.Msg = "获取信息失败"
  90. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  91. return
  92. }
  93. if articlePermission == nil {
  94. br.Msg = "获取信息失败"
  95. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  96. return
  97. }
  98. articlePermissionPermissionName = articlePermission.PermissionName
  99. } else {
  100. articlePermissionPermissionName = detail.CategoryName
  101. }
  102. var hasPersion bool
  103. slice := strings.Split(articlePermissionPermissionName, ",")
  104. for _, v := range slice {
  105. if strings.Contains(companyPermission, v) {
  106. hasPersion = true
  107. }
  108. }
  109. if hasPersion {
  110. hasPermission = 1
  111. historyRecord := new(models.CygxArticleHistoryRecord)
  112. historyRecord.UserId = uid
  113. historyRecord.ArticleId = articleId
  114. historyRecord.CreateTime = time.Now()
  115. historyRecord.Mobile = user.Mobile
  116. historyRecord.Email = user.Email
  117. historyRecord.CompanyId = user.CompanyId
  118. historyRecord.CompanyName = user.CompanyName
  119. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  120. if recordCount == 0 {
  121. go models.AddCygxArticleHistoryRecord(historyRecord)
  122. } else {
  123. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  124. if err != nil {
  125. br.Msg = "获取信息失败"
  126. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  127. return
  128. }
  129. if detailNew.StopTime > 0 {
  130. go models.AddCygxArticleHistoryRecord(historyRecord)
  131. }
  132. }
  133. } else { //无该行业权限
  134. hasPermission = 3
  135. }
  136. if hasPermission == 1 {
  137. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  138. if !utils.Rc.IsExist(key) {
  139. //新增浏览记录
  140. record := new(models.CygxArticleViewRecord)
  141. record.UserId = uid
  142. record.ArticleId = articleId
  143. record.CreateTime = time.Now()
  144. record.Mobile = user.Mobile
  145. record.Email = user.Email
  146. record.CompanyId = user.CompanyId
  147. record.CompanyName = user.CompanyName
  148. go models.AddCygxArticleViewRecord(record)
  149. utils.Rc.Put(key, 1, 5*time.Second)
  150. models.ModifyReportLastViewTime(uid)
  151. }
  152. }
  153. }
  154. if strings.Contains(detail.CategoryName, "研选") {
  155. detail.IsResearch = true
  156. }
  157. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  158. if err != nil && err.Error() != utils.ErrNoRow() {
  159. br.Msg = "获取信息失败"
  160. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  161. return
  162. }
  163. if collectCount > 0 {
  164. detail.IsCollect = true
  165. }
  166. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  167. if err != nil && err.Error() != utils.ErrNoRow() {
  168. br.Msg = "获取信息失败"
  169. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  170. return
  171. }
  172. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  173. detail.IsInterviewApply = true
  174. detail.InterviewApplyStatus = interviewApplyItem.Status
  175. }
  176. //获取销售手机号
  177. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  178. if err != nil {
  179. br.Msg = "获取信息失败"
  180. br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  181. return
  182. }
  183. if sellerItem != nil {
  184. detail.SellerMobile = sellerItem.Mobile
  185. detail.SellerName = sellerItem.RealName
  186. }
  187. sellerList, err := models.GetSellerList(articleId)
  188. if err != nil {
  189. br.Msg = "获取信息失败"
  190. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  191. return
  192. }
  193. if detail.ArticleId >= utils.SummaryArticleId {
  194. //var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  195. //match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  196. //if match != nil {
  197. // for _, v := range match {
  198. // sellerAndMobile := &models.SellerRep{
  199. // SellerMobile: v,
  200. // SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  201. // }
  202. // sellerList = append(sellerList, sellerAndMobile)
  203. // }
  204. //}
  205. strnum := strings.Index(detail.SellerAndMobile, "-")
  206. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  207. if strnum > 0 {
  208. nickName := detail.SellerAndMobile[0:strnum]
  209. sellerAndMobile := &models.SellerRep{
  210. SellerMobile: "",
  211. SellerName: nickName,
  212. }
  213. sellerList = append(sellerList, sellerAndMobile)
  214. }
  215. }
  216. detail.SellerList = sellerList
  217. } else { //潜在客户
  218. if applyCount > 0 {
  219. hasPermission = 5
  220. } else {
  221. hasPermission = 4
  222. }
  223. }
  224. Loop:
  225. if hasPermission != 1 {
  226. detail.Body = ""
  227. detail.BodyText = ""
  228. } else {
  229. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  230. if err != nil {
  231. br.Msg = "获取信息失败"
  232. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  233. return
  234. }
  235. detail.FollowNum = articleFollowdetail.DNum
  236. detail.CollectionNum = articleFollowdetail.AcNum
  237. if articleFollowdetail.MdNum > 0 {
  238. detail.IsFollow = true
  239. }
  240. if detail.IsSummary == 1 {
  241. detail.IsBelongSummary = true
  242. }
  243. if detail.IsReport == 1 {
  244. detail.IsBelongReport = true
  245. }
  246. }
  247. fmt.Println(uid)
  248. resp := new(models.ArticleDetailResp)
  249. resp.HasPermission = hasPermission
  250. resp.HasFree = hasFree
  251. resp.Detail = detail
  252. br.Ret = 200
  253. br.Success = true
  254. br.Msg = "获取成功"
  255. br.Data = resp
  256. }
  257. // @Title 收藏
  258. // @Description 收藏
  259. // @Param request body models.ArticleCollectReq true "type json string"
  260. // @Success 200 {object} models.FontsCollectResp
  261. // @router /collect [post]
  262. func (this *ArticleController) ArticleCollect() {
  263. br := new(models.BaseResponse).Init()
  264. defer func() {
  265. this.Data["json"] = br
  266. this.ServeJSON()
  267. }()
  268. user := this.User
  269. if user == nil {
  270. br.Msg = "请重新登录"
  271. br.Ret = 408
  272. return
  273. }
  274. uid := user.UserId
  275. var req models.ArticleCollectReq
  276. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  277. if err != nil {
  278. br.Msg = "参数解析异常!"
  279. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  280. return
  281. }
  282. count, err := models.GetArticleCollectCount(uid, req.ArticleId)
  283. if err != nil {
  284. br.Msg = "获取数据失败!"
  285. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  286. return
  287. }
  288. resp := new(models.ArticleCollectResp)
  289. if count <= 0 {
  290. item := new(models.CygxArticleCollect)
  291. item.ArticleId = req.ArticleId
  292. item.UserId = uid
  293. item.CreateTime = time.Now()
  294. _, err = models.AddCygxArticleCollect(item)
  295. if err != nil {
  296. br.Msg = "收藏失败"
  297. br.ErrMsg = "收藏失败,Err:" + err.Error()
  298. return
  299. }
  300. br.Msg = "收藏成功"
  301. resp.Status = 1
  302. } else {
  303. err = models.RemoveArticleCollect(uid, req.ArticleId)
  304. if err != nil {
  305. br.Msg = "取消收藏失败"
  306. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  307. return
  308. }
  309. br.Msg = "已取消收藏"
  310. resp.Status = 2
  311. }
  312. collectTotal, err := models.GetArticleCollectUsersCount(req.ArticleId)
  313. if err != nil {
  314. br.Msg = "获取数据失败"
  315. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  316. return
  317. }
  318. resp.CollectCount = collectTotal
  319. br.Ret = 200
  320. br.Success = true
  321. br.Data = resp
  322. }
  323. // @Title 访谈申请
  324. // @Description 访谈申请
  325. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  326. // @Success 200 {object} models.FontsCollectResp
  327. // @router /interview/apply [post]
  328. func (this *ArticleController) InterviewApply() {
  329. br := new(models.BaseResponse).Init()
  330. defer func() {
  331. this.Data["json"] = br
  332. this.ServeJSON()
  333. }()
  334. user := this.User
  335. if user == nil {
  336. br.Msg = "请重新登录"
  337. br.Ret = 408
  338. return
  339. }
  340. uid := user.UserId
  341. var req models.ArticleInterviewApplyReq
  342. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  343. if err != nil {
  344. br.Msg = "参数解析异常!"
  345. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  346. return
  347. }
  348. article, err := models.GetArticleDetailById(req.ArticleId)
  349. if err != nil {
  350. br.Msg = "获取纪要失败!"
  351. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  352. return
  353. }
  354. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  355. if err != nil {
  356. br.Msg = "获取数据失败!"
  357. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  358. return
  359. }
  360. resp := new(models.ArticleInterviewApplyResp)
  361. if count <= 0 {
  362. item := new(models.CygxInterviewApply)
  363. item.ArticleId = req.ArticleId
  364. item.UserId = uid
  365. item.CompanyId = user.CompanyId
  366. item.Status = "待邀请"
  367. item.Sort = 1
  368. item.ArticleTitle = article.Title
  369. item.CreateTime = time.Now()
  370. item.ModifyTime = time.Now()
  371. item.ArticleIdMd5 = article.ArticleIdMd5
  372. _, err = models.AddCygxInterviewApply(item)
  373. if err != nil {
  374. br.Msg = "申请失败"
  375. br.ErrMsg = "申请失败,Err:" + err.Error()
  376. return
  377. }
  378. br.Msg = "申请成功"
  379. resp.Status = 1
  380. //发送模板消息
  381. if user.CompanyId > 1 {
  382. mobile := user.Mobile
  383. if mobile == "" {
  384. mobile = user.Email
  385. }
  386. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  387. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  388. openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1)
  389. if openIpItem != nil && openIpItem.OpenId != "" {
  390. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  391. }
  392. }
  393. }
  394. } else {
  395. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  396. if err != nil {
  397. br.Msg = "取消申请失败"
  398. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  399. return
  400. }
  401. br.Msg = "已取消申请"
  402. resp.Status = 2
  403. if user.CompanyId > 1 {
  404. mobile := user.Mobile
  405. if mobile == "" {
  406. mobile = user.Email
  407. }
  408. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  409. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  410. openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1)
  411. if openIpItem != nil && openIpItem.OpenId != "" {
  412. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  413. }
  414. }
  415. }
  416. }
  417. br.Ret = 200
  418. br.Success = true
  419. br.Data = resp
  420. }
  421. // @Title 获取报告详情
  422. // @Description 获取报告详情接口
  423. // @Param ArticleIdMd5 query int true "报告ID"
  424. // @Success 200 {object} models.ArticleDetailResp
  425. // @router /look/detail [get]
  426. func (this *ArticleCommonController) Detail() {
  427. br := new(models.BaseResponse).Init()
  428. defer func() {
  429. this.Data["json"] = br
  430. this.ServeJSON()
  431. }()
  432. articleIdMd5 := this.GetString("ArticleIdMd5")
  433. if articleIdMd5 == "" {
  434. br.Msg = "参数错误"
  435. br.ErrMsg = "参数错误"
  436. return
  437. }
  438. resp := new(models.ArticleDetailResp)
  439. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  440. if err != nil && err.Error() != utils.ErrNoRow() {
  441. br.Msg = "获取信息失败"
  442. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  443. return
  444. }
  445. if detail == nil {
  446. resp.HasPermission = 2
  447. } else {
  448. resp.HasPermission = 1
  449. }
  450. if detail != nil {
  451. detail.Body = html.UnescapeString(detail.Body)
  452. detail.Abstract = html.UnescapeString(detail.Abstract)
  453. }
  454. sellerList, err := models.GetSellerList(detail.ArticleId)
  455. if err != nil {
  456. br.Msg = "获取信息失败"
  457. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(detail.ArticleId)
  458. return
  459. }
  460. if detail.ArticleId > 1000000 {
  461. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  462. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  463. if match != nil {
  464. for _, v := range match {
  465. sellerAndMobile := &models.SellerRep{
  466. SellerMobile: v,
  467. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  468. }
  469. sellerList = append(sellerList, sellerAndMobile)
  470. }
  471. }
  472. }
  473. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  474. detail.SellerList = sellerList
  475. resp.Detail = detail
  476. br.Ret = 200
  477. br.Success = true
  478. br.Msg = "获取成功"
  479. br.Data = resp
  480. }
  481. // @Title 上传文章阅读时间
  482. // @Description 上传文章阅读时间接口
  483. // @Param request body models.AddStopTimeRep true "type json string"
  484. // @Success 200 {object} models.ArticleDetailResp
  485. // @router /addStopTime [post]
  486. func (this *ArticleController) AddStopTime() {
  487. br := new(models.BaseResponse).Init()
  488. defer func() {
  489. this.Data["json"] = br
  490. this.ServeJSON()
  491. }()
  492. user := this.User
  493. if user == nil {
  494. br.Msg = "请登录"
  495. br.ErrMsg = "请登录,用户信息为空"
  496. br.Ret = 408
  497. return
  498. }
  499. var req models.AddStopTimeRep
  500. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  501. if err != nil {
  502. br.Msg = "参数解析异常!"
  503. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  504. return
  505. }
  506. uid := user.UserId
  507. articleId := req.ArticleId
  508. stopTime := req.StopTime
  509. if articleId <= 0 {
  510. br.Msg = "参数错误"
  511. br.ErrMsg = "参数错误"
  512. return
  513. }
  514. if stopTime == 0 {
  515. stopTime = 1
  516. //br.Msg = "时间格式错误"
  517. //br.ErrMsg = "时间错误"
  518. //return
  519. }
  520. detail := new(models.ArticleDetail)
  521. hasPermission := 0
  522. hasFree := 0
  523. //判断是否已经申请过
  524. applyCount, err := models.GetApplyRecordCount(uid)
  525. if err != nil && err.Error() != utils.ErrNoRow() {
  526. br.Msg = "获取信息失败"
  527. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  528. return
  529. }
  530. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  531. if user.CompanyId > 1 {
  532. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  533. if err != nil {
  534. br.Msg = "获取信息失败"
  535. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  536. return
  537. }
  538. detail, err = models.GetArticleDetailById(articleId)
  539. if err != nil {
  540. br.Msg = "获取信息失败"
  541. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  542. return
  543. }
  544. if companyPermission == "" {
  545. if applyCount > 0 {
  546. hasPermission = 5
  547. } else {
  548. hasPermission = 2
  549. }
  550. hasFree = 2
  551. goto Loop
  552. } else {
  553. hasFree = 1
  554. var articlePermissionPermissionName string
  555. if detail.CategoryId > 0 {
  556. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  557. if err != nil {
  558. br.Msg = "获取信息失败"
  559. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  560. return
  561. }
  562. if articlePermission == nil {
  563. br.Msg = "获取信息失败"
  564. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  565. return
  566. }
  567. articlePermissionPermissionName = articlePermission.PermissionName
  568. } else {
  569. articlePermissionPermissionName = detail.CategoryName
  570. }
  571. if strings.Contains(companyPermission, articlePermissionPermissionName) {
  572. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  573. if err == nil {
  574. //br.Msg = "获取信息失败"
  575. //br.ErrMsg = "获取最新阅读信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  576. //return
  577. hasPermission = 1
  578. historyRecord := new(models.AddStopTimeNewRep)
  579. historyRecord.StopTime = detailNew.StopTime + stopTime
  580. historyRecord.Id = detailNew.Id
  581. go models.AddArticleStopTime(historyRecord)
  582. }
  583. } else { //无该行业权限
  584. hasPermission = 3
  585. }
  586. }
  587. } else { //潜在客户
  588. if applyCount > 0 {
  589. hasPermission = 5
  590. } else {
  591. hasPermission = 4
  592. }
  593. }
  594. Loop:
  595. resp := new(models.ArticleDetailAddStopTimeRep)
  596. resp.HasPermission = hasPermission
  597. resp.HasFree = hasFree
  598. br.Ret = 200
  599. br.Success = true
  600. br.Msg = "操作成功"
  601. br.Data = resp
  602. }
  603. // @Title 文章带问
  604. // @Description 新增文章带问接口
  605. // @Param request body models.AddArticleAskRep true "type json string"
  606. // @Success Ret=200 新增成功
  607. // @router /askAdd [post]
  608. func (this *ArticleController) AskAdd() {
  609. br := new(models.BaseResponse).Init()
  610. defer func() {
  611. this.Data["json"] = br
  612. this.ServeJSON()
  613. }()
  614. user := this.User
  615. if user == nil {
  616. br.Msg = "请登录"
  617. br.ErrMsg = "请登录,SysUser Is Empty"
  618. br.Ret = 408
  619. return
  620. }
  621. var req models.AddArticleAskRep
  622. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  623. if err != nil {
  624. br.Msg = "参数解析异常!"
  625. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  626. return
  627. }
  628. if req.Content == "" {
  629. br.Msg = "建议内容不可为空"
  630. return
  631. }
  632. content := req.Content
  633. itemToken, err := services.WxGetToken()
  634. if err != nil {
  635. br.Msg = "GetWxAccessToken Err:" + err.Error()
  636. return
  637. }
  638. if itemToken.AccessToken == "" {
  639. br.Msg = "accessToken is empty"
  640. return
  641. }
  642. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  643. if err != nil {
  644. br.Msg = "内容校验失败!"
  645. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  646. return
  647. }
  648. if commerr.ErrCode != 0 {
  649. br.Msg = "内容违规,请重新提交!"
  650. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  651. return
  652. }
  653. articleId := req.ArticleId
  654. count, _ := models.GetArticleCountById(articleId)
  655. if count == 0 {
  656. br.Msg = "操作失败"
  657. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  658. return
  659. }
  660. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  661. if err != nil {
  662. br.Msg = "提交失败!"
  663. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  664. return
  665. }
  666. if companyDetail == nil {
  667. br.Msg = "提交失败!"
  668. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  669. return
  670. }
  671. item := new(models.CygxArticleAsk)
  672. item.UserId = user.UserId
  673. item.ArticleId = req.ArticleId
  674. item.CompanyId = user.CompanyId
  675. item.CompanyName = companyDetail.CompanyName
  676. item.CreateTime = time.Now()
  677. item.Mobile = user.Mobile
  678. item.Email = user.Email
  679. item.Content = content
  680. _, err = models.AddArticleAsk(item)
  681. if err != nil {
  682. br.Msg = "提交失败"
  683. br.ErrMsg = "提交失败,Err:" + err.Error()
  684. return
  685. }
  686. openIdList, err := models.GetWxOpenIdByMobileList()
  687. if err != nil {
  688. br.Msg = "提交失败"
  689. br.ErrMsg = "提交失败,Err:" + err.Error()
  690. return
  691. }
  692. detail, err := models.GetArticleDetailById(articleId)
  693. if err != nil {
  694. br.Msg = "获取信息失败"
  695. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  696. return
  697. }
  698. companyName := user.CompanyName + "-" + user.RealName + "(王芳)"
  699. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  700. br.Ret = 200
  701. br.Success = true
  702. br.Msg = "提交成功"
  703. }
  704. // @Title 下载PDF打水印
  705. // @Description 下载PDF打水印接口
  706. // @Param ArticleId query int true "报告ID"
  707. // @Success 200 {object} models.ArticleDetailFileLink
  708. // @router /pdfwatermark [get]
  709. func (this *ArticleController) Pdfwatermark() {
  710. br := new(models.BaseResponse).Init()
  711. defer func() {
  712. this.Data["json"] = br
  713. this.ServeJSON()
  714. }()
  715. user := this.User
  716. if user == nil {
  717. br.Msg = "请登录"
  718. br.ErrMsg = "请登录,用户信息为空"
  719. br.Ret = 408
  720. return
  721. }
  722. articleId, err := this.GetInt("ArticleId")
  723. if articleId <= 0 {
  724. br.Msg = "文章不存在"
  725. br.ErrMsg = "文章不存在,文章ID错误"
  726. return
  727. }
  728. detail := new(models.ArticleDetail)
  729. detail, err = models.GetArticleDetailById(articleId)
  730. if err != nil {
  731. br.Msg = "获取信息失败"
  732. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  733. return
  734. }
  735. fileLink := detail.FileLink
  736. if fileLink == "" {
  737. br.Msg = "下载失败"
  738. br.ErrMsg = "下载失败,报告链接不存在"
  739. return
  740. }
  741. mobile := user.Mobile
  742. if mobile == "" {
  743. mobile = user.Email
  744. }
  745. dataMap := make(map[string]interface{})
  746. dataMap["Mobile"] = mobile
  747. //dataMap["Name"] = user.RealName
  748. dataMap["Name"] = ""
  749. dataMap["FileLink"] = fileLink
  750. postUrl := "http://127.0.0.1:5007/pdfwatermark/" //
  751. fmt.Println("postUrl:", postUrl)
  752. postData, err := json.Marshal(dataMap)
  753. if err != nil {
  754. br.Msg = "获取postData数据失败"
  755. br.ErrMsg = "解析,Marshal,Err:" + err.Error()
  756. return
  757. }
  758. fmt.Println("publish ppt param:", string(postData))
  759. result, err := http.Post(postUrl, string(postData))
  760. if err != nil {
  761. br.Msg = "发布失败"
  762. br.ErrMsg = "Marshal,Err:" + err.Error()
  763. return
  764. }
  765. fmt.Println("publish pdf result:", string(result))
  766. var pdfResult PublishPdfResult
  767. err = json.Unmarshal(result, &pdfResult)
  768. if err != nil {
  769. br.Msg = "获取数据失败"
  770. br.ErrMsg = "Unmarshal,Err:" + err.Error()
  771. return
  772. }
  773. resp := new(models.ArticleDetailFileLink)
  774. filePathName := strings.TrimLeft(pdfResult.FilePath, ".")
  775. filePathOldName := strings.TrimLeft(pdfResult.FileOldPath, ".")
  776. filePath := pdfResult.Pdfpath + filePathName
  777. filePathOld := pdfResult.Pdfpath + filePathOldName
  778. fmt.Println(filePath)
  779. fmt.Println(filePathOld)
  780. randStr := utils.GetRandStringNoSpecialChar(28)
  781. fileName := randStr + ".pdf"
  782. hzUploadDir := "static/pdf/"
  783. savePath := hzUploadDir + time.Now().Format("200601/20060102/")
  784. savePath += fileName
  785. //上传到阿里云
  786. err = services.UploadFileToAliyun(fileName, filePath, savePath)
  787. if err != nil {
  788. br.Msg = "文件上传失败"
  789. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  790. return
  791. }
  792. utils.FileLog.Info("%s:", time.Now().Format(utils.FormatDateTime))
  793. utils.FileLog.Info("end update oss ")
  794. fileHost := "https://hzstatic.hzinsights.com/"
  795. resourceUrl := fileHost + savePath
  796. defer func() {
  797. os.Remove(filePath)
  798. os.Remove(filePathOld)
  799. }()
  800. resp.FileLink = resourceUrl
  801. br.Ret = 200
  802. br.Success = true
  803. br.Msg = "获取成功"
  804. br.Data = resp
  805. }
  806. type PublishPdfResult struct {
  807. Result string `json:"result"`
  808. FilePath string `json:"file_path"`
  809. FileOldPath string `json:"file_old_path"`
  810. Pdfpath string `json:"pdfpath"`
  811. }