front.go 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. package front
  2. import (
  3. "fmt"
  4. "jfw/config"
  5. "jfw/filter"
  6. "jfw/public"
  7. "jfw/qrmanager"
  8. "jfw/wx"
  9. "log"
  10. "math/rand"
  11. // "net/url"
  12. "regexp"
  13. "strconv"
  14. "github.com/SKatiyar/qr"
  15. //"math/rand"
  16. "qfw/util"
  17. "qfw/util/elastic"
  18. "qfw/util/redis"
  19. "strings"
  20. "sync"
  21. "time"
  22. ca "ucbsutil/cassandra"
  23. "github.com/go-xweb/httpsession"
  24. "github.com/go-xweb/xweb"
  25. "gopkg.in/mgo.v2/bson"
  26. )
  27. type userPool struct {
  28. lock sync.Mutex
  29. openIds []string
  30. user map[string]*map[string]interface{}
  31. }
  32. type Front struct {
  33. *xweb.Action
  34. ajaxPolling xweb.Mapper `xweb:"/front/ajaxPolling"` //登录轮询
  35. getLoginNum xweb.Mapper `xweb:"/front/getLoginNum/(.*)"` //
  36. login xweb.Mapper `xweb:"/front/login/(.*)"` //登录
  37. hasSign xweb.Mapper `xweb:"/front/hasSign"` //是否登录
  38. signOut xweb.Mapper `xweb:"/front/signOut"` //注销
  39. sess xweb.Mapper `xweb:"/front/sess/(.*)"` //微信跳转session登录
  40. viewdemo xweb.Mapper `xweb:"/front/viewdemo"` //微信跳转session登录
  41. getpage xweb.Mapper `xweb:"/swordfish/getpage"`
  42. wxsearch xweb.Mapper `xweb:"/swordfish/search"` //剑鱼微信查询
  43. wxsearchlist xweb.Mapper `xweb:"/swordfish/searchlist"` //剑鱼微信查询结果展示
  44. wxsearchlistPaging xweb.Mapper `xweb:"/swordfish/searchlist/paging"` //剑鱼微信查询结果展示--分页
  45. delWxHistorySearch xweb.Mapper `xweb:"/swordfish/delWxHistorySearch"` //剑鱼微信删除历史搜索
  46. ajaxReq xweb.Mapper `xweb:"/member/swordfish/ajaxReq"`
  47. wxpushView xweb.Mapper `xweb:"/wxpush/wxpushview"` //推送结果预览
  48. wxpushViewPaging xweb.Mapper `xweb:"/wxpush/wxpushview/paging"` //推送结果预览--分页
  49. guide xweb.Mapper `xweb:"/swordfish/guide/(.*)"`
  50. share xweb.Mapper `xweb:"/swordfish/share/([^.]*)"`
  51. wxprotocol xweb.Mapper `xweb:"/swordfish/wxprotocol"` //微信剑鱼协议
  52. delc xweb.Mapper `xweb:"/delcache/(.+)"` //删除模板缓存
  53. wxpushListInfo xweb.Mapper `xweb:"/wxpush/bidinfo/(.*)"` //推送列表
  54. feedback xweb.Mapper `xweb:"/swordfish/feedback"` //意见反馈
  55. wxpushAjaxReq xweb.Mapper `xweb:"/wxpush/bid/ajaxReq"`
  56. newSordfish xweb.Mapper `xweb:"/"` //剑鱼pc首页
  57. searchinfolist xweb.Mapper `xweb:"/swordfish/searchinfolist(.*).html"` //剑鱼pc查询
  58. about xweb.Mapper `xweb:"/swordfish/about"`
  59. shareabout xweb.Mapper `xweb:"/swordfish/shareabout/([^.]*)"`
  60. getIndexData xweb.Mapper `xweb:"/front/index.*"`
  61. urlrecord xweb.Mapper `xweb:"/front/urlrecord.*"`
  62. isrecord xweb.Mapper `xweb:"/front/isrecord/(.*)"`
  63. praise xweb.Mapper `xweb:"/swordfish/praise"`
  64. getpraise xweb.Mapper `xweb:"/swordfish/getpraise"`
  65. aboutsearch xweb.Mapper `xweb:"/swordfish/aboutsearch"`
  66. aboutSR xweb.Mapper `xweb:"/swordfish/aboutsearchresult"`
  67. delOL xweb.Mapper `xweb:"/swordfish/delovertimelist"` //手动删除30天无更新数据
  68. pcAjaxReq xweb.Mapper `xweb:"/front/pcAjaxReq"`
  69. myFeedbacks xweb.Mapper `xweb:"/swordfish/myFeedbacks"`
  70. wxerr xweb.Mapper `xweb:"/mob/err"`
  71. getRecomKWs xweb.Mapper `xweb:"/member/getRecomKWs"` //获取推荐关键词
  72. behaviorRecord xweb.Mapper `xweb:"/member/behaviorRecord"` //记录用户点击的关键词
  73. tSGuide xweb.Mapper `xweb:"/front/tenderSubscribe/guide"` //引导页
  74. transfer xweb.Mapper `xweb:"/front/transfer"` //原文链接中转
  75. jyblog xweb.Mapper `xweb:"/jyblog/index([^.]*).html"` //剑鱼博客
  76. jybdetail xweb.Mapper `xweb:"/jyblog/([^.]*).html"` //剑鱼博客三级页
  77. blogpraise xweb.Mapper `xweb:"/jyblog/blogpraise"` //剑鱼博客三级页点赞
  78. searchResult xweb.Mapper `xweb:"/list/(\\w+)/(\\w+).html"` //剑鱼分类 地区结果列表
  79. encrypt xweb.Mapper `xweb:"/share/encrypt"` //分享三级页加密
  80. historypush xweb.Mapper `xweb:"/swordfish/historypush"` //历时推送记录
  81. historypushPaging xweb.Mapper `xweb:"/swordfish/historypush/paging"` //历时推送记录--分页
  82. aboutus xweb.Mapper `xweb:"/front/aboutus.html"` //关于我们
  83. busicooperation xweb.Mapper `xweb:"/front/busicooperation.html"` //商务合作
  84. //bidsearchforent xweb.Mapper `xweb:"/front/bidsearchforent.html"` //中标企业搜索
  85. /********************wxkeyset:v1.8**************************/
  86. wxKeysetAjaxReq xweb.Mapper `xweb:"/wxkeyset/ajaxReq"` //订阅词ajax请求
  87. wxKeyset xweb.Mapper `xweb:"/wxkeyset/keyset/(\\w+)"` //订阅词设置
  88. subscribe xweb.Mapper `xweb:"/front/subscribe.html"` //电脑版剑鱼设置
  89. gethotkey xweb.Mapper `xweb:"/front/gethotkey"` //获取热词
  90. rediskw xweb.Mapper `xweb:"/front/rediskw"` //pc订阅词存redis
  91. notin xweb.Mapper `xweb:"/notin/page"` //未登录用户访问三级页中转页
  92. topics xweb.Mapper `xweb:"/promotional/topics.html"` //SEM推广
  93. mobtopics xweb.Mapper `xweb:"/promotional/mobtopics.html"` //移动端专题推广
  94. followinfo xweb.Mapper `xweb:"/front/followinfo"` //redis用户关注日志
  95. /********************dev:2.0**************************/
  96. getClassifyList xweb.Mapper `xweb:"/front/getClassifyList"` //得到标签页表格数据
  97. advservices xweb.Mapper `xweb:"/front/advservices.html"` //广告服务
  98. extension xweb.Mapper `xweb:"/extension/(.*).html"` //推广页面
  99. recInof xweb.Mapper `xweb:"/front/recovery/info"` //纠错记录
  100. downloadJyApp xweb.Mapper `xweb:"/front/downloadJyApp"` //下载剑鱼app的中转地址
  101. downloadJyAppQr xweb.Mapper `xweb:"/front/downloadJyApp/qr"` //扫码下载
  102. limitSearchText xweb.Mapper `xweb:"/front/limitSearchText"` //扫码下载
  103. hpshare xweb.Mapper `xweb:"/front/homepage/wxshare"` //扫码分享
  104. hp xweb.Mapper `xweb:"/front/hp.html"` //QQ 分享好友到首页
  105. setSeoVersion xweb.Mapper `xweb:"/front/setSeoVersion"`
  106. //疫苗查询
  107. ymSearch xweb.Mapper `xweb:"/front/yimiao/search"`
  108. ymResult xweb.Mapper `xweb:"/front/yimiao/result"`
  109. ymResultHmtl xweb.Mapper `xweb:"/front/yimiao/html/(.+).html"`
  110. //落地页-18-08
  111. jylabShareTimeline xweb.Mapper `xweb:"/front/jylabShareTimeline"`
  112. //落地页-18-08
  113. landingPage xweb.Mapper `xweb:"/front/landingpage.html"`
  114. //滑动验证
  115. sendMessage xweb.Mapper `xweb:"/front/sendMessage"`
  116. lpsubmit xweb.Mapper `xweb:"/front/landpage/submit"`
  117. checkPhoneNum xweb.Mapper `xweb:"/front/landpage/checkPhoneNum"`
  118. captcha xweb.Mapper `xweb:"/front/landpage/captcha"`
  119. //修改强制分享主动分享状态和时间
  120. updateShareStatus xweb.Mapper `xweb:"/share/updateShareStatus"`
  121. UpdateShareStatus_repair xweb.Mapper `xweb:"/share/UpdateShareStatus_repair"`
  122. hasPushHistory xweb.Mapper `xweb:"/front/hasPushHistory"`
  123. //静态页面通用地址
  124. staticPage xweb.Mapper `xweb:"/front/staticPage/(.+)"`
  125. }
  126. var sewx util.SimpleEncrypt //微信的加密方法
  127. var mongodb = public.MQFW
  128. var urlMap map[string]interface{}
  129. //var userPoolSize = 1000
  130. //var up userPool
  131. var se = util.SE //移到tools中
  132. var isIosReg = regexp.MustCompile("\\(i[^;]+;( U;)? CPU.+Mac OS X")
  133. func init() {
  134. sewx = util.SimpleEncrypt{Key: "topnet"}
  135. xweb.AddAction(&Front{})
  136. xweb.AddAction(&Short{})
  137. urlMap = config.Sysconfig["redirect"].(map[string]interface{})
  138. //userPoolSize = util.IntAllDef(config.Sysconfig["userPoolSize"], userPoolSize)
  139. //up.user = make(map[string]*map[string]interface{})
  140. }
  141. //
  142. func (f *Front) Hp() error {
  143. return f.Redirect("/")
  144. }
  145. //二维码图片
  146. func (f *Front) Hpshare() error {
  147. w := f.ResponseWriter
  148. w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  149. w.Header().Set("Pragma", "no-cache")
  150. w.Header().Set("Expires", "0")
  151. w.Header().Set("Content-Type", "image/png")
  152. data := config.Sysconfig["webdomain"].(string)
  153. r, _ := qr.Encode(data, qr.M)
  154. pngdat := r.PNG()
  155. _, err := w.Write(pngdat)
  156. return err
  157. }
  158. //
  159. func (f *Front) RecInof() error {
  160. var msg = ""
  161. var flag = true
  162. var tyflag = false
  163. id := util.DecodeArticleId2ByCheck(f.GetString("id"))[0] //文章id
  164. fieldName := f.GetString("fieldName") //纠错字段
  165. fwtScode := f.GetString("fwtscode") //纠错前权重最低字段
  166. if strings.Contains(fieldName, "price") || strings.Contains(fieldName, "bidamount") || strings.Contains(fieldName, "budget") {
  167. //tyflag = true
  168. }
  169. reccont := f.GetString("reccont") //纠错之后的内容
  170. originalcont := f.GetString("originalcont") //纠错之前的内容
  171. //纠错随机回复
  172. recoveryText, _ := config.Sysconfig["recoveryText"].([]interface{})
  173. recVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(recoveryText))
  174. msg = util.ObjToString(recoveryText[recVal])
  175. myopenid, _ := f.Session().Get("s_m_openid").(string)
  176. data := make(map[string]interface{})
  177. var obj map[string]interface{}
  178. if myopenid != "" && fieldName != "" {
  179. data["s_nickname"] = util.ObjToString(f.GetSession("s_nickname"))
  180. data["s_openid"] = myopenid
  181. fields := strings.Split(fieldName, "-")
  182. if len(fields) == 1 {
  183. data["s_field"] = fieldName //纠错字段
  184. } else if len(fields) == 2 {
  185. var fdone = fields[0]
  186. var fdtwo = fields[1]
  187. if strings.Contains(fdone, "winnerorder") {
  188. fdone = fdone[len(fdone)-1 : len(fdone)]
  189. data["s_field"] = "winnerorder." + fdone + "." + fdtwo //纠错字段
  190. } else {
  191. data["s_field"] = "package." + fdone + "." + fdtwo //纠错字段
  192. }
  193. } else if len(fields) == 3 {
  194. var fdone = fields[0]
  195. var fdtwo = fields[1]
  196. var fdthree = fields[2]
  197. data["s_field"] = "package." + fdone + ".winnerorder." + fdtwo + "." + fdthree //纠错字段
  198. }
  199. data["s_beforecont"] = originalcont
  200. data["s_aftercont"] = reccont
  201. data["s_id"] = id //纠错文章id
  202. data["l_recoverydate"] = time.Now().Unix() //纠错时间
  203. rrid := mongodb.Save("recoveryrecord", data)
  204. if len(rrid) > 0 {
  205. //log.Println("用户纠错记录保存成功!")
  206. }
  207. brobj, ok := mongodb.Find("bidding_rec", bson.M{"s_id": id}, `{"l_recoverydate":-1}`, nil, false, 0, 1)
  208. if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
  209. obj = (*brobj)[0]
  210. } else {
  211. aobj, ok := mongodb.FindById("bidding", id, nil)
  212. if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
  213. aobj, ok = mongodb.FindById("bidding_back", id, nil)
  214. }
  215. obj = *aobj
  216. }
  217. if ok && obj != nil && len(obj) != 0 {
  218. obj["s_id"] = id
  219. obj["l_recoverydate"] = time.Now().Unix()
  220. var packageArr = util.ObjToMap(obj["package"])
  221. if len(fields) == 1 {
  222. if tyflag {
  223. obj[fieldName], _ = strconv.ParseFloat(reccont, 64)
  224. } else {
  225. obj[fieldName] = reccont
  226. }
  227. } else if len(fields) == 2 {
  228. var fdone = fields[0]
  229. var fdtwo = fields[1]
  230. if strings.Contains(fdone, "winnerorder") {
  231. var winnerorderArr = obj["winnerorder"].([]interface{})
  232. fdone = fdone[len(fdone)-1 : len(fdone)]
  233. kk, _ := strconv.Atoi(fdone)
  234. if len(winnerorderArr) > 0 {
  235. for k, v := range winnerorderArr {
  236. if k == kk {
  237. if tyflag {
  238. v.(map[string]interface{})[fdtwo], _ = strconv.ParseFloat(reccont, 64)
  239. } else {
  240. v.(map[string]interface{})[fdtwo] = reccont
  241. }
  242. break
  243. }
  244. }
  245. }
  246. } else {
  247. var pkgdata = (*packageArr)[fdone].(map[string]interface{})
  248. if tyflag {
  249. pkgdata[fdtwo], _ = strconv.ParseFloat(reccont, 64)
  250. } else {
  251. pkgdata[fdtwo] = reccont
  252. }
  253. }
  254. } else if len(fields) == 3 {
  255. var fdone = fields[0]
  256. var fdtwo, _ = strconv.Atoi(fields[1])
  257. var fdthree = fields[2]
  258. var pkgdata = (*packageArr)[fdone].(map[string]interface{})
  259. var pkgchilddata = pkgdata["winnerorder"].([]interface{})
  260. if len(pkgchilddata) > 0 {
  261. for k, v := range pkgchilddata {
  262. if k == fdtwo {
  263. if tyflag {
  264. v.(map[string]interface{})[fdthree], _ = strconv.ParseFloat(reccont, 64)
  265. } else {
  266. v.(map[string]interface{})[fdthree] = reccont
  267. }
  268. break
  269. }
  270. }
  271. }
  272. }
  273. brid := mongodb.Save("bidding_rec", obj)
  274. if len(brid) > 0 {
  275. redis.Del("other", "jypcdetail__rec"+id)
  276. updateLastWrongField(id, fwtScode)
  277. }
  278. }
  279. }
  280. f.ServeJson(map[string]interface{}{"msg": msg, "flag": flag})
  281. return nil
  282. }
  283. //更新取到的权重最低的字段到bidding表
  284. func updateLastWrongField(id, result string) {
  285. if result == "" {
  286. return
  287. }
  288. mongodb.Update("bidding", map[string]interface{}{
  289. "_id": bson.ObjectIdHex(id),
  290. }, map[string]interface{}{
  291. "$set": map[string]interface{}{
  292. "lastwrongfield": result,
  293. },
  294. }, false, false)
  295. }
  296. //轮询查登录状态
  297. func (f *Front) AjaxPolling() {
  298. reqType, _ := f.GetInteger("reqType")
  299. if reqType == 1 {
  300. shareIds := f.GetString("shareIds")
  301. shareidlist := strings.Split(shareIds, "___")
  302. if shareIds != "" && len(shareidlist) > 1 {
  303. shareidnum := shareidlist[0]
  304. shareidkop := shareidlist[1]
  305. PutWsByCode(se.DecodeString(shareidnum), nil, f.Session())
  306. PutWsByCode(se.DecodeString(shareidkop), nil, f.Session())
  307. f.ServeJson(map[string]string{})
  308. }
  309. } else if reqType == 2 {
  310. userInfo, _ := f.GetSession("rpcBackUserInfo").(map[string]interface{})
  311. f.ServeJson(userInfo)
  312. } else if reqType == 3 {
  313. reply := ""
  314. userId := se.DecodeString(f.GetString("userId"))
  315. qrToLab_ok, _ := redis.Exists("other", "qrToLab_"+userId)
  316. if qrToLab_ok {
  317. redis.Del("other", "qrToLab_"+userId)
  318. reply = "qrToLab_ok"
  319. }
  320. qrToLab_open_ok, _ := redis.Exists("other", "qrToLab_open_"+userId)
  321. if qrToLab_open_ok {
  322. redis.Del("other", "qrToLab_open_"+userId)
  323. reply = "qrToLab_open_ok"
  324. }
  325. if qrToLab_ok && qrToLab_open_ok {
  326. reply = "qrToLab_ok_open_ok"
  327. }
  328. f.ServeJson(map[string]string{"result": reply})
  329. } else if reqType == 4 {
  330. openid, _ := f.GetSession("s_m_openid").(string)
  331. ok := false
  332. if openid != "" {
  333. key := fmt.Sprintf("pcbiddetail_shareTimeline_%s", openid)
  334. ok, _ = redis.Exists("other", key)
  335. if ok {
  336. redis.Del("other", key)
  337. }
  338. }
  339. f.ServeJson(map[string]interface{}{"result": ok})
  340. }
  341. }
  342. //广告服务
  343. func (f *Front) Advservices() error {
  344. var shareid = f.GetString("id")
  345. if len(shareid) == 0 {
  346. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jyggfwy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
  347. }
  348. f.T["logid"] = config.Seoconfig["jyggfwy"].(string)
  349. f.T["shareid"] = se.EncodeString(shareid)
  350. return f.Render("/pc/advservices.html", &f.T)
  351. }
  352. //移动端专题推广
  353. func (f *Front) Mobtopics() error {
  354. return f.Render("/active/mobtopics.html")
  355. }
  356. //移动端专题推广
  357. func (f *Front) Extension(page string) error {
  358. //今日头条和百度推广用的同一个页面,如以后有变动,需拆分成两个。
  359. if page != "tengxun" {
  360. page = "baidu"
  361. }
  362. return f.Render("/active/ext-" + page + ".html")
  363. }
  364. //SEM推广
  365. func (f *Front) Topics() error {
  366. var shareid = f.GetString("id")
  367. if len(shareid) == 0 {
  368. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jySEMtgy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
  369. }
  370. f.T["logid"] = config.Seoconfig["jySEMtgy"].(string)
  371. f.T["shareid"] = se.EncodeString(shareid)
  372. f.DisableHttpCache()
  373. // lastBids := elastic.GetPage("bidding", "bidding", "{}", `{"publishtime":-1}`, `"_id","title","publishtime","toptype","subtype","type","area","href"`, 0, 18)
  374. // if lastBids != nil && len(*lastBids) > 0 {
  375. // lbnHtml, olHtml := structureLastBidsHtml(lastBids)
  376. // f.T["lbnHtml"] = lbnHtml
  377. // f.T["olHtml"] = olHtml
  378. // }
  379. return f.Render("/pc/landingpage.html", &f.T)
  380. }
  381. //
  382. func (f *Front) Notin() error {
  383. ref := f.GetSession("referer")
  384. if ref != nil && ref != "" {
  385. f.T["ref"] = ref.(string)
  386. }
  387. var shareid = f.GetString("id")
  388. if len(shareid) == 0 {
  389. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jysskzy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
  390. }
  391. f.T["logid"] = config.Seoconfig["jysskzy"].(string)
  392. f.T["shareid"] = se.EncodeString(shareid)
  393. return f.Render("/pc/notin.html", &f.T)
  394. }
  395. //
  396. func (f *Front) Followinfo() error {
  397. var pid = f.GetString("pid")
  398. var kid = f.GetString("kid")
  399. var oid = f.GetString("oid")
  400. oldData := redis.Get("sso", "p_userdata_"+se.DecodeString(oid))
  401. var Rurl = util.ObjToString(f.GetSession("RURL"))
  402. var Rref = f.GetString("rref")
  403. rheader := f.Request.Header
  404. rhdua := "" //UA
  405. if len(rheader["User-Agent"]) > 0 {
  406. rhdua = rheader["User-Agent"][0]
  407. }
  408. userData := make(map[string]interface{})
  409. userData["Ros"] = filter.GetOS(rhdua)
  410. userData["Rip"] = filter.GetIp(f.Request)
  411. userData["Rbrowse"] = filter.GetBrowse(rhdua)
  412. if f.GetSession("RReferer") == nil || util.ObjToString(f.GetSession("RReferer")) == "" {
  413. if Rref == "" {
  414. f.SetSession("RReferer", Rurl)
  415. } else {
  416. f.SetSession("RReferer", Rref)
  417. }
  418. }
  419. userData["RURL"] = Rurl
  420. modulelist := config.Seoconfig["module"].(map[string]interface{})
  421. for k, v := range modulelist {
  422. if strings.Contains(Rurl, k) {
  423. f.SetSession("RModule", v)
  424. }
  425. }
  426. if f.GetSession("RModule") == nil || util.ObjToString(f.GetSession("RModule")) == "" {
  427. f.SetSession("RModule", "首页")
  428. }
  429. //活动页模块
  430. if len(Rurl) > 1 && strings.Contains(Rurl, "id=") {
  431. activeCode := strings.Split(Rurl, "id=")[1]
  432. //首先查看是否从百度等搜索引擎过来的referer
  433. sourcelist := config.Seoconfig["source"].(map[string]interface{})
  434. for k, v := range sourcelist {
  435. if strings.Contains(activeCode, k) {
  436. if f.GetSession("RSource") == nil {
  437. f.SetSession("RSource", v)
  438. f.SetSession("RModule", activeCode+"活动页")
  439. f.SetSession("RActiveCode", activeCode)
  440. }
  441. }
  442. }
  443. }
  444. userData["RModule"] = f.GetSession("RModule")
  445. userData["RActiveCode"] = f.GetSession("RActiveCode")
  446. userData["RReferer"] = f.GetSession("RReferer")
  447. if f.GetSession("RSource") == nil || util.ObjToString(f.GetSession("RSource")) == "" {
  448. //首先查看是否从百度等搜索引擎过来的referer
  449. refererlist := config.Seoconfig["referer"].(map[string]interface{})
  450. for k, v := range refererlist {
  451. if strings.Contains(Rref, k) {
  452. if f.GetSession("RSource") == nil {
  453. f.SetSession("RSource", v)
  454. }
  455. }
  456. }
  457. if f.GetSession("RSource") == nil || util.ObjToString(f.GetSession("RSource")) == "" {
  458. f.SetSession("RSource", "剑鱼网站")
  459. }
  460. }
  461. userData["RSource"] = f.GetSession("RSource")
  462. userData["Rparamkey"] = f.GetSession("paramkey")
  463. userData["Rparampublishtime"] = f.GetSession("parampublishtime")
  464. userData["Rparamarea"] = f.GetSession("paramarea")
  465. userData["Rparaminfotype"] = f.GetSession("paraminfotype")
  466. userData["Rprojectname"] = f.GetSession("projectname")
  467. if oldData != nil {
  468. redis.Put("sso", "p_userdata_"+se.DecodeString(pid), oldData, 13*60)
  469. redis.Put("sso", "p_userdata_"+se.DecodeString(kid), oldData, 13*60)
  470. } else {
  471. redis.Put("sso", "p_userdata_"+se.DecodeString(pid), userData, 13*60)
  472. redis.Put("sso", "p_userdata_"+se.DecodeString(kid), userData, 13*60)
  473. }
  474. f.ServeJson(map[string]string{
  475. "result": "ok",
  476. })
  477. return nil
  478. }
  479. //
  480. func (f *Front) Login(key string) error {
  481. shareid := se.DecodeString(key)
  482. openid := redis.GetStr("sso", "p_usershare_"+shareid)
  483. if openid != "" {
  484. f.SetSession("openid", openid)
  485. redisheadimg := redis.Get("other", "newUser-"+openid)
  486. if redisheadimg == nil {
  487. redisheadimg = ""
  488. }
  489. user, _ := mongodb.FindOneByField("user", `{"s_m_openid":"`+openid+`"}`, `{"s_nickname":1,"s_headimage":1,"s_m_openid":1,"_id":1}`)
  490. if user != nil && len(*user) > 0 {
  491. f.ServeJson(map[string]string{
  492. "result": "ok",
  493. "s_nickname": fmt.Sprint((*user)["s_nickname"]),
  494. "s_headimage": fmt.Sprint((*user)["s_headimage"]),
  495. "redisheadimg": fmt.Sprint(redisheadimg),
  496. "encryptId": se.EncodeString(util.BsonIdToSId((*user)["_id"])),
  497. })
  498. (*user)["shareid"] = shareid
  499. nick := fmt.Sprint((*user)["s_nickname"])
  500. f.SetSession("nickname", nick)
  501. f.SetSession("s_nickname", nick)
  502. f.SetSession("s_m_openid", fmt.Sprint((*user)["s_m_openid"]))
  503. f.SetSession("userId", util.BsonIdToSId((*user)["_id"]))
  504. f.SetSession("user", *user)
  505. } else {
  506. f.ServeJson(map[string]string{
  507. "result": "fail",
  508. })
  509. }
  510. } else {
  511. f.ServeJson(map[string]string{
  512. "result": "fail",
  513. })
  514. }
  515. return nil
  516. }
  517. //用户是否登录
  518. func (f *Front) HasSign() error {
  519. tmp := f.Session().Get("user")
  520. openid := f.GetSession("s_m_openid")
  521. if openid == nil {
  522. openid = ""
  523. }
  524. redisheadimg := redis.Get("other", "newUser-"+openid.(string))
  525. if redisheadimg == nil {
  526. redisheadimg = ""
  527. }
  528. if user, ok := tmp.(map[string]interface{}); ok {
  529. f.Session().Set("user", user)
  530. f.ServeJson(map[string]string{
  531. "result": "ok",
  532. "s_nickname": fmt.Sprint(user["s_nickname"]),
  533. "s_headimage": fmt.Sprint(user["s_headimage"]),
  534. "redisheadimg": fmt.Sprint(redisheadimg),
  535. "encryptId": se.EncodeString(util.BsonIdToSId(user["_id"])),
  536. })
  537. }
  538. return nil
  539. }
  540. //用户注销
  541. func (f *Front) SignOut() error {
  542. f.DelSession("rpcBackUserInfo")
  543. f.DelSession("user")
  544. f.DelSession("s_nickname")
  545. f.DelSession("openid")
  546. f.DelSession("s_m_openid")
  547. f.DelSession("userId")
  548. f.ServeJson("ok")
  549. //sess := f.GetSession("user")
  550. //if user, ok := sess.(map[string]interface{}); ok {
  551. //shareid := fmt.Sprint(user["shareid"])
  552. // redis.Del("sso", "p_usershare_"+shareid)
  553. // //重新生成二维码,
  554. // id, _ := strconv.Atoi(shareid)
  555. // public.GetShareQR(uint32(id))
  556. //
  557. // expires := time.Now().Add(-2 * time.Hour)
  558. // log.Println("exp:", expires)
  559. // cookie := &http.Cookie{
  560. // Name: "userid_secure",
  561. // Value: "",
  562. // Path: "/",
  563. // HttpOnly: true,
  564. // MaxAge: 0,
  565. // Expires: expires,
  566. // }
  567. // log.Println("cookie:", cookie)
  568. // f.SetCookie(cookie)
  569. //}
  570. return nil
  571. }
  572. //微信公众号获取数字
  573. func (f *Front) GetLoginNum(prestr string) error {
  574. var oid = f.GetString("oid")
  575. var Rref = f.GetString("rref")
  576. f.SetSession("Rref", Rref)
  577. shareid, shareidot := qrmanager.QrCodeManager.GetQRCode(oid, prestr, f.Session(), f.Request)
  578. //log.Println("登录获取shareid:", shareid)
  579. f.ServeJson(map[string]string{
  580. "num": se.EncodeString(shareid),
  581. "numot": se.EncodeString(shareidot),
  582. })
  583. return nil
  584. }
  585. //一键报告
  586. func (m *Front) Onekey() error {
  587. defer util.Catch()
  588. fkid := util.DecodeArticleId2ByCheck(m.GetString("fkid"))[0]
  589. //onekeyid := redis.Get("other", "onekey_"+fkid)
  590. flag := "N"
  591. data := make(map[string]interface{})
  592. //if onekeyid == nil {
  593. if fkid != "" {
  594. //intdata, _ := mongodb.FindOne("interaction", `{"s_fkid":"`+fkid+`","i_type":7}`)
  595. //if len(*intdata) == 0 {
  596. userId, _ := m.GetSession("userId").(string)
  597. if userId != "" {
  598. userInfo, _ := mongodb.FindById("user", userId, nil)
  599. s_nickname, _ := (*userInfo)["s_nickname"].(string)
  600. s_name, _ := (*userInfo)["s_name"].(string)
  601. s_phone, _ := (*userInfo)["s_phone"].(string)
  602. if s_nickname != "" { //昵称
  603. data["s_username"] = s_nickname
  604. } else if s_name != "" { //s_name
  605. data["s_username"] = s_name
  606. } else if s_phone != "" {
  607. data["s_username"] = s_phone
  608. } else {
  609. data["s_username"] = userId
  610. }
  611. if s_name != "" {
  612. data["s_submitname"] = s_name
  613. } else if s_nickname != "" {
  614. data["s_submitname"] = s_nickname
  615. } else if s_phone != "" {
  616. data["s_submitname"] = s_phone
  617. } else {
  618. data["s_submitname"] = userId
  619. }
  620. data["s_submitid"] = userId
  621. }
  622. data["i_type"] = 7
  623. value := m.GetString("value")
  624. value = strings.Replace(value, "'", "&qpos;", 1)
  625. if len([]rune(value)) > 200 {
  626. value = util.SubString(value, 0, 200)
  627. }
  628. data["s_remark"] = "剑鱼-一键报告排版问题\n" + value
  629. data["s_mop"] = m.GetString("mop") //来源:移动端or电脑端
  630. data["s_title"] = m.GetString("title")
  631. data["i_status"] = 0
  632. data["l_submitdate"] = time.Now().Unix()
  633. data["s_source"] = m.GetString("source")
  634. data["s_primaryhref"] = m.GetString("primaryhref")
  635. data["s_fkid"] = fkid
  636. data["s_from"] = "wx"
  637. id := mongodb.Save("interaction", data)
  638. if len(id) > 0 {
  639. flag = "Y"
  640. }
  641. //} else if (*intdata)["i_status"] == 1 {
  642. // set := make(map[string]interface{})
  643. // set["i_status"] = 0
  644. // set["s_opinion"] = ""
  645. // set["s_auditname"] = ""
  646. // set["s_editorname"] = ""
  647. // set["l_submitdate"] = time.Now().Unix()
  648. // id := mongodb.Update("interaction", `{"s_fkid":"`+fkid+`","i_type":7}`, &map[string]interface{}{"$set": set}, false, false)
  649. // if id {
  650. // flag = "Y"
  651. // }
  652. //}
  653. redis.Put("other", "onekey_"+fkid, fkid, 10*60)
  654. }
  655. //}
  656. m.ServeJson(map[string]interface{}{
  657. "flag": flag,
  658. })
  659. return nil
  660. }
  661. //
  662. func (m *Front) Encrypt() error {
  663. defer util.Catch()
  664. id := m.GetString("id")
  665. s_openid := m.GetSession("s_m_openid")
  666. flag := "F"
  667. var sid_openid string
  668. util.Try(func() {
  669. if id != "" && s_openid != nil {
  670. id = util.DecodeArticleId2ByCheck(id)[0]
  671. sid_openid = util.EncodeArticleId2ByCheck(id, s_openid.(string))
  672. flag = "T"
  673. }
  674. }, func(e interface{}) {
  675. log.Println("分享短地址加密出错", e)
  676. })
  677. m.ServeJson(map[string]interface{}{
  678. "flag": flag,
  679. "sid_openid": sid_openid,
  680. })
  681. return nil
  682. }
  683. //
  684. func (m *Front) Wxerr() error {
  685. return m.Render("/_err.html")
  686. }
  687. //查找用户并创建session
  688. func FindUserAndCreateSess(openid string, sess *httpsession.Session) (ok bool) {
  689. _person, ok := public.MQFW.FindOne("user", bson.M{"s_m_openid": openid})
  690. if ok && *_person != nil && len(*_person) > 0 {
  691. person := *_person
  692. //加入session
  693. // if person["i_know"] != nil {
  694. // sess.Set("iknow", person["i_know"])
  695. // }
  696. if person["i_shareknow"] != nil {
  697. sess.Set("shareknow", person["i_shareknow"])
  698. }
  699. sess.Set("userId", (person["_id"].(bson.ObjectId)).Hex())
  700. sess.Set("s_m_openid", person["s_m_openid"])
  701. sess.Set("openid", person["s_m_openid"])
  702. sess.Set("s_nickname", person["s_nickname"])
  703. if person["s_avatar"] == nil {
  704. sess.Set("s_avatar", person["s_headimage"])
  705. } else {
  706. sess.Set("s_avatar", person["s_avatar"])
  707. }
  708. go updateUserPushStatus(util.BsonIdToSId(person["_id"]))
  709. }
  710. return
  711. }
  712. //微信跳转创建session
  713. func (m *Front) Sess(ostr string) error {
  714. defer util.Catch()
  715. if strings.Contains(ostr, "&") {
  716. ostr = strings.Split(ostr, "&")[0]
  717. }
  718. strs := strings.Split(ostr, "__")
  719. str := strings.Split(sewx.DecodeString(strs[0]), ",")
  720. if len(str) == 4 {
  721. openid := str[0]
  722. ok := FindUserAndCreateSess(openid, m.Session())
  723. if ok {
  724. actionurl := util.ObjToString(urlMap[str[3]])
  725. if actionurl != "" {
  726. if len(strs) > 1 {
  727. if strings.Contains(actionurl, "followent/newInfo") {
  728. actionurl = fmt.Sprintf(actionurl, (strs[1] + "___" + strs[2]))
  729. } else {
  730. //支持多个参数%s..
  731. actionurl = fmt.Sprintf(actionurl, func(tmps []string) []interface{} {
  732. res := make([]interface{}, len(tmps))
  733. for k, v := range tmps {
  734. res[k] = v
  735. }
  736. return res
  737. }(strs[1:])...)
  738. }
  739. }
  740. m.Redirect(actionurl)
  741. } else {
  742. if !ok {
  743. log.Println("数据库连接超时!", openid)
  744. } else {
  745. log.Println("解析结果:", str, ",actionurl为空")
  746. }
  747. m.Render("_error.html")
  748. }
  749. } else {
  750. go public.SaveAbnormal(openid)
  751. log.Println("没有找到该用户:", openid)
  752. m.Render("_error.html")
  753. }
  754. } else {
  755. log.Println("解析出错,解析结果:", str)
  756. m.Render("_error.html")
  757. }
  758. return nil
  759. }
  760. //修改用户推送的状态,i_ispush
  761. //当用户有操作的时候,认为是可以收到推送的,修改i_ispush为1
  762. func updateUserPushStatus(userid string) {
  763. set := bson.M{"$set": bson.M{"i_ispush": 1}}
  764. mongodb.UpdateById("user", userid, set)
  765. mongodb.Update("follow_project", bson.M{"s_userid": userid}, set, false, true)
  766. mongodb.Update("jylab_followent", bson.M{"s_userid": userid}, set, false, true)
  767. }
  768. //删除模板缓存
  769. func (d *Front) Delc(url string) {
  770. defer util.Catch()
  771. d.App.TemplateMgr.CacheDelete(strings.Replace(url, "GG", "/", 1))
  772. d.WriteBytes([]byte("ok,清除路径:" + url))
  773. }
  774. func (m *Front) Viewdemo() {
  775. m.Redirect("/swordfish/guide/-1")
  776. }
  777. //剑鱼用户协议
  778. func (m *Front) Wxprotocol() error {
  779. return m.Render("/weixin/wxprotocol.html")
  780. }
  781. //推送列表
  782. func (m *Front) WxpushListInfo(_id string) error {
  783. defer util.Catch()
  784. userid := util.ObjToString(m.GetSession("userId"))
  785. if userid == "" {
  786. m.T["isWeixin"] = 1
  787. return m.Render("/weixin/about.html")
  788. }
  789. //打开推送列表日志
  790. date := util.Int64All(_id)
  791. if date > 0 {
  792. go ca.SaveCache("jy_pushvisit", map[string]interface{}{
  793. "openid": userid,
  794. "pdate": date,
  795. "vsid": "-1", //打开列表页,无sid默认为-1
  796. "date": time.Now(),
  797. "isopen": true,
  798. })
  799. //获取已浏览记录
  800. visited := ca.Search("select vsid from jy_pushvisit where openid=? and pdate=?", userid, date)
  801. vsidList := []string{}
  802. for _, v := range visited {
  803. vsidList = append(vsidList, (v["vsid"]).(string))
  804. }
  805. //获取推送信息
  806. _, openId := public.GetOldOpenid(userid)
  807. data := ca.SearchOne("select * from jy_push where id=? and openid=? and date=?", util.FormatDateByInt64(&date, util.Date_Short_Layout), openId, _id)
  808. res := make(map[string]interface{})
  809. if len(data) > 0 {
  810. data["visit"] = vsidList
  811. res = data
  812. res["bmatch"] = true
  813. //更换key
  814. val := public.ChangeMapKeyForCass(res)
  815. m.T["data"] = val
  816. }
  817. /*else { //查mongodb
  818. go mongodb.Update("wxpush", `{"s_m_openid":"`+openid+`","l_date":`+fmt.Sprint(date)+`}`,
  819. map[string]interface{}{
  820. "$set": map[string]interface{}{
  821. "isopen": true,
  822. }},
  823. true, false)
  824. tmp, ok := mongodb.FindOne("wxpush", `{"s_m_openid":"`+openid+`","l_date":`+fmt.Sprint(date)+`}`)
  825. if ok {
  826. (*tmp)["bmatch"] = true
  827. m.T["data"] = &tmp
  828. } else {
  829. (*tmp)["bmatch"] = false
  830. m.T["data"] = &tmp
  831. }
  832. }*/
  833. }
  834. /*else { //日志迁移,过一段时间可删除
  835. go mongodb.UpdateById("wxpush", _id, map[string]interface{}{
  836. "$set": map[string]interface{}{
  837. "isopen": true,
  838. },
  839. })
  840. tmp, ok := mongodb.FindById("wxpush", _id, nil)
  841. if ok {
  842. (*tmp)["bmatch"] = true
  843. m.T["data"] = &tmp
  844. } else {
  845. (*tmp)["bmatch"] = false
  846. m.T["data"] = &tmp
  847. }
  848. }*/
  849. m.T["_id"] = _id
  850. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  851. m.T["openid"] = se.EncodeString(util.ObjToString(m.GetSession("s_m_openid")))
  852. mynickname, _ := m.Session().Get("s_nickname").(string)
  853. myavatar, _ := m.Session().Get("s_avatar").(string)
  854. m.T["nickname"] = mynickname
  855. m.T["avatar"] = myavatar
  856. m.T["forceShareFlag"] = public.CheckUserNeedForceShare(userid, public.ShareType_push)
  857. return m.Render("/weixin/wxpush.html", &m.T)
  858. }
  859. func (m *Front) Feedback() error {
  860. defer util.Catch()
  861. m.T["openid"] = se.EncodeString(util.ObjToString(m.GetSession("s_m_openid")))
  862. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  863. userId, _ := m.GetSession("userId").(string)
  864. 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)
  865. m.T["list"] = list
  866. fkid := m.GetString("fkid")
  867. if fkid != "" {
  868. fkid = util.DecodeArticleId2ByCheck(fkid)[0]
  869. }
  870. fromName := m.GetString("fromName")
  871. if fromName != "" {
  872. if fromName == "zndy" {
  873. fromName = "剑鱼实验室-智能订阅"
  874. } else if fromName == "sjdc" {
  875. fromName = "剑鱼实验室-数据导出"
  876. } else if fromName == "cjss" {
  877. fromName = "剑鱼实验室-超级搜索"
  878. } else if fromName == "zbqy" {
  879. fromName = "剑鱼实验室-中标企业"
  880. } else if fromName == "gzqy" {
  881. fromName = "剑鱼实验室-关注企业"
  882. }
  883. }
  884. _, m.T["advertText"] = getRewardText()
  885. m.T["advertImg"] = config.Sysconfig["advertImg"]
  886. m.T["advertName"] = config.Sysconfig["advertName"]
  887. m.T["advertUrl"] = config.Sysconfig["advertUrl"]
  888. m.T["fkid"] = fkid
  889. m.T["fromName"] = fromName
  890. return m.Render("/weixin/feedback.html", &m.T)
  891. }
  892. func (m *Front) GetIndexData() {
  893. defer util.Catch()
  894. redis_obj := redis.Get("other", "sw_index")
  895. var one map[string]interface{}
  896. if redis_obj != nil {
  897. one = redis_obj.(map[string]interface{})
  898. log.Println("newpage from the cache...")
  899. } else {
  900. rs, err := mongodb.Find("swordfish_index", nil, `{"_id":-1}`, nil, false, 0, 1)
  901. if err {
  902. one = (*rs)[0]
  903. one["i_site"] = util.IntAll(one["i_entsite"]) + util.IntAll(one["i_govsite"])
  904. avg := util.IntAll(one["i_bidmonth"])/21 + util.IntAll(one["i_bidmonth"])%21
  905. one["i_avg"] = avg
  906. one["i_my"] = util.IntAll(one["i_entsite"]) * 35 / 100
  907. one["i_hy"] = util.IntAll(one["i_entsite"]) * 15 / 100
  908. one["i_zb"] = util.IntAll(one["i_entsite"]) - util.IntAll(one["i_my"]) - util.IntAll(one["i_hy"])
  909. redis.Put("other", "sw_index", one, 60*60*2)
  910. } else {
  911. m.ServeJson("n")
  912. }
  913. }
  914. m.ServeJson(one)
  915. }
  916. func (m *Front) Urlrecord() {
  917. m.Render("/weixin/urlrecord.html")
  918. }
  919. func (m *Front) Isrecord(name string) {
  920. defer util.Catch()
  921. querystr := `{"$or":[{"s_name":"%s"},{"s_url":"%s"}]}`
  922. if name != "" {
  923. rs, _ := mongodb.Find("bidurlinfo", fmt.Sprintf(querystr, name, name), nil, nil, false, -1, -1)
  924. if len(*rs) == 0 {
  925. m.Write("f")
  926. } else {
  927. m.Write("y")
  928. }
  929. } else {
  930. m.Write("n")
  931. }
  932. }
  933. //招标订阅向导
  934. func (f *Front) TSGuide() error {
  935. defer util.Catch()
  936. userid := util.ObjToString(f.GetSession("userId"))
  937. if userid == "" {
  938. return f.Redirect("/swordfish/share/-1")
  939. }
  940. if f.Method() == "GET" {
  941. if !isInTSguide(userid) {
  942. return f.Redirect("/wxkeyset/keyset/index")
  943. }
  944. f.T["signature"] = wx.SignJSSDK(f.Site() + f.Url())
  945. return f.Render("/weixin/wxtsguide.html")
  946. } else {
  947. reqType := f.GetString("reqType")
  948. result := make(bson.M)
  949. if reqType == "save" {
  950. var keyMaps []map[string]interface{}
  951. keyWord := f.GetSlice("keyWord")
  952. for _, v := range keyWord {
  953. vs := processKeyword(v)
  954. if vs == nil {
  955. continue
  956. }
  957. keyMaps = append(keyMaps, map[string]interface{}{
  958. "key": vs,
  959. })
  960. if len(keyMaps) >= 10 {
  961. break
  962. }
  963. }
  964. saveData := bson.M{
  965. "o_jy.a_key": keyMaps,
  966. "o_jy.l_modifydate": time.Now().Unix(),
  967. "i_ts_guide": 2,
  968. }
  969. result["flag"] = mongodb.UpdateById("user", userid, bson.M{"$set": saveData})
  970. } else if reqType == "over" {
  971. mongodb.UpdateById("user", userid, bson.M{"$set": bson.M{"i_ts_guide": 1}})
  972. } else if reqType == "preview" {
  973. rlt := elastic.GetByNgram(INDEX, TYPE, strings.Split(f.GetString("key"), " "), "", FINDF, `{"publishtime":-1}`, `"_id","title","publishtime","toptype","subtype","type","area","href","areaval"`, 0, 10)
  974. if *rlt != nil && len(*rlt) > 0 {
  975. for _, v := range *rlt {
  976. v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
  977. }
  978. }
  979. result["data"] = rlt
  980. }
  981. f.ServeJson(result)
  982. }
  983. return nil
  984. }
  985. func isInTSguide(userid string) bool {
  986. if userid == "" {
  987. return false
  988. }
  989. data, ok := mongodb.FindById("user", userid, `{"o_jy":1,"i_ts_guide":1}`)
  990. if ok {
  991. o_jy, _ := (*data)["o_jy"].(map[string]interface{})
  992. i_ts_guide := util.IntAll((*data)["i_ts_guide"])
  993. if i_ts_guide == 2 || (i_ts_guide == 0 && len(o_jy) == 0) {
  994. return true
  995. }
  996. }
  997. return false
  998. }
  999. //查看原文中转
  1000. func (f *Front) Transfer() error {
  1001. return f.Redirect(f.GetString("url"))
  1002. }
  1003. //关于我们
  1004. func (f *Front) Aboutus() error {
  1005. code := f.GetString("code")
  1006. if mobileReg.MatchString(f.UserAgent()) {
  1007. return f.Redirect("/swordfish/about" + util.If(code != "", "?code="+code, "").(string))
  1008. }
  1009. if ret := redis.Get("other", "aboutus"); ret != nil && false {
  1010. return f.SetBody([]byte(ret.(string)))
  1011. } else {
  1012. var shareid = f.GetString("id")
  1013. if len(shareid) == 0 {
  1014. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jygywmy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
  1015. }
  1016. f.T["logid"] = config.Seoconfig["jygywmy"].(string)
  1017. f.T["shareid"] = se.EncodeString(shareid)
  1018. f.T["code"] = code
  1019. content, _ := f.Render4Cache("/pc/aboutus.html", &f.T)
  1020. redis.Put("other", "aboutus", string(content), -1)
  1021. return f.SetBody(content)
  1022. }
  1023. }
  1024. //商务合作
  1025. func (f *Front) Busicooperation() error {
  1026. var shareid = f.GetString("id")
  1027. if len(shareid) == 0 {
  1028. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jyswhzy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
  1029. }
  1030. f.T["logid"] = config.Seoconfig["jyswhzy"].(string)
  1031. f.T["shareid"] = se.EncodeString(shareid)
  1032. content, _ := f.Render4Cache("/pc/businesscooperation.html", &f.T)
  1033. return f.SetBody(content)
  1034. }
  1035. var keyLock sync.Mutex
  1036. func (f *Front) Gethotkey() error {
  1037. keyLock.Lock()
  1038. defer keyLock.Unlock()
  1039. keys := []interface{}{}
  1040. tmp := redis.Get("sso", "jy_hotkeys")
  1041. if tmp != nil {
  1042. keys = tmp.([]interface{})
  1043. } else {
  1044. if keys := public.GetHotkeys(); keys != nil && len(keys) > 0 {
  1045. log.Println("存储订阅词----Gethotkey")
  1046. redis.Put("sso", "jy_hotkeys", keys, -1)
  1047. }
  1048. }
  1049. f.ServeJson(keys)
  1050. return nil
  1051. }
  1052. //redis存储用户搜索关键词 企业 项目信息
  1053. func (f *Front) Rediskw() error {
  1054. skw := f.GetString("skw")
  1055. num := f.GetString("num")
  1056. if skw != "" && num != "" {
  1057. skw = strings.Replace(skw, ";", " ", -1)
  1058. log.Println(skw)
  1059. num = se.DecodeString(num)
  1060. redis.Put("sso", "pc_subscribe_"+num, skw, 15*60)
  1061. }
  1062. return nil
  1063. }
  1064. func (f *Front) DownloadJyApp() error {
  1065. userAgent := f.UserAgent()
  1066. isIos := isIosReg.MatchString(userAgent)
  1067. source := f.GetString("source")
  1068. code := f.GetString("code")
  1069. downloadPlatform := f.GetString("platform")
  1070. //不是ios,并且在微信打开,跳转到中转页面
  1071. if downloadPlatform == "" && !isIos && strings.Contains(userAgent, "MicroMessenger") {
  1072. return f.Redirect("/jyapp/free/download/weixin?source=" + source + "&code=" + code)
  1073. }
  1074. isDownloadIos := downloadPlatform == "ios" || isIos
  1075. pageName := f.GetString("page")
  1076. //
  1077. onlyFlag := code + downloadPlatform + pageName + source
  1078. downLoadJyAppCode := f.GetSession("downLoadJyAppCode")
  1079. if downLoadJyAppCode == nil || util.ObjToString(downLoadJyAppCode) != onlyFlag {
  1080. now := time.Now()
  1081. platform := ""
  1082. if isIos {
  1083. platform = "ios"
  1084. } else if mobileReg.MatchString(userAgent) {
  1085. platform = "android"
  1086. } else {
  1087. platform = "pc"
  1088. }
  1089. go mongodb.Save("jyapp_downloadlog", map[string]interface{}{
  1090. "platform": platform,
  1091. "code": code,
  1092. "createtime": now.Unix(),
  1093. "type": util.If(isDownloadIos, "appstore", "apk"),
  1094. "page": pageName,
  1095. "source": source,
  1096. "refer": f.Refer(),
  1097. "ip": filter.GetIp(f.Request),
  1098. "userAgent": userAgent,
  1099. "i_year": now.Year(),
  1100. "i_month": now.Month(),
  1101. "i_day": now.Day(),
  1102. "i_hour": now.Hour(),
  1103. "i_minutes": now.Minute(),
  1104. })
  1105. }
  1106. f.SetSession("downLoadJyAppCode", onlyFlag)
  1107. //ios直接跳到应用商店
  1108. jyapp := config.Sysconfig["jyapp"].(map[string]interface{})
  1109. apkurl, _ := jyapp["apkurl"].(string)
  1110. appstoreurl, _ := jyapp["appstoreurl"].(string)
  1111. if isDownloadIos {
  1112. return f.Redirect(appstoreurl)
  1113. }
  1114. return f.Redirect(apkurl)
  1115. }
  1116. func (f *Front) DownloadJyAppQr() error {
  1117. w := f.ResponseWriter
  1118. w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  1119. w.Header().Set("Pragma", "no-cache")
  1120. w.Header().Set("Expires", "0")
  1121. w.Header().Set("Content-Type", "image/png")
  1122. data := config.Sysconfig["webdomain"].(string) + "/front/downloadJyApp?source=" + f.GetString("source") + "&page=" + f.GetString("page") + "&code=" + f.GetString("code")
  1123. r, _ := qr.Encode(data, qr.M)
  1124. pngdat := r.PNG()
  1125. _, err := w.Write(pngdat)
  1126. return err
  1127. }
  1128. func (f *Front) LimitSearchText() {
  1129. userid := util.ObjToString(f.GetSession("userId"))
  1130. if userid == "" || !public.Lst.IsCanLogin(userid) {
  1131. f.Write("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\">需要登录!")
  1132. return
  1133. }
  1134. timeout, _ := f.GetInteger("t")
  1135. if timeout > 0 || timeout == -1 {
  1136. public.Lst.TimeOut = timeout
  1137. }
  1138. count, _ := f.GetInteger("c")
  1139. if (count > 0 || count == -1 || count == -2) && count != public.Lst.Count && public.Lst.Flag {
  1140. public.Lst.Count = count
  1141. public.Lst.Init()
  1142. }
  1143. flag, _ := f.GetInteger("f")
  1144. status := ""
  1145. if flag == -2 { //重置
  1146. status = "重置"
  1147. public.InitLimitSearchText(true)
  1148. } else if flag == -1 && public.Lst.Flag { //关闭
  1149. status = "关闭"
  1150. public.Lst.Flag = false
  1151. public.Lst.Clear()
  1152. } else if flag == 1 && !public.Lst.Flag { //打开
  1153. status = "打开"
  1154. public.Lst.Flag = true
  1155. public.Lst.Init()
  1156. } else {
  1157. if public.Lst.Flag {
  1158. status = "打开"
  1159. } else {
  1160. status = "关闭"
  1161. }
  1162. }
  1163. totalPage, _ := f.GetInteger("p")
  1164. if totalPage > 0 && public.Lst.Flag {
  1165. public.Lst.TotalPage = totalPage
  1166. }
  1167. 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))
  1168. }
  1169. //设置js css 版本号,修改以后记得同步更新seo.json中的值
  1170. func (f *Front) SetSeoVersion() {
  1171. //!@111qqq@! md5=51a3b7b4ed3cf140
  1172. if f.GetString("p") != "51a3b7b4ed3cf140" {
  1173. return
  1174. }
  1175. version := ""
  1176. if f.GetString("v") == "" {
  1177. version = config.Seoconfig_Version
  1178. if version == "" {
  1179. version, _ = config.Seoconfig["version"].(string)
  1180. }
  1181. } else {
  1182. version = f.GetString("v")
  1183. config.Seoconfig_Version = version
  1184. }
  1185. f.Write("当前版本号:" + version)
  1186. }
  1187. func (f *Front) YmSearch() {
  1188. f.Render("/weixin/yimiao/search.html")
  1189. }
  1190. func ymResult(a, y, n string) ([]string, []int, map[int]map[string]int, map[int]map[string]map[string]string) {
  1191. q := map[string]interface{}{}
  1192. if a != "" {
  1193. q["area"] = a
  1194. }
  1195. if y != "" {
  1196. q["year"] = util.IntAll(strings.TrimRight(y, "年"))
  1197. }
  1198. list, ok := mongodb.Find("yimiao", q, nil, nil, false, -1, -1)
  1199. nameMap := map[string]bool{}
  1200. yearMap := map[int]map[string]int{}
  1201. titleHrefMap := map[int]map[string]map[string]string{}
  1202. if ok {
  1203. for _, v := range *list {
  1204. vis := v["list"].([]interface{})
  1205. year := util.IntAll(v["year"])
  1206. if year < 2000 {
  1207. continue
  1208. }
  1209. href := util.ObjToString(v["href"])
  1210. id := util.ObjToString(v["id"])
  1211. if id != "" {
  1212. href = util.ObjToString(config.Sysconfig["webdomain"]) + "/article/content/" + util.EncodeArticleId2ByCheck(util.ObjToString(v["id"])) + ".html"
  1213. }
  1214. if titleHrefMap[year] == nil {
  1215. titleHrefMap[year] = map[string]map[string]string{}
  1216. }
  1217. title := util.ObjToString(v["title"])
  1218. for _, vi := range vis {
  1219. vim, _ := vi.(map[string]interface{})
  1220. name := strings.TrimSpace(util.ObjToString(vim["name"]))
  1221. if name == "" {
  1222. continue
  1223. }
  1224. number := util.IntAll(vim["number"])
  1225. if n != "" && n != name {
  1226. continue
  1227. }
  1228. if yearMap[year] == nil {
  1229. yearMap[year] = map[string]int{}
  1230. }
  1231. yearMap[year][name] = yearMap[year][name] + number
  1232. if title != "" && href != "" {
  1233. if titleHrefMap[year][name] == nil {
  1234. titleHrefMap[year][name] = map[string]string{}
  1235. }
  1236. titleHrefMap[year][name][title] = href
  1237. }
  1238. nameMap[name] = true
  1239. }
  1240. }
  1241. }
  1242. names := []string{}
  1243. for k, _ := range nameMap {
  1244. names = append(names, k)
  1245. }
  1246. years := []int{}
  1247. for k, _ := range yearMap {
  1248. years = append(years, k)
  1249. }
  1250. return names, years, yearMap, titleHrefMap
  1251. }
  1252. func (f *Front) YmResultHmtl(s string) error {
  1253. ss := strings.Split(s, "_")
  1254. a := ss[0]
  1255. y := ss[1]
  1256. n := ss[2]
  1257. if a == "1" {
  1258. a = ""
  1259. }
  1260. if y == "1" {
  1261. y = ""
  1262. }
  1263. if n == "1" {
  1264. n = ""
  1265. }
  1266. names, years, yearMap, _ := ymResult(a, y, n)
  1267. f.T["years"] = years
  1268. f.T["names"] = names
  1269. f.T["yearMap"] = yearMap
  1270. f.T["area"] = a
  1271. return f.Render("/weixin/yimiao/three.html")
  1272. }
  1273. func (f *Front) YmResult() error {
  1274. a := f.GetString("a")
  1275. y := f.GetString("y")
  1276. n := f.GetString("n")
  1277. names, years, yearMap, titleHrefMap := ymResult(a, y, n)
  1278. f.T["years"] = years
  1279. f.T["names"] = names
  1280. f.T["name"] = n
  1281. f.T["yearMap"] = yearMap
  1282. f.T["titleHrefMap"] = titleHrefMap
  1283. f.T["area"] = a
  1284. f.T["signature"] = wx.SignJSSDK(f.Site() + f.Url())
  1285. if f.GetString("t") == "s" {
  1286. return f.Render("/weixin/yimiao/share.html")
  1287. } else {
  1288. return f.Render("/weixin/yimiao/result.html")
  1289. }
  1290. }
  1291. //
  1292. func (f *Front) JylabShareTimeline() {
  1293. userid := util.ObjToString(f.GetSession("userId"))
  1294. if userid == "" {
  1295. f.ServeJson(map[string]interface{}{
  1296. "status": false,
  1297. })
  1298. return
  1299. }
  1300. reqType := f.GetString("reqType")
  1301. if reqType == "update" {
  1302. public.UpdateShareStatus(userid, "wx", 3, 1, 0, false)
  1303. f.ServeJson(map[string]interface{}{
  1304. "status": true,
  1305. })
  1306. } else {
  1307. jylabsharetimeline := 1
  1308. if public.CheckUserNeedForceShare(userid, public.ShareType_lab) {
  1309. jylabsharetimeline = 0
  1310. }
  1311. f.ServeJson(map[string]interface{}{
  1312. "jylabsharetimeline": jylabsharetimeline,
  1313. })
  1314. }
  1315. }
  1316. /**
  1317. 成功分享后 更改分享相关信息
  1318. shareType - 分享类型 1-详情页 2-推送列表 3-实验室
  1319. shareProperty - 分享性质 1-被动分享 2-主动分享
  1320. */
  1321. func (s *Front) UpdateShareStatus() error {
  1322. userid := util.ObjToString(s.GetSession("userId"))
  1323. shareType, _ := s.GetInt("shareType")
  1324. shareProperty, _ := s.GetInt("shareProperty")
  1325. ispcforceshare, _ := s.GetInt("ispcforceshare")
  1326. platform := s.GetString("platform")
  1327. if platform == "" {
  1328. platform = "wx"
  1329. }
  1330. public.UpdateShareStatus(userid, platform, shareType, shareProperty, ispcforceshare, s.GetString("isRepair") == "y")
  1331. s.ServeJson(map[string]interface{}{})
  1332. return nil
  1333. }
  1334. func (s *Front) StaticPage(pagename string) error {
  1335. return s.Render("/staticpage/" + pagename)
  1336. }