shorturl.go 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. package front
  2. import (
  3. "database/sql"
  4. "errors"
  5. "fmt"
  6. "jy/src/jfw/config"
  7. "jy/src/jfw/wx"
  8. "log"
  9. "math/rand"
  10. "net/url"
  11. "strconv"
  12. "github.com/gogf/gf/v2/util/gconv"
  13. "jy/src/jfw/jyutil"
  14. "app.yhyue.com/moapp/jypkg/public"
  15. util "app.yhyue.com/moapp/jybase/common"
  16. "app.yhyue.com/moapp/jybase/date"
  17. mg "app.yhyue.com/moapp/jybase/mongodb"
  18. elastic "app.yhyue.com/moapp/jybase/es"
  19. "regexp"
  20. "strings"
  21. "time"
  22. "app.yhyue.com/moapp/jybase/encrypt"
  23. "app.yhyue.com/moapp/jybase/go-xweb/xweb"
  24. "app.yhyue.com/moapp/jybase/redis"
  25. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
  26. "github.com/SKatiyar/qr"
  27. "go.mongodb.org/mongo-driver/bson"
  28. )
  29. type Short struct {
  30. *xweb.Action
  31. article xweb.Mapper `xweb:"/article/(\\w+)/(.*).html"` //([pm])
  32. qr xweb.Mapper `xweb:"/biddetail/(\\w+)/qr/(.+)"`
  33. replication xweb.Mapper `xweb:"/front/shorturl/replication"` //用户复制操作记录入库
  34. nologinArticle xweb.Mapper `xweb:"/nologin/(\\w+)/(.*).html"` //([pm]) 无需登录
  35. }
  36. var (
  37. mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
  38. DateFullLayout = "2006-01-02 15:04:05"
  39. Map_stype = map[string]bool{
  40. "content": true,
  41. "entservice": true,
  42. "bdprivate": true,
  43. "mailprivate": true,
  44. "bdcontent": true,
  45. "indexcontent": true,
  46. "advancedProject": true,
  47. }
  48. seoAgentReg = regexp.MustCompile("Baiduspider|360Spider|bingbot|Googlebot")
  49. detailNeedMosaic map[string]interface{}
  50. TypeCodeMap = map[string]string{
  51. "拟建": "拟建项目",
  52. "采购意向": "采购意向",
  53. "预告": "招标预告",
  54. "预审": "资格预审",
  55. "预审结果": "资格预审结果",
  56. "论证意见": "论证意见",
  57. "需求公示": "需求公示",
  58. "招标": "公开招标",
  59. "邀标": "邀请招标",
  60. "询价": "询价采购",
  61. "竞谈": "竞争性谈判",
  62. "单一": "单一来源采购",
  63. "竞价": "竞价公告",
  64. "变更": "变更公告",
  65. "中标": "中标公示",
  66. "成交": "成交公告",
  67. "废标": "废标公告",
  68. "流标": "流标公告",
  69. "合同": "合同公告信息",
  70. "验收": "验收公告信息",
  71. "违规": "违规信息",
  72. }
  73. )
  74. func (s *Short) Article(stype, id string) error {
  75. userId, _ := s.GetSession("userId").(string)
  76. if (stype == "content" || stype == "indexcontent") && userId == "" {
  77. if seoAgentReg.MatchString(s.UserAgent()) {
  78. sids := encrypt.CommonDecodeArticle(stype, id)
  79. return s.NologinCommon("", stype, id, sids[0])
  80. } else {
  81. return s.Redirect("/notin/page")
  82. }
  83. }
  84. return s.LoginCommon(userId, stype, id)
  85. }
  86. func (s *Short) LoginCommon(userId, stype, id string) error {
  87. client := s.Header("User-Agent")
  88. bm := mobileReg.MatchString(client)
  89. //电脑端 剑鱼快照页面访问
  90. if stype == "content" && !bm {
  91. //工作桌面内嵌 快照页
  92. //老地址(地址不包含aside)且非工作桌面地址
  93. if !strings.Contains(s.Request.URL.String(), "aside") && !strings.Contains(s.Request.URL.String(), "page_workDesktop") {
  94. paramSuffix := ".html?aside=0"
  95. replaceStr := ".html"
  96. if strings.Contains(s.Request.URL.String(), "?") {
  97. replaceStr = ".html?"
  98. paramSuffix = ".html?aside=0&"
  99. }
  100. return s.Redirect(fmt.Sprintf("%s%s%s", config.Sysconfig["workDesktopUrl"].(string), config.Sysconfig["webdomain"].(string), url.QueryEscape(strings.Replace(s.Request.URL.String(), replaceStr, paramSuffix, 1))))
  101. }
  102. }
  103. //先判断是否有session
  104. source := s.GetString("source")
  105. disWord := s.GetString("disWord")
  106. aboutUrl := "/swordfish/about"
  107. //是否已经检查过,默认是检查过-true,分享过来的是未检查过-false
  108. // checkIsSubscribeFlag := true
  109. // if source == "app_infocontentshare" || source == "wx_infocontentshare" {
  110. // checkIsSubscribeFlag = false
  111. // }
  112. from_userid := ""
  113. if source != "" {
  114. aboutUrl += "?source=" + source
  115. if strings.Contains(source, "wx_infocontentshare") {
  116. decodeArr := encrypt.DecodeArticleId2ByCheck(id)
  117. if len(decodeArr) > 1 {
  118. from_userid = se.Encode2Hex(GetUserId(decodeArr[1])) //加密用户userid
  119. }
  120. } else if strings.Contains(source, "app_infocontentshare") {
  121. if from := s.GetString("from"); from != "" {
  122. from_userid = from
  123. }
  124. }
  125. aboutUrl += "&from=" + from_userid
  126. }
  127. if !Map_stype[stype] {
  128. s.Redirect("/not/nottype", 302)
  129. return nil
  130. } else if stype == "content" || stype == "bdcontent" || stype == "advancedProject" {
  131. if userId == "" {
  132. if s.GetString("state") == "wx" {
  133. //微信跳回来的
  134. if code := s.GetString("code"); code != "" {
  135. if openid := jyutil.Getopenid(code); openid != "" {
  136. if CheckUserIsSubscribe(openid) {
  137. FindUserAndCreateSess(openid, s.Session(), "wx", false, true)
  138. }
  139. }
  140. }
  141. } else if public.CheckWxBrowser(s.Request) {
  142. //所有参数都不再使用,跳到微信验证用户
  143. return s.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(s.Site()+s.Url()), "wx"), 302)
  144. }
  145. }
  146. if disWord != "" {
  147. from_userid = disWordNil(disWord, userId)
  148. }
  149. if userId == "" { //} && !regclient.MatchString(client) { //没有用户session //搜索引擎让过
  150. s.Session().Set("referer", s.Request.RequestURI)
  151. if bm { //是否是移动端访问
  152. s.Redirect(aboutUrl, 302)
  153. } else {
  154. if stype == "bdcontent" {
  155. var retMap = make(map[string]interface{})
  156. stype = "content"
  157. _id := encrypt.CommonDecodeArticle(stype, id)[0]
  158. _, _, _, obj := pcVRT(_id, "", stype, true)
  159. if obj != nil && len(obj) > 0 {
  160. retMap["_id"] = id
  161. retMap["title"], _ = obj["title"].(string)
  162. retMap["area"], _ = obj["area"].(string)
  163. retMap["subtype"], _ = obj["subtype"].(string)
  164. retMap["subscopeclass"], _ = obj["s_subscopeclass"].(string)
  165. retMap["publishtime"] = util.IntAll(obj["publishtime"])
  166. retMap["keywords"] = KeyWordHandle(obj)
  167. retMap["description"] = DescriptionHandle(stype, obj)
  168. }
  169. s.T["shareid"] = config.Seoconfig["baiduSEM-p"].(string)
  170. s.T["logid"] = config.Seoconfig["baiduSEM-p"].(string)
  171. s.T["obj"] = retMap
  172. s.Render("/pc/biddetail_bd.html", &s.T)
  173. } else {
  174. s.Redirect("/notin/page", 302)
  175. }
  176. }
  177. return nil
  178. }
  179. if stype == "bdcontent" {
  180. stype = "content"
  181. }
  182. } else if stype == "entservice" { //大客户数据快照展示
  183. //se := util.SimpleEncrypt{"entservice"}
  184. sid := encrypt.SE3.DecodeString(id)
  185. if len(sid) == 0 || (len(sid) > 0 && sid == "") {
  186. s.Redirect("/notin/page", 302)
  187. return nil
  188. }
  189. catchKey := fmt.Sprintf("jypcdetail_%s_%s_%s", userId, stype, sid)
  190. if res := redis.Get("newother", catchKey); res == nil || res == "" {
  191. industry := s.GetString("industry")
  192. var shareid = s.GetString("id")
  193. if len(shareid) == 0 {
  194. shareid = "10"
  195. }
  196. s.T["logid"] = config.Seoconfig["jysskzy"].(string)
  197. s.T["shareid"] = se.EncodeString(shareid)
  198. s.T["keywords"] = s.GetString("kds")
  199. ssOpenid := s.Session().Get("s_m_openid")
  200. po, bo, wo, obj := pcVRT(sid, industry, stype, true)
  201. if obj != nil && len(obj) > 0 {
  202. if len(po) > 0 {
  203. s.T["projectOther"] = po
  204. }
  205. if len(bo) > 0 {
  206. s.T["buyerOther"] = bo
  207. }
  208. if len(wo) > 0 {
  209. s.T["winnerOther"] = wo
  210. }
  211. obj["urlpath"] = s.Uri()
  212. obj["industry"] = industry
  213. if ssOpenid != nil {
  214. obj["ucbsId"] = encrypt.EncodeArticleId2ByCheck("ucbs#" + ssOpenid.(string) + "#" + id)
  215. }
  216. //if false && isbid(obj["subtype"]) {
  217. // //bidding表有数据就有,没有不再查此中标企业得其他信息--需求来自数据和质量
  218. // obj["winner_enttel"] = "" //getwinnertel(obj["winner"])
  219. //}
  220. //判断时间 //如果是seo页面超过时间访问的进入首页
  221. comeinTime := time.Unix(util.Int64All(obj["comeintime"]), 0)
  222. if stype == "indexcontent" {
  223. if count := public.MQFW.Count("seobidding", map[string]interface{}{"bid": sid}); count <= 0 && comeinTime.Before(time.Now().Add(time.Duration(-util.IntAll(config.Sysconfig["seoBeforeTimeHour"]))*time.Hour)) {
  224. return s.Redirect("/")
  225. }
  226. }
  227. FieldProcessing(obj, ssOpenid, industry, id, from_userid, userId, stype, false)
  228. if obj["projectname"] != nil {
  229. s.SetSession("projectname", obj["projectname"])
  230. }
  231. if obj["entidlist"] != nil { //大会员中标企业跳转至画像
  232. s_winner := util.ObjToString(obj["s_winner"])
  233. idObjs, _ := obj["entidlist"].([]interface{})
  234. winnerIdArr := []string{}
  235. for _, v := range strings.Split(s_winner, ",") {
  236. if v == "-" || !isInStringArr(util.ObjArrToStringArr(idObjs), v) {
  237. continue
  238. }
  239. winnerIdArr = append(winnerIdArr, encrypt.EncodeArticleId2ByCheck(v))
  240. obj["entIds"] = winnerIdArr
  241. }
  242. }
  243. if obj["publishtime"] != nil {
  244. obj["publishtimeShorDate"] = time.Unix(util.Int64All(obj["publishtime"]), 0).Format(date.Date_Short_Layout)
  245. }
  246. s.T["url"] = s.Uri()
  247. obj["keywords"] = KeyWordHandle(obj)
  248. obj["description"] = DescriptionHandle(stype, obj)
  249. s.T["obj"] = obj
  250. content, _ := s.Render4Cache("/pc/biddetail_rec.html", &s.T)
  251. redis.Put("newother", catchKey, string(content), 60*20)
  252. return s.SetBody(content)
  253. }
  254. } else {
  255. return s.SetBody([]byte(res.(string)))
  256. }
  257. }
  258. ssOpenid := s.Session().Get("s_m_openid")
  259. var (
  260. res *map[string]interface{}
  261. ok bool
  262. )
  263. if userId == "" && ssOpenid != nil {
  264. res, ok = mongodb.FindOneByField("user", bson.M{"s_m_openid": ssOpenid, "s_unionid": bson.M{"$ne": ssOpenid}}, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1,"l_vip_starttime":1}`)
  265. if ok {
  266. userId = mg.BsonIdToSId((*res)["_id"])
  267. }
  268. } else if userId != "" {
  269. //判断用户是否是vip
  270. res = jyutil.Compatible.Select(userId, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1,"l_vip_starttime":1}`)
  271. }
  272. entid := util.Int64All(s.GetSession("entId"))
  273. userPower := jy.GetBigVipUserBaseMsg(s.Session(), *config.Middleground)
  274. var (
  275. isEntnicheNew bool = userPower.EntIsNew //新版超级订阅
  276. isOldVip bool = false //新购超级订阅不能查看拟建项目详情页
  277. isVip bool = userPower.VipStatus > 0 //超级订阅
  278. isMember bool = userPower.Status > 0 //大会员
  279. isEntniche bool = userPower.EntnicheStatus > 0 //商机管理
  280. privatedata bool = userPower.PrivateGD //广东移动DICT 用户
  281. isEntService bool = userPower.Data.Ent.PowerSource > 0 && userPower.Data.Entniche.IsEntPower > 0 //商机管理服务
  282. )
  283. if res != nil && len(*res) > 0 {
  284. if isVip && util.Int64All((*res)["l_vip_starttime"]) < util.Int64All(config.Sysconfig["contextOldVipLimit"]) {
  285. isOldVip = true
  286. }
  287. }
  288. entId := util.IntAll(entid)
  289. if entId > 0 && userPower.EntInfo[entId] != nil {
  290. isEntniche = userPower.EntInfo[entId].Status == 1 && userPower.EntInfo[entId].IsPower
  291. isEntnicheNew = userPower.EntInfo[entId].IsNew && isEntniche
  292. if isEntService = userPower.EntInfo[entId].IsService && userPower.EntInfo[entId].IsPower; isEntService {
  293. isEntnicheNew = false
  294. isEntniche = false
  295. }
  296. }
  297. if !isEntniche && privatedata {
  298. isEntniche = true
  299. }
  300. s.T["isVip"] = isVip
  301. s.T["isMember"] = isMember
  302. s.T["isEntniche"] = isEntniche
  303. s.T["isEntnicheNew"] = isEntnicheNew
  304. s.T["isEntService"] = isEntService
  305. if bm {
  306. //判断有没有取关,取关的话,跳转到关于剑鱼标讯页面
  307. if ssOpenid != nil && ssOpenid != "" {
  308. isSubscribe := CheckUserIsSubscribe(ssOpenid.(string))
  309. if !isSubscribe {
  310. return s.Redirect(aboutUrl, 302)
  311. }
  312. //之前sessionkeep.go中没有放userId,造成关注有问题
  313. if userId == "" {
  314. FindUserAndCreateSess(ssOpenid.(string), s.Session(), "wx", false, true)
  315. }
  316. }
  317. surl := s.GetString("url")
  318. kds := s.GetString("keywords")
  319. industry := s.GetString("industry")
  320. var shareopenid, sid string
  321. sid_openid := encrypt.CommonDecodeArticle(stype, id)
  322. switch len(sid_openid) {
  323. case 0:
  324. s.Redirect(aboutUrl, 302)
  325. return nil
  326. default:
  327. shareopenid, sid = SwiDef(sid_openid)
  328. }
  329. s.T["keywords"] = kds
  330. if shareopenid != "" {
  331. s.T["shareopenid"] = shareopenid
  332. }
  333. myopenid, _ := s.Session().Get("s_m_openid").(string)
  334. if myopenid == "" {
  335. myopenid = shareopenid
  336. s.T["openid"] = myopenid //"-1"
  337. } else {
  338. s.T["openid"] = se.EncodeString(myopenid) //"-1"
  339. }
  340. mynickname, _ := s.GetSession("s_nickname").(string)
  341. myavatar, _ := s.GetSession("s_avatar").(string)
  342. s.T["nickname"] = mynickname
  343. s.T["avatar"] = myavatar
  344. s.T["signature"] = wx.SignJSSDK(s.Site() + s.Url())
  345. obj := wxvisitD(sid, userId, myopenid, stype, (isVip && isOldVip) || isMember || isEntniche)
  346. canRead := false
  347. if ((isVip && isOldVip) || isMember || isEntniche) || //老版本vip、大会员、商机管理
  348. ((isVip && !isOldVip) && (!(util.ObjToString(obj["subtype"]) == "拟建" || util.ObjToString(obj["subtype"]) == "采购意向"))) || //新超级订阅非采购意向”和“拟建项目”
  349. stype == "mailprivate" || stype == "indexcontent" || stype == "bdprivate" { //邮箱推送
  350. canRead = true
  351. } else {
  352. canRead = SeeDetailLimit(obj, userId, sid)
  353. }
  354. if stype == "advancedProject" {
  355. newCanRead := false
  356. //判断此用户是否有打开的权限
  357. newUserId := s.GetSession("base_user_id")
  358. pushData := public.BaseMysql.FindOne("leadproject_push", map[string]interface{}{"user_id": newUserId, "info_id": sid}, "id", "")
  359. //访问次数加1
  360. if pushData == nil {
  361. newCanRead = false
  362. } else {
  363. public.BaseMysql.UpdateOrDeleteBySql("UPDATE leadproject_push SET visit_count=visit_count+1 ,lastvisit_time=? WHERE id = ?", time.Now().Format("2006-01-02 15:04:05"), (*pushData)["id"])
  364. newCanRead = true
  365. }
  366. if newCanRead || canRead {
  367. obj = wxvisitD(sid, userId, myopenid, stype, true)
  368. canRead = true
  369. }
  370. s.T["canRead"] = canRead
  371. }
  372. if len(obj) > 0 {
  373. if canRead {
  374. FieldProcessing(obj, ssOpenid, industry, id, from_userid, userId, stype, true)
  375. //免费用户正文手机号替换
  376. if obj["site"] == "剑鱼信息发布平台" && !isMember {
  377. //采购电话中标单位电话置空
  378. if util.InterfaceToStr(obj["buyertel"]) != "" {
  379. obj["buyertel"] = "freeView"
  380. }
  381. if util.InterfaceToStr(obj["winnertel"]) != "" {
  382. obj["winnertel"] = "freeView"
  383. }
  384. //正文电话 手机号 邮箱处理
  385. if detail, _ := obj["detail"].(string); detail != "" {
  386. //手机号
  387. re1 := regexp.MustCompile("1[345789]{1}\\d{9}")
  388. detail1 := re1.ReplaceAllString(detail, `<span class="freeView">点击查看</span>`)
  389. code := util.InterfaceToStr(obj["projectcode"])
  390. if code != "" {
  391. detail1 = strings.ReplaceAll(detail1, code, "*********")
  392. }
  393. //座机
  394. re2 := regexp.MustCompile("((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?")
  395. detail2 := re2.ReplaceAllString(detail1, `<span class="freeView">点击查看</span>`)
  396. re4 := regexp.MustCompile("((400)-)(\\d{3,4}-)(\\d{3,})")
  397. detail4 := re4.ReplaceAllString(detail2, `<span class="freeView">点击查看</span>`)
  398. //邮箱
  399. re3 := regexp.MustCompile("([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)")
  400. detail3 := re3.ReplaceAllString(detail4, `<span class="freeView">点击查看</span>`)
  401. obj["detail"] = strings.ReplaceAll(strings.ReplaceAll(detail3, `<span class="freeView">点击查看</span><span class="freeView">点击查看</span>`, `<span class="freeView">点击查看</span>`), "*********", code)
  402. }
  403. }
  404. if obj["entidlist"] != nil { //大会员中标企业跳转至画像
  405. s_winner := util.ObjToString(obj["s_winner"])
  406. idObjs, _ := obj["entidlist"].([]interface{})
  407. winnerIdArr := []string{}
  408. for _, v := range strings.Split(s_winner, ",") {
  409. if v == "-" || !isInStringArr(util.ObjArrToStringArr(idObjs), v) {
  410. continue
  411. }
  412. winnerIdArr = append(winnerIdArr, encrypt.EncodeArticleId2ByCheck(v))
  413. obj["entIds"] = winnerIdArr
  414. }
  415. }
  416. s.T["advertcode"] = s.GetString("advertcode")
  417. } else {
  418. obj = map[string]interface{}{
  419. "title": obj["title"],
  420. "_id": obj["_id"],
  421. "subtype": obj["subtype"],
  422. }
  423. }
  424. //纠错随机回复
  425. recoveryRight, _ := config.Sysconfig["recoveryRight"].([]interface{})
  426. recVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(recoveryRight))
  427. s.T["recVal"] = util.ObjToString(recoveryRight[recVal])
  428. s.T["advertImg"] = config.Sysconfig["advertImg"]
  429. s.T["advertName"] = config.Sysconfig["advertName"]
  430. s.T["advertUrl"] = config.Sysconfig["advertUrl"]
  431. s.T["canRead"] = canRead
  432. obj["industry"] = industry
  433. obj["keywords"] = KeyWordHandle(obj)
  434. obj["description"] = DescriptionHandle(stype, obj)
  435. s.T["obj"] = obj
  436. //获取打赏文案
  437. s.T["rewardText"], s.T["advertText"] = getRewardText()
  438. content, _ := s.Render4Cache("/weixin/wxinfocontent_rec.html", &s.T)
  439. return s.SetBody(content)
  440. }
  441. if surl != "" {
  442. return s.Redirect(surl)
  443. }
  444. } else {
  445. sids := encrypt.CommonDecodeArticle(stype, id)
  446. if len(sids) == 0 || (len(sids) > 0 && sids[0] == "") {
  447. s.Redirect("/notin/page", 302)
  448. return nil
  449. }
  450. sid := sids[0]
  451. //免费用户浏览三级页判断留资与浏览次数
  452. indust := s.GetString("industry")
  453. if userId != "" && stype == "indexcontent" { //已登录用户直接跳转至正常三级页
  454. return s.Redirect(fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", sid)))
  455. }
  456. industry := s.GetString("industry")
  457. var shareid = s.GetString("id")
  458. if len(shareid) == 0 {
  459. shareid = "10"
  460. }
  461. s.T["logid"] = config.Seoconfig["jysskzy"].(string)
  462. s.T["shareid"] = se.EncodeString(shareid)
  463. s.T["keywords"] = s.GetString("kds")
  464. s.DisableHttpCache()
  465. po, bo, wo, obj := pcVRT(sid, industry, stype, isVip || isMember || isEntniche)
  466. if obj != nil && len(obj) > 0 {
  467. var node bool
  468. if ((isVip && isOldVip) || isMember || isEntniche) || //老版本vip、大会员、商机管理
  469. ((isVip && !isOldVip) && (!(util.ObjToString(obj["subtype"]) == "拟建" || util.ObjToString(obj["subtype"]) == "采购意向"))) || //新超级订阅非采购意向”和“拟建项目”
  470. stype == "mailprivate" || stype == "indexcontent" || stype == "bdprivate" { //邮箱推送
  471. node = true
  472. } else {
  473. _, _, _, objc := pcVRT(sid, indust, stype, isVip || isMember || isEntniche)
  474. node = SeeDetailLimit(objc, userId, sid)
  475. }
  476. if obj["publishtime"] != nil {
  477. obj["publishtimeShorDate"] = time.Unix(util.Int64All(obj["publishtime"]), 0).Format(date.Date_Short_Layout)
  478. }
  479. s.T["canRead"] = node
  480. if stype == "advancedProject" {
  481. canRead := false
  482. //判断此用户是否有打开的权限
  483. newUserId := s.GetSession("base_user_id")
  484. pushData := public.BaseMysql.FindOne("leadproject_push", map[string]interface{}{"user_id": newUserId, "info_id": sid}, "id", "")
  485. //访问次数加1
  486. if pushData == nil {
  487. canRead = false
  488. } else {
  489. public.BaseMysql.UpdateOrDeleteBySql("UPDATE leadproject_push SET visit_count=visit_count+1 ,lastvisit_time=? WHERE id = ?", time.Now().Format("2006-01-02 15:04:05"), (*pushData)["id"])
  490. canRead = true
  491. }
  492. if canRead || node {
  493. _, _, _, obj = pcVRT(sid, indust, stype, true)
  494. canRead = true
  495. node = canRead
  496. }
  497. s.T["canRead"] = canRead
  498. }
  499. if node {
  500. if len(po) > 0 {
  501. s.T["projectOther"] = po
  502. }
  503. if len(bo) > 0 {
  504. s.T["buyerOther"] = bo
  505. }
  506. if len(wo) > 0 {
  507. s.T["winnerOther"] = wo
  508. }
  509. //判断时间 //如果是seo页面超过时间访问的进入首页
  510. comeinTime := time.Unix(util.Int64All(obj["comeintime"]), 0)
  511. if stype == "indexcontent" {
  512. if count := public.MQFW.Count("seobidding", map[string]interface{}{"bid": sid}); count <= 0 && comeinTime.Before(time.Now().Add(time.Duration(-util.IntAll(config.Sysconfig["seoBeforeTimeHour"]))*time.Hour)) {
  513. return s.Redirect("/")
  514. }
  515. }
  516. FieldProcessing(obj, ssOpenid, industry, id, from_userid, userId, stype, false)
  517. //免费用户正文手机号替换
  518. if obj["site"] == "剑鱼信息发布平台" && !isMember {
  519. //采购电话中标单位电话置空
  520. if util.InterfaceToStr(obj["buyertel"]) != "" {
  521. obj["buyertel"] = "freeView"
  522. }
  523. if util.InterfaceToStr(obj["winnertel"]) != "" {
  524. obj["winnertel"] = "freeView"
  525. }
  526. //正文电话 手机号 邮箱处理
  527. if detail, _ := obj["detail"].(string); detail != "" {
  528. //手机号
  529. re1 := regexp.MustCompile("1[345789]{1}\\d{9}")
  530. detail1 := re1.ReplaceAllString(detail, `<span class="freeView">点击查看</span>`)
  531. code := util.InterfaceToStr(obj["projectcode"])
  532. if code != "" {
  533. detail1 = strings.ReplaceAll(detail1, code, "*********")
  534. }
  535. //座机
  536. re2 := regexp.MustCompile("((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?")
  537. detail2 := re2.ReplaceAllString(detail1, `<span class="freeView">点击查看</span>`)
  538. re4 := regexp.MustCompile("((400)-)(\\d{3,4}-)(\\d{3,})")
  539. detail4 := re4.ReplaceAllString(detail2, `<span class="freeView">点击查看</span>`)
  540. //邮箱
  541. re3 := regexp.MustCompile("([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)")
  542. detail3 := re3.ReplaceAllString(detail4, `<span class="freeView">点击查看</span>`)
  543. obj["detail"] = strings.ReplaceAll(strings.ReplaceAll(detail3, `<span class="freeView">点击查看</span><span class="freeView">点击查看</span>`, `<span class="freeView">点击查看</span>`), "*********", code)
  544. }
  545. }
  546. if obj["projectname"] != nil {
  547. s.SetSession("projectname", obj["projectname"])
  548. }
  549. if obj["entidlist"] != nil { //大会员中标企业跳转至画像
  550. s_winner := util.ObjToString(obj["s_winner"])
  551. idObjs, _ := obj["entidlist"].([]interface{})
  552. winnerIdArr := []string{}
  553. for _, v := range strings.Split(s_winner, ",") {
  554. if v == "-" || !isInStringArr(util.ObjArrToStringArr(idObjs), v) {
  555. continue
  556. }
  557. winnerIdArr = append(winnerIdArr, encrypt.EncodeArticleId2ByCheck(v))
  558. obj["entIds"] = winnerIdArr
  559. }
  560. }
  561. } else {
  562. obj = map[string]interface{}{
  563. "title": obj["title"],
  564. "_id": obj["_id"],
  565. "subtype": obj["subtype"],
  566. "stypeadd": obj["stypeadd"],
  567. }
  568. }
  569. obj["urlpath"] = s.Uri()
  570. obj["industry"] = industry
  571. if ssOpenid != nil {
  572. obj["ucbsId"] = encrypt.EncodeArticleId2ByCheck("ucbs#" + ssOpenid.(string) + "#" + id)
  573. }
  574. obj["keywords"] = KeyWordHandle(obj)
  575. obj["description"] = DescriptionHandle(stype, obj)
  576. s.T["obj"] = obj
  577. s.T["url"] = s.Uri()
  578. return s.Render("/pc/biddetail_rec.html", &s.T)
  579. }
  580. }
  581. return nil
  582. }
  583. func CNode(userId string) bool {
  584. if hasRetainedCapital(userId, "jyarticle_see3_plus") {
  585. return true
  586. }
  587. rM := map[string]interface{}{}
  588. rdata, ok := mongodb.Find("saleLeads", map[string]interface{}{
  589. "userid": userId,
  590. }, `{"createtime":-1}`, nil, false, 0, 10)
  591. if rdata != nil && len(*rdata) > 0 && ok {
  592. for _, v := range *rdata {
  593. for kk, vv := range v {
  594. if vv == nil {
  595. continue
  596. }
  597. if rM[kk] != nil {
  598. continue
  599. }
  600. rM[kk] = vv
  601. }
  602. }
  603. delete(rM, "_id")
  604. delete(rM, "userid")
  605. delete(rM, "createtime")
  606. delete(rM, "client")
  607. }
  608. if userinfo := jyutil.Compatible.Select(userId, `{"s_phone":1,"s_m_phone":1,"s_myemail":1,"s_company":1,"o_jy":1,"o_vipjy":1}`); userinfo != nil && len(*userinfo) > 0 {
  609. s_phone := util.ObjToString((*userinfo)["s_phone"])
  610. phone := util.If(s_phone == "", util.ObjToString((*userinfo)["s_m_phone"]), s_phone)
  611. if rM["phone"] == nil || rM["phone"] == "" {
  612. rM["phone"] = phone
  613. }
  614. if rM["company"] == nil || rM["company"] == "" {
  615. rM["company"] = util.ObjToString((*userinfo)["s_company"])
  616. }
  617. }
  618. if rM["name"] != nil && rM["name"] != "" && rM["phone"] != nil && rM["phone"] != "" && rM["company"] != nil && rM["company"] != "" && rM["position"] != nil && rM["position"] != "" && rM["companyType"] != "" {
  619. if rM["position"] != "总裁" && rM["position"] != "总经理" && (rM["branch"] == nil || rM["branch"] == "") {
  620. return false
  621. }
  622. return true
  623. }
  624. return false
  625. }
  626. // 查看公告详情次数限制
  627. func SeeDetailLimit(obj map[string]interface{}, userId, sid string) bool {
  628. watchKey := fmt.Sprintf("article_count_%d_%s_%d_%s", time.Now().Year(), time.Now().Month(), time.Now().Day(), userId)
  629. subTypeStr, _ := obj["subtype"].(string)
  630. if strings.Contains(subTypeStr, "拟建") || strings.Contains(subTypeStr, "采购意向") {
  631. return false
  632. } else {
  633. //检验是否留资
  634. if CNode(userId) {
  635. return true
  636. }
  637. if seeRes := redis.Get("other", watchKey); seeRes != nil && seeRes != "" {
  638. if resVal, _ := seeRes.(string); resVal != "" {
  639. sidss := strings.Split(resVal, "_")
  640. canRead := config.Sysconfig["canReadNotice"]
  641. if len(sidss) < util.IntAll(canRead) {
  642. sidss = append(sidss, sid)
  643. arrs := RemoveDuplicatesAndEmpty(sidss)
  644. newVal := strings.Join(arrs, "_")
  645. redis.Put("other", watchKey, newVal, jy.GetExpire())
  646. return true
  647. } else {
  648. for _, v := range sidss {
  649. if sid == v {
  650. return true
  651. }
  652. }
  653. return false
  654. }
  655. }
  656. } else {
  657. redis.Put("other", watchKey, sid, jy.GetExpire())
  658. return true
  659. }
  660. }
  661. return false
  662. }
  663. func SwiDef(sid_openid []string) (string, string) {
  664. var shareopenid, sid string
  665. if len(sid_openid) > 1 {
  666. sid = sid_openid[0]
  667. shareopenid = sid_openid[1]
  668. } else {
  669. sid = sid_openid[0]
  670. }
  671. return shareopenid, sid
  672. }
  673. // user 权限获取
  674. func UserPermission(userId string, ssOpenid interface{}) (bool, bool, bool) {
  675. var (
  676. res *map[string]interface{}
  677. isVip, isMember, isEntniche, privatedata bool
  678. )
  679. if userId == "" && ssOpenid != nil {
  680. res, _ = mongodb.FindOneByField("user", bson.M{"s_m_openid": ssOpenid, "s_unionid": bson.M{"$ne": ssOpenid}}, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1}`)
  681. userId = mg.BsonIdToSId((*res)["_id"])
  682. } else {
  683. //判断用户是否是vip
  684. res = jyutil.Compatible.Select(userId, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1}`)
  685. }
  686. isVip = util.IntAll((*res)["i_vip_status"]) == 1 || util.IntAll((*res)["i_vip_status"]) == 2
  687. isMember = util.IntAll((*res)["i_member_status"]) > 0
  688. if phone, _ := util.If(util.ObjToString((*res)["s_phone"]) != "", util.ObjToString((*res)["s_phone"]), util.ObjToString((*res)["s_m_phone"])).(string); phone != "" {
  689. isEntniche = public.Mysql.CountBySql(`SELECT count(1) from entniche_user a INNER JOIN entniche_info b on (a.phone=? and a.power=1 and a.ent_id=b.id and b.status>0)`, phone) > 0
  690. privatedata = public.Mysql.CountBySql(`select count(1) from privatedata where phone = ?`, phone) > 0
  691. }
  692. if !isEntniche && privatedata {
  693. isEntniche = true
  694. }
  695. return isVip, isMember, isEntniche
  696. }
  697. // pc 移动共用字段处理
  698. func FieldProcessing(obj map[string]interface{}, ssOpenid interface{}, industry, id, from_userid, userId, stype string, b bool) {
  699. obj["industry"] = industry
  700. if ssOpenid != nil {
  701. obj["ucbsId"] = encrypt.EncodeArticleId2ByCheck("ucbs#" + ssOpenid.(string) + "#" + id)
  702. }
  703. //判断是否公开联系人信息
  704. if util.Int64All(obj["buyerhint"]) == 2 {
  705. obj["buyerperson"] = ""
  706. obj["buyertel"] = ""
  707. }
  708. if !b {
  709. href, _ := obj["href"].(string)
  710. href = strings.Replace(href, "\n", "", -1)
  711. if href != "" && !strings.HasPrefix(href, "http") {
  712. href = "http://" + href
  713. }
  714. obj["url"] = href
  715. }
  716. //大会员中标企业跳转至画像
  717. if obj["entidlist"] != nil {
  718. if s_winner := util.ObjToString(obj["s_winner"]); s_winner != "" {
  719. entIdArr, winnerMap := []string{}, map[string]interface{}{}
  720. swinnerArr := strings.Split(s_winner, ",")
  721. eidList, _ := obj["entidlist"].([]interface{})
  722. //先查询entlist 如果长度和s_winner不一致 根据企业名称查询id
  723. if len(eidList) != len(swinnerArr) {
  724. for _, v := range swinnerArr {
  725. winnerMap[v] = ""
  726. //临时更改为企业名称查询企业id
  727. rData := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"bool":{"should":[{"term":{"company_name":"%s"}},{"term":{"hname":"%s"}}],"minimum_should_match":1}},"_source":["name","_id","capital","company_phone"],"size":1}`, v, v))
  728. if rData != nil && len(*rData) == 1 {
  729. if entId := util.ObjToString((*rData)[0]["_id"]); entId != "" {
  730. entIdArr = append(entIdArr, encrypt.EncodeArticleId2ByCheck(util.ObjToString((*rData)[0]["_id"])))
  731. winnerMap[v] = encrypt.EncodeArticleId2ByCheck(util.ObjToString((*rData)[0]["_id"]))
  732. }
  733. }
  734. }
  735. } else {
  736. for k, v := range eidList {
  737. vstr := util.ObjToString(v)
  738. if vstr == "-" {
  739. continue
  740. }
  741. winnerMap[swinnerArr[k]] = encrypt.EncodeArticleId2ByCheck(vstr)
  742. }
  743. }
  744. obj["entId"] = entIdArr
  745. obj["winnerMap"] = winnerMap
  746. }
  747. }
  748. //移动端需要处理--剑鱼币
  749. if b && from_userid != "" && se.Decode4Hex(from_userid) != "" && se.Decode4Hex(from_userid) != userId && util.ObjToString(obj["subtype"]) != "拟建" { //分享开打的
  750. article_id := encrypt.CommonDecodeArticle(stype, id)[0]
  751. key := fmt.Sprintf("integral_article_%s_%s_%s", article_id, from_userid, userId)
  752. if redis.Incr("other", key) == 1 {
  753. redis.SetExpire("other", key, 60*60*24)
  754. err := jy.Publish(public.Mgo_Log, config.Sysconfig["nsq"].(string), config.Sysconfig["nsq_topic"].(string), jy.Jyweb_article_open, se.Decode4Hex(from_userid), jy.Jywx_node1)
  755. if err != nil {
  756. log.Println("nsq队列写入失败-->", jy.Jyweb_article_open, se.Decode4Hex(from_userid))
  757. }
  758. }
  759. }
  760. }
  761. // disWord 为空时处理
  762. func disWordNil(disWord, userId string) string {
  763. var from_userid string
  764. redisDis := redis.GetStr("other", "DIS_"+disWord[1:])
  765. if redisDis != "" {
  766. suffix := disWord[len(disWord)-3:]
  767. //公告三级页处理
  768. if suffix == suffix_msgt {
  769. effectiveTimeStr := strings.Split(redisDis, "##")[3]
  770. effectiveTime, _ := strconv.ParseInt(effectiveTimeStr, 10, 64)
  771. //是否计算佣金
  772. if time.Now().Unix() <= effectiveTime {
  773. belongUserId := strings.Split(redisDis, "##")[1]
  774. //if (belongUserId != userId) {
  775. public.Mysql.ExecTx("口号使用", func(tx *sql.Tx) bool {
  776. //口号是否使用过
  777. wordInfo := public.Mysql.Find("dis_word", map[string]interface{}{"userId": userId, "password": disWord}, "id", "", 0, 0)
  778. if len((*wordInfo)) == 0 {
  779. //新增口号使用
  780. start_time := time.Now().Format(DateFullLayout)
  781. termValidityInt, _ := strconv.Atoi(fmt.Sprint(config.Sysconfig["termValidity"]))
  782. stop_time := TimeProcessing(time.Now().Format(DateFullLayout), termValidityInt).Format(DateFullLayout)
  783. insert := map[string]interface{}{
  784. "password": disWord,
  785. "userId": userId,
  786. "belong_userid": belongUserId,
  787. "start_time": start_time,
  788. "stop_time": stop_time,
  789. }
  790. insert_1 := public.Mysql.InsertByTx(tx, "dis_word", insert) //口号使用表
  791. log.Println("插入口号使用表", insert_1)
  792. from_userid = se.Encode2Hex(belongUserId)
  793. }
  794. return true
  795. })
  796. }
  797. //}
  798. }
  799. }
  800. return from_userid
  801. }
  802. // 检查用户是否关注
  803. func CheckUserIsSubscribe(openid string) bool {
  804. user, ok := mongodb.FindOneByField("user", map[string]interface{}{
  805. "i_appid": 2,
  806. "s_m_openid": openid,
  807. "s_unionid": map[string]interface{}{"$ne": openid},
  808. }, `{"i_ispush":1}`)
  809. if ok && user != nil {
  810. if (*user)["_id"] == nil || util.IntAllDef((*user)["i_ispush"], 1) == 0 {
  811. return false
  812. } else {
  813. return true
  814. }
  815. }
  816. return false
  817. }
  818. func (s *Short) Qr(t, id string) error {
  819. w := s.ResponseWriter
  820. w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  821. w.Header().Set("Pragma", "no-cache")
  822. w.Header().Set("Expires", "0")
  823. w.Header().Set("Content-Type", "image/png")
  824. kds := s.GetString("kds")
  825. industry := s.GetString("industry")
  826. param := "?scan_source=pc"
  827. if t == "force" {
  828. param += "&ispcforceshare=1"
  829. }
  830. if kds != "" {
  831. param += "&keywords=" + kds
  832. }
  833. if industry != "" {
  834. param += "&industry=" + industry
  835. }
  836. data := config.Sysconfig["webdomain"].(string) + "/article/content/" + id + ".html" + param
  837. r, _ := qr.Encode(data, qr.M)
  838. pngdat := r.PNG()
  839. _, err := w.Write(pngdat)
  840. return err
  841. }
  842. func (s *Short) Replication() {
  843. userId, OK := s.GetSession("userId").(string)
  844. if OK && userId != "" {
  845. mongodb.Save("copyaction", map[string]interface{}{
  846. "userid": userId,
  847. "createtime": time.Now().Unix(),
  848. "url": s.Request.Referer(),
  849. "client": s.Header("User-Agent"),
  850. })
  851. }
  852. }
  853. func isbid(typ interface{}) bool {
  854. if typ != nil {
  855. subtype := util.ObjToString(typ)
  856. if subtype == "中标" || subtype == "合同" || subtype == "成交" {
  857. return true
  858. }
  859. }
  860. return false
  861. }
  862. // 中标企业库
  863. func getwinnertel(company interface{}) string {
  864. if company != nil {
  865. data, _ := public.Mgo_Ent.FindOne("winner_enterprise", map[string]interface{}{
  866. "company_name": util.ObjToString(company),
  867. })
  868. if (*data)["company_phone"] != nil {
  869. return util.ObjToString((*data)["company_phone"])
  870. }
  871. }
  872. return ""
  873. }
  874. func GetUserId(openid string) string {
  875. data, ok := public.MQFW.FindOne("user", map[string]interface{}{"s_m_openid": openid})
  876. if data != nil && len(*data) > 0 && ok {
  877. userid := mg.BsonIdToSId((*data)["_id"])
  878. return userid
  879. }
  880. return ""
  881. }
  882. func RemoveDuplicatesAndEmpty(a []string) (ret []string) {
  883. a_len := len(a)
  884. for i := 0; i < a_len; i++ {
  885. if (i > 0 && a[i-1] == a[i]) || len(a[i]) == 0 {
  886. continue
  887. }
  888. ret = append(ret, a[i])
  889. }
  890. return
  891. }
  892. // 该节点是否留资
  893. func hasRetainedCapital(uid, source string) bool {
  894. if count, err := mongodb.CountByErr("saleLeads", map[string]interface{}{"userid": uid, "source": source}); err != nil || count > 0 {
  895. return true
  896. }
  897. return false
  898. }
  899. func isInStringArr(arr []string, key string) bool {
  900. for _, v := range arr {
  901. if v == key {
  902. return true
  903. }
  904. }
  905. return false
  906. }
  907. func ReplaceStringByRegex(str, rule, replace string) (string, error) {
  908. reg, err := regexp.Compile(rule)
  909. if reg == nil || err != nil {
  910. return "", errors.New("正则MustCompile错误:" + err.Error())
  911. }
  912. return reg.ReplaceAllString(str, replace), nil
  913. }
  914. // 未登录用户进行数据过滤 name 配置文件
  915. func Filter(obj map[string]interface{}) map[string]interface{} {
  916. detail := fmt.Sprint(obj["detail"])
  917. mosaicText := fmt.Sprintf(`<span style="color:#2ABED1;">%s</span>`, util.ObjToString(config.Sysconfig["detailMosaic"]))
  918. detailText := fmt.Sprintf(`<span class="noLoginMosaic" style="color: #2ABED1;">%s</span>`, util.ObjToString(config.Sysconfig["detailMosaic"]))
  919. //for k, _ := range obj {
  920. // if ok, _ := detailNeedMosaic[k].(bool); ok {
  921. // if util.ObjToString(obj[k]) != "" {
  922. // detail = strings.ReplaceAll(detail, util.ObjToString(obj[k]), detailText)
  923. // }
  924. // //中标企业信息
  925. // if k == "winnerMap" && obj[k] != nil {
  926. // winnerNewMap := map[string]interface{}{}
  927. // winnerMap := util.ObjToMap(obj[k])
  928. // for _, wv := range *winnerMap {
  929. // winnerNewMap[mosaicText] = wv
  930. // }
  931. // obj[k] = winnerNewMap
  932. // } else {
  933. // obj[k] = mosaicText
  934. // }
  935. // }
  936. //}
  937. //
  938. for dk, dv := range detailNeedMosaic {
  939. if !dv.(bool) {
  940. continue
  941. }
  942. //if util.ObjToString(obj[dk]) != "" {
  943. // detail = strings.ReplaceAll(detail, util.ObjToString(obj[dk]), detailText)
  944. //}
  945. if util.InterfaceToStr(obj[dk]) != "" {
  946. value, b := obj[dk].(float64)
  947. if b {
  948. replaceStr := fmt.Sprintf("%v", int64(value))
  949. detail = strings.ReplaceAll(detail, replaceStr, detailText)
  950. } else {
  951. detail = strings.ReplaceAll(detail, util.InterfaceToStr(obj[dk]), detailText)
  952. }
  953. }
  954. //中标企业信息
  955. if dk == "winnerMap" {
  956. winnerNewMap := map[string]interface{}{}
  957. if obj[dk] != nil {
  958. winnerMap := util.ObjToMap(obj[dk])
  959. for _, wv := range *winnerMap {
  960. winnerNewMap[mosaicText] = wv
  961. }
  962. }
  963. obj[dk] = winnerNewMap
  964. } else {
  965. obj[dk] = mosaicText
  966. }
  967. }
  968. obj["detail"] = detail
  969. return obj
  970. }
  971. // 未登录用户进行数据过滤 name 配置文件
  972. func SearchFilter(obj map[string]interface{}) map[string]interface{} {
  973. //detail := fmt.Sprint(obj["detail"])
  974. //mosaicText := fmt.Sprintf(`<span style="cursor:pointer;">%s</span>`, util.ObjToString(config.Sysconfig["detailMosaic"]))
  975. //for k, _ := range obj {
  976. // needMosaic, _ := config.Sysconfig["detailNeedMosaic"].(map[string]interface{})
  977. // if ok, _ := needMosaic[k].(bool); ok {
  978. // //if util.ObjToString(obj[k]) != "" {
  979. // // detail = strings.ReplaceAll(detail, util.ObjToString(obj[k]), mosaicText)
  980. // // //敏感词过滤
  981. // //}
  982. // if k == "winnerMap" {
  983. // winnerMap, _ := obj[k].(map[string]interface{})
  984. // mosaicMap := map[string]interface{}{}
  985. // for i := 0; i < len(winnerMap); i++ {
  986. // mosaicMap[mosaicText] = mosaicText
  987. // }
  988. // obj["winnerMap"] = mosaicMap
  989. // } else {
  990. // obj[k] = mosaicText
  991. // }
  992. //
  993. // }
  994. //}
  995. //数字打码
  996. //detail = RegDetail(detail)
  997. //detail = fsw.Repl(detail)
  998. //obj["detail"] = detail
  999. if detailNeedMosaic == nil {
  1000. detailNeedMosaic, _ = config.Sysconfig["detailNeedMosaic"].(map[string]interface{})
  1001. }
  1002. for dk, dv := range detailNeedMosaic {
  1003. if !dv.(bool) {
  1004. continue
  1005. }
  1006. //中标企业信息
  1007. if dk == "winnerMap" {
  1008. winnerNewMap := map[string]interface{}{}
  1009. if obj[dk] != nil {
  1010. winnerMap := util.ObjToMap(obj[dk])
  1011. for _, wv := range *winnerMap {
  1012. winnerNewMap[util.ObjToString(config.Sysconfig["detailMosaic"])] = wv
  1013. }
  1014. }
  1015. obj[dk] = winnerNewMap
  1016. } else {
  1017. obj[dk] = util.ObjToString(config.Sysconfig["detailMosaic"])
  1018. }
  1019. }
  1020. return obj
  1021. }
  1022. func (s *Short) NologinArticle(stype, id string) error {
  1023. userId := util.ObjToString(s.GetSession("userId"))
  1024. sids := encrypt.CommonDecodeArticle(stype, id)
  1025. if len(sids) == 0 || (len(sids) > 0 && sids[0] == "") {
  1026. s.Redirect("/notin/page", 302)
  1027. return nil
  1028. }
  1029. if userId != "" { //已登录用户直接跳转至正常三级页
  1030. return s.LoginCommon(userId, stype, id)
  1031. }
  1032. if detailNeedMosaic == nil {
  1033. detailNeedMosaic, _ = config.Sysconfig["detailNeedMosaic"].(map[string]interface{})
  1034. }
  1035. return s.NologinCommon(userId, stype, id, sids[0])
  1036. }
  1037. func (s *Short) NologinCommon(userId, stype, id, sid string) error {
  1038. tg := &Tags{}
  1039. catchKey := fmt.Sprintf("jypcdetail_nologin_%s_%s", stype, sid)
  1040. if res := redis.Get("newother", catchKey); res == nil || res == "" {
  1041. industry := s.GetString("industry")
  1042. var shareid = s.GetString("id")
  1043. if len(shareid) == 0 {
  1044. shareid = "10"
  1045. }
  1046. s.T["logid"] = config.Seoconfig["jysskzy"].(string)
  1047. s.T["shareid"] = se.EncodeString(shareid)
  1048. //s.T["keywords"] = s.GetString("kds")
  1049. s.DisableHttpCache()
  1050. po, bo, wo, obj := pcVRT(sid, industry, stype, false)
  1051. if obj != nil && len(obj) > 0 {
  1052. if len(po) > 0 {
  1053. s.T["projectOther"] = po
  1054. }
  1055. if len(bo) > 0 {
  1056. s.T["buyerOther"] = bo
  1057. }
  1058. if len(wo) > 0 {
  1059. s.T["winnerOther"] = wo
  1060. }
  1061. FieldProcessing(obj, "", industry, id, "", userId, stype, false)
  1062. obj["urlpath"] = s.Uri()
  1063. obj["industry"] = industry
  1064. if userId == "" {
  1065. obj["winnerTitle"] = obj["winner"]
  1066. obj["buyerTitle"] = obj["buyer"]
  1067. obj["projectnameTitle"] = obj["projectname"]
  1068. obj["projectcodeTitle"] = obj["projectcode"]
  1069. log.Println(time.Now().UnixNano())
  1070. obj = Filter(obj)
  1071. //obj["description"] = fmt.Sprintf("%s,%s。", obj["title"], baseInfo(obj))
  1072. }
  1073. obj["agency"] = ""
  1074. if obj["publishtime"] != nil {
  1075. obj["publishtimeShorDate"] = time.Unix(util.Int64All(obj["publishtime"]), 0).Format(date.Date_Short_Layout)
  1076. }
  1077. obj["keywords"] = KeyWordHandle(obj)
  1078. obj["description"] = DescriptionHandle("nologin", obj)
  1079. s.T["obj"] = obj
  1080. s.T["url"] = s.Uri()
  1081. s.T["newBidInfoList"] = tg.GetNewBidInfo()
  1082. s.T["industryInfoList"] = tg.GetConsult()
  1083. s.T["hotLabelList"] = tg.GetHotLabel(30)
  1084. content, _ := s.Render4Cache("/pc/tags/detail.html", &s.T)
  1085. redis.Put("newother", catchKey, string(content), 60*2)
  1086. return s.SetBody(content)
  1087. }
  1088. } else {
  1089. return s.SetBody([]byte(res.(string)))
  1090. }
  1091. return nil
  1092. }
  1093. /*
  1094. TDK description
  1095. */
  1096. func baseInfo(obj map[string]interface{}) string {
  1097. info := ""
  1098. info += "省份:"
  1099. //{{if eq .T.obj.area "A"}}全国{{else}}{{.T.obj.area}}{{end}}
  1100. if area := util.ObjToString(obj["area"]); area == "A" {
  1101. info += "全国"
  1102. } else {
  1103. info += area
  1104. }
  1105. info += ",城市:" + util.ObjToString(obj["city"])
  1106. info += ",招标代理机构:" + util.ObjToString(obj["agency"])
  1107. info += ",项目名称:" + util.ObjToString(obj["projectname"])
  1108. info += ",采购单位:" + util.ObjToString(obj["buyer"])
  1109. info += ",采购联系人:" + util.ObjToString(obj["buyerperson"])
  1110. info += ",采购电话:" + util.ObjToString(obj["buyertel"])
  1111. if obj["package"] == nil {
  1112. info += ",项目预算(元):" + util.ObjToString(obj["budget"])
  1113. }
  1114. if util.ObjToString(obj["subtype"]) == "单一" && util.ObjToString(obj["package"]) == "" {
  1115. info += ",拟定单一来源采购供应商:" + util.ObjToString(obj["winner"])
  1116. }
  1117. subtype := util.ObjToString(obj["subtype"])
  1118. if subtype == "中标" || subtype == "成交" || subtype == "合同" {
  1119. if obj["winnerMap"] != nil {
  1120. info += ",中标单位:"
  1121. i := 0
  1122. for k, _ := range *util.ObjToMap(obj["winnerMap"]) {
  1123. i++
  1124. info += k
  1125. if i != len(*util.ObjToMap(obj["winnerMap"])) {
  1126. info += "、"
  1127. }
  1128. }
  1129. }
  1130. if obj["bidamount"] != nil {
  1131. info += ",中标金额(元):" + util.ObjToString(obj["bidamount"])
  1132. }
  1133. if obj["bidamount"] != nil {
  1134. info += ",联系方式:" + util.ObjToString(obj["bidamount"])
  1135. }
  1136. }
  1137. return info
  1138. }
  1139. // 分段匹配数字打码
  1140. func RegDetail(html string) string {
  1141. mosaicText := util.ObjToString(config.Sysconfig["detailMosaicTxt"])
  1142. reg := regexp.MustCompile("<[^<>]{1,1000}>") //分段正则
  1143. s := reg.FindAllStringIndex(html, -1) //全文匹配分段
  1144. if len(s) > 0 { //走分段替换
  1145. arr := []string{}
  1146. index := 0
  1147. for _, v := range s {
  1148. if len(v) == 2 {
  1149. // log.Println(html[index:v[0]])
  1150. txt, _ := ReplaceStringByRegex(html[index:v[0]], "[0-9]+", mosaicText)
  1151. arr = append(arr, txt) //替换
  1152. arr = append(arr, html[v[0]:v[1]])
  1153. index = v[1]
  1154. }
  1155. }
  1156. return strings.Join(arr, "")
  1157. }
  1158. return ""
  1159. }
  1160. func KeyWordHandle(obj map[string]interface{}) string {
  1161. keywordArr := []string{}
  1162. owner := util.InterfaceToStr(obj["owner"])
  1163. buyer := util.InterfaceToStr(obj["buyer"])
  1164. if buyer == "" {
  1165. buyer = owner
  1166. }
  1167. if buyer != "" && buyer != config.Sysconfig["detailMosaicTxt"] {
  1168. keywordArr = append(keywordArr, buyer)
  1169. }
  1170. if util.InterfaceToStr(obj["s_winner"]) != "" && util.InterfaceToStr(obj["s_winner"]) != config.Sysconfig["detailMosaicTxt"] {
  1171. keywordArr = append(keywordArr, util.InterfaceToStr(obj["s_winner"]))
  1172. }
  1173. if obj["purchasinglist"] != nil && obj["purchasinglist"] != "" {
  1174. i := 0
  1175. for _, v := range gconv.SliceMap(obj["purchasinglist"]) {
  1176. if i == 5 {
  1177. break
  1178. }
  1179. if util.InterfaceToStr(v["itemname"]) != "" && util.InterfaceToStr(obj["s_winner"]) != config.Sysconfig["detailMosaicTxt"] {
  1180. keywordArr = append(keywordArr, util.InterfaceToStr(v["itemname"]))
  1181. i++
  1182. }
  1183. }
  1184. }
  1185. if util.InterfaceToStr(obj["subtype"]) != "" && util.InterfaceToStr(obj["subtype"]) != "其它" {
  1186. keywordArr = append(keywordArr, TypeCodeMap[util.InterfaceToStr(obj["subtype"])])
  1187. }
  1188. if util.InterfaceToStr(obj["area"]) != "" {
  1189. keywordArr = append(keywordArr, util.InterfaceToStr(obj["area"])+"招标")
  1190. }
  1191. if util.InterfaceToStr(obj["city"]) != "" {
  1192. keywordArr = append(keywordArr, util.InterfaceToStr(obj["city"])+"招标")
  1193. }
  1194. keywordArr = append(keywordArr, "剑鱼标讯")
  1195. keyword := strings.Join(keywordArr, ",")
  1196. return keyword
  1197. }
  1198. func DescriptionHandle(stype string, obj map[string]interface{}) string {
  1199. description := ""
  1200. publishtime := util.Int64All(obj["l_publishtime"])
  1201. if publishtime == 0 {
  1202. publishtime = util.Int64All(obj["publishtime"])
  1203. }
  1204. pushTime := time.Unix(publishtime, 0)
  1205. title := util.InterfaceToStr(obj["title"])
  1206. owner := util.InterfaceToStr(obj["owner"])
  1207. buyer := util.InterfaceToStr(obj["buyer"])
  1208. if buyer == "" {
  1209. buyer = owner
  1210. }
  1211. s_winner := util.InterfaceToStr(obj["s_winner"])
  1212. area := util.InterfaceToStr(obj["area"])
  1213. city := util.InterfaceToStr(obj["city"])
  1214. if stype == "bdprivate" {
  1215. //bdprivate
  1216. //{项目标题},采购单位:{采购单位名称},成交供应商:{中标企业名称},公告日期:{公告日期}。
  1217. descriptionArr := []string{}
  1218. if title != "" {
  1219. descriptionArr = append(descriptionArr, title)
  1220. }
  1221. if buyer != "" {
  1222. descriptionArr = append(descriptionArr, fmt.Sprintf("采购单位:%s", buyer))
  1223. }
  1224. if s_winner != "" {
  1225. descriptionArr = append(descriptionArr, fmt.Sprintf("成交供应商:%s", s_winner))
  1226. }
  1227. if publishtime != 0 {
  1228. descriptionArr = append(descriptionArr, fmt.Sprintf("公告日期:%s", pushTime.Format("2006年01月02日")))
  1229. }
  1230. descriptionArr = append(descriptionArr, "查看该项目信息详情请访问剑鱼标讯官网。")
  1231. description = strings.Join(descriptionArr, ",")
  1232. } else {
  1233. //descriptionStr = "%s,项目所属地区是%s%s,项目采购单位是%s,项目发布时间是%s"
  1234. descriptionArr := []string{}
  1235. if title != "" {
  1236. descriptionArr = append(descriptionArr, title)
  1237. }
  1238. if area != "" || city != "" {
  1239. descriptionArr = append(descriptionArr, fmt.Sprintf("项目所属地区是%s%s", area, city))
  1240. }
  1241. if buyer != "" {
  1242. descriptionArr = append(descriptionArr, fmt.Sprintf("项目采购单位是%s", buyer))
  1243. }
  1244. if publishtime != 0 {
  1245. descriptionArr = append(descriptionArr, fmt.Sprintf("项目发布时间是%s", pushTime.Format("2006年01月02日")))
  1246. }
  1247. descriptionArr = append(descriptionArr, "查看该项目信息详情请访问剑鱼标讯官网。")
  1248. description = strings.Join(descriptionArr, ",")
  1249. }
  1250. return description
  1251. }