frontRouter.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. package front
  2. import (
  3. "fmt"
  4. "jy/src/jfw/config"
  5. "jy/src/jfw/jyutil"
  6. "jy/src/jfw/wx"
  7. "net/url"
  8. "regexp"
  9. "strings"
  10. "app.yhyue.com/moapp/jybase/common"
  11. "app.yhyue.com/moapp/jybase/encrypt"
  12. elastic "app.yhyue.com/moapp/jybase/es"
  13. "app.yhyue.com/moapp/jybase/redis"
  14. "app.yhyue.com/moapp/jypkg/public"
  15. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
  16. //"strings"
  17. "app.yhyue.com/moapp/jybase/go-xweb/xweb"
  18. )
  19. //前端通用路由
  20. type CommonRouter struct {
  21. *xweb.Action
  22. wxCommonPage xweb.Mapper `xweb:"/weixin/frontPage/(.*)/(sess|free)/(.*)"` //新的历时推送记录
  23. pcCommonPage xweb.Mapper `xweb:"/swordfish/frontPage/(.*)/(sess|free)/(.*)"` //新的历时推送记录
  24. //积分页面路由
  25. integralIndex xweb.Mapper `xweb:"/swordfish/integral/"`
  26. integralPage xweb.Mapper `xweb:"/swordfish/integral/(.*)"`
  27. //文库页面路由
  28. docsIndex xweb.Mapper `xweb:"/swordfish/docs/"`
  29. docsPage xweb.Mapper `xweb:"/swordfish/docs/(.*)"`
  30. //线上课程
  31. xspcIndex xweb.Mapper `xweb:"/jyxspc/"`
  32. xspcPage xweb.Mapper `xweb:"/jyxspc/(.*)"`
  33. //卡卷页面路由
  34. couponIndex xweb.Mapper `xweb:"/swordfish/coupon/"`
  35. couponPage xweb.Mapper `xweb:"/swordfish/coupon/(.*)"`
  36. couponActive xweb.Mapper `xweb:"/swordfish/CA"`
  37. //商机管理
  38. entpcIndex xweb.Mapper `xweb:"/entpc/"`
  39. entpcPage xweb.Mapper `xweb:"/entpc/(.*)"`
  40. //pc大会员
  41. bigpcIndex xweb.Mapper `xweb:"/swordfish/page_big_pc/"`
  42. bigpcPage xweb.Mapper `xweb:"/swordfish/page_big_pc/(.*)"`
  43. //双十一活动留资
  44. activityLeads xweb.Mapper `xweb:"/weixin/leads/(.*)"`
  45. //组织机构:organizational structure
  46. orgpcIndex xweb.Mapper `xweb:"/orgpc/"`
  47. orgpcPage xweb.Mapper `xweb:"/orgpc/(.*)"`
  48. //pcweb
  49. webIndex xweb.Mapper `xweb:"/swordfish/page_web_pc/"`
  50. webPcPage xweb.Mapper `xweb:"/swordfish/page_web_pc/(.*)"`
  51. //socialweb
  52. socialIndex xweb.Mapper `xweb:"/swordfish/page_knowledge_base/"`
  53. socialPcPage xweb.Mapper `xweb:"/swordfish/page_knowledge_base/(.*)"`
  54. //微信端企业订阅设置
  55. toSetEntPushSetPage xweb.Mapper `xweb:"/front/entniche/toSetEntPushSetPage"` //订阅收费推送设置
  56. }
  57. func init() {
  58. xweb.AddAction(&CommonRouter{})
  59. jy.InitBigVipService(public.Mysql)
  60. }
  61. func (this *CommonRouter) WxCommonPage(folder, loginSign, htmlPage string) error {
  62. if loginSign != "free" {
  63. openid, _ := this.GetSession("s_m_openid").(string)
  64. if openid == "" || (openid != "" && !CheckUserIsSubscribe(openid)) {
  65. stateKey := this.GetString("state")
  66. if stateKey == "" { //公众号回调
  67. return this.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(this.Site()+this.Url()), "wx"), 302)
  68. }
  69. openid = jyutil.Getopenid(this.GetString("code"))
  70. if ok, _, _ := FindUserAndCreateSess(openid, this.Session(), "wx", false, true); !ok {
  71. return this.Redirect("/swordfish/about")
  72. }
  73. }
  74. if !CheckUserIsSubscribe(openid) {
  75. return this.Redirect("/swordfish/about")
  76. }
  77. }
  78. this.T["signature"] = wx.SignJSSDK(this.Site() + this.Url())
  79. return this.Render(fmt.Sprintf("/frontRouter/wx/%s/%s/%s.html", folder, loginSign, htmlPage))
  80. }
  81. func (this *CommonRouter) PcCommonPage(folder, loginSign, htmlPage string) error {
  82. var shareid = this.GetString("id")
  83. if len(shareid) == 0 {
  84. shareid = "10"
  85. }
  86. this.T["shareid"] = se.EncodeString(shareid)
  87. if loginSign != "free" {
  88. if userid, _ := this.GetSession("userId").(string); userid == "" {
  89. var shareid = this.GetString("id")
  90. if len(shareid) == 0 {
  91. shareid = "10"
  92. }
  93. this.T["logid"] = config.Seoconfig["jysskzy"].(string)
  94. this.T["shareid"] = se.EncodeString(shareid)
  95. return this.Render("/pc/notin.html", &this.T)
  96. }
  97. }
  98. if folder == "collection" {
  99. this.T["logid"] = config.Seoconfig["collection"].(string)
  100. }
  101. return this.Render(fmt.Sprintf("/frontRouter/pc/%s/%s/%s.html", folder, loginSign, htmlPage))
  102. }
  103. // WebIndex 前端vue页面公共路由
  104. func (this *CommonRouter) WebIndex() error {
  105. return this.Render(fmt.Sprintf("/micro/web-pc/index.html"))
  106. }
  107. // WebPcPage 前端vue页面公共路由
  108. func (this *CommonRouter) WebPcPage(page string) error {
  109. if userId, _ := this.GetSession("userId").(string); userId == "" { //P414
  110. if cc, err := this.GetCookie(jy.ChannelCookieName); err == nil {
  111. this.T["cooperateCode"] = cc.Value
  112. }
  113. }
  114. return this.Render(fmt.Sprintf("/micro/web-pc/index.html"))
  115. }
  116. // SocialIndex 前端vue页面公共路由
  117. func (this *CommonRouter) SocialIndex() error {
  118. return this.Render(fmt.Sprintf("/micro/social-pc/index.html"))
  119. }
  120. // SocialPcPage 前端vue页面公共路由
  121. func (this *CommonRouter) SocialPcPage(page string) error {
  122. return this.Render(fmt.Sprintf("/micro/social-pc/index.html"))
  123. }
  124. // 积分
  125. func (this *CommonRouter) IntegralIndex() error {
  126. return this.doIntegralPage()
  127. }
  128. func (this *CommonRouter) IntegralPage(htmlPage string) error {
  129. return this.doIntegralPage()
  130. }
  131. func (this *CommonRouter) doIntegralPage() error {
  132. userid, _ := this.GetSession("userId").(string)
  133. if userid == "" {
  134. return this.Redirect("/notin/page")
  135. }
  136. return this.Render(fmt.Sprintf("/frontRouter/pc/integral/sess/index.html"))
  137. }
  138. // 文库
  139. func (this *CommonRouter) DocsIndex() error {
  140. return this.doDocsPage()
  141. }
  142. func (this *CommonRouter) DocsPage(htmlPage string) error {
  143. return this.doDocsPage()
  144. }
  145. func (this *CommonRouter) doDocsPage() error {
  146. //userid, _ := this.GetSession("userId").(string)
  147. //if userid == "" {
  148. // return this.Redirect("/notin/page")
  149. //}
  150. return this.Render(fmt.Sprintf("/frontRouter/pc/docs/sess/index.html"))
  151. }
  152. // XspcIndex 线上课程
  153. func (this *CommonRouter) XspcIndex() error {
  154. return this.doXspcPage()
  155. }
  156. func (this *CommonRouter) XspcPage(htmlPage string) error {
  157. return this.doXspcPage()
  158. }
  159. func (this *CommonRouter) doXspcPage() error {
  160. //userid, _ := this.GetSession("userId").(string)
  161. //if userid == "" {
  162. // return this.Redirect("/notin/page")
  163. //}
  164. return this.Render(fmt.Sprintf("/frontRouter/pc/xspc/sess/index.html"))
  165. }
  166. // 商机管理
  167. func (this *CommonRouter) EntpcIndex() error {
  168. return this.doEntpcPage()
  169. }
  170. func (this *CommonRouter) EntpcPage(htmlPage string) error {
  171. return this.doEntpcPage()
  172. }
  173. func (this *CommonRouter) doEntpcPage() error {
  174. //P325 采购单位搜索调整,未登录用户也能访问采购单位画像
  175. ///entpc/unit_portrayal/天津银行股份有限公司
  176. userid, _ := this.GetSession("userId").(string)
  177. if userid == "" {
  178. return this.Redirect("/notin/page")
  179. }
  180. return this.Render(fmt.Sprintf("/frontRouter/pc/entpc/sess/index.html"))
  181. }
  182. // 大会员
  183. func (this *CommonRouter) BigpcIndex() error {
  184. return this.doPcBigPage("", "")
  185. }
  186. func (this *CommonRouter) BigpcPage(htmlPage string) error {
  187. types := this.GetString("type")
  188. return this.doPcBigPage(htmlPage, types)
  189. }
  190. var bigVipFreePageReg = regexp.MustCompile(`set_.*|free|unit_portrayal|analysis_(search|result)|pro_follow_detail|client_portrayal`)
  191. // 工作桌面需求 不需要判断用户权限
  192. func (this *CommonRouter) doPcBigPage(pageSign, types string) error {
  193. //page := pageSign
  194. userid, _ := this.GetSession("userId").(string)
  195. //没有登录跳转登录页面(采购单位画像| 企业画像 除外)
  196. if !strings.Contains(pageSign, "unit_portrayal") && !strings.Contains(pageSign, "ent_portrait") && !strings.Contains(pageSign, "ent_ser_portrait") && userid == "" {
  197. return this.Redirect("/notin/page")
  198. }
  199. if userid == "" {
  200. if strings.Contains(pageSign, "ent_ser_portrait") || strings.Contains(pageSign, "ent_portrait") {
  201. urlArr := strings.Split(pageSign, "_portrait/")
  202. entId := encrypt.DecodeArticleId2ByCheck(urlArr[len(urlArr)-1])[0]
  203. if seoId := EsSeoId(true, entId); seoId != "" {
  204. return this.Redirect(fmt.Sprintf("/qy/%s.html", seoId))
  205. }
  206. } else if strings.Contains(pageSign, "unit_portrayal") {
  207. urlArr := strings.Split(pageSign, "unit_portrayal/")
  208. //buyerName := urlArr[len(urlArr)-1]
  209. // 解码 URL 编码的字符串
  210. buyer, _ := url.QueryUnescape(urlArr[len(urlArr)-1])
  211. //buyer := this.GetString("buyer")
  212. if seoId := EsSeoId(false, buyer); seoId != "" {
  213. return this.Redirect(fmt.Sprintf("/dw/%s.html", seoId))
  214. }
  215. }
  216. }
  217. return this.Render(fmt.Sprintf("/frontRouter/pc/page_big_pc/sess/index.html"))
  218. }
  219. func EsSeoId(isWinner bool, idName string) string {
  220. if idName == "" {
  221. return idName
  222. }
  223. var seoId string
  224. redisKey := fmt.Sprintf("getSeoId_%v_%s", isWinner, idName)
  225. seoId = redis.GetStr("newother", redisKey)
  226. if seoId != "" {
  227. return seoId
  228. }
  229. if isWinner {
  230. winnerSeo := elastic.GetById("qyxy", "qyxy", idName)
  231. if winnerSeo != nil && len(*winnerSeo) > 0 {
  232. seoId = common.InterfaceToStr((*winnerSeo)[0]["nseo_id"])
  233. }
  234. } else {
  235. q := fmt.Sprintf(`{"query": {"bool": {"must": [{"match": {"buyer_name": "%s"}}]}},"from": 0,"size": 1,"_source":["seo_id"]}`, idName)
  236. winnerSeo := elastic.Get("buyer", "buyer", q)
  237. if winnerSeo != nil && len(*winnerSeo) > 0 {
  238. seoId = common.InterfaceToStr((*winnerSeo)[0]["seo_id"])
  239. }
  240. }
  241. if seoId != "" {
  242. redis.Put("newother", redisKey, seoId, -1)
  243. }
  244. return seoId
  245. }
  246. // 卡卷
  247. func (this *CommonRouter) CouponIndex() error {
  248. return this.doCouponPage()
  249. }
  250. func (this *CommonRouter) CouponPage(htmlPage string) error {
  251. return this.doCouponPage()
  252. }
  253. func (this *CommonRouter) doCouponPage() error {
  254. userid, _ := this.GetSession("userId").(string)
  255. if userid == "" {
  256. return this.Redirect("/notin/page")
  257. }
  258. return this.Render(fmt.Sprintf("/frontRouter/pc/coupon/sess/index.html"))
  259. }
  260. // 卡卷活动中转页
  261. func (this *CommonRouter) CouponActive() error {
  262. var url = "/"
  263. if this.GetString("url") != "" {
  264. url = this.GetString("url")
  265. }
  266. userid, _ := this.GetSession("userId").(string)
  267. if userid == "" {
  268. this.T["ref"] = url
  269. var shareid = this.GetString("id")
  270. if len(shareid) == 0 {
  271. shareid = "10"
  272. }
  273. this.T["logid"] = config.Seoconfig["jysskzy"].(string)
  274. this.T["shareid"] = se.EncodeString(shareid)
  275. return this.Render("/pc/notin.html", &this.T)
  276. }
  277. return this.Redirect(url)
  278. }
  279. // 活动留资
  280. func (this *CommonRouter) ActivityLeads(sign string) error {
  281. userid, _ := this.GetSession("userId").(string)
  282. if data, ok := mongodb.FindOne("saleLeads", map[string]interface{}{
  283. "userid": userid,
  284. "source": sign,
  285. }); data != nil && ok && len(*data) > 0 {
  286. return this.Redirect(config.ActiveConfig.Lottery)
  287. }
  288. return this.Redirect(fmt.Sprintf("/weixin/frontPage/bigmember/free/perfect_info?source=%v", sign))
  289. }
  290. // 组织架构
  291. func (this *CommonRouter) OrgpcIndex() error {
  292. return this.doEntpcPage()
  293. }
  294. func (this *CommonRouter) OrgpcPage(htmlPage string) error {
  295. return this.doOrgpcPage()
  296. }
  297. func (this *CommonRouter) doOrgpcPage() error {
  298. return this.Render(fmt.Sprintf("/frontRouter/pc/page_entbase_pc/sess/index.html"))
  299. }
  300. // ToSetEntPushSetPage 推送设置
  301. func (this *CommonRouter) ToSetEntPushSetPage() {
  302. this.Render("/weixin/entniche/entniche_seniorset.html")
  303. }