htgj.go 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/medivhzhan/weapp/v2"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/services"
  8. "hongze/hongze_cygx/utils"
  9. "html"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. //type HtgjController struct {
  15. // BaseAuthController
  16. //}
  17. type BaseHtgjController struct {
  18. BaseCommonController
  19. }
  20. // @Title 首页列表接口(海通国际)
  21. // @Description 首页列表接口(海通国际)
  22. // @Param PageSize query int true "每页数据条数"
  23. // @Param CurrentIndex query int true "当前页页码,从1开始"
  24. // @Param ChartPermissionId query int true "品类id,最新传0"
  25. // @Param CompanyCode query string false "机构编号"
  26. // @Param CompanyName query string false "机构名称"
  27. // @Param Email query string false "邮箱"
  28. // @Param Sign query string false "加密签名"
  29. // @Success 200 {object} models.HomeListResp
  30. // @router /home/listPublic [get]
  31. func (this *BaseHtgjController) ListHomePublic() {
  32. br := new(models.BaseResponse).Init()
  33. defer func() {
  34. this.Data["json"] = br
  35. this.ServeJSON()
  36. }()
  37. companyCode := this.GetString("CompanyCode")
  38. companyName := this.GetString("CompanyName")
  39. email := this.GetString("Email")
  40. sign := this.GetString("Sign")
  41. var userType int
  42. var err error
  43. if companyCode != "" && companyName != "" && email != "" {
  44. errMsg, errHt, wxUser, _ := services.CheckHtgj(companyCode, companyName, email, sign)
  45. if errHt != nil {
  46. br.Msg = "获取"
  47. br.ErrMsg = "获取数据失败,Err:" + errHt.Error()
  48. return
  49. }
  50. if errMsg != "" {
  51. br.Msg = errMsg
  52. return
  53. }
  54. user := wxUser
  55. if user == nil {
  56. br.Msg = "请登录"
  57. br.ErrMsg = "请登录,用户信息为空"
  58. br.Ret = 408
  59. return
  60. }
  61. userType, _, err = services.GetUserType(user.CompanyId)
  62. if err != nil {
  63. br.Msg = "获取信息失败"
  64. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  65. return
  66. }
  67. }
  68. pageSize, _ := this.GetInt("PageSize")
  69. currentIndex, _ := this.GetInt("CurrentIndex")
  70. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  71. var startSize int
  72. if pageSize <= 0 {
  73. pageSize = utils.PageSize20
  74. }
  75. if currentIndex <= 0 {
  76. currentIndex = 1
  77. }
  78. startSize = paging.StartIndex(currentIndex, pageSize)
  79. var condition string
  80. var pars []interface{}
  81. var total int
  82. resp := new(models.HomeListResp)
  83. page := paging.GetPaging(currentIndex, pageSize, total)
  84. resp.HaveResearch = true
  85. condition += ` AND is_summary = 1 `
  86. if chartPermissionId > 0 {
  87. categoryId, err := models.GetCategoryId(chartPermissionId)
  88. if err != nil && err.Error() != utils.ErrNoRow() {
  89. br.Msg = "获取信息失败"
  90. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  91. return
  92. }
  93. categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
  94. if err != nil {
  95. br.Msg = "获取信息失败"
  96. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  97. return
  98. }
  99. if userType == 1 && strings.Contains(categoryinfo.PermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  100. resp.HaveResearch = false
  101. resp.Paging = page
  102. br.Ret = 200
  103. br.Success = true
  104. br.Msg = "获取成功"
  105. br.Data = resp
  106. return
  107. }
  108. page = paging.GetPaging(currentIndex, pageSize, total)
  109. if categoryId != "" {
  110. condition += ` AND category_id IN(` + categoryId + `)`
  111. //condition += ` OR ( category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%' AND publish_status = 1 AND is_summary = 1 )`
  112. } else {
  113. condition += ` AND category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  114. }
  115. }
  116. //永续客户无法查看研选分类的内容
  117. if userType == 1 {
  118. condition += ` AND category_name NOT LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  119. }
  120. total, err = models.GetHomeCount(condition, pars)
  121. if err != nil {
  122. br.Msg = "获取信息失败"
  123. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  124. return
  125. }
  126. page = paging.GetPaging(currentIndex, pageSize, total)
  127. list, err := models.GetHomeList(condition, pars, startSize, pageSize)
  128. if err != nil {
  129. br.Msg = "获取信息失败"
  130. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  131. return
  132. }
  133. for k, v := range list {
  134. item := list[k]
  135. //如果文章一开始的内容是图片,优先展示第一张图片
  136. imgurl, _ := services.FixArticleImgUrl(html.UnescapeString(list[k].Body))
  137. newBody, _ := services.GetReportContentTextSub(item.Body)
  138. list[k].Body = newBody
  139. if imgurl != "" {
  140. list[k].BodyHtml = imgurl
  141. }
  142. list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDateTimeNoSecond) //时间字符串格式转时间格式
  143. if strings.Contains(item.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  144. list[k].IsResearch = true
  145. }
  146. if list[k].ArticleId < utils.SummaryArticleId {
  147. list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
  148. list[k].IsNeedJump = true
  149. }
  150. if item.Pv > 999 {
  151. list[k].Pv = 999
  152. }
  153. }
  154. resp.List = list
  155. resp.Paging = page
  156. br.Ret = 200
  157. br.Success = true
  158. br.Msg = "获取成功"
  159. br.Data = resp
  160. }
  161. // @Title 获取搜索推荐词
  162. // @Description 获取搜索推荐词
  163. // @Success 200 {object} models.ConfigResp
  164. // @router /home/detail [get]
  165. func (this *BaseHtgjController) BrowseHistoryList() {
  166. br := new(models.BaseResponse).Init()
  167. defer func() {
  168. this.Data["json"] = br
  169. this.ServeJSON()
  170. }()
  171. resp := new(models.ConfigResp)
  172. detail := new(models.CygxConfig)
  173. //configCode := "hot_search"
  174. //detail, err := models.GetConfigByCode(configCode)
  175. hotSearch, err := models.GetHotSearch()
  176. if err != nil {
  177. br.Msg = "获取数据失败"
  178. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  179. return
  180. }
  181. chartList, err := models.GetChartListConfig()
  182. if err != nil {
  183. br.Msg = "获取信息失败"
  184. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  185. return
  186. }
  187. for _, v := range chartList {
  188. item := new(models.KeyWord)
  189. item.KeyWord = v.Title
  190. resp.List = append(resp.List, item)
  191. }
  192. var condition string
  193. var pars []interface{}
  194. currentTime := time.Now()
  195. starTime := currentTime.AddDate(0, 0, -8).Format("2006-01-02") + " 00:00:00"
  196. endTime := currentTime.AddDate(0, 0, -1).Format("2006-01-02") + " 23:59:59"
  197. condition += ` AND create_time < ` + "'" + endTime + "'" + `AND create_time > ` + "'" + starTime + "'"
  198. hotList, err := models.GetSearchKeyWordTop(condition, pars)
  199. if err != nil {
  200. br.Msg = "获取信息失败"
  201. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  202. return
  203. }
  204. for _, v := range hotList {
  205. item := new(models.KeyWord)
  206. item.KeyWord = v.KeyWord
  207. resp.ListHot = append(resp.ListHot, item)
  208. }
  209. detail.ConfigValue = hotSearch
  210. resp.Item = detail
  211. br.Msg = "获取成功!"
  212. br.Ret = 200
  213. br.Success = true
  214. br.Data = resp
  215. }
  216. // @Title 访谈申请(海通国际)
  217. // @Description 访谈申请(海通国际)
  218. // @Param request body models.ArticleInterviewApplyReqHtgj true "type json string"
  219. // @Success 200 {object} models.FontsCollectResp
  220. // @router /interview/apply [post]
  221. func (this *BaseHtgjController) InterviewApply() {
  222. br := new(models.BaseResponse).Init()
  223. defer func() {
  224. this.Data["json"] = br
  225. this.ServeJSON()
  226. }()
  227. var req models.ArticleInterviewApplyReqHtgj
  228. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  229. if err != nil {
  230. br.Msg = "参数解析异常!"
  231. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  232. return
  233. }
  234. //articleId := req.ArticleId
  235. companyCode := req.CompanyCode
  236. companyName := req.CompanyName
  237. wxuUserName := req.Email
  238. sign := req.Sign
  239. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  240. br.Msg = "上传失败"
  241. br.ErrMsg = "必填参数不能为空"
  242. return
  243. }
  244. companyNameHt := companyCode + "_" + companyName
  245. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  246. if errMsg != "" {
  247. br.Msg = errMsg
  248. return
  249. }
  250. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  251. if err != nil {
  252. br.Msg = "获取信息失败"
  253. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  254. return
  255. }
  256. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  257. if err != nil {
  258. br.Msg = "获取信息失败"
  259. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  260. return
  261. }
  262. uid := user.UserId
  263. article, err := models.GetArticleDetailById(req.ArticleId)
  264. if err != nil {
  265. br.Msg = "获取纪要失败!"
  266. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  267. return
  268. }
  269. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  270. if err != nil {
  271. br.Msg = "获取数据失败!"
  272. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  273. return
  274. }
  275. resp := new(models.ArticleInterviewApplyResp)
  276. if count <= 0 {
  277. item := new(models.CygxInterviewApply)
  278. item.ArticleId = req.ArticleId
  279. item.UserId = uid
  280. item.CompanyId = user.CompanyId
  281. item.Status = "待邀请"
  282. item.Sort = 1
  283. item.ArticleTitle = article.Title
  284. item.CreateTime = time.Now()
  285. item.ModifyTime = time.Now()
  286. item.ArticleIdMd5 = article.ArticleIdMd5
  287. _, err = models.AddCygxInterviewApply(item)
  288. if err != nil {
  289. br.Msg = "申请失败"
  290. br.ErrMsg = "申请失败,Err:" + err.Error()
  291. return
  292. }
  293. br.Msg = "申请成功"
  294. resp.Status = 1
  295. //发送模板消息
  296. if user.CompanyId > 1 {
  297. mobile := user.Mobile
  298. if mobile == "" {
  299. mobile = user.Email
  300. }
  301. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  302. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  303. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  304. if openIpItem != nil && openIpItem.OpenId != "" {
  305. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  306. }
  307. }
  308. }
  309. } else {
  310. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  311. if err != nil {
  312. br.Msg = "取消申请失败"
  313. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  314. return
  315. }
  316. br.Msg = "已取消申请"
  317. resp.Status = 2
  318. if user.CompanyId > 1 {
  319. mobile := user.Mobile
  320. if mobile == "" {
  321. mobile = user.Email
  322. }
  323. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  324. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  325. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  326. if openIpItem != nil && openIpItem.OpenId != "" {
  327. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  328. }
  329. }
  330. }
  331. }
  332. br.Ret = 200
  333. br.Success = true
  334. br.Data = resp
  335. }
  336. // @Title 收藏(海通国际)
  337. // @Description 收藏(海通国际)
  338. // @Param request body models.ArticleInterviewApplyReqHtgj true "type json string"
  339. // @Success 200 {object} models.FontsCollectResp
  340. // @router /collect [post]
  341. func (this *BaseHtgjController) ArticleCollect() {
  342. br := new(models.BaseResponse).Init()
  343. defer func() {
  344. this.Data["json"] = br
  345. this.ServeJSON()
  346. }()
  347. var req models.ArticleInterviewApplyReqHtgj
  348. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  349. if err != nil {
  350. br.Msg = "参数解析异常!"
  351. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  352. return
  353. }
  354. articleId := req.ArticleId
  355. companyCode := req.CompanyCode
  356. companyName := req.CompanyName
  357. wxuUserName := req.Email
  358. sign := req.Sign
  359. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  360. br.Msg = "上传失败"
  361. br.ErrMsg = "必填参数不能为空"
  362. return
  363. }
  364. companyNameHt := companyCode + "_" + companyName
  365. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  366. if errMsg != "" {
  367. br.Msg = errMsg
  368. return
  369. }
  370. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  371. if err != nil {
  372. br.Msg = "获取信息失败"
  373. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  374. return
  375. }
  376. wxuser, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  377. if err != nil {
  378. br.Msg = "获取信息失败"
  379. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  380. return
  381. }
  382. uid := wxuser.UserId
  383. user := new(models.WxUserItem)
  384. user.Mobile = wxuser.Mobile
  385. user.Email = wxuser.Email
  386. user.CompanyId = wxuser.CompanyId
  387. user.RealName = wxuser.RealName
  388. user.CompanyName = companyInfo.CompanyName
  389. detail, err := models.GetArticleDetailById(articleId)
  390. if err != nil {
  391. br.Msg = "获取信息失败"
  392. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  393. return
  394. }
  395. count, err := models.GetArticleCollectCount(uid, articleId)
  396. if err != nil {
  397. br.Msg = "获取数据失败!"
  398. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  399. return
  400. }
  401. resp := new(models.ArticleCollectResp)
  402. if count <= 0 {
  403. item := new(models.CygxArticleCollect)
  404. item.ArticleId = req.ArticleId
  405. item.UserId = uid
  406. item.CreateTime = time.Now()
  407. item.Mobile = user.Mobile
  408. item.Email = user.Email
  409. item.CompanyId = user.CompanyId
  410. item.CompanyName = user.CompanyName
  411. item.RealName = user.RealName
  412. _, err = models.AddCygxArticleCollect(item)
  413. if err != nil {
  414. br.Msg = "收藏失败"
  415. br.ErrMsg = "收藏失败,Err:" + err.Error()
  416. return
  417. }
  418. br.Msg = "收藏成功"
  419. resp.Status = 1
  420. // 文章收藏消息发送
  421. go services.ArticleUserRemind(user, detail, 2)
  422. } else {
  423. err = models.RemoveArticleCollect(uid, articleId)
  424. if err != nil {
  425. br.Msg = "取消收藏失败"
  426. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  427. return
  428. }
  429. br.Msg = "已取消收藏"
  430. resp.Status = 2
  431. }
  432. collectTotal, err := models.GetArticleCollectUsersCount(articleId)
  433. if err != nil {
  434. br.Msg = "获取数据失败"
  435. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  436. return
  437. }
  438. resp.CollectCount = collectTotal
  439. br.Ret = 200
  440. br.Success = true
  441. br.Data = resp
  442. }
  443. // @Title 文章带问(海通国际)
  444. // @Description 新增文章带问接口(海通国际)
  445. // @Param request body models.ArticleAskReqHtgj true "type json string"
  446. // @Success Ret=200 新增成功
  447. // @router /askAdd [post]
  448. func (this *BaseHtgjController) AskAdd() {
  449. br := new(models.BaseResponse).Init()
  450. defer func() {
  451. this.Data["json"] = br
  452. this.ServeJSON()
  453. }()
  454. var req models.ArticleAskReqHtgj
  455. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  456. if err != nil {
  457. br.Msg = "参数解析异常!"
  458. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  459. return
  460. }
  461. articleId := req.ArticleId
  462. companyCode := req.CompanyCode
  463. companyName := req.CompanyName
  464. wxuUserName := req.Email
  465. content := req.Content
  466. sign := req.Sign
  467. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  468. br.Msg = "上传失败"
  469. br.ErrMsg = "必填参数不能为空"
  470. return
  471. }
  472. companyNameHt := companyCode + "_" + companyName
  473. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  474. if errMsg != "" {
  475. br.Msg = errMsg
  476. return
  477. }
  478. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  479. if err != nil {
  480. br.Msg = "获取信息失败"
  481. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  482. return
  483. }
  484. wxuser, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  485. if err != nil {
  486. br.Msg = "获取信息失败"
  487. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  488. return
  489. }
  490. user := new(models.WxUserItem)
  491. user.Mobile = wxuser.Mobile
  492. user.Email = wxuser.Email
  493. user.CompanyId = wxuser.CompanyId
  494. user.RealName = wxuser.RealName
  495. user.CompanyName = companyInfo.CompanyName
  496. itemToken, err := services.WxGetToken()
  497. if err != nil {
  498. br.Msg = "GetWxAccessToken Err:" + err.Error()
  499. return
  500. }
  501. if itemToken.AccessToken == "" {
  502. br.Msg = "accessToken is empty"
  503. return
  504. }
  505. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  506. if err != nil {
  507. br.Msg = "内容校验失败!"
  508. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  509. return
  510. }
  511. if commerr.ErrCode != 0 {
  512. br.Msg = "内容违规,请重新提交!"
  513. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  514. return
  515. }
  516. count, _ := models.GetArticleCountById(articleId)
  517. if count == 0 {
  518. br.Msg = "操作失败"
  519. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  520. return
  521. }
  522. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  523. if err != nil {
  524. br.Msg = "提交失败!"
  525. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  526. return
  527. }
  528. if companyDetail == nil {
  529. br.Msg = "提交失败!"
  530. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  531. return
  532. }
  533. item := new(models.CygxArticleAsk)
  534. item.UserId = user.UserId
  535. item.ArticleId = req.ArticleId
  536. item.CompanyId = user.CompanyId
  537. item.CompanyName = companyDetail.CompanyName
  538. item.CreateTime = time.Now()
  539. item.Mobile = user.Mobile
  540. item.Email = user.Email
  541. item.Content = content
  542. _, err = models.AddArticleAsk(item)
  543. if err != nil {
  544. br.Msg = "提交失败"
  545. br.ErrMsg = "提交失败,Err:" + err.Error()
  546. return
  547. }
  548. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  549. if err != nil {
  550. br.Msg = "获取信息失败"
  551. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  552. return
  553. }
  554. var mobile string
  555. if utils.RunMode == "release" {
  556. //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  557. mobile = utils.WxMsgTemplateIdAskMsgMobileAll
  558. } else {
  559. mobile = utils.WxMsgTemplateIdAskMsgMobile
  560. }
  561. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  562. if err != nil {
  563. br.Msg = "提交失败"
  564. br.ErrMsg = "提交失败,Err:" + err.Error()
  565. return
  566. }
  567. detail, err := models.GetArticleDetailById(articleId)
  568. if err != nil {
  569. br.Msg = "获取信息失败"
  570. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  571. return
  572. }
  573. companyName = user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  574. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  575. br.Ret = 200
  576. br.Success = true
  577. br.Msg = "提交成功"
  578. }
  579. // @Title 获取所有品种(无需token)
  580. // @Description 获取所有品种(无需token)
  581. // @Success 200 {object} models.ChartPermissionResp
  582. // @router /permission/allPublic [get]
  583. func (this *BaseHtgjController) PermissionPublic() {
  584. br := new(models.BaseResponse).Init()
  585. defer func() {
  586. this.Data["json"] = br
  587. this.ServeJSON()
  588. }()
  589. var condition string
  590. list, err := models.GetChartPermissionAll(condition)
  591. if err != nil {
  592. br.Msg = "获取信息失败"
  593. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  594. return
  595. }
  596. resp := new(models.ChartPermissionResp)
  597. for k, v := range list {
  598. resp.List = append(resp.List, v)
  599. if services.GetShowSustainable() && v.PermissionName == "研选" {
  600. resp.List[k].IsShowSustainable = true
  601. }
  602. }
  603. resp.List = list
  604. br.Ret = 200
  605. br.Success = true
  606. br.Msg = "获取成功"
  607. br.Data = resp
  608. }
  609. // @Title 上传文章阅读时间(无需token)
  610. // @Description 上传文章阅读时间接口(无需token)
  611. // @Param request body models.AddStopTimeHtgjRep true "type json string"
  612. // @Success 200 {object} models.ArticleDetailResp
  613. // @router /article/addStopTimePublic [post]
  614. func (this *BaseHtgjController) AddStopTimePublic() {
  615. br := new(models.BaseResponse).Init()
  616. defer func() {
  617. this.Data["json"] = br
  618. this.ServeJSON()
  619. }()
  620. var req models.AddStopTimeHtgjRep
  621. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  622. if err != nil {
  623. br.Msg = "参数解析异常!"
  624. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  625. return
  626. }
  627. articleId := req.ArticleId
  628. stopTime := req.StopTime
  629. outType := req.OutType
  630. source := req.Source
  631. companyCode := req.CompanyCode
  632. companyName := req.CompanyName
  633. wxuUserName := req.Email
  634. sign := req.Sign
  635. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  636. br.Msg = "上传失败"
  637. br.ErrMsg = "必填参数不能为空"
  638. return
  639. }
  640. companyNameHt := companyCode + "_" + companyName
  641. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  642. if errMsg != "" {
  643. br.Msg = errMsg
  644. return
  645. }
  646. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  647. if err != nil {
  648. br.Msg = "获取信息失败"
  649. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  650. return
  651. }
  652. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  653. if err != nil {
  654. br.Msg = "获取信息失败"
  655. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  656. return
  657. }
  658. uid := user.UserId
  659. if articleId <= 0 {
  660. br.Msg = "文章ID不存在"
  661. br.ErrMsg = "参数错误"
  662. return
  663. }
  664. if stopTime == 0 {
  665. stopTime = 1
  666. }
  667. if outType != 2 {
  668. outType = 1
  669. }
  670. if source != "PC" {
  671. source = "MOBILE"
  672. }
  673. detail := new(models.ArticleDetail)
  674. hasPermission := 0
  675. hasFree := 0
  676. //判断是否已经申请过
  677. applyCount, err := models.GetApplyRecordCount(uid)
  678. if err != nil && err.Error() != utils.ErrNoRow() {
  679. br.Msg = "获取信息失败"
  680. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  681. return
  682. }
  683. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  684. if user.CompanyId > 1 {
  685. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  686. if err != nil {
  687. br.Msg = "获取信息失败"
  688. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  689. return
  690. }
  691. detail, err = models.GetArticleDetailById(articleId)
  692. if err != nil {
  693. br.Msg = "获取信息失败"
  694. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  695. return
  696. }
  697. if companyPermission == "" {
  698. if applyCount > 0 {
  699. hasPermission = 5
  700. } else {
  701. hasPermission = 2
  702. }
  703. hasFree = 2
  704. goto Loop
  705. } else {
  706. hasFree = 1
  707. var articlePermissionPermissionName string
  708. if detail.CategoryId > 0 {
  709. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  710. if err != nil {
  711. br.Msg = "获取信息失败"
  712. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  713. return
  714. }
  715. if articlePermission == nil {
  716. br.Msg = "获取信息失败"
  717. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  718. return
  719. }
  720. articlePermissionPermissionName = articlePermission.PermissionName
  721. } else {
  722. articlePermissionPermissionName = detail.CategoryName
  723. }
  724. var hasPersion bool
  725. slice := strings.Split(articlePermissionPermissionName, ",")
  726. for _, v := range slice {
  727. if strings.Contains(companyPermission, v) {
  728. hasPersion = true
  729. }
  730. }
  731. if hasPersion {
  732. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  733. if err == nil {
  734. hasPermission = 1
  735. historyRecord := new(models.AddStopTimeNewRep)
  736. historyRecord.StopTime = detailNew.StopTime + stopTime
  737. historyRecord.Id = detailNew.Id
  738. historyRecord.OutType = outType
  739. go models.UpdateArticleStopTime(historyRecord)
  740. }
  741. //不统计本公司的阅读记录、正常退出的不做时间差统计
  742. if user.CompanyId != 16 && stopTime > 3 {
  743. key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
  744. record := new(models.CygxArticleHistoryRecordNewpv)
  745. record.UserId = uid
  746. record.ArticleId = articleId
  747. record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  748. record.ModifyTime = time.Now()
  749. record.Mobile = user.Mobile
  750. record.Email = user.Email
  751. record.CompanyId = user.CompanyId
  752. record.CompanyName = companyInfo.CompanyName
  753. record.StopTime = stopTime
  754. record.OutType = outType
  755. record.Source = source
  756. if !utils.Rc.IsExist(key) || outType != 2 {
  757. //新增浏览记录
  758. go models.AddCygxArticleViewRecordNewpv(record)
  759. recordRedis := new(services.ReportViewRecord)
  760. recordRedis.UserId = user.UserId
  761. recordRedis.ReportId = articleId
  762. recordRedis.Mobile = user.Mobile
  763. recordRedis.Email = user.Email
  764. recordRedis.RealName = user.RealName
  765. recordRedis.CompanyName = companyName
  766. //recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  767. go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
  768. } else {
  769. go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
  770. }
  771. utils.Rc.Put(key, 1, 10*time.Minute)
  772. }
  773. models.ModifyReportLastViewTime(uid)
  774. } else { //无该行业权限
  775. hasPermission = 3
  776. }
  777. }
  778. } else { //潜在客户
  779. if applyCount > 0 {
  780. hasPermission = 5
  781. } else {
  782. hasPermission = 4
  783. }
  784. }
  785. Loop:
  786. resp := new(models.ArticleDetailAddStopTimeRep)
  787. resp.HasPermission = hasPermission
  788. resp.HasFree = hasFree
  789. br.Ret = 200
  790. br.Success = true
  791. br.Msg = "操作成功"
  792. br.Data = resp
  793. }
  794. // @Title 获取报告详情(无需token)
  795. // @Description 获取报告详情接口
  796. // @Param ArticleId query int true "报告ID"
  797. // @Param CompanyCode query string false "机构编号"
  798. // @Param CompanyName query string false "机构名称"
  799. // @Param Email query string false "邮箱"
  800. // @Param Sign query string false "加密签名"
  801. // @Success 200 {object} models.ArticleDetailHtgjResp
  802. // @router /detailPublic [get]
  803. func (this *BaseHtgjController) DetailPublic() {
  804. br := new(models.BaseResponse).Init()
  805. defer func() {
  806. this.Data["json"] = br
  807. this.ServeJSON()
  808. }()
  809. articleId, _ := this.GetInt("ArticleId")
  810. companyCode := this.GetString("CompanyCode")
  811. companyNameHt := this.GetString("CompanyName")
  812. email := this.GetString("Email")
  813. sign := this.GetString("Sign")
  814. resp := new(models.ArticleDetailHtgjResp)
  815. if companyCode == "" || email == "" {
  816. resp.HasPermission = 2
  817. br.Ret = 200
  818. br.Success = true
  819. br.Msg = "获取成功"
  820. br.Data = resp
  821. return
  822. }
  823. if articleId <= 0 {
  824. br.Msg = "文章不存在"
  825. br.ErrMsg = "文章不存在,文章ID错误"
  826. return
  827. }
  828. errMsg, err, wxUser, companyName := services.CheckHtgj(companyCode, companyNameHt, email, sign)
  829. if errMsg != "" {
  830. br.Msg = errMsg
  831. return
  832. }
  833. companyPermission, err := models.GetCompanyPermission(wxUser.CompanyId)
  834. if err != nil {
  835. br.Msg = "获取信息失败"
  836. br.ErrMsg = "获取用户权限失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(articleId)
  837. return
  838. }
  839. hasPermission := 0
  840. uid := wxUser.UserId
  841. detail, err := models.GetArticleDetailById(articleId)
  842. if err != nil {
  843. br.Msg = "获取信息失败"
  844. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  845. return
  846. }
  847. detail.Body = html.UnescapeString(detail.Body)
  848. 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)
  849. detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
  850. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  851. var articlePermissionPermissionName string
  852. if detail.CategoryId > 0 {
  853. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  854. if err != nil {
  855. br.Msg = "获取信息失败"
  856. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  857. return
  858. }
  859. if articlePermission == nil {
  860. br.Msg = "获取信息失败"
  861. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  862. return
  863. }
  864. articlePermissionPermissionName = articlePermission.PermissionName
  865. } else {
  866. articlePermissionPermissionName = detail.CategoryName
  867. }
  868. var hasPersion bool
  869. slice := strings.Split(articlePermissionPermissionName, ",")
  870. for _, v := range slice {
  871. if strings.Contains(companyPermission, v) {
  872. hasPersion = true
  873. }
  874. }
  875. if hasPersion {
  876. hasPermission = 1
  877. }
  878. if strings.Contains(detail.CategoryName, "研选") {
  879. detail.IsResearch = true
  880. }
  881. resp.HasPermission = hasPermission
  882. if hasPermission == 1 {
  883. //获取销售手机号
  884. sellerItem, err := models.GetSellerByCompanyId(wxUser.CompanyId)
  885. if err != nil {
  886. br.Msg = "获取信息失败"
  887. br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  888. return
  889. }
  890. if sellerItem != nil {
  891. detail.SellerMobile = sellerItem.Mobile
  892. detail.SellerName = sellerItem.RealName
  893. }
  894. sellerList, err := models.GetSellerList(articleId)
  895. if err != nil {
  896. br.Msg = "获取信息失败"
  897. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
  898. return
  899. }
  900. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  901. strnum := strings.Index(detail.SellerAndMobile, "-")
  902. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  903. if strnum > 0 {
  904. nickName := detail.SellerAndMobile[0:strnum]
  905. sellerAndMobile := &models.SellerRep{
  906. SellerMobile: "",
  907. SellerName: nickName,
  908. }
  909. sellerList = append(sellerList, sellerAndMobile)
  910. }
  911. }
  912. detail.SellerList = sellerList
  913. historyRecord := new(models.CygxArticleHistoryRecord)
  914. historyRecord.UserId = wxUser.UserId
  915. historyRecord.ArticleId = articleId
  916. historyRecord.CreateTime = time.Now()
  917. historyRecord.Mobile = wxUser.Mobile
  918. historyRecord.Email = wxUser.Email
  919. historyRecord.CompanyId = wxUser.CompanyId
  920. historyRecord.CompanyName = companyName
  921. recordCount, _ := models.GetNoAddStoptimeArticleCount(wxUser.UserId, articleId)
  922. if recordCount == 0 {
  923. go models.AddCygxArticleHistoryRecord(historyRecord)
  924. } else {
  925. detailNew, err := models.GetNewArticleHistoryRecord(wxUser.UserId, articleId)
  926. if err != nil {
  927. br.Msg = "获取信息失败"
  928. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  929. return
  930. }
  931. if detailNew.StopTime > 0 {
  932. go models.AddCygxArticleHistoryRecord(historyRecord)
  933. }
  934. }
  935. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(wxUser.UserId)
  936. if !utils.Rc.IsExist(key) {
  937. //新增浏览记录
  938. record := new(models.CygxArticleViewRecord)
  939. record.UserId = wxUser.UserId
  940. record.ArticleId = articleId
  941. record.CreateTime = time.Now()
  942. record.Mobile = wxUser.Mobile
  943. record.Email = wxUser.Email
  944. record.CompanyId = wxUser.CompanyId
  945. record.CompanyName = companyName
  946. go models.AddCygxArticleViewRecord(record)
  947. utils.Rc.Put(key, 1, 5*time.Second)
  948. models.ModifyReportLastViewTime(wxUser.UserId)
  949. }
  950. if detail.ArticleId < utils.SummaryArticleId {
  951. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(utils.HtgjPublicMobile)
  952. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
  953. detail.IsNeedJump = true
  954. }
  955. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  956. if err != nil && err.Error() != utils.ErrNoRow() {
  957. br.Msg = "获取信息失败"
  958. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  959. return
  960. }
  961. if collectCount > 0 {
  962. detail.IsCollect = true
  963. }
  964. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  965. if err != nil && err.Error() != utils.ErrNoRow() {
  966. br.Msg = "获取信息失败"
  967. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  968. return
  969. }
  970. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  971. detail.IsInterviewApply = true
  972. detail.InterviewApplyStatus = interviewApplyItem.Status
  973. }
  974. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  975. if err != nil {
  976. br.Msg = "获取信息失败"
  977. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  978. return
  979. }
  980. detail.FollowNum = articleFollowdetail.DNum
  981. detail.CollectionNum = articleFollowdetail.AcNum
  982. resp.Detail = detail
  983. resp.Detail = detail
  984. }
  985. resp.CompanyName = companyName
  986. br.Ret = 200
  987. br.Success = true
  988. br.Msg = "获取成功"
  989. br.Data = resp
  990. }
  991. // @Title 页面访问统计(无需token)
  992. // @Description 上传页面访问统计(无需token)
  993. // @Param request body models.CygxPageHistoryRecordHtgjRep true "type json string"
  994. // @Success Ret=200 新增成功
  995. // @router /pageHistoryPublic [post]
  996. func (this *BaseHtgjController) PageHistoryPublic() {
  997. br := new(models.BaseResponse).Init()
  998. defer func() {
  999. this.Data["json"] = br
  1000. this.ServeJSON()
  1001. }()
  1002. var req models.CygxPageHistoryRecordHtgjRep
  1003. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1004. if err != nil {
  1005. br.Msg = "参数解析异常!"
  1006. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1007. return
  1008. }
  1009. companyCode := req.CompanyCode
  1010. companyName := req.CompanyName
  1011. wxuUserName := req.Email
  1012. sign := req.Sign
  1013. if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
  1014. br.Msg = "上传失败"
  1015. br.ErrMsg = "必填参数不能为空"
  1016. return
  1017. }
  1018. companyNameHt := companyCode + "_" + companyName
  1019. errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
  1020. if errMsg != "" {
  1021. br.Msg = errMsg
  1022. return
  1023. }
  1024. companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
  1025. if err != nil {
  1026. br.Msg = "获取信息失败"
  1027. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1028. return
  1029. }
  1030. user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
  1031. if err != nil {
  1032. br.Msg = "获取信息失败"
  1033. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1034. return
  1035. }
  1036. item := new(models.CygxPageHistoryRecord)
  1037. item.UserId = user.UserId
  1038. item.CreateTime = time.Now()
  1039. item.Mobile = user.Mobile
  1040. item.Email = user.Email
  1041. item.CompanyId = user.CompanyId
  1042. item.CompanyName = companyName
  1043. item.DetailId = req.DetailId
  1044. item.ChartPermissionId = req.ChartPermissionId
  1045. item.IndustrialManagementId = req.IndustrialManagementId
  1046. item.PageType = "ArticleCopy"
  1047. _, err = models.AddCygxPageHistoryRecord(item)
  1048. if err != nil {
  1049. br.Msg = "记录信息失败"
  1050. br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
  1051. return
  1052. }
  1053. br.Ret = 200
  1054. br.Success = true
  1055. br.Msg = "新增成功"
  1056. }