article.go 27 KB

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