12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538 |
- package front
- import (
- "fmt"
- "jfw/config"
- "jfw/jyutil"
- "jfw/public"
- "jfw/qrmanager"
- "jfw/tag"
- "jfw/wx"
- "log"
- "math/rand"
- mgdb "mongodb"
- "net/url"
- "qfw/util"
- "qfw/util/elastic"
- "qfw/util/jy"
- "qfw/util/redis"
- "regexp"
- "strconv"
- "strings"
- "sync"
- "time"
- "github.com/SKatiyar/qr"
- "github.com/go-xweb/httpsession"
- "github.com/go-xweb/xweb"
- "go.mongodb.org/mongo-driver/bson"
- "go.mongodb.org/mongo-driver/bson/primitive"
- )
- type Front struct {
- *xweb.Action
- ajaxPolling xweb.Mapper `xweb:"/front/ajaxPolling"` //登录轮询
- getLoginNum xweb.Mapper `xweb:"/front/getLoginNum/(.*)"` //
- login xweb.Mapper `xweb:"/front/login/(.*)"` //登录
- hasSign xweb.Mapper `xweb:"/front/hasSign"` //是否登录
- signOut xweb.Mapper `xweb:"/front/signOut"` //注销
- sess xweb.Mapper `xweb:"/front/sess/(.*)"` //微信跳转session登录
- viewdemo xweb.Mapper `xweb:"/front/viewdemo"` //微信跳转session登录
- getpage xweb.Mapper `xweb:"/swordfish/getpage"`
- wxsearch xweb.Mapper `xweb:"/swordfish/search"` //剑鱼标讯微信查询
- wxsearchlist xweb.Mapper `xweb:"/swordfish/searchlist"` //剑鱼标讯微信查询结果展示
- wxsearchlistPaging xweb.Mapper `xweb:"/swordfish/searchlist/paging"` //剑鱼标讯微信查询结果展示--分页
- delWxHistorySearch xweb.Mapper `xweb:"/swordfish/delWxHistorySearch"` //剑鱼标讯微信删除历史搜索
- ajaxReq xweb.Mapper `xweb:"/member/swordfish/ajaxReq"`
- wxpushView xweb.Mapper `xweb:"/wxpush/wxpushview"` //推送结果预览
- wxpushViewPaging xweb.Mapper `xweb:"/wxpush/wxpushview/paging"` //推送结果预览--分页
- guide xweb.Mapper `xweb:"/swordfish/guide/(.*)"`
- share xweb.Mapper `xweb:"/swordfish/share/([^.]*)"`
- wxprotocol xweb.Mapper `xweb:"/swordfish/wxprotocol"` //微信剑鱼标讯协议
- delc xweb.Mapper `xweb:"/delcache/(.+)"` //删除模板缓存
- wxpushListInfo xweb.Mapper `xweb:"/wxpush/bidinfo/(.*)"` //推送列表
- feedback xweb.Mapper `xweb:"/swordfish/feedback"` //意见反馈
- wxpushAjaxReq xweb.Mapper `xweb:"/wxpush/bid/ajaxReq"`
- searchinfolist xweb.Mapper `xweb:"/swordfish/searchinfolist(.*).html"` //剑鱼标讯pc查询
- about xweb.Mapper `xweb:"/swordfish/about"`
- shareabout xweb.Mapper `xweb:"/swordfish/shareabout/([^.]*)"`
- getIndexData xweb.Mapper `xweb:"/front/index.*"`
- urlrecord xweb.Mapper `xweb:"/front/urlrecord.*"`
- isrecord xweb.Mapper `xweb:"/front/isrecord/(.*)"`
- praise xweb.Mapper `xweb:"/swordfish/praise"`
- aboutsearch xweb.Mapper `xweb:"/swordfish/aboutsearch"`
- aboutSR xweb.Mapper `xweb:"/swordfish/aboutsearchresult"`
- delOL xweb.Mapper `xweb:"/swordfish/delovertimelist"` //手动删除30天无更新数据
- pcAjaxReq xweb.Mapper `xweb:"/front/pcAjaxReq"`
- myFeedbacks xweb.Mapper `xweb:"/swordfish/myFeedbacks"`
- wxerr xweb.Mapper `xweb:"/mob/err"`
- getRecomKWs xweb.Mapper `xweb:"/member/getRecomKWs"` //获取推荐关键词
- behaviorRecord xweb.Mapper `xweb:"/member/behaviorRecord"` //记录用户点击的关键词
- tSGuide xweb.Mapper `xweb:"/front/tenderSubscribe/guide"` //引导页
- transfer xweb.Mapper `xweb:"/front/transfer"` //原文链接中转
- jyblog xweb.Mapper `xweb:"/jyblog/index([^.]*).html"` //剑鱼标讯博客
- jybdetail xweb.Mapper `xweb:"/jyblog/([^.]*).html"` //剑鱼标讯博客三级页
- blogpraise xweb.Mapper `xweb:"/jyblog/blogpraise"` //剑鱼标讯博客三级页点赞
- encrypt xweb.Mapper `xweb:"/share/encrypt"` //分享三级页加密
- newhistorypush xweb.Mapper `xweb:"/swordfish/newhistorypush"` //新的历时推送记录
- historypush xweb.Mapper `xweb:"/swordfish/historypush"` //历时推送记录
- historypushPaging xweb.Mapper `xweb:"/swordfish/historypush/paging"` //历时推送记录--分页
- aboutus xweb.Mapper `xweb:"/front/aboutus.html"` //关于我们
- busicooperation xweb.Mapper `xweb:"/front/busicooperation.html"` //商务合作
- /********************wxkeyset:v1.8**************************/
- wxKeysetAjaxReq xweb.Mapper `xweb:"/wxkeyset/ajaxReq"` //订阅词ajax请求
- wxKeyset xweb.Mapper `xweb:"/wxkeyset/keyset/(\\w+)"` //订阅词设置
- subscribe xweb.Mapper `xweb:"/front/subscribe.html"` //电脑版剑鱼标讯设置
- gethotkey xweb.Mapper `xweb:"/front/gethotkey"` //获取热词
- rediskw xweb.Mapper `xweb:"/front/rediskw"` //pc订阅词存redis
- notin xweb.Mapper `xweb:"/notin/page"` //未登录用户访问三级页中转页
- topics xweb.Mapper `xweb:"/promotional/topics.html"` //SEM推广
- mobtopics xweb.Mapper `xweb:"/promotional/mobtopics.html"` //移动端专题推广
- followinfo xweb.Mapper `xweb:"/front/followinfo"` //redis用户关注日志
- /********************dev:2.0**************************/
- getClassifyList xweb.Mapper `xweb:"/front/getClassifyList"` //得到标签页表格数据
- advservices xweb.Mapper `xweb:"/front/advservices.html"` //广告服务
- extension xweb.Mapper `xweb:"/extension/(.*).html"` //推广页面
- recInof xweb.Mapper `xweb:"/front/recovery/info"` //纠错记录
- downloadJyApp xweb.Mapper `xweb:"/front/downloadJyApp"` //下载剑鱼标讯app的中转地址
- downloadJyAppQr xweb.Mapper `xweb:"/front/downloadJyApp/qr"` //扫码下载
- //downloadJyAppQrOther xweb.Mapper `xweb:"/front/downloadJyApp/qrOther"` //扫码下载
- limitSearchText xweb.Mapper `xweb:"/front/limitSearchText"` //扫码下载
- hpshare xweb.Mapper `xweb:"/front/homepage/wxshare"` //扫码分享
- hp xweb.Mapper `xweb:"/front/hp.html"` //QQ 分享好友到首页
- setSeoVersion xweb.Mapper `xweb:"/front/setSeoVersion"`
- //疫苗查询
- ymSearch xweb.Mapper `xweb:"/front/yimiao/search"`
- ymResult xweb.Mapper `xweb:"/front/yimiao/result"`
- ymResultHmtl xweb.Mapper `xweb:"/front/yimiao/html/(.+).html"`
- //落地页-18-08
- jylabShareTimeline xweb.Mapper `xweb:"/front/jylabShareTimeline"`
- //滑动验证
- sendMessage xweb.Mapper `xweb:"/front/sendMessage"`
- lpsubmit xweb.Mapper `xweb:"/front/landpage/submit"`
- checkPhoneNum xweb.Mapper `xweb:"/front/landpage/checkPhoneNum"`
- captcha xweb.Mapper `xweb:"/front/landpage/captcha"`
- //修改强制分享主动分享状态和时间
- updateShareStatus xweb.Mapper `xweb:"/share/updateShareStatus"`
- UpdateShareStatus_repair xweb.Mapper `xweb:"/share/UpdateShareStatus_repair"`
- hasPushHistory xweb.Mapper `xweb:"/front/hasPushHistory"`
- //静态页面通用地址
- staticPage xweb.Mapper `xweb:"/front/staticPage/(.+)"`
- //数据服务页面
- dataService xweb.Mapper `xweb:"/front/dataService.html"`
- //打赏页面
- payIndex xweb.Mapper `xweb:"/weixin/pay/index"` //微信打赏
- //获取打赏标语
- rewardText xweb.Mapper `xweb:"/front/rewardText"`
- //生成二维码
- qr xweb.Mapper `xweb:"/qr"`
- //app下载页面
- downloadapppage xweb.Mapper `xweb:"/front/downloadapppage/(weixin|normal)"`
- //创建订单来源统计
- orderSource xweb.Mapper `xweb:"/front/order/source"`
- reloadTo xweb.Mapper `xweb:"/front/reloadTo/(.*)"` //前端页面跳转
- //根据广告位代码获取广告
- getAdByCode xweb.Mapper `xweb:"/front/getAdByCode"`
- }
- var sewx util.SimpleEncrypt //微信的加密方法
- var mongodb = public.MQFW
- var urlMap map[string]interface{}
- var se = util.SE //移到tools中
- var isIosReg = regexp.MustCompile("\\(i[^;]+;( U;)? CPU.+Mac OS X")
- func init() {
- sewx = util.SimpleEncrypt{Key: "topnet"}
- xweb.AddAction(&Front{})
- xweb.AddAction(&Short{})
- xweb.AddAction(&OrgStructure{})
- urlMap = config.Sysconfig["redirect"].(map[string]interface{})
- }
- //前端页面加载
- func (this *Front) ReloadTo(href string) {
- this.T["transfer"] = fmt.Sprintf("%s/%s", config.Sysconfig["webdomain"].(string), href)
- this.Render("/pc/reloadTo.html", &this.T)
- }
- //获取打赏标语
- func (this *Front) RewardText() {
- rewardText, _ := getRewardText()
- this.Write(rewardText)
- return
- }
- //
- func (f *Front) Hp() error {
- return f.Redirect("/")
- }
- //二维码图片
- func (f *Front) Qr() error {
- w := f.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")
- r, _ := qr.Encode(config.Sysconfig["webdomain"].(string)+f.GetString("url"), qr.M)
- pngdat := r.PNG()
- _, err := w.Write(pngdat)
- return err
- }
- //二维码图片
- func (f *Front) Hpshare() error {
- w := f.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")
- r, _ := qr.Encode(config.Sysconfig["webdomain"].(string), qr.M)
- pngdat := r.PNG()
- _, err := w.Write(pngdat)
- return err
- }
- func (f *Front) DataService() {
- f.T["openPlatformUrl"] = config.Sysconfig["openPlatformUrl"].(string)
- f.T["logid"] = config.Seoconfig["jysy"].(string)
- f.Render("/pc/dataService.html", &f.T)
- }
- func (p *Front) PayIndex() error {
- defer util.Catch()
- param := p.GetString("param")
- params := strings.Split(param, "_")
- id := util.DecodeArticleId2ByCheck(params[1])[0]
- title := ""
- if id != "" {
- data, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, id, `{"title":1}`)
- if ok && (data == nil || *data == nil || len(*data) == 0) {
- data, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, id, `{"title":1}`)
- }
- if ok && data != nil && len(*data) > 0 {
- title, _ = (*data)["title"].(string)
- }
- }
- p.T["source"] = params[0]
- p.T["id"] = id
- p.T["pid"] = params[1]
- p.T["title"] = title
- p.T["signature"] = wx.SignJSSDK(p.Site() + p.Url())
- return p.Render("/weixin/pay.html", &p.T)
- }
- //
- func (f *Front) RecInof() error {
- var msg = ""
- var flag = true
- var tyflag = false
- id := util.DecodeArticleId2ByCheck(f.GetString("id"))[0] //文章id
- fieldName := f.GetString("fieldName") //纠错字段
- fwtScode := f.GetString("fwtscode") //纠错前权重最低字段
- if strings.Contains(fieldName, "price") || strings.Contains(fieldName, "bidamount") || strings.Contains(fieldName, "budget") {
- //tyflag = true
- }
- reccont := f.GetString("reccont") //纠错之后的内容
- originalcont := f.GetString("originalcont") //纠错之前的内容
- //纠错随机回复
- recoveryText, _ := config.Sysconfig["recoveryText"].([]interface{})
- recVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(recoveryText))
- msg = util.ObjToString(recoveryText[recVal])
- myopenid, _ := f.Session().Get("s_m_openid").(string)
- data := make(map[string]interface{})
- var obj map[string]interface{}
- if myopenid != "" && fieldName != "" {
- data["s_nickname"] = util.ObjToString(f.GetSession("s_nickname"))
- data["s_openid"] = myopenid
- fields := strings.Split(fieldName, "-")
- if len(fields) == 1 {
- data["s_field"] = fieldName //纠错字段
- } else if len(fields) == 2 {
- var fdone = fields[0]
- var fdtwo = fields[1]
- if strings.Contains(fdone, "winnerorder") {
- fdone = fdone[len(fdone)-1:]
- data["s_field"] = "winnerorder." + fdone + "." + fdtwo //纠错字段
- } else {
- data["s_field"] = "package." + fdone + "." + fdtwo //纠错字段
- }
- } else if len(fields) == 3 {
- var fdone = fields[0]
- var fdtwo = fields[1]
- var fdthree = fields[2]
- data["s_field"] = "package." + fdone + ".winnerorder." + fdtwo + "." + fdthree //纠错字段
- }
- data["s_beforecont"] = originalcont
- data["s_aftercont"] = reccont
- data["s_id"] = id //纠错文章id
- data["l_recoverydate"] = time.Now().Unix() //纠错时间
- _ = mongodb.Save("recoveryrecord", data)
- brobj, ok := mongodb.Find("bidding_rec", bson.M{"s_id": id}, `{"l_recoverydate":-1}`, nil, false, 0, 1)
- if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
- obj = (*brobj)[0]
- } else {
- aobj, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, id, nil)
- if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
- aobj, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, id, nil)
- }
- obj = *aobj
- }
- if ok && obj != nil && len(obj) != 0 {
- obj["s_id"] = id
- obj["l_recoverydate"] = time.Now().Unix()
- var packageArr = util.ObjToMap(obj["package"])
- if len(fields) == 1 {
- if tyflag {
- obj[fieldName], _ = strconv.ParseFloat(reccont, 64)
- } else {
- obj[fieldName] = reccont
- }
- } else if len(fields) == 2 {
- var fdone = fields[0]
- var fdtwo = fields[1]
- if strings.Contains(fdone, "winnerorder") {
- var winnerorderArr = obj["winnerorder"].([]interface{})
- fdone = fdone[len(fdone)-1:]
- kk, _ := strconv.Atoi(fdone)
- if len(winnerorderArr) > 0 {
- for k, v := range winnerorderArr {
- if k == kk {
- if tyflag {
- v.(map[string]interface{})[fdtwo], _ = strconv.ParseFloat(reccont, 64)
- } else {
- v.(map[string]interface{})[fdtwo] = reccont
- }
- break
- }
- }
- }
- } else {
- var pkgdata = (*packageArr)[fdone].(map[string]interface{})
- if tyflag {
- pkgdata[fdtwo], _ = strconv.ParseFloat(reccont, 64)
- } else {
- pkgdata[fdtwo] = reccont
- }
- }
- } else if len(fields) == 3 {
- var fdone = fields[0]
- var fdtwo, _ = strconv.Atoi(fields[1])
- var fdthree = fields[2]
- var pkgdata = (*packageArr)[fdone].(map[string]interface{})
- var pkgchilddata = pkgdata["winnerorder"].([]interface{})
- if len(pkgchilddata) > 0 {
- for k, v := range pkgchilddata {
- if k == fdtwo {
- if tyflag {
- v.(map[string]interface{})[fdthree], _ = strconv.ParseFloat(reccont, 64)
- } else {
- v.(map[string]interface{})[fdthree] = reccont
- }
- break
- }
- }
- }
- }
- brid := mongodb.Save("bidding_rec", obj)
- if len(brid) > 0 {
- redis.Del("other", "jypcdetail__rec"+id)
- updateLastWrongField(id, fwtScode)
- }
- }
- }
- f.ServeJson(map[string]interface{}{"msg": msg, "flag": flag})
- return nil
- }
- //更新取到的权重最低的字段到bidding表
- func updateLastWrongField(id, result string) {
- if result == "" {
- return
- }
- public.Mgo_Bidding.UpdateById(public.DbConf.Mongodb.Bidding.Collection, id, map[string]interface{}{
- "$set": map[string]interface{}{
- "lastwrongfield": result,
- },
- })
- }
- //轮询查登录状态
- func (f *Front) AjaxPolling() {
- reqType, _ := f.GetInteger("reqType")
- if reqType == 1 {
- shareIds := f.GetString("shareIds")
- shareidlist := strings.Split(shareIds, "___")
- if shareIds != "" && len(shareidlist) > 1 {
- shareidnum := shareidlist[0]
- shareidkop := shareidlist[1]
- PutWsByCode(se.DecodeString(shareidnum), nil, f.Session())
- PutWsByCode(se.DecodeString(shareidkop), nil, f.Session())
- f.ServeJson(map[string]string{})
- }
- } else if reqType == 2 {
- userInfo, _ := f.GetSession("rpcBackUserInfo").(map[string]interface{})
- f.ServeJson(userInfo)
- } else if reqType == 3 {
- reply := ""
- userId := se.DecodeString(f.GetString("userId"))
- qrToLab_ok, _ := redis.Exists("other", "qrToLab_"+userId)
- if qrToLab_ok {
- redis.Del("other", "qrToLab_"+userId)
- reply = "qrToLab_ok"
- }
- qrToLab_open_ok, _ := redis.Exists("other", "qrToLab_open_"+userId)
- if qrToLab_open_ok {
- redis.Del("other", "qrToLab_open_"+userId)
- reply = "qrToLab_open_ok"
- }
- if qrToLab_ok && qrToLab_open_ok {
- reply = "qrToLab_ok_open_ok"
- }
- f.ServeJson(map[string]string{"result": reply})
- } else if reqType == 4 {
- openid, _ := f.GetSession("s_m_openid").(string)
- ok := false
- if openid != "" {
- key := fmt.Sprintf("pcbiddetail_shareTimeline_%s", openid)
- ok, _ = redis.Exists("other", key)
- if ok {
- redis.Del("other", key)
- }
- }
- f.ServeJson(map[string]interface{}{"result": ok})
- }
- }
- //广告服务
- func (f *Front) Advservices() error {
- var shareid = f.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jyggfwy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
- }
- f.T["logid"] = config.Seoconfig["jyggfwy"].(string)
- f.T["shareid"] = se.EncodeString(shareid)
- return f.Render("/pc/advservices.html", &f.T)
- }
- //移动端专题推广
- func (f *Front) Mobtopics() error {
- return f.Render("/active/mobtopics.html")
- }
- //移动端专题推广
- func (f *Front) Extension(page string) error {
- //今日头条和百度推广用的同一个页面,如以后有变动,需拆分成两个。
- if page != "tengxun" {
- page = "baidu"
- }
- return f.Render("/active/ext-" + page + ".html")
- }
- //SEM推广
- func (f *Front) Topics() error {
- f.T["logid"] = config.Seoconfig["jySEMtgy"].(string)
- f.DisableHttpCache()
- //底部最新招标数据 3*6 条信息
- news := PCS_list("").([]interface{}) //Newbids("")[0].([]interface{})
- listAll := [][]map[string]interface{}{}
- i := 1
- list := []map[string]interface{}{}
- now := time.Now().Unix()
- for _, v := range news {
- if data, ok := v.(map[string]interface{}); ok {
- if data["publishtime"] == nil && data["time"] != nil {
- continue
- }
- if (now-util.Int64All(data["publishtime"]))/60 < 60 {
- data["printTime"] = fmt.Sprintf("%d分钟前", (now-util.Int64All(data["publishtime"]))/60)
- } else if (now-util.Int64All(data["publishtime"]))/(60*60) < 24 {
- data["printTime"] = fmt.Sprintf("%d小时前", (now-util.Int64All(data["publishtime"]))/(60*60))
- } else {
- data["printTime"] = data["time"]
- }
- data["index"] = i
- i++
- list = append(list, data)
- }
- if len(list) >= 6 {
- listAll = append(listAll, list)
- list = []map[string]interface{}{}
- i = 1
- }
- if len(listAll) >= 3 {
- break
- }
- }
- f.T["list"] = listAll
- f.T["logid"] = config.Seoconfig["jySEMtgy"].(string)
- return f.Render("/pc/landingpage.html", &f.T)
- }
- //
- func (f *Front) Notin() error {
- refer := "/"
- tmp := f.Header("Referer")
- if tmp != f.Request.URL.String() {
- refer = tmp
- }
- f.T["ref"] = refer
- var shareid = f.GetString("id")
- if len(shareid) == 0 {
- shareid = "10"
- }
- f.T["logid"] = config.Seoconfig["jysskzy"].(string)
- f.T["shareid"] = se.EncodeString(shareid)
- return f.Render("/pc/notin.html", &f.T)
- }
- //
- func (f *Front) Followinfo() error {
- var pid = f.GetString("pid")
- var kid = f.GetString("kid")
- var oid = f.GetString("oid")
- oldData := redis.Get("sso", "p_userdata_"+se.DecodeString(oid))
- var Rurl = util.ObjToString(f.GetSession("RURL"))
- var Rref = f.GetString("rref")
- rheader := f.Request.Header
- rhdua := "" //UA
- if len(rheader["User-Agent"]) > 0 {
- rhdua = rheader["User-Agent"][0]
- }
- userData := make(map[string]interface{})
- userData["Ros"] = util.GetOS(rhdua)
- userData["Rip"] = util.GetIp(f.Request)
- userData["Rbrowse"] = util.GetBrowse(rhdua)
- if f.GetSession("RReferer") == nil || util.ObjToString(f.GetSession("RReferer")) == "" {
- if Rref == "" {
- f.SetSession("RReferer", Rurl)
- } else {
- f.SetSession("RReferer", Rref)
- }
- }
- userData["RURL"] = Rurl
- modulelist := config.Seoconfig["module"].(map[string]interface{})
- for k, v := range modulelist {
- if strings.Contains(Rurl, k) {
- f.SetSession("RModule", v)
- }
- }
- if f.GetSession("RModule") == nil || util.ObjToString(f.GetSession("RModule")) == "" {
- f.SetSession("RModule", "首页")
- }
- //活动页模块
- if len(Rurl) > 1 && strings.Contains(Rurl, "id=") {
- activeCode := strings.Split(Rurl, "id=")[1]
- //首先查看是否从百度等搜索引擎过来的referer
- sourcelist := config.Seoconfig["source"].(map[string]interface{})
- for k, v := range sourcelist {
- if strings.Contains(activeCode, k) {
- if f.GetSession("RSource") == nil {
- f.SetSession("RSource", v)
- f.SetSession("RModule", activeCode+"活动页")
- f.SetSession("RActiveCode", activeCode)
- }
- }
- }
- }
- userData["RModule"] = f.GetSession("RModule")
- userData["RActiveCode"] = f.GetSession("RActiveCode")
- userData["RReferer"] = f.GetSession("RReferer")
- if f.GetSession("RSource") == nil || util.ObjToString(f.GetSession("RSource")) == "" {
- //首先查看是否从百度等搜索引擎过来的referer
- refererlist := config.Seoconfig["referer"].(map[string]interface{})
- for k, v := range refererlist {
- if strings.Contains(Rref, k) {
- if f.GetSession("RSource") == nil {
- f.SetSession("RSource", v)
- }
- }
- }
- if f.GetSession("RSource") == nil || util.ObjToString(f.GetSession("RSource")) == "" {
- f.SetSession("RSource", "剑鱼标讯网站")
- }
- }
- userData["RSource"] = f.GetSession("RSource")
- userData["Rparamkey"] = f.GetSession("paramkey")
- userData["Rparampublishtime"] = f.GetSession("parampublishtime")
- userData["Rparamarea"] = f.GetSession("paramarea")
- userData["Rparaminfotype"] = f.GetSession("paraminfotype")
- userData["Rprojectname"] = f.GetSession("projectname")
- if oldData != nil {
- redis.Put("sso", "p_userdata_"+se.DecodeString(pid), oldData, 13*60)
- redis.Put("sso", "p_userdata_"+se.DecodeString(kid), oldData, 13*60)
- } else {
- redis.Put("sso", "p_userdata_"+se.DecodeString(pid), userData, 13*60)
- redis.Put("sso", "p_userdata_"+se.DecodeString(kid), userData, 13*60)
- }
- f.ServeJson(map[string]string{
- "result": "ok",
- })
- return nil
- }
- //
- func (f *Front) Login(key string) error {
- shareid := se.DecodeString(key)
- openid := redis.GetStr("sso", "p_usershare_"+shareid)
- if openid != "" {
- ok, user, userInfo := FindUserAndCreateSess(openid, f.Session(), "pc", true)
- if ok {
- (*user)["shareid"] = shareid
- f.SetSession("user", *user)
- f.ServeJson(userInfo)
- } else {
- f.ServeJson(map[string]string{
- "result": "fail",
- })
- }
- } else {
- f.ServeJson(map[string]string{
- "result": "fail",
- })
- }
- return nil
- }
- //用户是否登录
- func (f *Front) HasSign() error {
- if userId, _ := f.GetSession("userId").(string); userId != "" {
- m := map[string]interface{}{
- "result": "ok",
- "s_nickname": f.GetSession("s_nickname"),
- "s_headimage": f.GetSession("s_avatar"),
- "encryptId": se.EncodeString(userId),
- }
- //是否需要重新登录,企业基础架构给虚拟账号重置密码后,需要重新登录
- if resetpwd, _ := redis.Exists("other", "resetpwd_"+userId); resetpwd {
- redis.Del("other", "resetpwd_"+userId)
- redis.Del("session", f.Session().Id())
- m["resetpwd"] = resetpwd
- }
- if openid, _ := f.GetSession("s_m_openid").(string); openid != "" {
- m["openid"] = se.EncodeString(openid)
- }
- f.ServeJson(m)
- }
- return nil
- }
- //用户注销
- func (f *Front) SignOut() error {
- userId, _ := f.GetSession("userId").(string)
- if userId != "" {
- redis.Del("other", jyutil.LoginRedisKey(userId))
- jy.DelUnlimitSessionId(fmt.Sprint(f.Session().Id()), userId) //多账号
- }
- f.DelSession("rpcBackUserInfo")
- f.DelSession("user")
- f.DelSession("s_nickname")
- f.DelSession("openid")
- f.DelSession("s_m_openid")
- f.DelSession("userId")
- f.DelSession("DataExportVerifyEmail_val")
- f.DelSession("DataExportVerifyPhone_val")
- f.DelSession("phoneAuthTime")
- f.DelSession("mailAuthTime")
- f.DelSession("phone")
- //entbase 企业信息
- f.DelSession("entId")
- f.DelSession("entName")
- f.DelSession("entUserId")
- f.DelSession("frameworkEntId")
- f.DelSession("frameworkEntName")
- f.ServeJson("ok")
- return nil
- }
- //微信公众号获取数字
- func (f *Front) GetLoginNum(prestr string) error {
- var oid = f.GetString("oid")
- var Rref = f.GetString("rref")
- f.SetSession("Rref", Rref)
- shareid, shareidot := qrmanager.QrCodeManager.GetQRCode(oid, prestr, f.Session(), f.Request)
- if prestr == config.Seoconfig["jydyy"].(string) { //订阅页面扫码回复信息
- redis.Put("sso", "pc_subscribe_reply_"+shareidot, "1", 15*60)
- }
- f.ServeJson(map[string]string{
- "num": se.EncodeString(shareid),
- "numot": se.EncodeString(shareidot),
- })
- return nil
- }
- //一键报告
- func (m *Front) Onekey() error {
- defer util.Catch()
- fkid := util.DecodeArticleId2ByCheck(m.GetString("fkid"))[0]
- flag := "N"
- data := make(map[string]interface{})
- if fkid != "" {
- userId, _ := m.GetSession("userId").(string)
- if userId != "" {
- userInfo, _ := mongodb.FindById("user", userId, nil)
- s_nickname, _ := (*userInfo)["s_nickname"].(string)
- s_name, _ := (*userInfo)["s_name"].(string)
- s_phone, _ := (*userInfo)["s_phone"].(string)
- if s_nickname != "" { //昵称
- data["s_username"] = s_nickname
- } else if s_name != "" { //s_name
- data["s_username"] = s_name
- } else if s_phone != "" {
- data["s_username"] = s_phone
- } else {
- data["s_username"] = userId
- }
- if s_name != "" {
- data["s_submitname"] = s_name
- } else if s_nickname != "" {
- data["s_submitname"] = s_nickname
- } else if s_phone != "" {
- data["s_submitname"] = s_phone
- } else {
- data["s_submitname"] = userId
- }
- data["s_submitid"] = userId
- }
- data["i_type"] = 7
- value := m.GetString("value")
- value = strings.Replace(value, "'", "&qpos;", 1)
- if len([]rune(value)) > 200 {
- value = util.SubString(value, 0, 200)
- }
- data["s_remark"] = "剑鱼标讯-一键报告排版问题\n" + value
- data["s_mop"] = m.GetString("mop") //来源:移动端or电脑端
- data["s_title"] = m.GetString("title")
- data["i_status"] = 0
- data["l_submitdate"] = time.Now().Unix()
- data["s_source"] = m.GetString("source")
- data["s_primaryhref"] = m.GetString("primaryhref")
- data["s_fkid"] = fkid
- data["s_from"] = "wx"
- id := mongodb.Save("interaction", data)
- if len(id) > 0 {
- flag = "Y"
- }
- redis.Put("other", "onekey_"+fkid, fkid, 10*60)
- }
- m.ServeJson(map[string]interface{}{
- "flag": flag,
- })
- return nil
- }
- //
- func (m *Front) Encrypt() error {
- defer util.Catch()
- id := m.GetString("id")
- s_openid := m.GetSession("s_m_openid")
- flag := "F"
- var sid_openid string
- util.Try(func() {
- if id != "" && s_openid != nil {
- id = util.DecodeArticleId2ByCheck(id)[0]
- sid_openid = util.EncodeArticleId2ByCheck(id, s_openid.(string))
- flag = "T"
- }
- }, func(e interface{}) {
- log.Println("分享短地址加密出错", e)
- })
- m.ServeJson(map[string]interface{}{
- "flag": flag,
- "sid_openid": sid_openid,
- })
- return nil
- }
- //
- func (m *Front) Wxerr() error {
- return m.Render("/_err.html")
- }
- //查找用户并创建session
- func FindUserAndCreateSess(openid string, sess *httpsession.Session, typ string, flag bool) (bool, *map[string]interface{}, map[string]interface{}) {
- return CreateSession(map[string]interface{}{
- "s_m_openid": openid,
- "s_unionid": map[string]interface{}{"$ne": openid}, //处理排除未关注用户点击菜单创建的用户
- "i_ispush": 1,
- }, sess, typ, flag)
- }
- func FindUserAndCreateSessById(userId primitive.ObjectID, sess *httpsession.Session, flag bool) (bool, *map[string]interface{}, map[string]interface{}) {
- return CreateSession(map[string]interface{}{
- "_id": userId,
- }, sess, "pc", flag)
- }
- func CreateSession(q map[string]interface{}, sess *httpsession.Session, typ string, flag bool) (bool, *map[string]interface{}, map[string]interface{}) {
- if q == nil || len(q) == 0 {
- return false, nil, nil
- }
- person, sessionVal := jyutil.GetSessionVal(q)
- if person == nil {
- return false, nil, nil
- }
- userid := util.ObjToString(sessionVal["userId"])
- if pcSessionFlag, ok := config.Sysconfig["pcSessionFlag"].(bool); pcSessionFlag && ok && flag {
- //无限制登陆用户
- if util.IntAll(sessionVal["i_unlimited"]) <= 0 {
- redis.Put("other", jyutil.LoginRedisKey(userid), sess.Id(), 3600*util.IntAllDef(config.Sysconfig["pcSessionTimeout"], 168))
- }
- }
- sessionVal["platform"] = typ
- sess.SetMultiple(sessionVal)
- infoData := map[string]interface{}{
- "result": "ok",
- "s_nickname": sessionVal["s_nickname"],
- "s_headimage": sessionVal["s_avatar"],
- }
- if openid, _ := (*person)["s_m_openid"].(string); openid != "" {
- infoData["openid"] = se.EncodeString(openid)
- } else {
- infoData["openid"] = ""
- }
- //大会员动画 清除首页缓存
- redis.Del("other", "jypcindex")
- //清除企业基础架构给虚拟账号重置密码后需要重新登录的标识
- redis.Del("other", "resetpwd_"+userid)
- return true, person, infoData
- }
- var bindUrl = "/front/account/phone/bind?mode=mergeBind"
- //微信跳转创建session
- func (m *Front) Sess(ostr string) error {
- defer util.Catch()
- if strings.Contains(ostr, "&") {
- ostr = strings.Split(ostr, "&")[0]
- }
- strs := strings.Split(ostr, "__")
- str := strings.Split(sewx.DecodeString(strs[0]), ",")
- if len(str) == 4 {
- openid := str[0]
- ok := false
- if str[1] == "_id" {
- ok, _, _ = FindUserAndCreateSessById(mgdb.StringTOBsonId(openid), m.Session(), false)
- } else {
- ok, _, _ = FindUserAndCreateSess(openid, m.Session(), "wx", false)
- }
- log.Println("ok:", ok)
- if ok {
- actionurl := util.ObjToString(urlMap[str[3]])
- if actionurl != "" {
- if len(strs) > 1 {
- if strings.Contains(actionurl, "followent/newInfo") {
- actionurl = fmt.Sprintf(actionurl, (strs[1] + "___" + strs[2]))
- } else {
- //支持多个参数%s..
- actionurl = fmt.Sprintf(actionurl, func(tmps []string) []interface{} {
- res := make([]interface{}, strings.Count(actionurl, "%s"))
- for k := range res {
- if k < len(tmps) {
- res[k] = tmps[k]
- } else {
- res[k] = ""
- }
- }
- return res
- }(strs[1:])...)
- }
- }
- //绑定手机号 跳转
- if flag, _ := config.Sysconfig["phoneFilterFlag"].(bool); flag { //开关是否开启
- //action走的nginx配置,需要单独在sess中判断
- for k, v := range config.PhoneFilterConfig["sessUrl"].(map[string]interface{}) {
- if strings.Contains(actionurl, k) {
- uid, _ := m.GetSession("userId").(string)
- if NeedBind(uid) {
- if mobileReg.MatchString(m.UserAgent()) {
- redirectTo := actionurl
- if util.ObjToString(v) != "" {
- redirectTo = util.ObjToString(v)
- }
- actionurl = bindUrl + "&redirectTo=" + encodeURIComponent(redirectTo)
- }
- }
- }
- }
- }
- //后续这个判断要去掉
- if str[1] == "uid" && str[3] == "rssset" {
- actionurl = actionurl + "?times=" + str[2]
- }
- m.Redirect(actionurl)
- } else {
- if !ok {
- log.Println("数据库连接超时!", openid)
- } else {
- log.Println("解析结果:", str, ",actionurl为空")
- }
- m.Render("_error.html")
- }
- } else {
- log.Println("没有找到该关注用户:", openid)
- m.Redirect("/swordfish/about", 302)
- }
- } else {
- log.Println("解析出错,解析结果:", str)
- m.Render("_error.html")
- }
- return nil
- }
- //删除模板缓存
- func (d *Front) Delc(url string) {
- defer util.Catch()
- d.App.TemplateMgr.CacheDelete(strings.Replace(url, "GG", "/", 1))
- d.WriteBytes([]byte("ok,清除路径:" + url))
- }
- func (m *Front) Viewdemo() {
- m.Redirect("/swordfish/guide/-1")
- }
- //剑鱼标讯用户协议
- func (m *Front) Wxprotocol() error {
- return m.Render("/weixin/wxprotocol.html")
- }
- //推送列表
- func (m *Front) WxpushListInfo(_id string) error {
- return m.Redirect("/swordfish/historypush")
- }
- func (m *Front) Feedback() error {
- defer util.Catch()
- m.T["openid"] = se.EncodeString(util.ObjToString(m.GetSession("s_m_openid")))
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- userId, _ := m.GetSession("userId").(string)
- list, _ := mongodb.Find("interaction", bson.M{"s_submitid": userId}, `{"l_submitdate":-1}`, `{"s_remark":1,"l_submitdate":1,"s_opinion":1,"i_status":1}`, false, 0, 200)
- m.T["list"] = list
- fkid := m.GetString("fkid")
- if fkid != "" {
- fkid = util.DecodeArticleId2ByCheck(fkid)[0]
- }
- fromName := m.GetString("fromName")
- if fromName != "" {
- if fromName == "zndy" {
- fromName = "剑鱼标讯实验室-智能订阅"
- } else if fromName == "sjdc" {
- fromName = "剑鱼标讯实验室-数据导出"
- } else if fromName == "cjss" {
- fromName = "剑鱼标讯实验室-超级搜索"
- } else if fromName == "zbqy" {
- fromName = "剑鱼标讯实验室-中标企业"
- } else if fromName == "gzqy" {
- fromName = "剑鱼标讯实验室-关注企业"
- }
- }
- _, m.T["advertText"] = getRewardText()
- m.T["advertImg"] = config.Sysconfig["advertImg"]
- m.T["advertName"] = config.Sysconfig["advertName"]
- m.T["advertUrl"] = config.Sysconfig["advertUrl"]
- m.T["fkid"] = fkid
- m.T["fromName"] = fromName
- return m.Render("/weixin/feedback.html", &m.T)
- }
- func (m *Front) GetIndexData() {
- defer util.Catch()
- redis_obj := redis.Get("other", "sw_index")
- var one map[string]interface{}
- if redis_obj != nil {
- one = redis_obj.(map[string]interface{})
- } else {
- rs, err := mongodb.Find("swordfish_index", nil, `{"_id":-1}`, nil, false, 0, 1)
- if err {
- one = (*rs)[0]
- one["i_site"] = util.IntAll(one["i_entsite"]) + util.IntAll(one["i_govsite"])
- avg := util.IntAll(one["i_bidmonth"])/21 + util.IntAll(one["i_bidmonth"])%21
- one["i_avg"] = avg
- one["i_my"] = util.IntAll(one["i_entsite"]) * 35 / 100
- one["i_hy"] = util.IntAll(one["i_entsite"]) * 15 / 100
- one["i_zb"] = util.IntAll(one["i_entsite"]) - util.IntAll(one["i_my"]) - util.IntAll(one["i_hy"])
- redis.Put("other", "sw_index", one, 60*60*2)
- } else {
- m.ServeJson("n")
- }
- }
- m.ServeJson(one)
- }
- func (m *Front) Urlrecord() {
- m.Render("/weixin/urlrecord.html")
- }
- func (m *Front) Isrecord(name string) {
- defer util.Catch()
- querystr := `{"$or":[{"s_name":"%s"},{"s_url":"%s"}]}`
- if name != "" {
- rs, _ := mongodb.Find("bidurlinfo", fmt.Sprintf(querystr, name, name), nil, nil, false, -1, -1)
- if len(*rs) == 0 {
- m.Write("f")
- } else {
- m.Write("y")
- }
- } else {
- m.Write("n")
- }
- }
- //招标订阅向导
- func (f *Front) TSGuide() error {
- defer util.Catch()
- userid := util.ObjToString(f.GetSession("userId"))
- if userid == "" {
- return f.Redirect("/swordfish/share/-1")
- }
- if f.Method() == "GET" {
- if !isInTSguide(userid) {
- return f.Redirect("/wxkeyset/keyset/index")
- }
- f.T["signature"] = wx.SignJSSDK(f.Site() + f.Url())
- return f.Render("/weixin/wxtsguide.html")
- } else {
- reqType := f.GetString("reqType")
- // index, _ := f.GetInteger("index")
- result := make(bson.M)
- if reqType == "save" {
- var keyMaps []map[string]interface{}
- keyWord := f.GetSlice("keyWord")
- area := f.GetString("area")
- if area == "" {
- result["flag"] = false
- } else { //20210930增加免费用户必须选择一个地区
- for _, v := range keyWord {
- vs := processKeyword(v)
- if vs == nil {
- continue
- }
- keyMaps = append(keyMaps, map[string]interface{}{
- "key": vs,
- "notkey": []string{},
- "from": 1, //用于记录是否可以选择全国
- })
- if len(keyMaps) >= 10 {
- break
- }
- }
- areas := map[string]interface{}{
- area: []string{},
- }
- saveData := bson.M{
- "o_jy.o_area": areas,
- "o_jy.a_key": keyMaps,
- "o_jy.l_modifydate": time.Now().Unix(),
- "i_ts_guide": 2,
- }
- result["flag"] = mongodb.UpdateById("user", userid, bson.M{"$set": saveData})
- }
- } else if reqType == "over" {
- saveData := bson.M{
- "i_ts_guide": 1,
- }
- result["flag"] = mongodb.UpdateById("user", userid, bson.M{"$set": saveData})
- } else if reqType == "preview" {
- rlt := elastic.GetByNgram(INDEX, TYPE, strings.Split(f.GetString("key"), " "), "", FINDF, `{"publishtime":-1}`, `"_id","title","publishtime","toptype","subtype","type","area","href","areaval"`, 0, 10)
- if *rlt != nil && len(*rlt) > 0 {
- for _, v := range *rlt {
- v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
- }
- }
- result["data"] = rlt
- }
- if result["flag"] != nil && result["flag"].(bool) {
- jy.ClearBigVipUserPower(userid)
- }
- f.ServeJson(result)
- }
- return nil
- }
- func isInTSguide(userid string) bool {
- if userid == "" {
- return false
- }
- data, ok := mongodb.FindById("user", userid, `{"o_jy":1,"i_ts_guide":1,"":1,"i_member_status":1,"i_vip_status":1}`)
- if ok {
- //付费用户无免费订阅,不进入订阅向导页面
- if util.IntAll((*data)["i_member_status"]) > 0 || util.IntAll((*data)["i_vip_status"]) > 0 {
- return false
- }
- o_jy, _ := (*data)["o_jy"].(map[string]interface{})
- i_ts_guide := util.IntAll((*data)["i_ts_guide"])
- if i_ts_guide == 2 || (i_ts_guide == 0 && len(o_jy) == 0) {
- return true
- }
- }
- return false
- }
- //查看原文中转
- func (f *Front) Transfer() error {
- return f.Redirect(f.GetString("url"))
- }
- //关于我们
- func (f *Front) Aboutus() error {
- code := f.GetString("code")
- if mobileReg.MatchString(f.UserAgent()) {
- return f.Redirect("/swordfish/about" + util.If(code != "", "?code="+code, "").(string))
- }
- var shareid = f.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jygywmy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
- }
- f.T["logid"] = config.Seoconfig["jygywmy"].(string)
- f.T["shareid"] = se.EncodeString(shareid)
- f.T["code"] = code
- content, _ := f.Render4Cache("/pc/aboutus.html", &f.T)
- redis.Put("other", "aboutus", string(content), -1)
- return f.SetBody(content)
- }
- //商务合作
- func (f *Front) Busicooperation() error {
- var shareid = f.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jyswhzy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
- }
- f.T["logid"] = config.Seoconfig["jyswhzy"].(string)
- f.T["shareid"] = se.EncodeString(shareid)
- content, _ := f.Render4Cache("/pc/businesscooperation.html", &f.T)
- return f.SetBody(content)
- }
- var keyLock sync.Mutex
- func (f *Front) Gethotkey() error {
- keyLock.Lock()
- defer keyLock.Unlock()
- keys := []interface{}{}
- tmp := redis.Get("sso", "jy_hotkeys")
- if tmp != nil {
- keys = tmp.([]interface{})
- } else {
- if keys := public.GetHotkeys(); keys != nil && len(keys) > 0 {
- redis.Put("sso", "jy_hotkeys", keys, -1)
- }
- }
- f.ServeJson(keys)
- return nil
- }
- //redis存储用户搜索关键词 企业 项目信息
- func (f *Front) Rediskw() error {
- skw := f.GetString("skw")
- num := f.GetString("num")
- if skw != "" && num != "" {
- skw = strings.Replace(strings.Replace(skw, " ", "++", -1), ";", " ", -1)
- num = se.DecodeString(num)
- redis.Put("sso", "pc_subscribe_"+num, skw, 15*60)
- }
- return nil
- }
- func (f *Front) DownloadJyApp() error {
- userAgent := f.UserAgent()
- isIos := isIosReg.MatchString(userAgent)
- source := f.GetString("source")
- code := f.GetString("code")
- downloadPlatform := f.GetString("platform")
- jyapp := config.Sysconfig["jyapp"].(map[string]interface{})
- //不是ios,并且在微信打开,跳转到中转页面
- if downloadPlatform == "" && !isIos && strings.Contains(userAgent, "MicroMessenger") {
- return f.Redirect("/front/downloadapppage/weixin?source=" + source + "&code=" + code)
- }
- isDownloadIos := downloadPlatform == "ios" || isIos
- pageName := f.GetString("page")
- //
- onlyFlag := code + downloadPlatform + pageName + source
- downLoadJyAppCode := f.GetSession("downLoadJyAppCode")
- if downLoadJyAppCode == nil || util.ObjToString(downLoadJyAppCode) != onlyFlag {
- now := time.Now()
- platform := ""
- if isIos {
- platform = "ios"
- } else if mobileReg.MatchString(userAgent) {
- platform = "android"
- } else {
- platform = "pc"
- }
- go mongodb.Save("jyapp_downloadlog", map[string]interface{}{
- "platform": platform,
- "code": code,
- "createtime": now.Unix(),
- "type": util.If(isDownloadIos, "appstore", "apk"),
- "page": pageName,
- "source": source,
- "refer": f.Refer(),
- "ip": util.GetIp(f.Request),
- "userAgent": userAgent,
- "i_year": now.Year(),
- "i_month": now.Month(),
- "i_day": now.Day(),
- "i_hour": now.Hour(),
- "i_minutes": now.Minute(),
- })
- }
- f.SetSession("downLoadJyAppCode", onlyFlag)
- //ios直接跳到应用商店
- appstoreurl, _ := jyapp["appstoreurl"].(string)
- if isDownloadIos {
- return f.Redirect(appstoreurl)
- }
- domain, _ := jyapp["domain"].(string)
- apkurl, _ := jyapp["apkurl"].(string)
- return f.Redirect(getDownloadUri(code, source, domain+apkurl))
- }
- //获取app下载地址,不通code对应不通渠道的app包
- func getDownloadUri(code, source, download string) string {
- jyapp := config.Sysconfig["jyapp"].(map[string]interface{})
- channelMap := jyapp["channelDir"].(map[string]interface{})
- if dir, ok := channelMap[code]; ok {
- return fmt.Sprintf(download, dir)
- }
- //渠道信息未匹配上 根据source判断微信
- if source == "wx_othershare" || source == "wx_infocontentshare" || source == "weixinAutoRpl" || source == "weixinAapplySub" {
- //微信下载地址
- wxdir, ok := channelMap["wx01"]
- if ok {
- return fmt.Sprintf(download, wxdir)
- }
- }
- //全部未匹配上 取默认
- return fmt.Sprintf(download, channelMap["default"])
- }
- func (f *Front) DownloadJyAppQr() error {
- w := f.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")
- data := config.Sysconfig["webdomain"].(string) + "/front/downloadJyApp?source=" + f.GetString("source") + "&page=" + f.GetString("page") + "&code=" + f.GetString("code")
- r, _ := qr.Encode(data, qr.M)
- pngdat := r.PNG()
- _, err := w.Write(pngdat)
- return err
- }
- func (f *Front) DownloadJyAppQrOther() error {
- w := f.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")
- discored := f.GetString("discored")
- data := config.Sysconfig["webdomain"].(string) + "/X/" + discored
- r, _ := qr.Encode(data, qr.M)
- pngdat := r.PNG()
- _, err := w.Write(pngdat)
- return err
- }
- func (f *Front) LimitSearchText() {
- userid := util.ObjToString(f.GetSession("userId"))
- if userid == "" || !public.Lst.IsCanLogin(userid) {
- f.Write("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\">需要登录!")
- return
- }
- timeout, _ := f.GetInteger("t")
- if timeout > 0 || timeout == -1 {
- public.Lst.TimeOut = timeout
- }
- count, _ := f.GetInteger("c")
- if (count > 0 || count == -1 || count == -2) && count != public.Lst.Count && public.Lst.Flag {
- public.Lst.Count = count
- public.Lst.Init()
- }
- flag, _ := f.GetInteger("f")
- status := ""
- if flag == -2 { //重置
- status = "重置"
- public.InitLimitSearchText(true)
- } else if flag == -1 && public.Lst.Flag { //关闭
- status = "关闭"
- public.Lst.Flag = false
- public.Lst.Clear()
- } else if flag == 1 && !public.Lst.Flag { //打开
- status = "打开"
- public.Lst.Flag = true
- public.Lst.Init()
- } else {
- if public.Lst.Flag {
- status = "打开"
- } else {
- status = "关闭"
- }
- }
- totalPage, _ := f.GetInteger("p")
- if totalPage > 0 && public.Lst.Flag {
- public.Lst.TotalPage = totalPage
- }
- //vip 大会员等用户 单独通道占比
- percentage, _ := f.GetInteger("pct")
- if percentage > 0 && public.Lst.Flag {
- public.Lst.Percentage = percentage
- }
- f.Write("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\">" + fmt.Sprintf(public.Lst.Msg, status, public.Lst.Count, public.Lst.TimeOut, public.Lst.TotalPage))
- }
- //设置js css 版本号,修改以后记得同步更新seo.json中的值
- func (f *Front) SetSeoVersion() {
- //!@111qqq@! md5=51a3b7b4ed3cf140
- if f.GetString("p") != "51a3b7b4ed3cf140" {
- return
- }
- version := ""
- if f.GetString("v") == "" {
- version = config.Seoconfig_Version
- if version == "" {
- version, _ = config.Seoconfig["version"].(string)
- }
- } else {
- version = f.GetString("v")
- config.Seoconfig_Version = version
- }
- f.Write("当前版本号:" + version)
- }
- func (f *Front) YmSearch() {
- f.Render("/weixin/yimiao/search.html")
- }
- func ymResult(a, y, n string) ([]string, []int, map[int]map[string]int, map[int]map[string]map[string]string) {
- q := map[string]interface{}{}
- if a != "" {
- q["area"] = a
- }
- if y != "" {
- q["year"] = util.IntAll(strings.TrimRight(y, "年"))
- }
- list, ok := mongodb.Find("yimiao", q, nil, nil, false, -1, -1)
- nameMap := map[string]bool{}
- yearMap := map[int]map[string]int{}
- titleHrefMap := map[int]map[string]map[string]string{}
- if ok {
- for _, v := range *list {
- vis := v["list"].([]interface{})
- year := util.IntAll(v["year"])
- if year < 2000 {
- continue
- }
- href := util.ObjToString(v["href"])
- id := util.ObjToString(v["id"])
- if id != "" {
- href = util.ObjToString(config.Sysconfig["webdomain"]) + "/article/content/" + util.EncodeArticleId2ByCheck(util.ObjToString(v["id"])) + ".html"
- }
- if titleHrefMap[year] == nil {
- titleHrefMap[year] = map[string]map[string]string{}
- }
- title := util.ObjToString(v["title"])
- for _, vi := range vis {
- vim, _ := vi.(map[string]interface{})
- name := strings.TrimSpace(util.ObjToString(vim["name"]))
- if name == "" {
- continue
- }
- number := util.IntAll(vim["number"])
- if n != "" && n != name {
- continue
- }
- if yearMap[year] == nil {
- yearMap[year] = map[string]int{}
- }
- yearMap[year][name] = yearMap[year][name] + number
- if title != "" && href != "" {
- if titleHrefMap[year][name] == nil {
- titleHrefMap[year][name] = map[string]string{}
- }
- titleHrefMap[year][name][title] = href
- }
- nameMap[name] = true
- }
- }
- }
- names := []string{}
- for k, _ := range nameMap {
- names = append(names, k)
- }
- years := []int{}
- for k, _ := range yearMap {
- years = append(years, k)
- }
- return names, years, yearMap, titleHrefMap
- }
- func (f *Front) YmResultHmtl(s string) error {
- ss := strings.Split(s, "_")
- a := ss[0]
- y := ss[1]
- n := ss[2]
- if a == "1" {
- a = ""
- }
- if y == "1" {
- y = ""
- }
- if n == "1" {
- n = ""
- }
- names, years, yearMap, _ := ymResult(a, y, n)
- f.T["years"] = years
- f.T["names"] = names
- f.T["yearMap"] = yearMap
- f.T["area"] = a
- return f.Render("/weixin/yimiao/three.html")
- }
- func (f *Front) YmResult() error {
- a := f.GetString("a")
- y := f.GetString("y")
- n := f.GetString("n")
- names, years, yearMap, titleHrefMap := ymResult(a, y, n)
- f.T["years"] = years
- f.T["names"] = names
- f.T["name"] = n
- f.T["yearMap"] = yearMap
- f.T["titleHrefMap"] = titleHrefMap
- f.T["area"] = a
- f.T["signature"] = wx.SignJSSDK(f.Site() + f.Url())
- if f.GetString("t") == "s" {
- return f.Render("/weixin/yimiao/share.html")
- } else {
- return f.Render("/weixin/yimiao/result.html")
- }
- }
- //
- func (f *Front) JylabShareTimeline() {
- userid := util.ObjToString(f.GetSession("userId"))
- if userid == "" {
- f.ServeJson(map[string]interface{}{
- "status": false,
- })
- return
- }
- reqType := f.GetString("reqType")
- if reqType == "update" {
- public.UpdateShareStatus(userid, "wx", 3, 1, 0, false)
- f.ServeJson(map[string]interface{}{
- "status": true,
- })
- } else {
- jylabsharetimeline := 1
- if public.CheckUserNeedForceShare(userid, public.ShareType_lab) {
- jylabsharetimeline = 0
- }
- f.ServeJson(map[string]interface{}{
- "jylabsharetimeline": jylabsharetimeline,
- })
- }
- }
- /**
- 成功分享后 更改分享相关信息
- shareType - 分享类型 1-详情页 2-推送列表 3-实验室
- shareProperty - 分享性质 1-被动分享 2-主动分享
- */
- func (s *Front) UpdateShareStatus() error {
- userid := util.ObjToString(s.GetSession("userId"))
- shareType, _ := s.GetInt("shareType")
- shareProperty, _ := s.GetInt("shareProperty")
- ispcforceshare, _ := s.GetInt("ispcforceshare")
- platform := s.GetString("platform")
- if platform == "" {
- platform = "wx"
- }
- public.UpdateShareStatus(userid, platform, shareType, shareProperty, ispcforceshare, s.GetString("isRepair") == "y")
- s.ServeJson(map[string]interface{}{})
- return nil
- }
- func (s *Front) StaticPage(pagename string) error {
- return s.Render("/staticpage/" + pagename)
- }
- func (f *Front) Downloadapppage(from string) error {
- f.T["from"] = from
- f.T["source"] = f.GetString("source")
- f.T["code"] = f.GetString("code")
- return f.Render("/weixin/downloadpage.html", &f.T)
- }
- func (f *Front) OrderSource() {
- userid, _ := f.GetSession("userId").(string)
- if userid != "" {
- source := f.GetString("source") //来源
- typ := f.GetString("type") //订单类型
- terminal := f.GetString("terminal") //订单创建终端
- ordercode := f.GetString("ordercode")
- mongodb.Save("order_source", map[string]interface{}{
- "userid": userid,
- "source": source,
- "createtime": time.Now().Unix(),
- "type": typ,
- "terminal": terminal,
- "ordercode": ordercode,
- })
- }
- }
- func NeedBind(uid string) bool {
- if uid != "" {
- if person, sessionVal := jyutil.GetSessionVal(map[string]interface{}{"_id": mgdb.StringTOBsonId(util.ObjToString(uid))}); len(sessionVal) > 0 && person != nil {
- s_phone := util.ObjToString((*person)["s_phone"])
- if s_phone == "" {
- s_phone = util.ObjToString((*person)["s_m_phone"])
- }
- if s_phone != "" {
- return false
- }
- regtime := util.Int64All((*person)["l_registedate"])
- reg := time.Unix(regtime, 0)
- //新用户时间
- accountMergeOnline, _ := config.Sysconfig["accountMergeOnline"].(string)
- onLineTime, _ := time.ParseInLocation(util.Date_Full_Layout, accountMergeOnline, time.Local)
- if remind, _ := (*person)["b_merge_remind"].(bool); remind { //不再提醒
- return false
- }
- if onLineTime.Before(reg) { //新用户
- return true
- }
- }
- }
- return false
- }
- func encodeURIComponent(str string) string {
- r := url.QueryEscape(str)
- r = strings.Replace(r, "+", "%20", -1)
- return r
- }
- //
- func (f *Front) GetAdByCode() {
- m := map[string]interface{}{}
- if ad_name := f.GetString("ad_name"); ad_name != "" {
- ad_names := strings.Split(ad_name, ",")
- ad_indexs := strings.Split(f.GetString("ad_index"), ",")
- for k, v := range ad_names {
- index := -1
- if k < len(ad_indexs) {
- index = util.IntAll(ad_indexs[k])
- }
- m[v] = tag.Ad(v, index)
- }
- }
- f.ServeJson(m)
- }
|