article.go 52 KB

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