article.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. package controllers
  2. import (
  3. "bufio"
  4. "github.com/pdfcpu/pdfcpu/pkg/api"
  5. "github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
  6. "io"
  7. //"bufio"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/medivhzhan/weapp/v2"
  11. "os"
  12. //"github.com/pdfcpu/pdfcpu/pkg/api"
  13. //"github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
  14. "hongze/hongze_mfyx/models"
  15. "hongze/hongze_mfyx/services"
  16. "hongze/hongze_mfyx/utils"
  17. "html"
  18. nhttp "net/http"
  19. "strconv"
  20. "strings"
  21. "time"
  22. )
  23. type ArticleController struct {
  24. BaseAuthController
  25. }
  26. type ArticleCommonController struct {
  27. BaseCommonController
  28. }
  29. type ArticleControllerMobile struct {
  30. BaseAuthMobileController
  31. }
  32. // @Title 获取报告详情
  33. // @Description 获取报告详情接口
  34. // @Param ArticleId query int true "报告ID"
  35. // @Param IsSendWx query int false "是否是通过微信模版进来的 1是,其它否"
  36. // @Param InviteShareCode query string false "销售账号邀请码"
  37. // @Success 200 {object} models.ArticleDetailResp
  38. // @router /detail [get]
  39. func (this *ArticleController) Detail() {
  40. br := new(models.BaseResponse).Init()
  41. defer func() {
  42. this.Data["json"] = br
  43. this.ServeJSON()
  44. }()
  45. user := this.User
  46. if user == nil {
  47. br.Msg = "请登录"
  48. br.ErrMsg = "请登录,用户信息为空"
  49. br.Ret = 408
  50. return
  51. }
  52. uid := user.UserId
  53. articleId, err := this.GetInt("ArticleId")
  54. isSendWx, _ := this.GetInt("IsSendWx")
  55. if articleId <= 0 {
  56. br.Msg = "文章不存在"
  57. br.ErrMsg = "文章不存在,文章ID错误"
  58. return
  59. }
  60. inviteShareCode := this.GetString("InviteShareCode")
  61. detail := new(models.ArticleDetail)
  62. hasPermission := 0
  63. var haveResearch bool
  64. resp := new(models.ArticleDetailResp)
  65. detail, err = models.GetArticleDetailById(articleId)
  66. if err != nil {
  67. br.Msg = "获取信息失败"
  68. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  69. return
  70. }
  71. //记录分享来源
  72. if inviteShareCode != "" {
  73. go services.AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_ARTICLE, detail.Title, inviteShareCode, articleId)
  74. }
  75. detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
  76. detail.Body = html.UnescapeString(detail.Body)
  77. detail.Body = strings.Replace(detail.Body, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
  78. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  79. detail.Abstract = html.UnescapeString(detail.Abstract)
  80. //detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  81. //作者头像
  82. if detail.DepartmentId > 0 {
  83. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  84. if err == nil {
  85. detail.DepartmentImgUrl = departmentDetail.ImgUrl
  86. }
  87. }
  88. // 判断是否属于研选类型的报告
  89. detail.IsResearch = true
  90. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
  91. detail.IsCollect = articleCollectMap[detail.ArticleId]
  92. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  93. //是否是通过模板消息进来的
  94. if isSendWx == 1 {
  95. var condition string
  96. var pars []interface{}
  97. pars = make([]interface{}, 0)
  98. condition = ` AND article_id = ? `
  99. reportMappingMap, _ := services.GetReportMappingMap()
  100. if reportMappingMap[detail.CategoryId] {
  101. chooseCategoryMap, _ := services.GetChooseCategoryMap(user)
  102. detail.IsShowFollowButton = true
  103. detail.IsFollowButton = chooseCategoryMap[detail.CategoryId]
  104. } else {
  105. pars = append(pars, articleId)
  106. industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
  107. if err != nil && err.Error() != utils.ErrNoRow() {
  108. br.Msg = "获取信息失败"
  109. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  110. return
  111. }
  112. if len(industrialList) > 0 {
  113. industryUserFollowMap, err := services.GetIndustryUserFollowMap(user)
  114. if err != nil {
  115. br.Msg = "获取信息失败"
  116. br.ErrMsg = "GetActivitySignupResp,Err:" + err.Error()
  117. return
  118. }
  119. for _, v := range industrialList {
  120. if industryUserFollowMap[v.IndustrialManagementId] {
  121. detail.IsFollowButton = true
  122. }
  123. }
  124. detail.IsShowFollowButton = true
  125. }
  126. }
  127. }
  128. havePower, err := services.GetArticleDetailUserPower(user)
  129. if err != nil {
  130. br.Msg = "获取信息失败"
  131. br.ErrMsg = "校验用户权限失败,Err:" + err.Error()
  132. return
  133. }
  134. if havePower {
  135. hasPermission = 1
  136. go services.ArticleHistory(articleId, user)
  137. //30分钟之内阅读同一篇文章不错二次推送
  138. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  139. if !utils.Rc.IsExist(key) {
  140. go services.ArticleUserRemind(user, detail, 1)
  141. // 互动提醒
  142. go services.SendWxCategoryMsgInteractive(user, "阅读报告", articleId, detail.Title)
  143. utils.Rc.Put(key, 1, 30*time.Second)
  144. }
  145. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  146. if err != nil && err.Error() != utils.ErrNoRow() {
  147. br.Msg = "获取信息失败"
  148. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  149. return
  150. }
  151. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  152. detail.IsInterviewApply = true
  153. detail.InterviewApplyStatus = interviewApplyItem.Status
  154. }
  155. //获取销售手机号
  156. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  157. if err != nil && err.Error() != utils.ErrNoRow() {
  158. br.Msg = "获取信息失败"
  159. br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  160. return
  161. }
  162. if sellerItem != nil {
  163. detail.SellerMobile = sellerItem.Mobile
  164. detail.SellerName = sellerItem.RealName
  165. }
  166. sellerList, err := models.GetSellerList(articleId)
  167. if err != nil {
  168. br.Msg = "获取信息失败"
  169. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  170. return
  171. }
  172. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  173. strnum := strings.Index(detail.SellerAndMobile, "-")
  174. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  175. if strnum > 0 {
  176. nickName := detail.SellerAndMobile[0:strnum]
  177. sellerAndMobile := &models.SellerRep{
  178. SellerMobile: "",
  179. SellerName: nickName,
  180. }
  181. sellerList = append(sellerList, sellerAndMobile)
  182. }
  183. }
  184. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  185. if err != nil {
  186. br.Msg = "获取信息失败"
  187. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  188. return
  189. }
  190. detail.FollowNum = articleFollowdetail.DNum
  191. detail.CollectionNum = articleFollowdetail.AcNum
  192. if articleFollowdetail.MdNum > 0 {
  193. detail.IsFollow = true
  194. }
  195. if detail.IsSummary == 1 {
  196. detail.IsBelongSummary = true
  197. }
  198. if detail.IsReport == 1 {
  199. detail.IsBelongReport = true
  200. }
  201. } else {
  202. hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
  203. if err != nil && err.Error() != utils.ErrNoRow() {
  204. br.Msg = "获取信息失败"
  205. br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error()
  206. return
  207. }
  208. //权益客户对权益销售信息进行展示
  209. if hasPermission == 2 || hasPermission == 3 {
  210. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  211. if err != nil && err.Error() != utils.ErrNoRow() {
  212. br.Msg = "获取信息失败"
  213. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  214. return
  215. }
  216. if sellerItemQy != nil {
  217. detail.SellerMobile = sellerItemQy.Mobile
  218. detail.SellerName = sellerItemQy.RealName
  219. }
  220. }
  221. detail.Body = ""
  222. detail.BodyText = ""
  223. resp.IsShowWxPay = utils.IS_SHOW_WX_PAY //是否展示微信支付按钮
  224. resp.IsCompanyApply = services.GetUserApplyRecordCountByCompanyIdPay(user.CompanyId) //获取客户是否有过历史申请记录
  225. resp.IsNeedBusinessCard = services.GetCygxUserBusinessCardCount(user.UserId, user.CompanyId) //是否需要上传名片
  226. resp.GoodsList = services.GetUserGoodsCardList() //日卡月卡商品信息
  227. for _, v := range resp.GoodsList {
  228. resp.PopupPriceMsg += v.PopupPriceMsg //价格弹窗信息
  229. }
  230. }
  231. if hasPermission != 1 {
  232. hasPermission, err = services.GetUserPermissionCode(user.UserId, user.CompanyId)
  233. if err != nil {
  234. br.Msg = "获取信息失败"
  235. br.ErrMsg = "获取用户状态信息失败,Err:" + err.Error()
  236. return
  237. }
  238. }
  239. if detail.ArticleTypeId == 14 {
  240. detail.IsApplyAppointmentExpert = true //判断文章类型是否属于专家访谈 查研观向11.0
  241. }
  242. if user.UserId == 0 {
  243. hasPermission = 1
  244. }
  245. if detail.ArticleId < utils.SummaryArticleId {
  246. if user.Mobile != "" {
  247. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
  248. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
  249. } else {
  250. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
  251. }
  252. detail.IsNeedJump = true
  253. }
  254. resp.HasPermission = hasPermission
  255. resp.HaveResearch = haveResearch
  256. resp.Detail = detail
  257. if user.Mobile != "" {
  258. resp.Mobile = user.Mobile
  259. } else {
  260. resp.Mobile = user.Email
  261. }
  262. br.Ret = 200
  263. br.Success = true
  264. br.Msg = "获取成功"
  265. br.Data = resp
  266. }
  267. // @Title 收藏
  268. // @Description 收藏
  269. // @Param request body models.ArticleCollectReq true "type json string"
  270. // @Success 200 {object} models.FontsCollectResp
  271. // @router /collect [post]
  272. func (this *ArticleController) ArticleCollect() {
  273. br := new(models.BaseResponse).Init()
  274. defer func() {
  275. this.Data["json"] = br
  276. this.ServeJSON()
  277. }()
  278. user := this.User
  279. if user == nil {
  280. br.Msg = "请重新登录"
  281. br.Ret = 408
  282. return
  283. }
  284. uid := user.UserId
  285. var req models.ArticleCollectReq
  286. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  287. if err != nil {
  288. br.Msg = "参数解析异常!"
  289. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  290. return
  291. }
  292. articleId := req.ArticleId
  293. detail, err := models.GetArticleDetailById(articleId)
  294. if err != nil {
  295. br.Msg = "获取信息失败"
  296. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  297. return
  298. }
  299. count, err := models.GetArticleCollectCount(uid, articleId)
  300. if err != nil {
  301. br.Msg = "获取数据失败!"
  302. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  303. return
  304. }
  305. resp := new(models.ArticleCollectResp)
  306. if count <= 0 {
  307. item := new(models.CygxArticleCollect)
  308. item.ArticleId = req.ArticleId
  309. item.UserId = uid
  310. item.CreateTime = time.Now()
  311. item.Mobile = user.Mobile
  312. item.Email = user.Email
  313. item.CompanyId = user.CompanyId
  314. item.CompanyName = user.CompanyName
  315. item.RealName = user.RealName
  316. _, err = models.AddCygxArticleCollect(item)
  317. if err != nil {
  318. br.Msg = "收藏失败"
  319. br.ErrMsg = "收藏失败,Err:" + err.Error()
  320. return
  321. }
  322. br.Msg = "收藏成功"
  323. resp.Status = 1
  324. // 文章收藏消息发送
  325. //go services.ArticleUserRemind(user, detail, 2)
  326. go services.ArticleHistoryUserLabelLogAdd(articleId, user.UserId)
  327. // 互动提醒
  328. go services.SendWxCategoryMsgInteractive(user, "收藏报告", articleId, detail.Title)
  329. } else {
  330. err = models.RemoveArticleCollect(uid, articleId)
  331. if err != nil {
  332. br.Msg = "取消收藏失败"
  333. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  334. return
  335. }
  336. br.Msg = "已取消收藏"
  337. resp.Status = 2
  338. }
  339. collectTotal, err := models.GetArticleCollectUsersCount(articleId)
  340. if err != nil {
  341. br.Msg = "获取数据失败"
  342. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  343. return
  344. }
  345. resp.CollectCount = collectTotal
  346. br.Ret = 200
  347. br.Success = true
  348. br.Data = resp
  349. }
  350. // @Title 访谈申请
  351. // @Description 访谈申请
  352. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  353. // @Success 200 {object} models.FontsCollectResp
  354. // @router /interview/apply [post]
  355. func (this *ArticleController) InterviewApply() {
  356. br := new(models.BaseResponse).Init()
  357. defer func() {
  358. this.Data["json"] = br
  359. this.ServeJSON()
  360. }()
  361. user := this.User
  362. if user == nil {
  363. br.Msg = "请重新登录"
  364. br.Ret = 408
  365. return
  366. }
  367. uid := user.UserId
  368. var req models.ArticleInterviewApplyReq
  369. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  370. if err != nil {
  371. br.Msg = "参数解析异常!"
  372. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  373. return
  374. }
  375. article, err := models.GetArticleDetailById(req.ArticleId)
  376. if err != nil {
  377. br.Msg = "获取纪要失败!"
  378. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  379. return
  380. }
  381. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  382. if err != nil {
  383. br.Msg = "获取数据失败!"
  384. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  385. return
  386. }
  387. resp := new(models.ArticleInterviewApplyResp)
  388. if count <= 0 {
  389. item := new(models.CygxInterviewApply)
  390. item.ArticleId = req.ArticleId
  391. item.UserId = uid
  392. item.CompanyId = user.CompanyId
  393. item.Status = "待邀请"
  394. item.Sort = 1
  395. item.ArticleTitle = article.Title
  396. item.CreateTime = time.Now()
  397. item.ModifyTime = time.Now()
  398. item.ArticleIdMd5 = article.ArticleIdMd5
  399. _, err = models.AddCygxInterviewApply(item)
  400. if err != nil {
  401. br.Msg = "申请失败"
  402. br.ErrMsg = "申请失败,Err:" + err.Error()
  403. return
  404. }
  405. br.Msg = "申请成功"
  406. resp.Status = 1
  407. //发送模板消息
  408. if user.CompanyId > 1 {
  409. mobile := user.Mobile
  410. if mobile == "" {
  411. mobile = user.Email
  412. }
  413. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  414. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  415. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  416. if openIpItem != nil && openIpItem.OpenId != "" {
  417. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  418. }
  419. }
  420. }
  421. } else {
  422. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  423. if err != nil {
  424. br.Msg = "取消申请失败"
  425. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  426. return
  427. }
  428. br.Msg = "已取消申请"
  429. resp.Status = 2
  430. if user.CompanyId > 1 {
  431. mobile := user.Mobile
  432. if mobile == "" {
  433. mobile = user.Email
  434. }
  435. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  436. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  437. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  438. if openIpItem != nil && openIpItem.OpenId != "" {
  439. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  440. }
  441. }
  442. }
  443. }
  444. br.Ret = 200
  445. br.Success = true
  446. br.Data = resp
  447. }
  448. // @Title 上传文章阅读时间
  449. // @Description 上传文章阅读时间接口
  450. // @Param request body models.AddStopTimeRep true "type json string"
  451. // @Success 200 {object} models.ArticleDetailResp
  452. // @router /addStopTime [post]
  453. func (this *ArticleController) AddStopTime() {
  454. br := new(models.BaseResponse).Init()
  455. defer func() {
  456. this.Data["json"] = br
  457. this.ServeJSON()
  458. }()
  459. user := this.User
  460. if user == nil {
  461. br.Msg = "请登录"
  462. br.ErrMsg = "请登录,用户信息为空"
  463. br.Ret = 408
  464. return
  465. }
  466. var req models.AddStopTimeRep
  467. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  468. if err != nil {
  469. br.Msg = "参数解析异常!"
  470. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  471. return
  472. }
  473. //uid := user.UserId
  474. articleId := req.ArticleId
  475. stopTime := req.StopTime
  476. outType := req.OutType
  477. source := req.Source
  478. if articleId <= 0 {
  479. br.Msg = "参数错误"
  480. br.ErrMsg = "参数错误"
  481. return
  482. }
  483. if stopTime == 0 {
  484. stopTime = 1
  485. }
  486. if outType != 2 {
  487. outType = 1
  488. }
  489. if source != "PC" {
  490. source = "MOBILE"
  491. }
  492. hasPermission := 0
  493. hasFree := 0
  494. havePower, err := services.GetArticleDetailUserPower(user)
  495. if err != nil {
  496. br.Msg = "获取信息失败"
  497. br.ErrMsg = "校验用户权限失败,Err:" + err.Error()
  498. return
  499. }
  500. if havePower {
  501. hasPermission = 1
  502. go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
  503. } else {
  504. hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
  505. if err != nil && err.Error() != utils.ErrNoRow() {
  506. br.Msg = "获取信息失败"
  507. br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error()
  508. return
  509. }
  510. }
  511. resp := new(models.ArticleDetailAddStopTimeRep)
  512. resp.HasPermission = hasPermission
  513. resp.HasFree = hasFree
  514. br.Ret = 200
  515. br.Success = true
  516. br.Msg = "操作成功"
  517. br.Data = resp
  518. }
  519. // @Title 文章带问
  520. // @Description 新增文章带问接口
  521. // @Param request body models.AddArticleAskRep true "type json string"
  522. // @Success Ret=200 新增成功
  523. // @router /askAdd [post]
  524. func (this *ArticleController) AskAdd() {
  525. br := new(models.BaseResponse).Init()
  526. defer func() {
  527. this.Data["json"] = br
  528. this.ServeJSON()
  529. }()
  530. user := this.User
  531. if user == nil {
  532. br.Msg = "请登录"
  533. br.ErrMsg = "请登录,SysUser Is Empty"
  534. br.Ret = 408
  535. return
  536. }
  537. var req models.AddArticleAskRep
  538. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  539. if err != nil {
  540. br.Msg = "参数解析异常!"
  541. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  542. return
  543. }
  544. if req.Content == "" {
  545. br.Msg = "建议内容不可为空"
  546. return
  547. }
  548. content := req.Content
  549. itemToken, err := services.WxGetToken()
  550. if err != nil {
  551. br.Msg = "GetWxAccessToken Err:" + err.Error()
  552. return
  553. }
  554. if itemToken.AccessToken == "" {
  555. br.Msg = "accessToken is empty"
  556. return
  557. }
  558. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  559. if err != nil {
  560. br.Msg = "内容校验失败!"
  561. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  562. return
  563. }
  564. if commerr.ErrCode != 0 {
  565. br.Msg = "内容违规,请重新提交!"
  566. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  567. return
  568. }
  569. articleId := req.ArticleId
  570. count, _ := models.GetArticleCountById(articleId)
  571. if count == 0 {
  572. br.Msg = "操作失败"
  573. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  574. return
  575. }
  576. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  577. if err != nil {
  578. br.Msg = "提交失败!"
  579. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  580. return
  581. }
  582. if companyDetail == nil {
  583. br.Msg = "提交失败!"
  584. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  585. return
  586. }
  587. item := new(models.CygxArticleAsk)
  588. item.UserId = user.UserId
  589. item.ArticleId = req.ArticleId
  590. item.CompanyId = user.CompanyId
  591. item.CompanyName = companyDetail.CompanyName
  592. item.CreateTime = time.Now()
  593. item.Mobile = user.Mobile
  594. item.Email = user.Email
  595. item.Content = content
  596. _, err = models.AddArticleAsk(item)
  597. if err != nil {
  598. br.Msg = "提交失败"
  599. br.ErrMsg = "提交失败,Err:" + err.Error()
  600. return
  601. }
  602. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  603. if err != nil {
  604. br.Msg = "获取信息失败"
  605. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  606. return
  607. }
  608. var mobile string
  609. if utils.RunMode == "release" {
  610. mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  611. } else {
  612. mobile = utils.WxMsgTemplateIdAskMsgMobile + "," + companyItem.Mobile
  613. }
  614. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  615. if err != nil {
  616. br.Msg = "提交失败"
  617. br.ErrMsg = "提交失败,Err:" + err.Error()
  618. return
  619. }
  620. detail, err := models.GetArticleDetailById(articleId)
  621. if err != nil {
  622. br.Msg = "获取信息失败"
  623. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  624. return
  625. }
  626. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  627. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  628. //go services.SendWxCategoryMsgWithAsk(user.CompanyName, user.RealName, companyItem.SellerName, time.Now().Format(utils.FormatDateTimeMinute2), content, openIdList, req.ArticleId)
  629. br.Ret = 200
  630. br.Success = true
  631. br.Msg = "提交成功"
  632. }
  633. // @Title 下载PDF打水印
  634. // @Description 下载PDF打水印接口
  635. // @Param ArticleId query int true "报告ID"
  636. // @Success 200 {object} models.ArticleDetailFileLink
  637. // @router /pdfwatermark [get]
  638. func (this *ArticleController) Pdfwatermark() {
  639. br := new(models.BaseResponse).Init()
  640. defer func() {
  641. this.Data["json"] = br
  642. this.ServeJSON()
  643. }()
  644. user := this.User
  645. if user == nil {
  646. br.Msg = "请登录"
  647. br.ErrMsg = "请登录,用户信息为空"
  648. br.Ret = 408
  649. return
  650. }
  651. uid := user.UserId
  652. articleId, err := this.GetInt("ArticleId")
  653. if articleId <= 0 {
  654. br.Msg = "文章不存在"
  655. br.ErrMsg = "文章不存在,文章ID错误"
  656. return
  657. }
  658. //缓存校验
  659. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid, "ArticleId_", articleId)
  660. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  661. if ttlTime > 0 && user.CompanyId != 16 {
  662. br.Msg = "下载失败,下载过于频繁"
  663. br.ErrMsg = "下载失败,下载过于频繁:mobile" + user.Mobile
  664. return
  665. }
  666. resp := new(models.ArticleDetailFileLink)
  667. detail := new(models.ArticleDetail)
  668. detail, err = models.GetArticleDetailById(articleId)
  669. if err != nil {
  670. br.Msg = "获取信息失败"
  671. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  672. return
  673. }
  674. fileLink := detail.FileLink
  675. if fileLink == "" {
  676. br.Msg = "下载失败"
  677. br.ErrMsg = "下载失败,报告链接不存在"
  678. return
  679. }
  680. mobile := user.Mobile
  681. if mobile == "" {
  682. mobile = user.Email
  683. }
  684. sliceLink := strings.Split(fileLink, "/")
  685. uploadDir := "static/pdf/"
  686. //判断文件夹是否存在,不存在则创建
  687. if !utils.FileIsExist(uploadDir) {
  688. err = os.MkdirAll(uploadDir, 0755)
  689. if err != nil {
  690. br.Msg = "下载失败"
  691. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  692. return
  693. }
  694. }
  695. var oldFile string
  696. var newFile string
  697. //获取PDF源文件名称
  698. pdfName := sliceLink[len(sliceLink)-1]
  699. pdfName = utils.MD5(pdfName) + ".pdf"
  700. oldFile = uploadDir + pdfName
  701. //判断PDF本地是否存在,不存在则保存到本地
  702. if !utils.FileIsExist(oldFile) {
  703. res, err := nhttp.Get(fileLink)
  704. if err != nil {
  705. br.Msg = "下载失败"
  706. br.ErrMsg = "获取源文件失败,Err:" + err.Error()
  707. return
  708. }
  709. defer res.Body.Close()
  710. // 获得get请求响应的reader对象
  711. reader := bufio.NewReaderSize(res.Body, 32*1024)
  712. file, err := os.Create(oldFile)
  713. if err != nil {
  714. br.Msg = "下载失败"
  715. br.ErrMsg = "保存源文件到本地失败,Err:" + err.Error()
  716. return
  717. }
  718. defer file.Close()
  719. //获得文件的writer对象
  720. writer := bufio.NewWriter(file)
  721. written, _ := io.Copy(writer, reader)
  722. fmt.Printf("Total length: %d", written)
  723. }
  724. newFile = uploadDir + "new_" + pdfName
  725. onTop := true
  726. wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, " op:.4, pos:c ,points:16 ", onTop, 1)
  727. if err != nil {
  728. br.Msg = "下载失败"
  729. br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
  730. return
  731. }
  732. err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
  733. if err != nil {
  734. //br.Msg = "下载失败"
  735. //br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
  736. resp.FileLink = fileLink
  737. br.Ret = 200
  738. br.Success = true
  739. br.Msg = "获取成功"
  740. br.Data = resp
  741. return
  742. }
  743. randStr := utils.GetRandStringNoSpecialChar(28)
  744. fileName := randStr + ".pdf"
  745. savePath := uploadDir + time.Now().Format("200601/20060102/")
  746. savePath += fileName
  747. //上传到阿里云
  748. err = services.UploadFileToAliyun(fileName, newFile, savePath)
  749. if err != nil {
  750. br.Msg = "下载失败"
  751. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  752. return
  753. }
  754. fileHost := "https://hzstatic.hzinsights.com/"
  755. resourceUrl := fileHost + savePath
  756. defer func() {
  757. os.Remove(newFile)
  758. }()
  759. utils.Rc.SetNX(cacheKey, user.Mobile, time.Minute*5)
  760. resp.FileLink = resourceUrl
  761. br.Ret = 200
  762. br.Success = true
  763. br.Msg = "获取成功"
  764. br.Data = resp
  765. }
  766. // @Title 约访专家
  767. // @Description 约访专家接口
  768. // @Param request body models.CygxArticleIdReq true "type json string"
  769. // @Success 200 {object}
  770. // @router /applyAppointmentExpert [post]
  771. func (this *ArticleController) ApplyAppointmentExpert() {
  772. br := new(models.BaseResponse).Init()
  773. defer func() {
  774. this.Data["json"] = br
  775. this.ServeJSON()
  776. }()
  777. user := this.User
  778. if user == nil {
  779. br.Msg = "请登录"
  780. br.ErrMsg = "请登录,用户信息为空"
  781. br.Ret = 408
  782. return
  783. }
  784. fmt.Println(user)
  785. var req models.CygxArticleIdReq
  786. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  787. if err != nil {
  788. br.Msg = "参数解析异常!"
  789. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  790. return
  791. }
  792. articleId := req.ArticleId
  793. var condition string
  794. var pars []interface{}
  795. condition += ` AND article_id =? AND user_id = ? `
  796. pars = append(pars, articleId, user.UserId)
  797. total, err := models.GetCygxArticleApplyAppointmentExpertCount(condition, pars)
  798. if err != nil {
  799. br.Msg = "约访专家失败"
  800. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  801. return
  802. }
  803. if total > 0 {
  804. br.Msg = "您已提交申请,请勿重复提交。"
  805. return
  806. }
  807. err = services.AddArticleApplyAppointmentExpert(user, articleId)
  808. if err != nil {
  809. br.Msg = "约访专家失败"
  810. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  811. return
  812. }
  813. services.SendArticleApplyAppointmentExpertTemplateMsg(user, articleId)
  814. br.Ret = 200
  815. br.Success = true
  816. br.Msg = "操作成功"
  817. }
  818. // @Title 获取上海策略平台报告详情
  819. // @Description 获取上海策略平台报告详情接口
  820. // @Param ArticleId query int true "报告ID"
  821. // @Success 200 {object} models.ArticleDetailResp
  822. // @router /detail_vmp [get]
  823. func (this *ArticleController) DetailVmp() {
  824. br := new(models.BaseResponse).Init()
  825. defer func() {
  826. this.Data["json"] = br
  827. this.ServeJSON()
  828. }()
  829. user := this.User
  830. if user == nil {
  831. br.Msg = "请登录"
  832. br.ErrMsg = "请登录,用户信息为空"
  833. br.Ret = 408
  834. return
  835. }
  836. articleId, _ := this.GetInt("ArticleId")
  837. var clueApiUrl string
  838. clueApiUrl = fmt.Sprint(utils.ApiUrl, "articles/", articleId)
  839. authorization := utils.ApiAuthorization
  840. body, err := services.PublicGetDate(clueApiUrl, authorization)
  841. if err != nil {
  842. br.Msg = "约访专家失败"
  843. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  844. return
  845. }
  846. var articleResultDate models.ArticleDetailResultApi
  847. err = json.Unmarshal(body, &articleResultDate)
  848. if err != nil {
  849. br.Msg = "约访专家失败"
  850. br.ErrMsg = "约访专家失败,Err:" + err.Error()
  851. return
  852. }
  853. br.Ret = 200
  854. br.Success = true
  855. br.Msg = "获取成功"
  856. br.Data = articleResultDate
  857. }