package front import ( "database/sql" "errors" "fmt" "jy/src/jfw/config" "jy/src/jfw/wx" "log" "math/rand" "net/url" "strconv" "github.com/gogf/gf/v2/util/gconv" "jy/src/jfw/jyutil" "app.yhyue.com/moapp/jypkg/public" util "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/date" mg "app.yhyue.com/moapp/jybase/mongodb" elastic "app.yhyue.com/moapp/jybase/es" "regexp" "strings" "time" "app.yhyue.com/moapp/jybase/encrypt" "app.yhyue.com/moapp/jybase/go-xweb/xweb" "app.yhyue.com/moapp/jybase/redis" "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy" "github.com/SKatiyar/qr" "go.mongodb.org/mongo-driver/bson" ) type Short struct { *xweb.Action article xweb.Mapper `xweb:"/article/(\\w+)/(.*).html"` //([pm]) qr xweb.Mapper `xweb:"/biddetail/(\\w+)/qr/(.+)"` replication xweb.Mapper `xweb:"/front/shorturl/replication"` //用户复制操作记录入库 nologinArticle xweb.Mapper `xweb:"/nologin/(\\w+)/(.*).html"` //([pm]) 无需登录 } var ( mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)") DateFullLayout = "2006-01-02 15:04:05" Map_stype = map[string]bool{ "content": true, "entservice": true, "bdprivate": true, "mailprivate": true, "bdcontent": true, "indexcontent": true, "advancedProject": true, } seoAgentReg = regexp.MustCompile("Baiduspider|360Spider|bingbot|Googlebot") detailNeedMosaic map[string]interface{} TypeCodeMap = map[string]string{ "拟建": "拟建项目", "采购意向": "采购意向", "预告": "招标预告", "预审": "资格预审", "预审结果": "资格预审结果", "论证意见": "论证意见", "需求公示": "需求公示", "招标": "公开招标", "邀标": "邀请招标", "询价": "询价采购", "竞谈": "竞争性谈判", "单一": "单一来源采购", "竞价": "竞价公告", "变更": "变更公告", "中标": "中标公示", "成交": "成交公告", "废标": "废标公告", "流标": "流标公告", "合同": "合同公告信息", "验收": "验收公告信息", "违规": "违规信息", } ) func (s *Short) Article(stype, id string) error { userId, _ := s.GetSession("userId").(string) if (stype == "content" || stype == "indexcontent") && userId == "" { if seoAgentReg.MatchString(s.UserAgent()) { sids := encrypt.CommonDecodeArticle(stype, id) return s.NologinCommon("", stype, id, sids[0]) } else { return s.Redirect("/notin/page") } } return s.LoginCommon(userId, stype, id) } func (s *Short) LoginCommon(userId, stype, id string) error { client := s.Header("User-Agent") bm := mobileReg.MatchString(client) //电脑端 剑鱼快照页面访问 if stype == "content" && !bm { //工作桌面内嵌 快照页 //老地址(地址不包含aside)且非工作桌面地址 if !strings.Contains(s.Request.URL.String(), "aside") && !strings.Contains(s.Request.URL.String(), "page_workDesktop") { paramSuffix := ".html?aside=0" replaceStr := ".html" if strings.Contains(s.Request.URL.String(), "?") { replaceStr = ".html?" paramSuffix = ".html?aside=0&" } return s.Redirect(fmt.Sprintf("%s%s%s", config.Sysconfig["workDesktopUrl"].(string), config.Sysconfig["webdomain"].(string), url.QueryEscape(strings.Replace(s.Request.URL.String(), replaceStr, paramSuffix, 1)))) } } //先判断是否有session source := s.GetString("source") disWord := s.GetString("disWord") aboutUrl := "/swordfish/about" //是否已经检查过,默认是检查过-true,分享过来的是未检查过-false // checkIsSubscribeFlag := true // if source == "app_infocontentshare" || source == "wx_infocontentshare" { // checkIsSubscribeFlag = false // } from_userid := "" if source != "" { aboutUrl += "?source=" + source if strings.Contains(source, "wx_infocontentshare") { decodeArr := encrypt.DecodeArticleId2ByCheck(id) if len(decodeArr) > 1 { from_userid = se.Encode2Hex(GetUserId(decodeArr[1])) //加密用户userid } } else if strings.Contains(source, "app_infocontentshare") { if from := s.GetString("from"); from != "" { from_userid = from } } aboutUrl += "&from=" + from_userid } if !Map_stype[stype] { s.Redirect("/not/nottype", 302) return nil } else if stype == "content" || stype == "bdcontent" || stype == "advancedProject" { if userId == "" { if s.GetString("state") == "wx" { //微信跳回来的 if code := s.GetString("code"); code != "" { if openid := jyutil.Getopenid(code); openid != "" { if CheckUserIsSubscribe(openid) { FindUserAndCreateSess(openid, s.Session(), "wx", false, true) } } } } else if public.CheckWxBrowser(s.Request) { //所有参数都不再使用,跳到微信验证用户 return s.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(s.Site()+s.Url()), "wx"), 302) } } if disWord != "" { from_userid = disWordNil(disWord, userId) } if userId == "" { //} && !regclient.MatchString(client) { //没有用户session //搜索引擎让过 s.Session().Set("referer", s.Request.RequestURI) if bm { //是否是移动端访问 s.Redirect(aboutUrl, 302) } else { if stype == "bdcontent" { var retMap = make(map[string]interface{}) stype = "content" _id := encrypt.CommonDecodeArticle(stype, id)[0] _, _, _, obj := pcVRT(_id, "", stype, true) if obj != nil && len(obj) > 0 { retMap["_id"] = id retMap["title"], _ = obj["title"].(string) retMap["area"], _ = obj["area"].(string) retMap["subtype"], _ = obj["subtype"].(string) retMap["subscopeclass"], _ = obj["s_subscopeclass"].(string) retMap["publishtime"] = util.IntAll(obj["publishtime"]) retMap["keywords"] = KeyWordHandle(obj) retMap["description"] = DescriptionHandle(stype, obj) } s.T["shareid"] = config.Seoconfig["baiduSEM-p"].(string) s.T["logid"] = config.Seoconfig["baiduSEM-p"].(string) s.T["obj"] = retMap s.Render("/pc/biddetail_bd.html", &s.T) } else { s.Redirect("/notin/page", 302) } } return nil } if stype == "bdcontent" { stype = "content" } } else if stype == "entservice" { //大客户数据快照展示 //se := util.SimpleEncrypt{"entservice"} sid := encrypt.SE3.DecodeString(id) if len(sid) == 0 || (len(sid) > 0 && sid == "") { s.Redirect("/notin/page", 302) return nil } catchKey := fmt.Sprintf("jypcdetail_%s_%s_%s", userId, stype, sid) if res := redis.Get("newother", catchKey); res == nil || res == "" { industry := s.GetString("industry") var shareid = s.GetString("id") if len(shareid) == 0 { shareid = "10" } s.T["logid"] = config.Seoconfig["jysskzy"].(string) s.T["shareid"] = se.EncodeString(shareid) s.T["keywords"] = s.GetString("kds") ssOpenid := s.Session().Get("s_m_openid") po, bo, wo, obj := pcVRT(sid, industry, stype, true) if obj != nil && len(obj) > 0 { if len(po) > 0 { s.T["projectOther"] = po } if len(bo) > 0 { s.T["buyerOther"] = bo } if len(wo) > 0 { s.T["winnerOther"] = wo } obj["urlpath"] = s.Uri() obj["industry"] = industry if ssOpenid != nil { obj["ucbsId"] = encrypt.EncodeArticleId2ByCheck("ucbs#" + ssOpenid.(string) + "#" + id) } //if false && isbid(obj["subtype"]) { // //bidding表有数据就有,没有不再查此中标企业得其他信息--需求来自数据和质量 // obj["winner_enttel"] = "" //getwinnertel(obj["winner"]) //} //判断时间 //如果是seo页面超过时间访问的进入首页 comeinTime := time.Unix(util.Int64All(obj["comeintime"]), 0) if stype == "indexcontent" { if count := public.MQFW.Count("seobidding", map[string]interface{}{"bid": sid}); count <= 0 && comeinTime.Before(time.Now().Add(time.Duration(-util.IntAll(config.Sysconfig["seoBeforeTimeHour"]))*time.Hour)) { return s.Redirect("/") } } FieldProcessing(obj, ssOpenid, industry, id, from_userid, userId, stype, false) if obj["projectname"] != nil { s.SetSession("projectname", obj["projectname"]) } if obj["entidlist"] != nil { //大会员中标企业跳转至画像 s_winner := util.ObjToString(obj["s_winner"]) idObjs, _ := obj["entidlist"].([]interface{}) winnerIdArr := []string{} for _, v := range strings.Split(s_winner, ",") { if v == "-" || !isInStringArr(util.ObjArrToStringArr(idObjs), v) { continue } winnerIdArr = append(winnerIdArr, encrypt.EncodeArticleId2ByCheck(v)) obj["entIds"] = winnerIdArr } } if obj["publishtime"] != nil { obj["publishtimeShorDate"] = time.Unix(util.Int64All(obj["publishtime"]), 0).Format(date.Date_Short_Layout) } s.T["url"] = s.Uri() obj["keywords"] = KeyWordHandle(obj) obj["description"] = DescriptionHandle(stype, obj) s.T["obj"] = obj content, _ := s.Render4Cache("/pc/biddetail_rec.html", &s.T) redis.Put("newother", catchKey, string(content), 60*20) return s.SetBody(content) } } else { return s.SetBody([]byte(res.(string))) } } ssOpenid := s.Session().Get("s_m_openid") var ( res *map[string]interface{} ok bool ) if userId == "" && ssOpenid != nil { res, ok = mongodb.FindOneByField("user", bson.M{"s_m_openid": ssOpenid, "s_unionid": bson.M{"$ne": ssOpenid}}, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1,"l_vip_starttime":1}`) if ok { userId = mg.BsonIdToSId((*res)["_id"]) } } else if userId != "" { //判断用户是否是vip res = jyutil.Compatible.Select(userId, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1,"l_vip_starttime":1}`) } entid := util.Int64All(s.GetSession("entId")) userPower := jy.GetBigVipUserBaseMsg(s.Session(), *config.Middleground) var ( isEntnicheNew bool = userPower.EntIsNew //新版超级订阅 isOldVip bool = false //新购超级订阅不能查看拟建项目详情页 isVip bool = userPower.VipStatus > 0 //超级订阅 isMember bool = userPower.Status > 0 //大会员 isEntniche bool = userPower.EntnicheStatus > 0 //商机管理 privatedata bool = userPower.PrivateGD //广东移动DICT 用户 isEntService bool = userPower.Data.Ent.PowerSource > 0 && userPower.Data.Entniche.IsEntPower > 0 //商机管理服务 ) if res != nil && len(*res) > 0 { if isVip && util.Int64All((*res)["l_vip_starttime"]) < util.Int64All(config.Sysconfig["contextOldVipLimit"]) { isOldVip = true } } entId := util.IntAll(entid) if entId > 0 && userPower.EntInfo[entId] != nil { isEntniche = userPower.EntInfo[entId].Status == 1 && userPower.EntInfo[entId].IsPower isEntnicheNew = userPower.EntInfo[entId].IsNew && isEntniche if isEntService = userPower.EntInfo[entId].IsService && userPower.EntInfo[entId].IsPower; isEntService { isEntnicheNew = false isEntniche = false } } if !isEntniche && privatedata { isEntniche = true } s.T["isVip"] = isVip s.T["isMember"] = isMember s.T["isEntniche"] = isEntniche s.T["isEntnicheNew"] = isEntnicheNew s.T["isEntService"] = isEntService if bm { //判断有没有取关,取关的话,跳转到关于剑鱼标讯页面 if ssOpenid != nil && ssOpenid != "" { isSubscribe := CheckUserIsSubscribe(ssOpenid.(string)) if !isSubscribe { return s.Redirect(aboutUrl, 302) } //之前sessionkeep.go中没有放userId,造成关注有问题 if userId == "" { FindUserAndCreateSess(ssOpenid.(string), s.Session(), "wx", false, true) } } surl := s.GetString("url") kds := s.GetString("keywords") industry := s.GetString("industry") var shareopenid, sid string sid_openid := encrypt.CommonDecodeArticle(stype, id) switch len(sid_openid) { case 0: s.Redirect(aboutUrl, 302) return nil default: shareopenid, sid = SwiDef(sid_openid) } s.T["keywords"] = kds if shareopenid != "" { s.T["shareopenid"] = shareopenid } myopenid, _ := s.Session().Get("s_m_openid").(string) if myopenid == "" { myopenid = shareopenid s.T["openid"] = myopenid //"-1" } else { s.T["openid"] = se.EncodeString(myopenid) //"-1" } mynickname, _ := s.GetSession("s_nickname").(string) myavatar, _ := s.GetSession("s_avatar").(string) s.T["nickname"] = mynickname s.T["avatar"] = myavatar s.T["signature"] = wx.SignJSSDK(s.Site() + s.Url()) obj := wxvisitD(sid, userId, myopenid, stype, (isVip && isOldVip) || isMember || isEntniche) canRead := false if ((isVip && isOldVip) || isMember || isEntniche) || //老版本vip、大会员、商机管理 ((isVip && !isOldVip) && (!(util.ObjToString(obj["subtype"]) == "拟建" || util.ObjToString(obj["subtype"]) == "采购意向"))) || //新超级订阅非采购意向”和“拟建项目” stype == "mailprivate" || stype == "indexcontent" || stype == "bdprivate" { //邮箱推送 canRead = true } else { canRead = SeeDetailLimit(obj, userId, sid) } if stype == "advancedProject" { newCanRead := false //判断此用户是否有打开的权限 newUserId := s.GetSession("base_user_id") pushData := public.BaseMysql.FindOne("leadproject_push", map[string]interface{}{"user_id": newUserId, "info_id": sid}, "id", "") //访问次数加1 if pushData == nil { newCanRead = false } else { public.BaseMysql.UpdateOrDeleteBySql("UPDATE leadproject_push SET visit_count=visit_count+1 ,lastvisit_time=? WHERE id = ?", time.Now().Format("2006-01-02 15:04:05"), (*pushData)["id"]) newCanRead = true } if newCanRead || canRead { obj = wxvisitD(sid, userId, myopenid, stype, true) canRead = true } s.T["canRead"] = canRead } if len(obj) > 0 { if canRead { FieldProcessing(obj, ssOpenid, industry, id, from_userid, userId, stype, true) //免费用户正文手机号替换 if obj["site"] == "剑鱼信息发布平台" && !isMember { //采购电话中标单位电话置空 if util.InterfaceToStr(obj["buyertel"]) != "" { obj["buyertel"] = "freeView" } if util.InterfaceToStr(obj["winnertel"]) != "" { obj["winnertel"] = "freeView" } //正文电话 手机号 邮箱处理 if detail, _ := obj["detail"].(string); detail != "" { //手机号 re1 := regexp.MustCompile("1[345789]{1}\\d{9}") detail1 := re1.ReplaceAllString(detail, `点击查看`) code := util.InterfaceToStr(obj["projectcode"]) if code != "" { detail1 = strings.ReplaceAll(detail1, code, "*********") } //座机 re2 := regexp.MustCompile("((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?") detail2 := re2.ReplaceAllString(detail1, `点击查看`) re4 := regexp.MustCompile("((400)-)(\\d{3,4}-)(\\d{3,})") detail4 := re4.ReplaceAllString(detail2, `点击查看`) //邮箱 re3 := regexp.MustCompile("([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)") detail3 := re3.ReplaceAllString(detail4, `点击查看`) obj["detail"] = strings.ReplaceAll(strings.ReplaceAll(detail3, `点击查看点击查看`, `点击查看`), "*********", code) } } if obj["entidlist"] != nil { //大会员中标企业跳转至画像 s_winner := util.ObjToString(obj["s_winner"]) idObjs, _ := obj["entidlist"].([]interface{}) winnerIdArr := []string{} for _, v := range strings.Split(s_winner, ",") { if v == "-" || !isInStringArr(util.ObjArrToStringArr(idObjs), v) { continue } winnerIdArr = append(winnerIdArr, encrypt.EncodeArticleId2ByCheck(v)) obj["entIds"] = winnerIdArr } } s.T["advertcode"] = s.GetString("advertcode") } else { obj = map[string]interface{}{ "title": obj["title"], "_id": obj["_id"], "subtype": obj["subtype"], } } //纠错随机回复 recoveryRight, _ := config.Sysconfig["recoveryRight"].([]interface{}) recVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(recoveryRight)) s.T["recVal"] = util.ObjToString(recoveryRight[recVal]) s.T["advertImg"] = config.Sysconfig["advertImg"] s.T["advertName"] = config.Sysconfig["advertName"] s.T["advertUrl"] = config.Sysconfig["advertUrl"] s.T["canRead"] = canRead obj["industry"] = industry obj["keywords"] = KeyWordHandle(obj) obj["description"] = DescriptionHandle(stype, obj) s.T["obj"] = obj //获取打赏文案 s.T["rewardText"], s.T["advertText"] = getRewardText() content, _ := s.Render4Cache("/weixin/wxinfocontent_rec.html", &s.T) return s.SetBody(content) } if surl != "" { return s.Redirect(surl) } } else { sids := encrypt.CommonDecodeArticle(stype, id) if len(sids) == 0 || (len(sids) > 0 && sids[0] == "") { s.Redirect("/notin/page", 302) return nil } sid := sids[0] //免费用户浏览三级页判断留资与浏览次数 indust := s.GetString("industry") if userId != "" && stype == "indexcontent" { //已登录用户直接跳转至正常三级页 return s.Redirect(fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", sid))) } industry := s.GetString("industry") var shareid = s.GetString("id") if len(shareid) == 0 { shareid = "10" } s.T["logid"] = config.Seoconfig["jysskzy"].(string) s.T["shareid"] = se.EncodeString(shareid) s.T["keywords"] = s.GetString("kds") s.DisableHttpCache() po, bo, wo, obj := pcVRT(sid, industry, stype, isVip || isMember || isEntniche) if obj != nil && len(obj) > 0 { var node bool if ((isVip && isOldVip) || isMember || isEntniche) || //老版本vip、大会员、商机管理 ((isVip && !isOldVip) && (!(util.ObjToString(obj["subtype"]) == "拟建" || util.ObjToString(obj["subtype"]) == "采购意向"))) || //新超级订阅非采购意向”和“拟建项目” stype == "mailprivate" || stype == "indexcontent" || stype == "bdprivate" { //邮箱推送 node = true } else { _, _, _, objc := pcVRT(sid, indust, stype, isVip || isMember || isEntniche) node = SeeDetailLimit(objc, userId, sid) } if obj["publishtime"] != nil { obj["publishtimeShorDate"] = time.Unix(util.Int64All(obj["publishtime"]), 0).Format(date.Date_Short_Layout) } s.T["canRead"] = node if stype == "advancedProject" { canRead := false //判断此用户是否有打开的权限 newUserId := s.GetSession("base_user_id") pushData := public.BaseMysql.FindOne("leadproject_push", map[string]interface{}{"user_id": newUserId, "info_id": sid}, "id", "") //访问次数加1 if pushData == nil { canRead = false } else { public.BaseMysql.UpdateOrDeleteBySql("UPDATE leadproject_push SET visit_count=visit_count+1 ,lastvisit_time=? WHERE id = ?", time.Now().Format("2006-01-02 15:04:05"), (*pushData)["id"]) canRead = true } if canRead || node { _, _, _, obj = pcVRT(sid, indust, stype, true) canRead = true node = canRead } s.T["canRead"] = canRead } if node { if len(po) > 0 { s.T["projectOther"] = po } if len(bo) > 0 { s.T["buyerOther"] = bo } if len(wo) > 0 { s.T["winnerOther"] = wo } //判断时间 //如果是seo页面超过时间访问的进入首页 comeinTime := time.Unix(util.Int64All(obj["comeintime"]), 0) if stype == "indexcontent" { if count := public.MQFW.Count("seobidding", map[string]interface{}{"bid": sid}); count <= 0 && comeinTime.Before(time.Now().Add(time.Duration(-util.IntAll(config.Sysconfig["seoBeforeTimeHour"]))*time.Hour)) { return s.Redirect("/") } } FieldProcessing(obj, ssOpenid, industry, id, from_userid, userId, stype, false) //免费用户正文手机号替换 if obj["site"] == "剑鱼信息发布平台" && !isMember { //采购电话中标单位电话置空 if util.InterfaceToStr(obj["buyertel"]) != "" { obj["buyertel"] = "freeView" } if util.InterfaceToStr(obj["winnertel"]) != "" { obj["winnertel"] = "freeView" } //正文电话 手机号 邮箱处理 if detail, _ := obj["detail"].(string); detail != "" { //手机号 re1 := regexp.MustCompile("1[345789]{1}\\d{9}") detail1 := re1.ReplaceAllString(detail, `点击查看`) code := util.InterfaceToStr(obj["projectcode"]) if code != "" { detail1 = strings.ReplaceAll(detail1, code, "*********") } //座机 re2 := regexp.MustCompile("((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?") detail2 := re2.ReplaceAllString(detail1, `点击查看`) re4 := regexp.MustCompile("((400)-)(\\d{3,4}-)(\\d{3,})") detail4 := re4.ReplaceAllString(detail2, `点击查看`) //邮箱 re3 := regexp.MustCompile("([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)") detail3 := re3.ReplaceAllString(detail4, `点击查看`) obj["detail"] = strings.ReplaceAll(strings.ReplaceAll(detail3, `点击查看点击查看`, `点击查看`), "*********", code) } } if obj["projectname"] != nil { s.SetSession("projectname", obj["projectname"]) } if obj["entidlist"] != nil { //大会员中标企业跳转至画像 s_winner := util.ObjToString(obj["s_winner"]) idObjs, _ := obj["entidlist"].([]interface{}) winnerIdArr := []string{} for _, v := range strings.Split(s_winner, ",") { if v == "-" || !isInStringArr(util.ObjArrToStringArr(idObjs), v) { continue } winnerIdArr = append(winnerIdArr, encrypt.EncodeArticleId2ByCheck(v)) obj["entIds"] = winnerIdArr } } } else { obj = map[string]interface{}{ "title": obj["title"], "_id": obj["_id"], "subtype": obj["subtype"], "stypeadd": obj["stypeadd"], } } obj["urlpath"] = s.Uri() obj["industry"] = industry if ssOpenid != nil { obj["ucbsId"] = encrypt.EncodeArticleId2ByCheck("ucbs#" + ssOpenid.(string) + "#" + id) } obj["keywords"] = KeyWordHandle(obj) obj["description"] = DescriptionHandle(stype, obj) s.T["obj"] = obj s.T["url"] = s.Uri() return s.Render("/pc/biddetail_rec.html", &s.T) } } return nil } func CNode(userId string) bool { if hasRetainedCapital(userId, "jyarticle_see3_plus") { return true } rM := map[string]interface{}{} rdata, ok := mongodb.Find("saleLeads", map[string]interface{}{ "userid": userId, }, `{"createtime":-1}`, nil, false, 0, 10) if rdata != nil && len(*rdata) > 0 && ok { for _, v := range *rdata { for kk, vv := range v { if vv == nil { continue } if rM[kk] != nil { continue } rM[kk] = vv } } delete(rM, "_id") delete(rM, "userid") delete(rM, "createtime") delete(rM, "client") } if userinfo := jyutil.Compatible.Select(userId, `{"s_phone":1,"s_m_phone":1,"s_myemail":1,"s_company":1,"o_jy":1,"o_vipjy":1}`); userinfo != nil && len(*userinfo) > 0 { s_phone := util.ObjToString((*userinfo)["s_phone"]) phone := util.If(s_phone == "", util.ObjToString((*userinfo)["s_m_phone"]), s_phone) if rM["phone"] == nil || rM["phone"] == "" { rM["phone"] = phone } if rM["company"] == nil || rM["company"] == "" { rM["company"] = util.ObjToString((*userinfo)["s_company"]) } } if rM["name"] != nil && rM["name"] != "" && rM["phone"] != nil && rM["phone"] != "" && rM["company"] != nil && rM["company"] != "" && rM["position"] != nil && rM["position"] != "" && rM["companyType"] != "" { if rM["position"] != "总裁" && rM["position"] != "总经理" && (rM["branch"] == nil || rM["branch"] == "") { return false } return true } return false } // 查看公告详情次数限制 func SeeDetailLimit(obj map[string]interface{}, userId, sid string) bool { watchKey := fmt.Sprintf("article_count_%d_%s_%d_%s", time.Now().Year(), time.Now().Month(), time.Now().Day(), userId) subTypeStr, _ := obj["subtype"].(string) if strings.Contains(subTypeStr, "拟建") || strings.Contains(subTypeStr, "采购意向") { return false } else { //检验是否留资 if CNode(userId) { return true } if seeRes := redis.Get("other", watchKey); seeRes != nil && seeRes != "" { if resVal, _ := seeRes.(string); resVal != "" { sidss := strings.Split(resVal, "_") canRead := config.Sysconfig["canReadNotice"] if len(sidss) < util.IntAll(canRead) { sidss = append(sidss, sid) arrs := RemoveDuplicatesAndEmpty(sidss) newVal := strings.Join(arrs, "_") redis.Put("other", watchKey, newVal, jy.GetExpire()) return true } else { for _, v := range sidss { if sid == v { return true } } return false } } } else { redis.Put("other", watchKey, sid, jy.GetExpire()) return true } } return false } func SwiDef(sid_openid []string) (string, string) { var shareopenid, sid string if len(sid_openid) > 1 { sid = sid_openid[0] shareopenid = sid_openid[1] } else { sid = sid_openid[0] } return shareopenid, sid } // user 权限获取 func UserPermission(userId string, ssOpenid interface{}) (bool, bool, bool) { var ( res *map[string]interface{} isVip, isMember, isEntniche, privatedata bool ) if userId == "" && ssOpenid != nil { res, _ = mongodb.FindOneByField("user", bson.M{"s_m_openid": ssOpenid, "s_unionid": bson.M{"$ne": ssOpenid}}, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1}`) userId = mg.BsonIdToSId((*res)["_id"]) } else { //判断用户是否是vip res = jyutil.Compatible.Select(userId, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1}`) } isVip = util.IntAll((*res)["i_vip_status"]) == 1 || util.IntAll((*res)["i_vip_status"]) == 2 isMember = util.IntAll((*res)["i_member_status"]) > 0 if phone, _ := util.If(util.ObjToString((*res)["s_phone"]) != "", util.ObjToString((*res)["s_phone"]), util.ObjToString((*res)["s_m_phone"])).(string); phone != "" { isEntniche = public.Mysql.CountBySql(`SELECT count(1) from entniche_user a INNER JOIN entniche_info b on (a.phone=? and a.power=1 and a.ent_id=b.id and b.status>0)`, phone) > 0 privatedata = public.Mysql.CountBySql(`select count(1) from privatedata where phone = ?`, phone) > 0 } if !isEntniche && privatedata { isEntniche = true } return isVip, isMember, isEntniche } // pc 移动共用字段处理 func FieldProcessing(obj map[string]interface{}, ssOpenid interface{}, industry, id, from_userid, userId, stype string, b bool) { obj["industry"] = industry if ssOpenid != nil { obj["ucbsId"] = encrypt.EncodeArticleId2ByCheck("ucbs#" + ssOpenid.(string) + "#" + id) } //判断是否公开联系人信息 if util.Int64All(obj["buyerhint"]) == 2 { obj["buyerperson"] = "" obj["buyertel"] = "" } if !b { href, _ := obj["href"].(string) href = strings.Replace(href, "\n", "", -1) if href != "" && !strings.HasPrefix(href, "http") { href = "http://" + href } obj["url"] = href } //大会员中标企业跳转至画像 if obj["entidlist"] != nil { if s_winner := util.ObjToString(obj["s_winner"]); s_winner != "" { entIdArr, winnerMap := []string{}, map[string]interface{}{} swinnerArr := strings.Split(s_winner, ",") eidList, _ := obj["entidlist"].([]interface{}) //先查询entlist 如果长度和s_winner不一致 根据企业名称查询id if len(eidList) != len(swinnerArr) { for _, v := range swinnerArr { winnerMap[v] = "" //临时更改为企业名称查询企业id rData := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"bool":{"should":[{"term":{"company_name":"%s"}},{"term":{"hname":"%s"}}],"minimum_should_match":1}},"_source":["name","_id","capital","company_phone"],"size":1}`, v, v)) if rData != nil && len(*rData) == 1 { if entId := util.ObjToString((*rData)[0]["_id"]); entId != "" { entIdArr = append(entIdArr, encrypt.EncodeArticleId2ByCheck(util.ObjToString((*rData)[0]["_id"]))) winnerMap[v] = encrypt.EncodeArticleId2ByCheck(util.ObjToString((*rData)[0]["_id"])) } } } } else { for k, v := range eidList { vstr := util.ObjToString(v) if vstr == "-" { continue } winnerMap[swinnerArr[k]] = encrypt.EncodeArticleId2ByCheck(vstr) } } obj["entId"] = entIdArr obj["winnerMap"] = winnerMap } } //移动端需要处理--剑鱼币 if b && from_userid != "" && se.Decode4Hex(from_userid) != "" && se.Decode4Hex(from_userid) != userId && util.ObjToString(obj["subtype"]) != "拟建" { //分享开打的 article_id := encrypt.CommonDecodeArticle(stype, id)[0] key := fmt.Sprintf("integral_article_%s_%s_%s", article_id, from_userid, userId) if redis.Incr("other", key) == 1 { redis.SetExpire("other", key, 60*60*24) err := jy.Publish(public.Mgo_Log, config.Sysconfig["nsq"].(string), config.Sysconfig["nsq_topic"].(string), jy.Jyweb_article_open, se.Decode4Hex(from_userid), jy.Jywx_node1) if err != nil { log.Println("nsq队列写入失败-->", jy.Jyweb_article_open, se.Decode4Hex(from_userid)) } } } } // disWord 为空时处理 func disWordNil(disWord, userId string) string { var from_userid string redisDis := redis.GetStr("other", "DIS_"+disWord[1:]) if redisDis != "" { suffix := disWord[len(disWord)-3:] //公告三级页处理 if suffix == suffix_msgt { effectiveTimeStr := strings.Split(redisDis, "##")[3] effectiveTime, _ := strconv.ParseInt(effectiveTimeStr, 10, 64) //是否计算佣金 if time.Now().Unix() <= effectiveTime { belongUserId := strings.Split(redisDis, "##")[1] //if (belongUserId != userId) { public.Mysql.ExecTx("口号使用", func(tx *sql.Tx) bool { //口号是否使用过 wordInfo := public.Mysql.Find("dis_word", map[string]interface{}{"userId": userId, "password": disWord}, "id", "", 0, 0) if len((*wordInfo)) == 0 { //新增口号使用 start_time := time.Now().Format(DateFullLayout) termValidityInt, _ := strconv.Atoi(fmt.Sprint(config.Sysconfig["termValidity"])) stop_time := TimeProcessing(time.Now().Format(DateFullLayout), termValidityInt).Format(DateFullLayout) insert := map[string]interface{}{ "password": disWord, "userId": userId, "belong_userid": belongUserId, "start_time": start_time, "stop_time": stop_time, } insert_1 := public.Mysql.InsertByTx(tx, "dis_word", insert) //口号使用表 log.Println("插入口号使用表", insert_1) from_userid = se.Encode2Hex(belongUserId) } return true }) } //} } } return from_userid } // 检查用户是否关注 func CheckUserIsSubscribe(openid string) bool { user, ok := mongodb.FindOneByField("user", map[string]interface{}{ "i_appid": 2, "s_m_openid": openid, "s_unionid": map[string]interface{}{"$ne": openid}, }, `{"i_ispush":1}`) if ok && user != nil { if (*user)["_id"] == nil || util.IntAllDef((*user)["i_ispush"], 1) == 0 { return false } else { return true } } return false } func (s *Short) Qr(t, id string) error { w := s.ResponseWriter w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Header().Set("Pragma", "no-cache") w.Header().Set("Expires", "0") w.Header().Set("Content-Type", "image/png") kds := s.GetString("kds") industry := s.GetString("industry") param := "?scan_source=pc" if t == "force" { param += "&ispcforceshare=1" } if kds != "" { param += "&keywords=" + kds } if industry != "" { param += "&industry=" + industry } data := config.Sysconfig["webdomain"].(string) + "/article/content/" + id + ".html" + param r, _ := qr.Encode(data, qr.M) pngdat := r.PNG() _, err := w.Write(pngdat) return err } func (s *Short) Replication() { userId, OK := s.GetSession("userId").(string) if OK && userId != "" { mongodb.Save("copyaction", map[string]interface{}{ "userid": userId, "createtime": time.Now().Unix(), "url": s.Request.Referer(), "client": s.Header("User-Agent"), }) } } func isbid(typ interface{}) bool { if typ != nil { subtype := util.ObjToString(typ) if subtype == "中标" || subtype == "合同" || subtype == "成交" { return true } } return false } // 中标企业库 func getwinnertel(company interface{}) string { if company != nil { data, _ := public.Mgo_Ent.FindOne("winner_enterprise", map[string]interface{}{ "company_name": util.ObjToString(company), }) if (*data)["company_phone"] != nil { return util.ObjToString((*data)["company_phone"]) } } return "" } func GetUserId(openid string) string { data, ok := public.MQFW.FindOne("user", map[string]interface{}{"s_m_openid": openid}) if data != nil && len(*data) > 0 && ok { userid := mg.BsonIdToSId((*data)["_id"]) return userid } return "" } func RemoveDuplicatesAndEmpty(a []string) (ret []string) { a_len := len(a) for i := 0; i < a_len; i++ { if (i > 0 && a[i-1] == a[i]) || len(a[i]) == 0 { continue } ret = append(ret, a[i]) } return } // 该节点是否留资 func hasRetainedCapital(uid, source string) bool { if count, err := mongodb.CountByErr("saleLeads", map[string]interface{}{"userid": uid, "source": source}); err != nil || count > 0 { return true } return false } func isInStringArr(arr []string, key string) bool { for _, v := range arr { if v == key { return true } } return false } func ReplaceStringByRegex(str, rule, replace string) (string, error) { reg, err := regexp.Compile(rule) if reg == nil || err != nil { return "", errors.New("正则MustCompile错误:" + err.Error()) } return reg.ReplaceAllString(str, replace), nil } // 未登录用户进行数据过滤 name 配置文件 func Filter(obj map[string]interface{}) map[string]interface{} { detail := fmt.Sprint(obj["detail"]) mosaicText := fmt.Sprintf(`%s`, util.ObjToString(config.Sysconfig["detailMosaic"])) detailText := fmt.Sprintf(`%s`, util.ObjToString(config.Sysconfig["detailMosaic"])) //for k, _ := range obj { // if ok, _ := detailNeedMosaic[k].(bool); ok { // if util.ObjToString(obj[k]) != "" { // detail = strings.ReplaceAll(detail, util.ObjToString(obj[k]), detailText) // } // //中标企业信息 // if k == "winnerMap" && obj[k] != nil { // winnerNewMap := map[string]interface{}{} // winnerMap := util.ObjToMap(obj[k]) // for _, wv := range *winnerMap { // winnerNewMap[mosaicText] = wv // } // obj[k] = winnerNewMap // } else { // obj[k] = mosaicText // } // } //} // for dk, dv := range detailNeedMosaic { if !dv.(bool) { continue } //if util.ObjToString(obj[dk]) != "" { // detail = strings.ReplaceAll(detail, util.ObjToString(obj[dk]), detailText) //} if util.InterfaceToStr(obj[dk]) != "" { value, b := obj[dk].(float64) if b { replaceStr := fmt.Sprintf("%v", int64(value)) detail = strings.ReplaceAll(detail, replaceStr, detailText) } else { detail = strings.ReplaceAll(detail, util.InterfaceToStr(obj[dk]), detailText) } } //中标企业信息 if dk == "winnerMap" { winnerNewMap := map[string]interface{}{} if obj[dk] != nil { winnerMap := util.ObjToMap(obj[dk]) for _, wv := range *winnerMap { winnerNewMap[mosaicText] = wv } } obj[dk] = winnerNewMap } else { obj[dk] = mosaicText } } obj["detail"] = detail return obj } // 未登录用户进行数据过滤 name 配置文件 func SearchFilter(obj map[string]interface{}) map[string]interface{} { //detail := fmt.Sprint(obj["detail"]) //mosaicText := fmt.Sprintf(`%s`, util.ObjToString(config.Sysconfig["detailMosaic"])) //for k, _ := range obj { // needMosaic, _ := config.Sysconfig["detailNeedMosaic"].(map[string]interface{}) // if ok, _ := needMosaic[k].(bool); ok { // //if util.ObjToString(obj[k]) != "" { // // detail = strings.ReplaceAll(detail, util.ObjToString(obj[k]), mosaicText) // // //敏感词过滤 // //} // if k == "winnerMap" { // winnerMap, _ := obj[k].(map[string]interface{}) // mosaicMap := map[string]interface{}{} // for i := 0; i < len(winnerMap); i++ { // mosaicMap[mosaicText] = mosaicText // } // obj["winnerMap"] = mosaicMap // } else { // obj[k] = mosaicText // } // // } //} //数字打码 //detail = RegDetail(detail) //detail = fsw.Repl(detail) //obj["detail"] = detail if detailNeedMosaic == nil { detailNeedMosaic, _ = config.Sysconfig["detailNeedMosaic"].(map[string]interface{}) } for dk, dv := range detailNeedMosaic { if !dv.(bool) { continue } //中标企业信息 if dk == "winnerMap" { winnerNewMap := map[string]interface{}{} if obj[dk] != nil { winnerMap := util.ObjToMap(obj[dk]) for _, wv := range *winnerMap { winnerNewMap[util.ObjToString(config.Sysconfig["detailMosaic"])] = wv } } obj[dk] = winnerNewMap } else { obj[dk] = util.ObjToString(config.Sysconfig["detailMosaic"]) } } return obj } func (s *Short) NologinArticle(stype, id string) error { userId := util.ObjToString(s.GetSession("userId")) sids := encrypt.CommonDecodeArticle(stype, id) if len(sids) == 0 || (len(sids) > 0 && sids[0] == "") { s.Redirect("/notin/page", 302) return nil } if userId != "" { //已登录用户直接跳转至正常三级页 return s.LoginCommon(userId, stype, id) } if detailNeedMosaic == nil { detailNeedMosaic, _ = config.Sysconfig["detailNeedMosaic"].(map[string]interface{}) } return s.NologinCommon(userId, stype, id, sids[0]) } func (s *Short) NologinCommon(userId, stype, id, sid string) error { tg := &Tags{} catchKey := fmt.Sprintf("jypcdetail_nologin_%s_%s", stype, sid) if res := redis.Get("newother", catchKey); res == nil || res == "" { industry := s.GetString("industry") var shareid = s.GetString("id") if len(shareid) == 0 { shareid = "10" } s.T["logid"] = config.Seoconfig["jysskzy"].(string) s.T["shareid"] = se.EncodeString(shareid) //s.T["keywords"] = s.GetString("kds") s.DisableHttpCache() po, bo, wo, obj := pcVRT(sid, industry, stype, false) if obj != nil && len(obj) > 0 { if len(po) > 0 { s.T["projectOther"] = po } if len(bo) > 0 { s.T["buyerOther"] = bo } if len(wo) > 0 { s.T["winnerOther"] = wo } FieldProcessing(obj, "", industry, id, "", userId, stype, false) obj["urlpath"] = s.Uri() obj["industry"] = industry if userId == "" { obj["winnerTitle"] = obj["winner"] obj["buyerTitle"] = obj["buyer"] obj["projectnameTitle"] = obj["projectname"] obj["projectcodeTitle"] = obj["projectcode"] log.Println(time.Now().UnixNano()) obj = Filter(obj) //obj["description"] = fmt.Sprintf("%s,%s。", obj["title"], baseInfo(obj)) } obj["agency"] = "" if obj["publishtime"] != nil { obj["publishtimeShorDate"] = time.Unix(util.Int64All(obj["publishtime"]), 0).Format(date.Date_Short_Layout) } obj["keywords"] = KeyWordHandle(obj) obj["description"] = DescriptionHandle("nologin", obj) s.T["obj"] = obj s.T["url"] = s.Uri() s.T["newBidInfoList"] = tg.GetNewBidInfo() s.T["industryInfoList"] = tg.GetConsult() s.T["hotLabelList"] = tg.GetHotLabel(30) content, _ := s.Render4Cache("/pc/tags/detail.html", &s.T) redis.Put("newother", catchKey, string(content), 60*2) return s.SetBody(content) } } else { return s.SetBody([]byte(res.(string))) } return nil } /* TDK description */ func baseInfo(obj map[string]interface{}) string { info := "" info += "省份:" //{{if eq .T.obj.area "A"}}全国{{else}}{{.T.obj.area}}{{end}} if area := util.ObjToString(obj["area"]); area == "A" { info += "全国" } else { info += area } info += ",城市:" + util.ObjToString(obj["city"]) info += ",招标代理机构:" + util.ObjToString(obj["agency"]) info += ",项目名称:" + util.ObjToString(obj["projectname"]) info += ",采购单位:" + util.ObjToString(obj["buyer"]) info += ",采购联系人:" + util.ObjToString(obj["buyerperson"]) info += ",采购电话:" + util.ObjToString(obj["buyertel"]) if obj["package"] == nil { info += ",项目预算(元):" + util.ObjToString(obj["budget"]) } if util.ObjToString(obj["subtype"]) == "单一" && util.ObjToString(obj["package"]) == "" { info += ",拟定单一来源采购供应商:" + util.ObjToString(obj["winner"]) } subtype := util.ObjToString(obj["subtype"]) if subtype == "中标" || subtype == "成交" || subtype == "合同" { if obj["winnerMap"] != nil { info += ",中标单位:" i := 0 for k, _ := range *util.ObjToMap(obj["winnerMap"]) { i++ info += k if i != len(*util.ObjToMap(obj["winnerMap"])) { info += "、" } } } if obj["bidamount"] != nil { info += ",中标金额(元):" + util.ObjToString(obj["bidamount"]) } if obj["bidamount"] != nil { info += ",联系方式:" + util.ObjToString(obj["bidamount"]) } } return info } // 分段匹配数字打码 func RegDetail(html string) string { mosaicText := util.ObjToString(config.Sysconfig["detailMosaicTxt"]) reg := regexp.MustCompile("<[^<>]{1,1000}>") //分段正则 s := reg.FindAllStringIndex(html, -1) //全文匹配分段 if len(s) > 0 { //走分段替换 arr := []string{} index := 0 for _, v := range s { if len(v) == 2 { // log.Println(html[index:v[0]]) txt, _ := ReplaceStringByRegex(html[index:v[0]], "[0-9]+", mosaicText) arr = append(arr, txt) //替换 arr = append(arr, html[v[0]:v[1]]) index = v[1] } } return strings.Join(arr, "") } return "" } func KeyWordHandle(obj map[string]interface{}) string { keywordArr := []string{} owner := util.InterfaceToStr(obj["owner"]) buyer := util.InterfaceToStr(obj["buyer"]) if buyer == "" { buyer = owner } if buyer != "" && buyer != config.Sysconfig["detailMosaicTxt"] { keywordArr = append(keywordArr, buyer) } if util.InterfaceToStr(obj["s_winner"]) != "" && util.InterfaceToStr(obj["s_winner"]) != config.Sysconfig["detailMosaicTxt"] { keywordArr = append(keywordArr, util.InterfaceToStr(obj["s_winner"])) } if obj["purchasinglist"] != nil && obj["purchasinglist"] != "" { i := 0 for _, v := range gconv.SliceMap(obj["purchasinglist"]) { if i == 5 { break } if util.InterfaceToStr(v["itemname"]) != "" && util.InterfaceToStr(obj["s_winner"]) != config.Sysconfig["detailMosaicTxt"] { keywordArr = append(keywordArr, util.InterfaceToStr(v["itemname"])) i++ } } } if util.InterfaceToStr(obj["subtype"]) != "" && util.InterfaceToStr(obj["subtype"]) != "其它" { keywordArr = append(keywordArr, TypeCodeMap[util.InterfaceToStr(obj["subtype"])]) } if util.InterfaceToStr(obj["area"]) != "" { keywordArr = append(keywordArr, util.InterfaceToStr(obj["area"])+"招标") } if util.InterfaceToStr(obj["city"]) != "" { keywordArr = append(keywordArr, util.InterfaceToStr(obj["city"])+"招标") } keywordArr = append(keywordArr, "剑鱼标讯") keyword := strings.Join(keywordArr, ",") return keyword } func DescriptionHandle(stype string, obj map[string]interface{}) string { description := "" publishtime := util.Int64All(obj["l_publishtime"]) if publishtime == 0 { publishtime = util.Int64All(obj["publishtime"]) } pushTime := time.Unix(publishtime, 0) title := util.InterfaceToStr(obj["title"]) owner := util.InterfaceToStr(obj["owner"]) buyer := util.InterfaceToStr(obj["buyer"]) if buyer == "" { buyer = owner } s_winner := util.InterfaceToStr(obj["s_winner"]) area := util.InterfaceToStr(obj["area"]) city := util.InterfaceToStr(obj["city"]) if stype == "bdprivate" { //bdprivate //{项目标题},采购单位:{采购单位名称},成交供应商:{中标企业名称},公告日期:{公告日期}。 descriptionArr := []string{} if title != "" { descriptionArr = append(descriptionArr, title) } if buyer != "" { descriptionArr = append(descriptionArr, fmt.Sprintf("采购单位:%s", buyer)) } if s_winner != "" { descriptionArr = append(descriptionArr, fmt.Sprintf("成交供应商:%s", s_winner)) } if publishtime != 0 { descriptionArr = append(descriptionArr, fmt.Sprintf("公告日期:%s", pushTime.Format("2006年01月02日"))) } descriptionArr = append(descriptionArr, "查看该项目信息详情请访问剑鱼标讯官网。") description = strings.Join(descriptionArr, ",") } else { //descriptionStr = "%s,项目所属地区是%s%s,项目采购单位是%s,项目发布时间是%s" descriptionArr := []string{} if title != "" { descriptionArr = append(descriptionArr, title) } if area != "" || city != "" { descriptionArr = append(descriptionArr, fmt.Sprintf("项目所属地区是%s%s", area, city)) } if buyer != "" { descriptionArr = append(descriptionArr, fmt.Sprintf("项目采购单位是%s", buyer)) } if publishtime != 0 { descriptionArr = append(descriptionArr, fmt.Sprintf("项目发布时间是%s", pushTime.Format("2006年01月02日"))) } descriptionArr = append(descriptionArr, "查看该项目信息详情请访问剑鱼标讯官网。") description = strings.Join(descriptionArr, ",") } return description }