article.go 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719
  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_cygx/models"
  15. "hongze/hongze_cygx/services"
  16. "hongze/hongze_cygx/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. // @Success 200 {object} models.ArticleDetailResp
  37. // @router /detail [get]
  38. func (this *ArticleController) Detail() {
  39. br := new(models.BaseResponse).Init()
  40. defer func() {
  41. this.Data["json"] = br
  42. this.ServeJSON()
  43. }()
  44. user := this.User
  45. if user == nil {
  46. br.Msg = "请登录"
  47. br.ErrMsg = "请登录,用户信息为空"
  48. br.Ret = 408
  49. return
  50. }
  51. uid := user.UserId
  52. articleId, err := this.GetInt("ArticleId")
  53. isSendWx, _ := this.GetInt("IsSendWx")
  54. if articleId <= 0 {
  55. br.Msg = "文章不存在"
  56. br.ErrMsg = "文章不存在,文章ID错误"
  57. return
  58. }
  59. detail := new(models.ArticleDetail)
  60. hasPermission := 0
  61. var haveResearch bool
  62. //判断是否已经申请过
  63. applyCount, err := models.GetApplyRecordCount(uid)
  64. if err != nil && err.Error() != utils.ErrNoRow() {
  65. br.Msg = "获取信息失败"
  66. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  67. return
  68. }
  69. resp := new(models.ArticleDetailResp)
  70. detail, err = models.GetArticleDetailById(articleId)
  71. if err != nil {
  72. br.Msg = "获取信息失败"
  73. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  74. return
  75. }
  76. lyjhTypeMap, _ := services.GetLyjhTypeMap()
  77. if _, ok := lyjhTypeMap[detail.CategoryId]; ok {
  78. detail.IsRoadShow = true
  79. }
  80. // 高毅资产的联系人,有权限的行业也不能查看报告详情页。提示无权限页面
  81. if detail.ArticleTypeId == 0 && user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
  82. _, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
  83. if err != nil {
  84. br.Msg = "获取信息失败"
  85. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  86. return
  87. }
  88. resp.PopupMsg = popupMsg
  89. resp.HasPermission = 3
  90. resp.SellerName = sellerName
  91. resp.SellerMobile = sellerMobile
  92. detail.Body = ""
  93. detail.Abstract = ""
  94. detail.BodyText = ""
  95. detail.SellerName = sellerName
  96. detail.SellerMobile = sellerMobile
  97. resp.Detail = detail
  98. br.Ret = 200
  99. br.Success = true
  100. br.Msg = "获取成功"
  101. br.Data = resp
  102. return
  103. }
  104. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
  105. detail.IsCollect = articleCollectMap[detail.ArticleId]
  106. if isSendWx == 1 {
  107. var condition string
  108. var pars []interface{}
  109. pars = make([]interface{}, 0)
  110. condition = ` AND article_id = ? `
  111. reportMappingMap, _ := services.GetReportMappingMap()
  112. if reportMappingMap[detail.CategoryId] {
  113. chooseCategoryMap, _ := services.GetChooseCategoryMap(user)
  114. detail.IsShowFollowButton = true
  115. detail.IsFollowButton = chooseCategoryMap[detail.CategoryId]
  116. } else {
  117. pars = append(pars, articleId)
  118. industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
  119. if err != nil && err.Error() != utils.ErrNoRow() {
  120. br.Msg = "获取信息失败"
  121. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  122. return
  123. }
  124. if len(industrialList) > 0 {
  125. industryUserFollowMap, err := services.GetIndustryUserFollowMap(user)
  126. if err != nil {
  127. br.Msg = "获取信息失败"
  128. br.ErrMsg = "GetActivitySignupResp,Err:" + err.Error()
  129. return
  130. }
  131. for _, v := range industrialList {
  132. if industryUserFollowMap[v.IndustrialManagementId] {
  133. detail.IsFollowButton = true
  134. }
  135. }
  136. detail.IsShowFollowButton = true
  137. }
  138. }
  139. }
  140. //是否属于专项调研报告
  141. if detail.SubCategoryName == "专项调研" {
  142. detail.IsSpecialArticle = true
  143. havePower, err := services.GetSpecialArticleDetailUserPower(user, detail)
  144. if err != nil {
  145. br.Msg = "获取信息失败"
  146. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  147. return
  148. }
  149. resp.IsSpecialArticle = true
  150. if !havePower {
  151. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
  152. if err != nil {
  153. br.Msg = "获取信息失败"
  154. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  155. return
  156. }
  157. resp.PopupMsg = popupMsg
  158. resp.HasPermission = hasPermission
  159. resp.SellerName = sellerName
  160. resp.SellerMobile = sellerMobile
  161. detail.Body = ""
  162. detail.Abstract = ""
  163. detail.BodyText = ""
  164. detail.SellerName = sellerName
  165. detail.SellerMobile = sellerMobile
  166. resp.Detail = detail
  167. br.Ret = 200
  168. br.Success = true
  169. br.Msg = "获取成功"
  170. br.Data = resp
  171. return
  172. }
  173. }
  174. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  175. if user.CompanyId > 1 {
  176. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  177. if err != nil {
  178. br.Msg = "获取信息失败"
  179. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  180. return
  181. }
  182. detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
  183. detail.Body = html.UnescapeString(detail.Body)
  184. 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)
  185. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  186. //detail.Abstract = html.UnescapeString(detail.Abstract)
  187. detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  188. if companyPermission == "" {
  189. if applyCount > 0 {
  190. hasPermission = 5
  191. } else {
  192. hasPermission = 2
  193. }
  194. goto Loop
  195. } else {
  196. var articlePermissionPermissionName string
  197. if detail.CategoryId > 0 {
  198. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  199. if err != nil {
  200. br.Msg = "获取信息失败"
  201. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  202. return
  203. }
  204. if articlePermission == nil {
  205. br.Msg = "获取信息失败"
  206. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  207. return
  208. }
  209. articlePermissionPermissionName = articlePermission.PermissionName
  210. } else {
  211. articlePermissionPermissionName = detail.CategoryName
  212. }
  213. var hasPersion bool
  214. slice := strings.Split(articlePermissionPermissionName, ",")
  215. for _, v := range slice {
  216. if strings.Contains(companyPermission, v) {
  217. hasPersion = true
  218. }
  219. }
  220. if strings.Contains(detail.CategoryName, "研选") {
  221. detail.IsResearch = true
  222. }
  223. userType, _, err := services.GetUserType(user.CompanyId)
  224. if err != nil {
  225. br.Msg = "获取信息失败"
  226. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  227. return
  228. }
  229. if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
  230. hasPersion = false
  231. }
  232. if detail.IsReport == 1 {
  233. detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
  234. if err != nil && err.Error() != utils.ErrNoRow() {
  235. br.Msg = "获取信息失败"
  236. br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
  237. return
  238. }
  239. permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  240. if err != nil {
  241. br.Msg = "获取信息失败"
  242. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  243. return
  244. }
  245. if detailCategory != nil {
  246. if detailCategory.PermissionType == 1 {
  247. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
  248. hasPersion = false
  249. }
  250. } else if detailCategory.PermissionType == 2 {
  251. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
  252. hasPersion = false
  253. }
  254. }
  255. }
  256. }
  257. if hasPersion {
  258. hasPermission = 1
  259. historyRecord := new(models.CygxArticleHistoryRecord)
  260. historyRecord.UserId = uid
  261. historyRecord.ArticleId = articleId
  262. historyRecord.CreateTime = time.Now()
  263. historyRecord.Mobile = user.Mobile
  264. historyRecord.Email = user.Email
  265. historyRecord.CompanyId = user.CompanyId
  266. historyRecord.CompanyName = user.CompanyName
  267. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  268. if recordCount == 0 {
  269. go models.AddCygxArticleHistoryRecord(historyRecord)
  270. } else {
  271. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  272. if err != nil {
  273. br.Msg = "获取信息失败"
  274. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  275. return
  276. }
  277. if detailNew.StopTime > 0 {
  278. go models.AddCygxArticleHistoryRecord(historyRecord)
  279. }
  280. }
  281. //30分钟之内阅读同一篇文章不错二次推送
  282. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  283. if !utils.Rc.IsExist(key) {
  284. go services.ArticleUserRemind(user, detail, 1)
  285. utils.Rc.Put(key, 1, 30*time.Second)
  286. }
  287. } else { //无该行业权限
  288. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  289. if err == nil && companyDetail.ProductId == 1 {
  290. hasPermission = 2
  291. } else {
  292. hasPermission = 3
  293. }
  294. }
  295. if hasPermission == 1 {
  296. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  297. if !utils.Rc.IsExist(key) {
  298. //新增浏览记录
  299. record := new(models.CygxArticleViewRecord)
  300. record.UserId = uid
  301. record.ArticleId = articleId
  302. record.CreateTime = time.Now()
  303. record.Mobile = user.Mobile
  304. record.Email = user.Email
  305. record.CompanyId = user.CompanyId
  306. record.CompanyName = user.CompanyName
  307. go models.AddCygxArticleViewRecord(record)
  308. utils.Rc.Put(key, 1, 5*time.Second)
  309. models.ModifyReportLastViewTime(uid)
  310. }
  311. }
  312. }
  313. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  314. if err != nil && err.Error() != utils.ErrNoRow() {
  315. br.Msg = "获取信息失败"
  316. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  317. return
  318. }
  319. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  320. detail.IsInterviewApply = true
  321. detail.InterviewApplyStatus = interviewApplyItem.Status
  322. }
  323. //获取销售手机号
  324. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  325. if err != nil && err.Error() != utils.ErrNoRow() {
  326. br.Msg = "获取信息失败"
  327. br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  328. return
  329. }
  330. if sellerItem != nil {
  331. detail.SellerMobile = sellerItem.Mobile
  332. detail.SellerName = sellerItem.RealName
  333. }
  334. sellerList, err := models.GetSellerList(articleId)
  335. if err != nil {
  336. br.Msg = "获取信息失败"
  337. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  338. return
  339. }
  340. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  341. strnum := strings.Index(detail.SellerAndMobile, "-")
  342. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  343. if strnum > 0 {
  344. nickName := detail.SellerAndMobile[0:strnum]
  345. sellerAndMobile := &models.SellerRep{
  346. SellerMobile: "",
  347. SellerName: nickName,
  348. }
  349. sellerList = append(sellerList, sellerAndMobile)
  350. }
  351. }
  352. detail.SellerList = sellerList
  353. //作者头像
  354. if detail.DepartmentId > 0 {
  355. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  356. if err == nil {
  357. detail.DepartmentImgUrl = departmentDetail.ImgUrl
  358. }
  359. }
  360. } else { //潜在客户
  361. if applyCount > 0 {
  362. hasPermission = 5
  363. } else {
  364. hasPermission = 4
  365. }
  366. }
  367. Loop:
  368. if hasPermission != 1 {
  369. detail.Body = ""
  370. detail.BodyText = ""
  371. } else {
  372. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  373. if err != nil {
  374. br.Msg = "获取信息失败"
  375. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  376. return
  377. }
  378. detail.FollowNum = articleFollowdetail.DNum
  379. detail.CollectionNum = articleFollowdetail.AcNum
  380. if articleFollowdetail.MdNum > 0 {
  381. detail.IsFollow = true
  382. }
  383. if detail.IsSummary == 1 {
  384. detail.IsBelongSummary = true
  385. }
  386. if detail.IsReport == 1 {
  387. detail.IsBelongReport = true
  388. }
  389. haveResearch = true
  390. }
  391. if hasPermission == 5 {
  392. companyPermissionNoStatus, err := models.GetCompanyPermissionByUserNoStatus(user.CompanyId)
  393. if err != nil {
  394. br.Msg = "获取信息失败"
  395. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  396. return
  397. }
  398. if companyPermissionNoStatus != "" {
  399. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  400. if err != nil && err.Error() != utils.ErrNoRow() {
  401. br.Msg = "获取信息失败"
  402. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  403. return
  404. }
  405. if sellerItemQy != nil {
  406. hasPermission = 3
  407. detail.SellerMobile = sellerItemQy.Mobile
  408. detail.SellerName = sellerItemQy.RealName
  409. }
  410. }
  411. }
  412. if hasPermission == 2 || hasPermission == 4 {
  413. //获取销售手机号
  414. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  415. if err != nil && err.Error() != utils.ErrNoRow() {
  416. br.Msg = "获取信息失败"
  417. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  418. return
  419. }
  420. if sellerItemQy != nil {
  421. hasPermission = 3
  422. detail.SellerMobile = sellerItemQy.Mobile
  423. detail.SellerName = sellerItemQy.RealName
  424. }
  425. }
  426. if detail.ArticleId < utils.SummaryArticleId {
  427. if user.Mobile != "" {
  428. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
  429. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
  430. } else {
  431. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
  432. }
  433. detail.IsNeedJump = true
  434. }
  435. // 处理研选下面的路演精华 的报告链接是否跳转
  436. if hasPermission == 1 && detail.ArticleId > utils.SummaryArticleId && detail.ArticleTypeId > 0 {
  437. //detail.PublishDate = utils.TimeRemoveHms2(detail.PublishDate)
  438. if detail.ReportLink != "" {
  439. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
  440. detail.ReportLink += "?token=" + chartUserTokenByMobile
  441. }
  442. }
  443. resp.HasPermission = hasPermission
  444. resp.HaveResearch = haveResearch
  445. resp.Detail = detail
  446. if user.Mobile != "" {
  447. resp.Mobile = user.Mobile
  448. } else {
  449. resp.Mobile = user.Email
  450. }
  451. br.Ret = 200
  452. br.Success = true
  453. br.Msg = "获取成功"
  454. br.Data = resp
  455. }
  456. // @Title 收藏
  457. // @Description 收藏
  458. // @Param request body models.ArticleCollectReq true "type json string"
  459. // @Success 200 {object} models.FontsCollectResp
  460. // @router /collect [post]
  461. func (this *ArticleController) ArticleCollect() {
  462. br := new(models.BaseResponse).Init()
  463. defer func() {
  464. this.Data["json"] = br
  465. this.ServeJSON()
  466. }()
  467. user := this.User
  468. if user == nil {
  469. br.Msg = "请重新登录"
  470. br.Ret = 408
  471. return
  472. }
  473. uid := user.UserId
  474. var req models.ArticleCollectReq
  475. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  476. if err != nil {
  477. br.Msg = "参数解析异常!"
  478. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  479. return
  480. }
  481. articleId := req.ArticleId
  482. detail, err := models.GetArticleDetailById(articleId)
  483. if err != nil {
  484. br.Msg = "获取信息失败"
  485. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  486. return
  487. }
  488. count, err := models.GetArticleCollectCount(uid, articleId)
  489. if err != nil {
  490. br.Msg = "获取数据失败!"
  491. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  492. return
  493. }
  494. resp := new(models.ArticleCollectResp)
  495. if count <= 0 {
  496. item := new(models.CygxArticleCollect)
  497. item.ArticleId = req.ArticleId
  498. item.UserId = uid
  499. item.CreateTime = time.Now()
  500. item.Mobile = user.Mobile
  501. item.Email = user.Email
  502. item.CompanyId = user.CompanyId
  503. item.CompanyName = user.CompanyName
  504. item.RealName = user.RealName
  505. _, err = models.AddCygxArticleCollect(item)
  506. if err != nil {
  507. br.Msg = "收藏失败"
  508. br.ErrMsg = "收藏失败,Err:" + err.Error()
  509. return
  510. }
  511. br.Msg = "收藏成功"
  512. resp.Status = 1
  513. // 文章收藏消息发送
  514. go services.ArticleUserRemind(user, detail, 2)
  515. } else {
  516. err = models.RemoveArticleCollect(uid, articleId)
  517. if err != nil {
  518. br.Msg = "取消收藏失败"
  519. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  520. return
  521. }
  522. br.Msg = "已取消收藏"
  523. resp.Status = 2
  524. }
  525. collectTotal, err := models.GetArticleCollectUsersCount(articleId)
  526. if err != nil {
  527. br.Msg = "获取数据失败"
  528. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  529. return
  530. }
  531. resp.CollectCount = collectTotal
  532. br.Ret = 200
  533. br.Success = true
  534. br.Data = resp
  535. }
  536. // @Title 访谈申请
  537. // @Description 访谈申请
  538. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  539. // @Success 200 {object} models.FontsCollectResp
  540. // @router /interview/apply [post]
  541. func (this *ArticleController) InterviewApply() {
  542. br := new(models.BaseResponse).Init()
  543. defer func() {
  544. this.Data["json"] = br
  545. this.ServeJSON()
  546. }()
  547. user := this.User
  548. if user == nil {
  549. br.Msg = "请重新登录"
  550. br.Ret = 408
  551. return
  552. }
  553. uid := user.UserId
  554. var req models.ArticleInterviewApplyReq
  555. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  556. if err != nil {
  557. br.Msg = "参数解析异常!"
  558. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  559. return
  560. }
  561. article, err := models.GetArticleDetailById(req.ArticleId)
  562. if err != nil {
  563. br.Msg = "获取纪要失败!"
  564. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  565. return
  566. }
  567. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  568. if err != nil {
  569. br.Msg = "获取数据失败!"
  570. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  571. return
  572. }
  573. resp := new(models.ArticleInterviewApplyResp)
  574. if count <= 0 {
  575. item := new(models.CygxInterviewApply)
  576. item.ArticleId = req.ArticleId
  577. item.UserId = uid
  578. item.CompanyId = user.CompanyId
  579. item.Status = "待邀请"
  580. item.Sort = 1
  581. item.ArticleTitle = article.Title
  582. item.CreateTime = time.Now()
  583. item.ModifyTime = time.Now()
  584. item.ArticleIdMd5 = article.ArticleIdMd5
  585. _, err = models.AddCygxInterviewApply(item)
  586. if err != nil {
  587. br.Msg = "申请失败"
  588. br.ErrMsg = "申请失败,Err:" + err.Error()
  589. return
  590. }
  591. br.Msg = "申请成功"
  592. resp.Status = 1
  593. //发送模板消息
  594. if user.CompanyId > 1 {
  595. mobile := user.Mobile
  596. if mobile == "" {
  597. mobile = user.Email
  598. }
  599. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  600. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  601. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  602. if openIpItem != nil && openIpItem.OpenId != "" {
  603. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  604. }
  605. }
  606. }
  607. } else {
  608. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  609. if err != nil {
  610. br.Msg = "取消申请失败"
  611. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  612. return
  613. }
  614. br.Msg = "已取消申请"
  615. resp.Status = 2
  616. if user.CompanyId > 1 {
  617. mobile := user.Mobile
  618. if mobile == "" {
  619. mobile = user.Email
  620. }
  621. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  622. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  623. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  624. if openIpItem != nil && openIpItem.OpenId != "" {
  625. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  626. }
  627. }
  628. }
  629. }
  630. br.Ret = 200
  631. br.Success = true
  632. br.Data = resp
  633. }
  634. // @Title 获取报告详情
  635. // @Description 获取报告详情接口
  636. // @Param ArticleIdMd5 query int true "报告ID"
  637. // @Success 200 {object} models.ArticleDetailResp
  638. // @router /look/detail [get]
  639. func (this *ArticleControllerMobile) DetailMd5() {
  640. br := new(models.BaseResponse).Init()
  641. defer func() {
  642. this.Data["json"] = br
  643. this.ServeJSON()
  644. }()
  645. user := this.User
  646. if user == nil {
  647. br.Msg = "请登录"
  648. br.ErrMsg = "请登录,用户信息为空"
  649. br.Ret = 408
  650. return
  651. }
  652. uid := user.UserId
  653. articleIdMd5 := this.GetString("ArticleIdMd5")
  654. if articleIdMd5 == "" {
  655. br.Msg = "参数错误"
  656. br.ErrMsg = "参数错误"
  657. return
  658. }
  659. resp := new(models.ArticleDetailResp)
  660. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  661. if err != nil {
  662. br.Msg = "获取信息失败"
  663. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  664. return
  665. }
  666. articleId := detail.ArticleId
  667. detail.Body = html.UnescapeString(detail.Body)
  668. hasPermission := 2
  669. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  670. if user.CompanyId > 1 {
  671. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  672. if err != nil {
  673. br.Msg = "获取信息失败"
  674. br.ErrMsg = "获取公司权限失败,Err:" + err.Error()
  675. return
  676. }
  677. detail.Body = html.UnescapeString(detail.Body)
  678. 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)
  679. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  680. detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
  681. if companyPermission == "" {
  682. hasPermission = 2
  683. } else {
  684. var articlePermissionPermissionName string
  685. if detail.CategoryId > 0 {
  686. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  687. if err != nil {
  688. br.Msg = "获取信息失败"
  689. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + articleIdMd5
  690. return
  691. }
  692. if articlePermission == nil {
  693. br.Msg = "获取信息失败"
  694. br.ErrMsg = "报告权限不存在,Err:" + articleIdMd5
  695. return
  696. }
  697. articlePermissionPermissionName = articlePermission.PermissionName
  698. } else {
  699. articlePermissionPermissionName = detail.CategoryName
  700. }
  701. var hasPersion bool
  702. slice := strings.Split(articlePermissionPermissionName, ",")
  703. for _, v := range slice {
  704. if strings.Contains(companyPermission, v) {
  705. hasPersion = true
  706. }
  707. }
  708. userType, _, err := services.GetUserType(user.CompanyId)
  709. if err != nil {
  710. br.Msg = "获取信息失败"
  711. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  712. return
  713. }
  714. if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
  715. hasPersion = false
  716. }
  717. if detail.IsReport == 1 {
  718. detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
  719. if err != nil && err.Error() != utils.ErrNoRow() {
  720. br.Msg = "获取信息失败"
  721. br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
  722. return
  723. }
  724. permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  725. if err != nil {
  726. br.Msg = "获取信息失败"
  727. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  728. return
  729. }
  730. if detailCategory != nil {
  731. if detailCategory.PermissionType == 1 {
  732. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
  733. hasPersion = false
  734. }
  735. } else if detailCategory.PermissionType == 2 {
  736. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
  737. hasPersion = false
  738. }
  739. }
  740. }
  741. }
  742. if hasPersion {
  743. hasPermission = 1
  744. record := new(models.CygxArticleHistoryRecordNewpv)
  745. record.UserId = uid
  746. record.ArticleId = articleId
  747. record.CreateTime = time.Now()
  748. record.ModifyTime = time.Now()
  749. record.Mobile = user.Mobile
  750. record.Email = user.Email
  751. record.CompanyId = user.CompanyId
  752. record.CompanyName = user.CompanyName
  753. //新增浏览记录
  754. go models.AddCygxArticleViewRecordNewpv(record)
  755. //30分钟之内阅读同一篇文章不错二次推送
  756. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  757. if !utils.Rc.IsExist(key) {
  758. go services.ArticleUserRemind(user, detail, 1)
  759. utils.Rc.Put(key, 1, 30*time.Second)
  760. }
  761. }
  762. if hasPermission == 1 {
  763. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  764. if !utils.Rc.IsExist(key) {
  765. //新增浏览记录
  766. record := new(models.CygxArticleViewRecord)
  767. record.UserId = uid
  768. record.ArticleId = articleId
  769. record.CreateTime = time.Now()
  770. record.Mobile = user.Mobile
  771. record.Email = user.Email
  772. record.CompanyId = user.CompanyId
  773. record.CompanyName = user.CompanyName
  774. go models.AddCygxArticleViewRecord(record)
  775. utils.Rc.Put(key, 1, 5*time.Second)
  776. models.ModifyReportLastViewTime(uid)
  777. }
  778. }
  779. }
  780. //作者头像
  781. if detail.DepartmentId > 0 {
  782. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  783. if err == nil {
  784. detail.DepartmentImgUrl = departmentDetail.ImgUrl
  785. detail.NickName = departmentDetail.NickName
  786. }
  787. }
  788. }
  789. detail.SellerAndMobile = "" //业务需要强制处理为空
  790. resp.HasPermission = hasPermission
  791. if hasPermission == 1 {
  792. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  793. resp.Detail = detail
  794. } else {
  795. if user.Mobile != "" {
  796. resp.Mobile = user.Mobile
  797. } else {
  798. resp.Mobile = user.Email
  799. }
  800. }
  801. br.Ret = 200
  802. br.Success = true
  803. br.Msg = "获取成功"
  804. br.Data = resp
  805. }
  806. // @Title 上传文章阅读时间
  807. // @Description 上传文章阅读时间接口
  808. // @Param request body models.AddStopTimeRep true "type json string"
  809. // @Success 200 {object} models.ArticleDetailResp
  810. // @router /addStopTime [post]
  811. func (this *ArticleController) AddStopTime() {
  812. br := new(models.BaseResponse).Init()
  813. defer func() {
  814. this.Data["json"] = br
  815. this.ServeJSON()
  816. }()
  817. user := this.User
  818. if user == nil {
  819. br.Msg = "请登录"
  820. br.ErrMsg = "请登录,用户信息为空"
  821. br.Ret = 408
  822. return
  823. }
  824. var req models.AddStopTimeRep
  825. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  826. if err != nil {
  827. br.Msg = "参数解析异常!"
  828. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  829. return
  830. }
  831. uid := user.UserId
  832. articleId := req.ArticleId
  833. stopTime := req.StopTime
  834. outType := req.OutType
  835. source := req.Source
  836. if articleId <= 0 {
  837. br.Msg = "参数错误"
  838. br.ErrMsg = "参数错误"
  839. return
  840. }
  841. if stopTime == 0 {
  842. stopTime = 1
  843. }
  844. if outType != 2 {
  845. outType = 1
  846. }
  847. if source != "PC" {
  848. source = "MOBILE"
  849. }
  850. detail := new(models.ArticleDetail)
  851. hasPermission := 0
  852. hasFree := 0
  853. //判断是否已经申请过
  854. applyCount, err := models.GetApplyRecordCount(uid)
  855. if err != nil && err.Error() != utils.ErrNoRow() {
  856. br.Msg = "获取信息失败"
  857. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  858. return
  859. }
  860. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  861. if user.CompanyId > 1 {
  862. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  863. if err != nil {
  864. br.Msg = "获取信息失败"
  865. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  866. return
  867. }
  868. detail, err = models.GetArticleDetailById(articleId)
  869. if err != nil {
  870. br.Msg = "获取信息失败"
  871. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  872. return
  873. }
  874. if companyPermission == "" {
  875. if applyCount > 0 {
  876. hasPermission = 5
  877. } else {
  878. hasPermission = 2
  879. }
  880. hasFree = 2
  881. goto Loop
  882. } else {
  883. hasFree = 1
  884. var articlePermissionPermissionName string
  885. if detail.CategoryId > 0 {
  886. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  887. if err != nil {
  888. br.Msg = "获取信息失败"
  889. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  890. return
  891. }
  892. if articlePermission == nil {
  893. br.Msg = "获取信息失败"
  894. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  895. return
  896. }
  897. articlePermissionPermissionName = articlePermission.PermissionName
  898. } else {
  899. articlePermissionPermissionName = detail.CategoryName
  900. }
  901. var hasPersion bool
  902. slice := strings.Split(articlePermissionPermissionName, ",")
  903. for _, v := range slice {
  904. if strings.Contains(companyPermission, v) {
  905. hasPersion = true
  906. }
  907. }
  908. if hasPersion {
  909. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  910. if err == nil {
  911. hasPermission = 1
  912. historyRecord := new(models.AddStopTimeNewRep)
  913. historyRecord.StopTime = detailNew.StopTime + stopTime
  914. historyRecord.Id = detailNew.Id
  915. historyRecord.OutType = outType
  916. go models.UpdateArticleStopTime(historyRecord)
  917. }
  918. //不统计本公司的阅读记录、正常退出的不做时间差统计
  919. if stopTime > 3 {
  920. key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
  921. record := new(models.CygxArticleHistoryRecordNewpv)
  922. record.UserId = uid
  923. record.ArticleId = articleId
  924. record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  925. record.ModifyTime = time.Now()
  926. record.Mobile = user.Mobile
  927. record.Email = user.Email
  928. record.CompanyId = user.CompanyId
  929. record.CompanyName = user.CompanyName
  930. record.StopTime = stopTime
  931. record.OutType = outType
  932. record.Source = source
  933. if !utils.Rc.IsExist(key) || outType != 2 {
  934. //新增浏览记录
  935. go models.AddCygxArticleViewRecordNewpv(record)
  936. recordRedis := new(services.ReportViewRecord)
  937. recordRedis.UserId = user.UserId
  938. recordRedis.ReportId = articleId
  939. recordRedis.Mobile = user.Mobile
  940. recordRedis.Email = user.Email
  941. recordRedis.RealName = user.RealName
  942. recordRedis.CompanyName = user.CompanyName
  943. recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  944. go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
  945. } else {
  946. go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
  947. }
  948. utils.Rc.Put(key, 1, 10*time.Minute)
  949. }
  950. models.ModifyReportLastViewTime(uid)
  951. } else { //无该行业权限
  952. hasPermission = 3
  953. }
  954. }
  955. } else { //潜在客户
  956. if applyCount > 0 {
  957. hasPermission = 5
  958. } else {
  959. hasPermission = 4
  960. }
  961. }
  962. Loop:
  963. resp := new(models.ArticleDetailAddStopTimeRep)
  964. resp.HasPermission = hasPermission
  965. resp.HasFree = hasFree
  966. br.Ret = 200
  967. br.Success = true
  968. br.Msg = "操作成功"
  969. br.Data = resp
  970. }
  971. // @Title 文章带问
  972. // @Description 新增文章带问接口
  973. // @Param request body models.AddArticleAskRep true "type json string"
  974. // @Success Ret=200 新增成功
  975. // @router /askAdd [post]
  976. func (this *ArticleController) AskAdd() {
  977. br := new(models.BaseResponse).Init()
  978. defer func() {
  979. this.Data["json"] = br
  980. this.ServeJSON()
  981. }()
  982. user := this.User
  983. if user == nil {
  984. br.Msg = "请登录"
  985. br.ErrMsg = "请登录,SysUser Is Empty"
  986. br.Ret = 408
  987. return
  988. }
  989. var req models.AddArticleAskRep
  990. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  991. if err != nil {
  992. br.Msg = "参数解析异常!"
  993. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  994. return
  995. }
  996. if req.Content == "" {
  997. br.Msg = "建议内容不可为空"
  998. return
  999. }
  1000. content := req.Content
  1001. itemToken, err := services.WxGetToken()
  1002. if err != nil {
  1003. br.Msg = "GetWxAccessToken Err:" + err.Error()
  1004. return
  1005. }
  1006. if itemToken.AccessToken == "" {
  1007. br.Msg = "accessToken is empty"
  1008. return
  1009. }
  1010. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  1011. if err != nil {
  1012. br.Msg = "内容校验失败!"
  1013. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  1014. return
  1015. }
  1016. if commerr.ErrCode != 0 {
  1017. br.Msg = "内容违规,请重新提交!"
  1018. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  1019. return
  1020. }
  1021. articleId := req.ArticleId
  1022. count, _ := models.GetArticleCountById(articleId)
  1023. if count == 0 {
  1024. br.Msg = "操作失败"
  1025. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  1026. return
  1027. }
  1028. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  1029. if err != nil {
  1030. br.Msg = "提交失败!"
  1031. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1032. return
  1033. }
  1034. if companyDetail == nil {
  1035. br.Msg = "提交失败!"
  1036. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  1037. return
  1038. }
  1039. item := new(models.CygxArticleAsk)
  1040. item.UserId = user.UserId
  1041. item.ArticleId = req.ArticleId
  1042. item.CompanyId = user.CompanyId
  1043. item.CompanyName = companyDetail.CompanyName
  1044. item.CreateTime = time.Now()
  1045. item.Mobile = user.Mobile
  1046. item.Email = user.Email
  1047. item.Content = content
  1048. _, err = models.AddArticleAsk(item)
  1049. if err != nil {
  1050. br.Msg = "提交失败"
  1051. br.ErrMsg = "提交失败,Err:" + err.Error()
  1052. return
  1053. }
  1054. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  1055. if err != nil {
  1056. br.Msg = "获取信息失败"
  1057. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  1058. return
  1059. }
  1060. var mobile string
  1061. if utils.RunMode == "release" {
  1062. //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  1063. mobile = utils.WxMsgTemplateIdAskMsgMobileAll
  1064. } else {
  1065. mobile = utils.WxMsgTemplateIdAskMsgMobile
  1066. }
  1067. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  1068. if err != nil {
  1069. br.Msg = "提交失败"
  1070. br.ErrMsg = "提交失败,Err:" + err.Error()
  1071. return
  1072. }
  1073. detail, err := models.GetArticleDetailById(articleId)
  1074. if err != nil {
  1075. br.Msg = "获取信息失败"
  1076. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1077. return
  1078. }
  1079. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  1080. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  1081. br.Ret = 200
  1082. br.Success = true
  1083. br.Msg = "提交成功"
  1084. }
  1085. // @Title 下载PDF打水印
  1086. // @Description 下载PDF打水印接口
  1087. // @Param ArticleId query int true "报告ID"
  1088. // @Success 200 {object} models.ArticleDetailFileLink
  1089. // @router /pdfwatermark [get]
  1090. func (this *ArticleController) Pdfwatermark() {
  1091. br := new(models.BaseResponse).Init()
  1092. defer func() {
  1093. this.Data["json"] = br
  1094. this.ServeJSON()
  1095. }()
  1096. user := this.User
  1097. if user == nil {
  1098. br.Msg = "请登录"
  1099. br.ErrMsg = "请登录,用户信息为空"
  1100. br.Ret = 408
  1101. return
  1102. }
  1103. uid := user.UserId
  1104. articleId, err := this.GetInt("ArticleId")
  1105. if articleId <= 0 {
  1106. br.Msg = "文章不存在"
  1107. br.ErrMsg = "文章不存在,文章ID错误"
  1108. return
  1109. }
  1110. //缓存校验
  1111. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid, "ArticleId_", articleId)
  1112. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  1113. if ttlTime > 0 && user.CompanyId != 16 {
  1114. br.Msg = "下载失败,下载过于频繁"
  1115. br.ErrMsg = "下载失败,下载过于频繁:mobile" + user.Mobile
  1116. return
  1117. }
  1118. resp := new(models.ArticleDetailFileLink)
  1119. detail := new(models.ArticleDetail)
  1120. detail, err = models.GetArticleDetailById(articleId)
  1121. if err != nil {
  1122. br.Msg = "获取信息失败"
  1123. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1124. return
  1125. }
  1126. fileLink := detail.FileLink
  1127. if fileLink == "" {
  1128. br.Msg = "下载失败"
  1129. br.ErrMsg = "下载失败,报告链接不存在"
  1130. return
  1131. }
  1132. mobile := user.Mobile
  1133. if mobile == "" {
  1134. mobile = user.Email
  1135. }
  1136. sliceLink := strings.Split(fileLink, "/")
  1137. uploadDir := "static/pdf/"
  1138. //判断文件夹是否存在,不存在则创建
  1139. if !utils.FileIsExist(uploadDir) {
  1140. err = os.MkdirAll(uploadDir, 0755)
  1141. if err != nil {
  1142. br.Msg = "下载失败"
  1143. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  1144. return
  1145. }
  1146. }
  1147. var oldFile string
  1148. var newFile string
  1149. //获取PDF源文件名称
  1150. pdfName := sliceLink[len(sliceLink)-1]
  1151. pdfName = utils.MD5(pdfName) + ".pdf"
  1152. oldFile = uploadDir + pdfName
  1153. //判断PDF本地是否存在,不存在则保存到本地
  1154. if !utils.FileIsExist(oldFile) {
  1155. res, err := nhttp.Get(fileLink)
  1156. if err != nil {
  1157. br.Msg = "下载失败"
  1158. br.ErrMsg = "获取源文件失败,Err:" + err.Error()
  1159. return
  1160. }
  1161. defer res.Body.Close()
  1162. // 获得get请求响应的reader对象
  1163. reader := bufio.NewReaderSize(res.Body, 32*1024)
  1164. file, err := os.Create(oldFile)
  1165. if err != nil {
  1166. br.Msg = "下载失败"
  1167. br.ErrMsg = "保存源文件到本地失败,Err:" + err.Error()
  1168. return
  1169. }
  1170. defer file.Close()
  1171. //获得文件的writer对象
  1172. writer := bufio.NewWriter(file)
  1173. written, _ := io.Copy(writer, reader)
  1174. fmt.Printf("Total length: %d", written)
  1175. }
  1176. newFile = uploadDir + "new_" + pdfName
  1177. onTop := true
  1178. wm, err := pdfcpu.ParseTextWatermarkDetails(mobile, " op:.4, pos:c ,points:16 ", onTop, 1)
  1179. if err != nil {
  1180. br.Msg = "下载失败"
  1181. br.ErrMsg = "生成水印文件失败,Err:" + err.Error()
  1182. return
  1183. }
  1184. err = api.AddWatermarksFile(oldFile, newFile, nil, wm, nil)
  1185. if err != nil {
  1186. //br.Msg = "下载失败"
  1187. //br.ErrMsg = "生成水印PDF失败,Err:" + err.Error()
  1188. resp.FileLink = fileLink
  1189. br.Ret = 200
  1190. br.Success = true
  1191. br.Msg = "获取成功"
  1192. br.Data = resp
  1193. return
  1194. }
  1195. randStr := utils.GetRandStringNoSpecialChar(28)
  1196. fileName := randStr + ".pdf"
  1197. savePath := uploadDir + time.Now().Format("200601/20060102/")
  1198. savePath += fileName
  1199. //上传到阿里云
  1200. err = services.UploadFileToAliyun(fileName, newFile, savePath)
  1201. if err != nil {
  1202. br.Msg = "下载失败"
  1203. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1204. return
  1205. }
  1206. fileHost := "https://hzstatic.hzinsights.com/"
  1207. resourceUrl := fileHost + savePath
  1208. defer func() {
  1209. os.Remove(newFile)
  1210. }()
  1211. utils.Rc.SetNX(cacheKey, user.Mobile, time.Minute*5)
  1212. resp.FileLink = resourceUrl
  1213. br.Ret = 200
  1214. br.Success = true
  1215. br.Msg = "获取成功"
  1216. br.Data = resp
  1217. }
  1218. // @Title 获取报告详情(无需token)
  1219. // @Description 获取报告详情接口
  1220. // @Param ArticleId query int true "报告ID"
  1221. // @Param CompanyCode query string false "机构编号"
  1222. // @Param CompanyName query string false "机构名称"
  1223. // @Param Email query string false "邮箱"
  1224. // @Param Sign query string false "加密签名"
  1225. // @Success 200 {object} models.ArticleDetailHtgjResp
  1226. // @router /detailPublic [get]
  1227. func (this *ArticleCommonController) DetailPublic() {
  1228. br := new(models.BaseResponse).Init()
  1229. defer func() {
  1230. this.Data["json"] = br
  1231. this.ServeJSON()
  1232. }()
  1233. articleId, _ := this.GetInt("ArticleId")
  1234. companyCode := this.GetString("CompanyCode")
  1235. companyNameHt := this.GetString("CompanyName")
  1236. email := this.GetString("Email")
  1237. sign := this.GetString("Sign")
  1238. resp := new(models.ArticleDetailHtgjResp)
  1239. if companyCode == "" || email == "" {
  1240. resp.HasPermission = 2
  1241. br.Ret = 200
  1242. br.Success = true
  1243. br.Msg = "获取成功"
  1244. br.Data = resp
  1245. return
  1246. }
  1247. if articleId <= 0 {
  1248. br.Msg = "文章不存在"
  1249. br.ErrMsg = "文章不存在,文章ID错误"
  1250. return
  1251. }
  1252. errMsg, err, wxUser, companyName := services.CheckHtgj(companyCode, companyNameHt, email, sign)
  1253. if errMsg != "" {
  1254. br.Msg = errMsg
  1255. return
  1256. }
  1257. companyPermission, err := models.GetCompanyPermission(wxUser.CompanyId)
  1258. if err != nil {
  1259. br.Msg = "获取信息失败"
  1260. br.ErrMsg = "获取用户权限失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(articleId)
  1261. return
  1262. }
  1263. hasPermission := 0
  1264. uid := wxUser.UserId
  1265. detail, err := models.GetArticleDetailById(articleId)
  1266. if err != nil {
  1267. br.Msg = "获取信息失败"
  1268. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1269. return
  1270. }
  1271. detail.Body = html.UnescapeString(detail.Body)
  1272. 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)
  1273. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  1274. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  1275. var articlePermissionPermissionName string
  1276. if detail.CategoryId > 0 {
  1277. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  1278. if err != nil {
  1279. br.Msg = "获取信息失败"
  1280. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1281. return
  1282. }
  1283. if articlePermission == nil {
  1284. br.Msg = "获取信息失败"
  1285. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1286. return
  1287. }
  1288. articlePermissionPermissionName = articlePermission.PermissionName
  1289. } else {
  1290. articlePermissionPermissionName = detail.CategoryName
  1291. }
  1292. var hasPersion bool
  1293. slice := strings.Split(articlePermissionPermissionName, ",")
  1294. for _, v := range slice {
  1295. if strings.Contains(companyPermission, v) {
  1296. hasPersion = true
  1297. }
  1298. }
  1299. if hasPersion {
  1300. hasPermission = 1
  1301. }
  1302. if strings.Contains(detail.CategoryName, "研选") {
  1303. detail.IsResearch = true
  1304. }
  1305. resp.HasPermission = hasPermission
  1306. if hasPermission == 1 {
  1307. //获取销售手机号
  1308. sellerItem, err := models.GetSellerByCompanyId(wxUser.CompanyId)
  1309. if err != nil {
  1310. br.Msg = "获取信息失败"
  1311. br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1312. return
  1313. }
  1314. if sellerItem != nil {
  1315. detail.SellerMobile = sellerItem.Mobile
  1316. detail.SellerName = sellerItem.RealName
  1317. }
  1318. sellerList, err := models.GetSellerList(articleId)
  1319. if err != nil {
  1320. br.Msg = "获取信息失败"
  1321. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  1322. return
  1323. }
  1324. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  1325. strnum := strings.Index(detail.SellerAndMobile, "-")
  1326. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  1327. if strnum > 0 {
  1328. nickName := detail.SellerAndMobile[0:strnum]
  1329. sellerAndMobile := &models.SellerRep{
  1330. SellerMobile: "",
  1331. SellerName: nickName,
  1332. }
  1333. sellerList = append(sellerList, sellerAndMobile)
  1334. }
  1335. }
  1336. detail.SellerList = sellerList
  1337. resp.Detail = detail
  1338. historyRecord := new(models.CygxArticleHistoryRecord)
  1339. historyRecord.UserId = wxUser.UserId
  1340. historyRecord.ArticleId = articleId
  1341. historyRecord.CreateTime = time.Now()
  1342. historyRecord.Mobile = wxUser.Mobile
  1343. historyRecord.Email = wxUser.Email
  1344. historyRecord.CompanyId = wxUser.CompanyId
  1345. historyRecord.CompanyName = companyName
  1346. recordCount, _ := models.GetNoAddStoptimeArticleCount(wxUser.UserId, articleId)
  1347. if recordCount == 0 {
  1348. go models.AddCygxArticleHistoryRecord(historyRecord)
  1349. } else {
  1350. detailNew, err := models.GetNewArticleHistoryRecord(wxUser.UserId, articleId)
  1351. if err != nil {
  1352. br.Msg = "获取信息失败"
  1353. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1354. return
  1355. }
  1356. if detailNew.StopTime > 0 {
  1357. go models.AddCygxArticleHistoryRecord(historyRecord)
  1358. }
  1359. }
  1360. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(wxUser.UserId)
  1361. if !utils.Rc.IsExist(key) {
  1362. //新增浏览记录
  1363. record := new(models.CygxArticleViewRecord)
  1364. record.UserId = wxUser.UserId
  1365. record.ArticleId = articleId
  1366. record.CreateTime = time.Now()
  1367. record.Mobile = wxUser.Mobile
  1368. record.Email = wxUser.Email
  1369. record.CompanyId = wxUser.CompanyId
  1370. record.CompanyName = companyName
  1371. go models.AddCygxArticleViewRecord(record)
  1372. utils.Rc.Put(key, 1, 5*time.Second)
  1373. models.ModifyReportLastViewTime(wxUser.UserId)
  1374. }
  1375. if detail.ArticleId < utils.SummaryArticleId {
  1376. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(utils.HtgjPublicMobile)
  1377. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
  1378. detail.IsNeedJump = true
  1379. }
  1380. if detail.ArticleId < utils.SummaryArticleId {
  1381. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(utils.HtgjPublicMobile)
  1382. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
  1383. detail.IsNeedJump = true
  1384. }
  1385. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  1386. if err != nil && err.Error() != utils.ErrNoRow() {
  1387. br.Msg = "获取信息失败"
  1388. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1389. return
  1390. }
  1391. if collectCount > 0 {
  1392. detail.IsCollect = true
  1393. }
  1394. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  1395. if err != nil && err.Error() != utils.ErrNoRow() {
  1396. br.Msg = "获取信息失败"
  1397. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1398. return
  1399. }
  1400. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  1401. detail.IsInterviewApply = true
  1402. detail.InterviewApplyStatus = interviewApplyItem.Status
  1403. }
  1404. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  1405. if err != nil {
  1406. br.Msg = "获取信息失败"
  1407. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  1408. return
  1409. }
  1410. detail.FollowNum = articleFollowdetail.DNum
  1411. detail.CollectionNum = articleFollowdetail.AcNum
  1412. resp.Detail = detail
  1413. }
  1414. resp.CompanyName = companyName
  1415. br.Ret = 200
  1416. br.Success = true
  1417. br.Msg = "获取成功"
  1418. br.Data = resp
  1419. }
  1420. // @Title 上传文章阅读时间(无需token)
  1421. // @Description 上传文章阅读时间接口(无需token)
  1422. // @Param request body models.AddStopTimeHtgjRep true "type json string"
  1423. // @Success 200 {object} models.ArticleDetailResp
  1424. // @router /addStopTimePublic [post]
  1425. func (this *ArticleCommonController) AddStopTimePublic() {
  1426. br := new(models.BaseResponse).Init()
  1427. defer func() {
  1428. this.Data["json"] = br
  1429. this.ServeJSON()
  1430. }()
  1431. var req models.AddStopTimeHtgjRep
  1432. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1433. if err != nil {
  1434. br.Msg = "参数解析异常!"
  1435. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1436. return
  1437. }
  1438. articleId := req.ArticleId
  1439. stopTime := req.StopTime
  1440. outType := req.OutType
  1441. source := req.Source
  1442. companyCode := req.CompanyCode
  1443. companyName := req.CompanyName
  1444. wxuUserName := req.Email
  1445. sign := req.Sign
  1446. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1447. br.Msg = "上传失败"
  1448. br.ErrMsg = "必填参数不能为空"
  1449. return
  1450. }
  1451. companyNameHt := companyCode + "_" + companyName
  1452. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1453. if errMsg != "" {
  1454. br.Msg = errMsg
  1455. return
  1456. }
  1457. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1458. if err != nil {
  1459. br.Msg = "获取信息失败"
  1460. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1461. return
  1462. }
  1463. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1464. if err != nil {
  1465. br.Msg = "获取信息失败"
  1466. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1467. return
  1468. }
  1469. uid := user.UserId
  1470. if articleId <= 0 {
  1471. br.Msg = "文章ID不存在"
  1472. br.ErrMsg = "参数错误"
  1473. return
  1474. }
  1475. if stopTime == 0 {
  1476. stopTime = 1
  1477. }
  1478. if outType != 2 {
  1479. outType = 1
  1480. }
  1481. if source != "PC" {
  1482. source = "MOBILE"
  1483. }
  1484. detail := new(models.ArticleDetail)
  1485. hasPermission := 0
  1486. hasFree := 0
  1487. //判断是否已经申请过
  1488. applyCount, err := models.GetApplyRecordCount(uid)
  1489. if err != nil && err.Error() != utils.ErrNoRow() {
  1490. br.Msg = "获取信息失败"
  1491. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1492. return
  1493. }
  1494. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  1495. if user.CompanyId > 1 {
  1496. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1497. if err != nil {
  1498. br.Msg = "获取信息失败"
  1499. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1500. return
  1501. }
  1502. detail, err = models.GetArticleDetailById(articleId)
  1503. if err != nil {
  1504. br.Msg = "获取信息失败"
  1505. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1506. return
  1507. }
  1508. if companyPermission == "" {
  1509. if applyCount > 0 {
  1510. hasPermission = 5
  1511. } else {
  1512. hasPermission = 2
  1513. }
  1514. hasFree = 2
  1515. goto Loop
  1516. } else {
  1517. hasFree = 1
  1518. var articlePermissionPermissionName string
  1519. if detail.CategoryId > 0 {
  1520. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  1521. if err != nil {
  1522. br.Msg = "获取信息失败"
  1523. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1524. return
  1525. }
  1526. if articlePermission == nil {
  1527. br.Msg = "获取信息失败"
  1528. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1529. return
  1530. }
  1531. articlePermissionPermissionName = articlePermission.PermissionName
  1532. } else {
  1533. articlePermissionPermissionName = detail.CategoryName
  1534. }
  1535. var hasPersion bool
  1536. slice := strings.Split(articlePermissionPermissionName, ",")
  1537. for _, v := range slice {
  1538. if strings.Contains(companyPermission, v) {
  1539. hasPersion = true
  1540. }
  1541. }
  1542. if hasPersion {
  1543. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  1544. if err == nil {
  1545. hasPermission = 1
  1546. historyRecord := new(models.AddStopTimeNewRep)
  1547. historyRecord.StopTime = detailNew.StopTime + stopTime
  1548. historyRecord.Id = detailNew.Id
  1549. historyRecord.OutType = outType
  1550. go models.UpdateArticleStopTime(historyRecord)
  1551. }
  1552. //不统计本公司的阅读记录、正常退出的不做时间差统计
  1553. if user.CompanyId != 16 && stopTime > 3 {
  1554. key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
  1555. record := new(models.CygxArticleHistoryRecordNewpv)
  1556. record.UserId = uid
  1557. record.ArticleId = articleId
  1558. record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  1559. record.ModifyTime = time.Now()
  1560. record.Mobile = user.Mobile
  1561. record.Email = user.Email
  1562. record.CompanyId = user.CompanyId
  1563. record.CompanyName = companyInfo.CompanyName
  1564. record.StopTime = stopTime
  1565. record.OutType = outType
  1566. record.Source = source
  1567. if !utils.Rc.IsExist(key) || outType != 2 {
  1568. //新增浏览记录
  1569. go models.AddCygxArticleViewRecordNewpv(record)
  1570. recordRedis := new(services.ReportViewRecord)
  1571. recordRedis.UserId = user.UserId
  1572. recordRedis.ReportId = articleId
  1573. recordRedis.Mobile = user.Mobile
  1574. recordRedis.Email = user.Email
  1575. recordRedis.RealName = user.RealName
  1576. recordRedis.CompanyName = companyName
  1577. recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  1578. go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
  1579. } else {
  1580. go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
  1581. }
  1582. utils.Rc.Put(key, 1, 10*time.Minute)
  1583. }
  1584. models.ModifyReportLastViewTime(uid)
  1585. } else { //无该行业权限
  1586. hasPermission = 3
  1587. }
  1588. }
  1589. } else { //潜在客户
  1590. if applyCount > 0 {
  1591. hasPermission = 5
  1592. } else {
  1593. hasPermission = 4
  1594. }
  1595. }
  1596. Loop:
  1597. resp := new(models.ArticleDetailAddStopTimeRep)
  1598. resp.HasPermission = hasPermission
  1599. resp.HasFree = hasFree
  1600. br.Ret = 200
  1601. br.Success = true
  1602. br.Msg = "操作成功"
  1603. br.Data = resp
  1604. }
  1605. // @Title 页面访问统计(无需token)
  1606. // @Description 上传页面访问统计(无需token)
  1607. // @Param request body models.CygxPageHistoryRecordHtgjRep true "type json string"
  1608. // @Success Ret=200 新增成功
  1609. // @router /pageHistoryPublic [post]
  1610. func (this *ArticleCommonController) PageHistoryPublic() {
  1611. br := new(models.BaseResponse).Init()
  1612. defer func() {
  1613. this.Data["json"] = br
  1614. this.ServeJSON()
  1615. }()
  1616. var req models.CygxPageHistoryRecordHtgjRep
  1617. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1618. if err != nil {
  1619. br.Msg = "参数解析异常!"
  1620. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1621. return
  1622. }
  1623. companyCode := req.CompanyCode
  1624. companyName := req.CompanyName
  1625. wxuUserName := req.Email
  1626. sign := req.Sign
  1627. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1628. br.Msg = "上传失败"
  1629. br.ErrMsg = "必填参数不能为空"
  1630. return
  1631. }
  1632. companyNameHt := companyCode + "_" + companyName
  1633. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1634. if errMsg != "" {
  1635. br.Msg = errMsg
  1636. return
  1637. }
  1638. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1639. if err != nil {
  1640. br.Msg = "获取信息失败"
  1641. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1642. return
  1643. }
  1644. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1645. if err != nil {
  1646. br.Msg = "获取信息失败"
  1647. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1648. return
  1649. }
  1650. item := new(models.CygxPageHistoryRecord)
  1651. item.UserId = user.UserId
  1652. item.CreateTime = time.Now()
  1653. item.Mobile = user.Mobile
  1654. item.Email = user.Email
  1655. item.CompanyId = user.CompanyId
  1656. item.CompanyName = companyName
  1657. item.DetailId = req.DetailId
  1658. item.ChartPermissionId = req.ChartPermissionId
  1659. item.IndustrialManagementId = req.IndustrialManagementId
  1660. item.PageType = "ArticleCopy"
  1661. _, err = models.AddCygxPageHistoryRecord(item)
  1662. if err != nil {
  1663. br.Msg = "记录信息失败"
  1664. br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
  1665. return
  1666. }
  1667. br.Ret = 200
  1668. br.Success = true
  1669. br.Msg = "新增成功"
  1670. }