123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- package front
- import (
- "fmt"
- "jy/src/jfw/config"
- "jy/src/jfw/jyutil"
- "jy/src/jfw/wx"
- "net/url"
- "regexp"
- "strings"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/encrypt"
- elastic "app.yhyue.com/moapp/jybase/es"
- "app.yhyue.com/moapp/jybase/redis"
- "app.yhyue.com/moapp/jypkg/public"
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
- //"strings"
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
- )
- //前端通用路由
- type CommonRouter struct {
- *xweb.Action
- wxCommonPage xweb.Mapper `xweb:"/weixin/frontPage/(.*)/(sess|free)/(.*)"` //新的历时推送记录
- pcCommonPage xweb.Mapper `xweb:"/swordfish/frontPage/(.*)/(sess|free)/(.*)"` //新的历时推送记录
- //积分页面路由
- integralIndex xweb.Mapper `xweb:"/swordfish/integral/"`
- integralPage xweb.Mapper `xweb:"/swordfish/integral/(.*)"`
- //文库页面路由
- docsIndex xweb.Mapper `xweb:"/swordfish/docs/"`
- docsPage xweb.Mapper `xweb:"/swordfish/docs/(.*)"`
- //线上课程
- xspcIndex xweb.Mapper `xweb:"/jyxspc/"`
- xspcPage xweb.Mapper `xweb:"/jyxspc/(.*)"`
- //卡卷页面路由
- couponIndex xweb.Mapper `xweb:"/swordfish/coupon/"`
- couponPage xweb.Mapper `xweb:"/swordfish/coupon/(.*)"`
- couponActive xweb.Mapper `xweb:"/swordfish/CA"`
- //商机管理
- entpcIndex xweb.Mapper `xweb:"/entpc/"`
- entpcPage xweb.Mapper `xweb:"/entpc/(.*)"`
- //pc大会员
- bigpcIndex xweb.Mapper `xweb:"/swordfish/page_big_pc/"`
- bigpcPage xweb.Mapper `xweb:"/swordfish/page_big_pc/(.*)"`
- //双十一活动留资
- activityLeads xweb.Mapper `xweb:"/weixin/leads/(.*)"`
- //组织机构:organizational structure
- orgpcIndex xweb.Mapper `xweb:"/orgpc/"`
- orgpcPage xweb.Mapper `xweb:"/orgpc/(.*)"`
- //pcweb
- webIndex xweb.Mapper `xweb:"/swordfish/page_web_pc/"`
- webPcPage xweb.Mapper `xweb:"/swordfish/page_web_pc/(.*)"`
- //socialweb
- socialIndex xweb.Mapper `xweb:"/swordfish/page_knowledge_base/"`
- socialPcPage xweb.Mapper `xweb:"/swordfish/page_knowledge_base/(.*)"`
- //微信端企业订阅设置
- toSetEntPushSetPage xweb.Mapper `xweb:"/front/entniche/toSetEntPushSetPage"` //订阅收费推送设置
- }
- func init() {
- xweb.AddAction(&CommonRouter{})
- jy.InitBigVipService(public.Mysql)
- }
- func (this *CommonRouter) WxCommonPage(folder, loginSign, htmlPage string) error {
- if loginSign != "free" {
- openid, _ := this.GetSession("s_m_openid").(string)
- if openid == "" || (openid != "" && !CheckUserIsSubscribe(openid)) {
- stateKey := this.GetString("state")
- if stateKey == "" { //公众号回调
- return this.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(this.Site()+this.Url()), "wx"), 302)
- }
- openid = jyutil.Getopenid(this.GetString("code"))
- if ok, _, _ := FindUserAndCreateSess(openid, this.Session(), "wx", false, true); !ok {
- return this.Redirect("/swordfish/about")
- }
- }
- if !CheckUserIsSubscribe(openid) {
- return this.Redirect("/swordfish/about")
- }
- }
- this.T["signature"] = wx.SignJSSDK(this.Site() + this.Url())
- return this.Render(fmt.Sprintf("/frontRouter/wx/%s/%s/%s.html", folder, loginSign, htmlPage))
- }
- func (this *CommonRouter) PcCommonPage(folder, loginSign, htmlPage string) error {
- var shareid = this.GetString("id")
- if len(shareid) == 0 {
- shareid = "10"
- }
- this.T["shareid"] = se.EncodeString(shareid)
- if loginSign != "free" {
- if userid, _ := this.GetSession("userId").(string); userid == "" {
- var shareid = this.GetString("id")
- if len(shareid) == 0 {
- shareid = "10"
- }
- this.T["logid"] = config.Seoconfig["jysskzy"].(string)
- this.T["shareid"] = se.EncodeString(shareid)
- return this.Render("/pc/notin.html", &this.T)
- }
- }
- if folder == "collection" {
- this.T["logid"] = config.Seoconfig["collection"].(string)
- }
- return this.Render(fmt.Sprintf("/frontRouter/pc/%s/%s/%s.html", folder, loginSign, htmlPage))
- }
- // WebIndex 前端vue页面公共路由
- func (this *CommonRouter) WebIndex() error {
- return this.Render(fmt.Sprintf("/micro/web-pc/index.html"))
- }
- // WebPcPage 前端vue页面公共路由
- func (this *CommonRouter) WebPcPage(page string) error {
- if userId, _ := this.GetSession("userId").(string); userId == "" { //P414
- if cc, err := this.GetCookie(jy.ChannelCookieName); err == nil {
- this.T["cooperateCode"] = cc.Value
- }
- }
- return this.Render(fmt.Sprintf("/micro/web-pc/index.html"))
- }
- // SocialIndex 前端vue页面公共路由
- func (this *CommonRouter) SocialIndex() error {
- return this.Render(fmt.Sprintf("/micro/social-pc/index.html"))
- }
- // SocialPcPage 前端vue页面公共路由
- func (this *CommonRouter) SocialPcPage(page string) error {
- return this.Render(fmt.Sprintf("/micro/social-pc/index.html"))
- }
- // 积分
- func (this *CommonRouter) IntegralIndex() error {
- return this.doIntegralPage()
- }
- func (this *CommonRouter) IntegralPage(htmlPage string) error {
- return this.doIntegralPage()
- }
- func (this *CommonRouter) doIntegralPage() error {
- userid, _ := this.GetSession("userId").(string)
- if userid == "" {
- return this.Redirect("/notin/page")
- }
- return this.Render(fmt.Sprintf("/frontRouter/pc/integral/sess/index.html"))
- }
- // 文库
- func (this *CommonRouter) DocsIndex() error {
- return this.doDocsPage()
- }
- func (this *CommonRouter) DocsPage(htmlPage string) error {
- return this.doDocsPage()
- }
- func (this *CommonRouter) doDocsPage() error {
- //userid, _ := this.GetSession("userId").(string)
- //if userid == "" {
- // return this.Redirect("/notin/page")
- //}
- return this.Render(fmt.Sprintf("/frontRouter/pc/docs/sess/index.html"))
- }
- // XspcIndex 线上课程
- func (this *CommonRouter) XspcIndex() error {
- return this.doXspcPage()
- }
- func (this *CommonRouter) XspcPage(htmlPage string) error {
- return this.doXspcPage()
- }
- func (this *CommonRouter) doXspcPage() error {
- //userid, _ := this.GetSession("userId").(string)
- //if userid == "" {
- // return this.Redirect("/notin/page")
- //}
- return this.Render(fmt.Sprintf("/frontRouter/pc/xspc/sess/index.html"))
- }
- // 商机管理
- func (this *CommonRouter) EntpcIndex() error {
- return this.doEntpcPage()
- }
- func (this *CommonRouter) EntpcPage(htmlPage string) error {
- return this.doEntpcPage()
- }
- func (this *CommonRouter) doEntpcPage() error {
- //P325 采购单位搜索调整,未登录用户也能访问采购单位画像
- ///entpc/unit_portrayal/天津银行股份有限公司
- userid, _ := this.GetSession("userId").(string)
- if userid == "" {
- return this.Redirect("/notin/page")
- }
- return this.Render(fmt.Sprintf("/frontRouter/pc/entpc/sess/index.html"))
- }
- // 大会员
- func (this *CommonRouter) BigpcIndex() error {
- return this.doPcBigPage("", "")
- }
- func (this *CommonRouter) BigpcPage(htmlPage string) error {
- types := this.GetString("type")
- return this.doPcBigPage(htmlPage, types)
- }
- var bigVipFreePageReg = regexp.MustCompile(`set_.*|free|unit_portrayal|analysis_(search|result)|pro_follow_detail|client_portrayal`)
- // 工作桌面需求 不需要判断用户权限
- func (this *CommonRouter) doPcBigPage(pageSign, types string) error {
- //page := pageSign
- userid, _ := this.GetSession("userId").(string)
- //没有登录跳转登录页面(采购单位画像| 企业画像 除外)
- if !strings.Contains(pageSign, "unit_portrayal") && !strings.Contains(pageSign, "ent_portrait") && !strings.Contains(pageSign, "ent_ser_portrait") && userid == "" {
- return this.Redirect("/notin/page")
- }
- if userid == "" {
- if strings.Contains(pageSign, "ent_ser_portrait") || strings.Contains(pageSign, "ent_portrait") {
- urlArr := strings.Split(pageSign, "_portrait/")
- entId := encrypt.DecodeArticleId2ByCheck(urlArr[len(urlArr)-1])[0]
- if seoId := EsSeoId(true, entId); seoId != "" {
- return this.Redirect(fmt.Sprintf("/qy/%s.html", seoId))
- }
- } else if strings.Contains(pageSign, "unit_portrayal") {
- urlArr := strings.Split(pageSign, "unit_portrayal/")
- //buyerName := urlArr[len(urlArr)-1]
- // 解码 URL 编码的字符串
- buyer, _ := url.QueryUnescape(urlArr[len(urlArr)-1])
- //buyer := this.GetString("buyer")
- if seoId := EsSeoId(false, buyer); seoId != "" {
- return this.Redirect(fmt.Sprintf("/dw/%s.html", seoId))
- }
- }
- }
- return this.Render(fmt.Sprintf("/frontRouter/pc/page_big_pc/sess/index.html"))
- }
- func EsSeoId(isWinner bool, idName string) string {
- if idName == "" {
- return idName
- }
- var seoId string
- redisKey := fmt.Sprintf("getSeoId_%v_%s", isWinner, idName)
- seoId = redis.GetStr("newother", redisKey)
- if seoId != "" {
- return seoId
- }
- if isWinner {
- winnerSeo := elastic.GetById("qyxy", "qyxy", idName)
- if winnerSeo != nil && len(*winnerSeo) > 0 {
- seoId = common.InterfaceToStr((*winnerSeo)[0]["nseo_id"])
- }
- } else {
- q := fmt.Sprintf(`{"query": {"bool": {"must": [{"match": {"buyer_name": "%s"}}]}},"from": 0,"size": 1,"_source":["seo_id"]}`, idName)
- winnerSeo := elastic.Get("buyer", "buyer", q)
- if winnerSeo != nil && len(*winnerSeo) > 0 {
- seoId = common.InterfaceToStr((*winnerSeo)[0]["seo_id"])
- }
- }
- if seoId != "" {
- redis.Put("newother", redisKey, seoId, -1)
- }
- return seoId
- }
- // 卡卷
- func (this *CommonRouter) CouponIndex() error {
- return this.doCouponPage()
- }
- func (this *CommonRouter) CouponPage(htmlPage string) error {
- return this.doCouponPage()
- }
- func (this *CommonRouter) doCouponPage() error {
- userid, _ := this.GetSession("userId").(string)
- if userid == "" {
- return this.Redirect("/notin/page")
- }
- return this.Render(fmt.Sprintf("/frontRouter/pc/coupon/sess/index.html"))
- }
- // 卡卷活动中转页
- func (this *CommonRouter) CouponActive() error {
- var url = "/"
- if this.GetString("url") != "" {
- url = this.GetString("url")
- }
- userid, _ := this.GetSession("userId").(string)
- if userid == "" {
- this.T["ref"] = url
- var shareid = this.GetString("id")
- if len(shareid) == 0 {
- shareid = "10"
- }
- this.T["logid"] = config.Seoconfig["jysskzy"].(string)
- this.T["shareid"] = se.EncodeString(shareid)
- return this.Render("/pc/notin.html", &this.T)
- }
- return this.Redirect(url)
- }
- // 活动留资
- func (this *CommonRouter) ActivityLeads(sign string) error {
- userid, _ := this.GetSession("userId").(string)
- if data, ok := mongodb.FindOne("saleLeads", map[string]interface{}{
- "userid": userid,
- "source": sign,
- }); data != nil && ok && len(*data) > 0 {
- return this.Redirect(config.ActiveConfig.Lottery)
- }
- return this.Redirect(fmt.Sprintf("/weixin/frontPage/bigmember/free/perfect_info?source=%v", sign))
- }
- // 组织架构
- func (this *CommonRouter) OrgpcIndex() error {
- return this.doEntpcPage()
- }
- func (this *CommonRouter) OrgpcPage(htmlPage string) error {
- return this.doOrgpcPage()
- }
- func (this *CommonRouter) doOrgpcPage() error {
- return this.Render(fmt.Sprintf("/frontRouter/pc/page_entbase_pc/sess/index.html"))
- }
- // ToSetEntPushSetPage 推送设置
- func (this *CommonRouter) ToSetEntPushSetPage() {
- this.Render("/weixin/entniche/entniche_seniorset.html")
- }
|