front.go 49 KB

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