12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403 |
- package front
- import (
- "fmt"
- "jfw/config"
- "jfw/filter"
- "jfw/public"
- "jfw/qrmanager"
- "jfw/wx"
- "log"
- "math/rand"
- // "net/url"
- "regexp"
- "strconv"
- "github.com/SKatiyar/qr"
- //"math/rand"
- "qfw/util"
- "qfw/util/elastic"
- "qfw/util/redis"
- "strings"
- "sync"
- "time"
- ca "ucbsutil/cassandra"
- "github.com/go-xweb/httpsession"
- "github.com/go-xweb/xweb"
- "gopkg.in/mgo.v2/bson"
- )
- type userPool struct {
- lock sync.Mutex
- openIds []string
- user map[string]*map[string]interface{}
- }
- 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"`
- newSordfish xweb.Mapper `xweb:"/"` //剑鱼pc首页
- 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"`
- getpraise xweb.Mapper `xweb:"/swordfish/getpraise"`
- 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"` //剑鱼博客三级页点赞
- searchResult xweb.Mapper `xweb:"/list/(\\w+)/(\\w+).html"` //剑鱼分类 地区结果列表
- encrypt xweb.Mapper `xweb:"/share/encrypt"` //分享三级页加密
- 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"` //商务合作
- //bidsearchforent xweb.Mapper `xweb:"/front/bidsearchforent.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"` //扫码下载
- 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"`
- //落地页-18-08
- landingPage xweb.Mapper `xweb:"/front/landingpage.html"`
- //滑动验证
- 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/(.+)"`
- }
- var sewx util.SimpleEncrypt //微信的加密方法
- var mongodb = public.MQFW
- var urlMap map[string]interface{}
- //var userPoolSize = 1000
- //var up userPool
- 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{})
- urlMap = config.Sysconfig["redirect"].(map[string]interface{})
- //userPoolSize = util.IntAllDef(config.Sysconfig["userPoolSize"], userPoolSize)
- //up.user = make(map[string]*map[string]interface{})
- }
- //
- func (f *Front) Hp() error {
- return f.Redirect("/")
- }
- //二维码图片
- 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")
- data := config.Sysconfig["webdomain"].(string)
- r, _ := qr.Encode(data, qr.M)
- pngdat := r.PNG()
- _, err := w.Write(pngdat)
- return err
- }
- //
- 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 : len(fdone)]
- 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() //纠错时间
- rrid := mongodb.Save("recoveryrecord", data)
- if len(rrid) > 0 {
- //log.Println("用户纠错记录保存成功!")
- }
- 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 := mongodb.FindById("bidding", id, nil)
- if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
- aobj, ok = mongodb.FindById("bidding_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 : len(fdone)]
- 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
- }
- mongodb.Update("bidding", map[string]interface{}{
- "_id": bson.ObjectIdHex(id),
- }, map[string]interface{}{
- "$set": map[string]interface{}{
- "lastwrongfield": result,
- },
- }, false, false)
- }
- //轮询查登录状态
- 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 {
- var shareid = f.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jySEMtgy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
- }
- f.T["logid"] = config.Seoconfig["jySEMtgy"].(string)
- f.T["shareid"] = se.EncodeString(shareid)
- f.DisableHttpCache()
- // lastBids := elastic.GetPage("bidding", "bidding", "{}", `{"publishtime":-1}`, `"_id","title","publishtime","toptype","subtype","type","area","href"`, 0, 18)
- // if lastBids != nil && len(*lastBids) > 0 {
- // lbnHtml, olHtml := structureLastBidsHtml(lastBids)
- // f.T["lbnHtml"] = lbnHtml
- // f.T["olHtml"] = olHtml
- // }
- return f.Render("/pc/landingpage.html", &f.T)
- }
- //
- func (f *Front) Notin() error {
- ref := f.GetSession("referer")
- if ref != nil && ref != "" {
- f.T["ref"] = ref.(string)
- }
- var shareid = f.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jysskzy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
- }
- 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"] = filter.GetOS(rhdua)
- userData["Rip"] = filter.GetIp(f.Request)
- userData["Rbrowse"] = filter.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 != "" {
- f.SetSession("openid", openid)
- redisheadimg := redis.Get("other", "newUser-"+openid)
- if redisheadimg == nil {
- redisheadimg = ""
- }
- user, _ := mongodb.FindOneByField("user", `{"s_m_openid":"`+openid+`"}`, `{"s_nickname":1,"s_headimage":1,"s_m_openid":1,"_id":1}`)
- if user != nil && len(*user) > 0 {
- f.ServeJson(map[string]string{
- "result": "ok",
- "s_nickname": fmt.Sprint((*user)["s_nickname"]),
- "s_headimage": fmt.Sprint((*user)["s_headimage"]),
- "redisheadimg": fmt.Sprint(redisheadimg),
- "encryptId": se.EncodeString(util.BsonIdToSId((*user)["_id"])),
- })
- (*user)["shareid"] = shareid
- nick := fmt.Sprint((*user)["s_nickname"])
- f.SetSession("nickname", nick)
- f.SetSession("s_nickname", nick)
- f.SetSession("s_m_openid", fmt.Sprint((*user)["s_m_openid"]))
- f.SetSession("userId", util.BsonIdToSId((*user)["_id"]))
- f.SetSession("user", *user)
- } else {
- f.ServeJson(map[string]string{
- "result": "fail",
- })
- }
- } else {
- f.ServeJson(map[string]string{
- "result": "fail",
- })
- }
- return nil
- }
- //用户是否登录
- func (f *Front) HasSign() error {
- tmp := f.Session().Get("user")
- openid := f.GetSession("s_m_openid")
- if openid == nil {
- openid = ""
- }
- redisheadimg := redis.Get("other", "newUser-"+openid.(string))
- if redisheadimg == nil {
- redisheadimg = ""
- }
- if user, ok := tmp.(map[string]interface{}); ok {
- f.Session().Set("user", user)
- f.ServeJson(map[string]string{
- "result": "ok",
- "s_nickname": fmt.Sprint(user["s_nickname"]),
- "s_headimage": fmt.Sprint(user["s_headimage"]),
- "redisheadimg": fmt.Sprint(redisheadimg),
- "encryptId": se.EncodeString(util.BsonIdToSId(user["_id"])),
- })
- }
- return nil
- }
- //用户注销
- func (f *Front) SignOut() error {
- f.DelSession("rpcBackUserInfo")
- f.DelSession("user")
- f.DelSession("s_nickname")
- f.DelSession("openid")
- f.DelSession("s_m_openid")
- f.DelSession("userId")
- f.ServeJson("ok")
- //sess := f.GetSession("user")
- //if user, ok := sess.(map[string]interface{}); ok {
- //shareid := fmt.Sprint(user["shareid"])
- // redis.Del("sso", "p_usershare_"+shareid)
- // //重新生成二维码,
- // id, _ := strconv.Atoi(shareid)
- // public.GetShareQR(uint32(id))
- //
- // expires := time.Now().Add(-2 * time.Hour)
- // log.Println("exp:", expires)
- // cookie := &http.Cookie{
- // Name: "userid_secure",
- // Value: "",
- // Path: "/",
- // HttpOnly: true,
- // MaxAge: 0,
- // Expires: expires,
- // }
- // log.Println("cookie:", cookie)
- // f.SetCookie(cookie)
- //}
- 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)
- //log.Println("登录获取shareid:", shareid)
- 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]
- //onekeyid := redis.Get("other", "onekey_"+fkid)
- flag := "N"
- data := make(map[string]interface{})
- //if onekeyid == nil {
- if fkid != "" {
- //intdata, _ := mongodb.FindOne("interaction", `{"s_fkid":"`+fkid+`","i_type":7}`)
- //if len(*intdata) == 0 {
- 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"
- }
- //} else if (*intdata)["i_status"] == 1 {
- // set := make(map[string]interface{})
- // set["i_status"] = 0
- // set["s_opinion"] = ""
- // set["s_auditname"] = ""
- // set["s_editorname"] = ""
- // set["l_submitdate"] = time.Now().Unix()
- // id := mongodb.Update("interaction", `{"s_fkid":"`+fkid+`","i_type":7}`, &map[string]interface{}{"$set": set}, false, false)
- // if id {
- // 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) (ok bool) {
- _person, ok := public.MQFW.FindOne("user", bson.M{"s_m_openid": openid})
- if ok && *_person != nil && len(*_person) > 0 {
- person := *_person
- //加入session
- // if person["i_know"] != nil {
- // sess.Set("iknow", person["i_know"])
- // }
- if person["i_shareknow"] != nil {
- sess.Set("shareknow", person["i_shareknow"])
- }
- sess.Set("userId", (person["_id"].(bson.ObjectId)).Hex())
- sess.Set("s_m_openid", person["s_m_openid"])
- sess.Set("openid", person["s_m_openid"])
- sess.Set("s_nickname", person["s_nickname"])
- if person["s_avatar"] == nil {
- sess.Set("s_avatar", person["s_headimage"])
- } else {
- sess.Set("s_avatar", person["s_avatar"])
- }
- go updateUserPushStatus(util.BsonIdToSId(person["_id"]))
- }
- return
- }
- //微信跳转创建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 := FindUserAndCreateSess(openid, m.Session())
- 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{}, len(tmps))
- for k, v := range tmps {
- res[k] = v
- }
- return res
- }(strs[1:])...)
- }
- }
- m.Redirect(actionurl)
- } else {
- if !ok {
- log.Println("数据库连接超时!", openid)
- } else {
- log.Println("解析结果:", str, ",actionurl为空")
- }
- m.Render("_error.html")
- }
- } else {
- go public.SaveAbnormal(openid)
- log.Println("没有找到该用户:", openid)
- m.Render("_error.html")
- }
- } else {
- log.Println("解析出错,解析结果:", str)
- m.Render("_error.html")
- }
- return nil
- }
- //修改用户推送的状态,i_ispush
- //当用户有操作的时候,认为是可以收到推送的,修改i_ispush为1
- func updateUserPushStatus(userid string) {
- set := bson.M{"$set": bson.M{"i_ispush": 1}}
- mongodb.UpdateById("user", userid, set)
- mongodb.Update("follow_project", bson.M{"s_userid": userid}, set, false, true)
- mongodb.Update("jylab_followent", bson.M{"s_userid": userid}, set, false, true)
- }
- //删除模板缓存
- 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 {
- defer util.Catch()
- userid := util.ObjToString(m.GetSession("userId"))
- if userid == "" {
- m.T["isWeixin"] = 1
- return m.Render("/weixin/about.html")
- }
- //打开推送列表日志
- date := util.Int64All(_id)
- if date > 0 {
- go ca.SaveCache("jy_pushvisit", map[string]interface{}{
- "openid": userid,
- "pdate": date,
- "vsid": "-1", //打开列表页,无sid默认为-1
- "date": time.Now(),
- "isopen": true,
- })
- //获取已浏览记录
- visited := ca.Search("select vsid from jy_pushvisit where openid=? and pdate=?", userid, date)
- vsidList := []string{}
- for _, v := range visited {
- vsidList = append(vsidList, (v["vsid"]).(string))
- }
- //获取推送信息
- _, openId := public.GetOldOpenid(userid)
- data := ca.SearchOne("select * from jy_push where id=? and openid=? and date=?", util.FormatDateByInt64(&date, util.Date_Short_Layout), openId, _id)
- res := make(map[string]interface{})
- if len(data) > 0 {
- data["visit"] = vsidList
- res = data
- res["bmatch"] = true
- //更换key
- val := public.ChangeMapKeyForCass(res)
- m.T["data"] = val
- }
- /*else { //查mongodb
- go mongodb.Update("wxpush", `{"s_m_openid":"`+openid+`","l_date":`+fmt.Sprint(date)+`}`,
- map[string]interface{}{
- "$set": map[string]interface{}{
- "isopen": true,
- }},
- true, false)
- tmp, ok := mongodb.FindOne("wxpush", `{"s_m_openid":"`+openid+`","l_date":`+fmt.Sprint(date)+`}`)
- if ok {
- (*tmp)["bmatch"] = true
- m.T["data"] = &tmp
- } else {
- (*tmp)["bmatch"] = false
- m.T["data"] = &tmp
- }
- }*/
- }
- /*else { //日志迁移,过一段时间可删除
- go mongodb.UpdateById("wxpush", _id, map[string]interface{}{
- "$set": map[string]interface{}{
- "isopen": true,
- },
- })
- tmp, ok := mongodb.FindById("wxpush", _id, nil)
- if ok {
- (*tmp)["bmatch"] = true
- m.T["data"] = &tmp
- } else {
- (*tmp)["bmatch"] = false
- m.T["data"] = &tmp
- }
- }*/
- m.T["_id"] = _id
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- m.T["openid"] = se.EncodeString(util.ObjToString(m.GetSession("s_m_openid")))
- mynickname, _ := m.Session().Get("s_nickname").(string)
- myavatar, _ := m.Session().Get("s_avatar").(string)
- m.T["nickname"] = mynickname
- m.T["avatar"] = myavatar
- m.T["forceShareFlag"] = public.CheckUserNeedForceShare(userid, public.ShareType_push)
- return m.Render("/weixin/wxpush.html", &m.T)
- }
- 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{})
- log.Println("newpage from the cache...")
- } 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")
- result := make(bson.M)
- if reqType == "save" {
- var keyMaps []map[string]interface{}
- keyWord := f.GetSlice("keyWord")
- for _, v := range keyWord {
- vs := processKeyword(v)
- if vs == nil {
- continue
- }
- keyMaps = append(keyMaps, map[string]interface{}{
- "key": vs,
- })
- if len(keyMaps) >= 10 {
- break
- }
- }
- saveData := bson.M{
- "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" {
- mongodb.UpdateById("user", userid, bson.M{"$set": bson.M{"i_ts_guide": 1}})
- } 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
- }
- 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}`)
- if ok {
- 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))
- }
- if ret := redis.Get("other", "aboutus"); ret != nil && false {
- return f.SetBody([]byte(ret.(string)))
- } else {
- 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 {
- log.Println("存储订阅词----Gethotkey")
- 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(skw, ";", " ", -1)
- log.Println(skw)
- 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")
- //不是ios,并且在微信打开,跳转到中转页面
- if downloadPlatform == "" && !isIos && strings.Contains(userAgent, "MicroMessenger") {
- return f.Redirect("/jyapp/free/download/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": filter.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直接跳到应用商店
- jyapp := config.Sysconfig["jyapp"].(map[string]interface{})
- apkurl, _ := jyapp["apkurl"].(string)
- appstoreurl, _ := jyapp["appstoreurl"].(string)
- if isDownloadIos {
- return f.Redirect(appstoreurl)
- }
- return f.Redirect(apkurl)
- }
- 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) 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
- }
- 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)
- }
|