shorturl.go 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  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 || (util.ObjToString(obj["subtype"]) == "拟建" || util.ObjToString(obj["subtype"]) == "采购意向") {
  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. if !canRead {
  417. //打码显示引导
  418. Filter(obj)
  419. s.T["isGuide"] = true
  420. }
  421. s.T["advertcode"] = s.GetString("advertcode")
  422. } else {
  423. obj = map[string]interface{}{
  424. "title": obj["title"],
  425. "_id": obj["_id"],
  426. "subtype": obj["subtype"],
  427. }
  428. }
  429. //纠错随机回复
  430. recoveryRight, _ := config.Sysconfig["recoveryRight"].([]interface{})
  431. recVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(recoveryRight))
  432. s.T["recVal"] = util.ObjToString(recoveryRight[recVal])
  433. s.T["advertImg"] = config.Sysconfig["advertImg"]
  434. s.T["advertName"] = config.Sysconfig["advertName"]
  435. s.T["advertUrl"] = config.Sysconfig["advertUrl"]
  436. s.T["canRead"] = canRead
  437. obj["industry"] = industry
  438. obj["keywords"] = KeyWordHandle(obj)
  439. obj["description"] = DescriptionHandle(stype, obj)
  440. s.T["obj"] = obj
  441. //获取打赏文案
  442. s.T["rewardText"], s.T["advertText"] = getRewardText()
  443. content, _ := s.Render4Cache("/weixin/wxinfocontent_rec.html", &s.T)
  444. return s.SetBody(content)
  445. }
  446. if surl != "" {
  447. return s.Redirect(surl)
  448. }
  449. } else {
  450. sids := encrypt.CommonDecodeArticle(stype, id)
  451. if len(sids) == 0 || (len(sids) > 0 && sids[0] == "") {
  452. s.Redirect("/notin/page", 302)
  453. return nil
  454. }
  455. sid := sids[0]
  456. //免费用户浏览三级页判断留资与浏览次数
  457. indust := s.GetString("industry")
  458. if userId != "" && stype == "indexcontent" { //已登录用户直接跳转至正常三级页
  459. return s.Redirect(fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", sid)))
  460. }
  461. industry := s.GetString("industry")
  462. var shareid = s.GetString("id")
  463. if len(shareid) == 0 {
  464. shareid = "10"
  465. }
  466. s.T["logid"] = config.Seoconfig["jysskzy"].(string)
  467. s.T["shareid"] = se.EncodeString(shareid)
  468. s.T["keywords"] = s.GetString("kds")
  469. s.DisableHttpCache()
  470. po, bo, wo, obj := pcVRT(sid, industry, stype, isVip || isMember || isEntniche)
  471. if obj != nil && len(obj) > 0 {
  472. var node bool
  473. if ((isVip && isOldVip) || isMember || isEntniche) || //老版本vip、大会员、商机管理
  474. ((isVip && !isOldVip) && (!(util.ObjToString(obj["subtype"]) == "拟建" || util.ObjToString(obj["subtype"]) == "采购意向"))) || //新超级订阅非采购意向”和“拟建项目”
  475. stype == "mailprivate" || stype == "indexcontent" || stype == "bdprivate" { //邮箱推送
  476. node = true
  477. } else {
  478. _, _, _, objc := pcVRT(sid, indust, stype, isVip || isMember || isEntniche)
  479. node = SeeDetailLimit(objc, userId, sid)
  480. }
  481. if obj["publishtime"] != nil {
  482. obj["publishtimeShorDate"] = time.Unix(util.Int64All(obj["publishtime"]), 0).Format(date.Date_Short_Layout)
  483. }
  484. s.T["canRead"] = node
  485. if stype == "advancedProject" {
  486. canRead := false
  487. //判断此用户是否有打开的权限
  488. newUserId := s.GetSession("base_user_id")
  489. pushData := public.BaseMysql.FindOne("leadproject_push", map[string]interface{}{"user_id": newUserId, "info_id": sid}, "id", "")
  490. //访问次数加1
  491. if pushData == nil {
  492. canRead = false
  493. } else {
  494. 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"])
  495. canRead = true
  496. }
  497. if canRead || node {
  498. _, _, _, obj = pcVRT(sid, indust, stype, true)
  499. canRead = true
  500. node = canRead
  501. }
  502. s.T["canRead"] = canRead
  503. }
  504. if node || (util.ObjToString(obj["subtype"]) == "拟建" || util.ObjToString(obj["subtype"]) == "采购意向") {
  505. if len(po) > 0 {
  506. s.T["projectOther"] = po
  507. }
  508. if len(bo) > 0 {
  509. s.T["buyerOther"] = bo
  510. }
  511. if len(wo) > 0 {
  512. s.T["winnerOther"] = wo
  513. }
  514. //判断时间 //如果是seo页面超过时间访问的进入首页
  515. comeinTime := time.Unix(util.Int64All(obj["comeintime"]), 0)
  516. if stype == "indexcontent" {
  517. 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)) {
  518. return s.Redirect("/")
  519. }
  520. }
  521. FieldProcessing(obj, ssOpenid, industry, id, from_userid, userId, stype, false)
  522. //免费用户正文手机号替换
  523. if obj["site"] == "剑鱼信息发布平台" && !isMember {
  524. //采购电话中标单位电话置空
  525. if util.InterfaceToStr(obj["buyertel"]) != "" {
  526. obj["buyertel"] = "freeView"
  527. }
  528. if util.InterfaceToStr(obj["winnertel"]) != "" {
  529. obj["winnertel"] = "freeView"
  530. }
  531. //正文电话 手机号 邮箱处理
  532. if detail, _ := obj["detail"].(string); detail != "" {
  533. //手机号
  534. re1 := regexp.MustCompile("1[345789]{1}\\d{9}")
  535. detail1 := re1.ReplaceAllString(detail, `<span class="freeView">点击查看</span>`)
  536. code := util.InterfaceToStr(obj["projectcode"])
  537. if code != "" {
  538. detail1 = strings.ReplaceAll(detail1, code, "*********")
  539. }
  540. //座机
  541. re2 := regexp.MustCompile("((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?")
  542. detail2 := re2.ReplaceAllString(detail1, `<span class="freeView">点击查看</span>`)
  543. re4 := regexp.MustCompile("((400)-)(\\d{3,4}-)(\\d{3,})")
  544. detail4 := re4.ReplaceAllString(detail2, `<span class="freeView">点击查看</span>`)
  545. //邮箱
  546. 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})(\\]?)")
  547. detail3 := re3.ReplaceAllString(detail4, `<span class="freeView">点击查看</span>`)
  548. obj["detail"] = strings.ReplaceAll(strings.ReplaceAll(detail3, `<span class="freeView">点击查看</span><span class="freeView">点击查看</span>`, `<span class="freeView">点击查看</span>`), "*********", code)
  549. }
  550. }
  551. if obj["projectname"] != nil {
  552. s.SetSession("projectname", obj["projectname"])
  553. }
  554. if obj["entidlist"] != nil { //大会员中标企业跳转至画像
  555. s_winner := util.ObjToString(obj["s_winner"])
  556. idObjs, _ := obj["entidlist"].([]interface{})
  557. winnerIdArr := []string{}
  558. for _, v := range strings.Split(s_winner, ",") {
  559. if v == "-" || !isInStringArr(util.ObjArrToStringArr(idObjs), v) {
  560. continue
  561. }
  562. winnerIdArr = append(winnerIdArr, encrypt.EncodeArticleId2ByCheck(v))
  563. obj["entIds"] = winnerIdArr
  564. }
  565. }
  566. if !node {
  567. //打码遮罩
  568. Filter(obj)
  569. s.T["isGuide"] = true
  570. }
  571. } else {
  572. obj = map[string]interface{}{
  573. "title": obj["title"],
  574. "_id": obj["_id"],
  575. "subtype": obj["subtype"],
  576. "stypeadd": obj["stypeadd"],
  577. }
  578. }
  579. obj["urlpath"] = s.Uri()
  580. obj["industry"] = industry
  581. if ssOpenid != nil {
  582. obj["ucbsId"] = encrypt.EncodeArticleId2ByCheck("ucbs#" + ssOpenid.(string) + "#" + id)
  583. }
  584. obj["keywords"] = KeyWordHandle(obj)
  585. obj["description"] = DescriptionHandle(stype, obj)
  586. s.T["obj"] = obj
  587. s.T["url"] = s.Uri()
  588. return s.Render("/pc/biddetail_rec.html", &s.T)
  589. }
  590. }
  591. return nil
  592. }
  593. func CNode(userId string) bool {
  594. if hasRetainedCapital(userId, "jyarticle_see3_plus") {
  595. return true
  596. }
  597. rM := map[string]interface{}{}
  598. rdata, ok := mongodb.Find("saleLeads", map[string]interface{}{
  599. "userid": userId,
  600. }, `{"createtime":-1}`, nil, false, 0, 10)
  601. if rdata != nil && len(*rdata) > 0 && ok {
  602. for _, v := range *rdata {
  603. for kk, vv := range v {
  604. if vv == nil {
  605. continue
  606. }
  607. if rM[kk] != nil {
  608. continue
  609. }
  610. rM[kk] = vv
  611. }
  612. }
  613. delete(rM, "_id")
  614. delete(rM, "userid")
  615. delete(rM, "createtime")
  616. delete(rM, "client")
  617. }
  618. 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 {
  619. s_phone := util.ObjToString((*userinfo)["s_phone"])
  620. phone := util.If(s_phone == "", util.ObjToString((*userinfo)["s_m_phone"]), s_phone)
  621. if rM["phone"] == nil || rM["phone"] == "" {
  622. rM["phone"] = phone
  623. }
  624. if rM["company"] == nil || rM["company"] == "" {
  625. rM["company"] = util.ObjToString((*userinfo)["s_company"])
  626. }
  627. }
  628. if rM["name"] != nil && rM["name"] != "" && rM["phone"] != nil && rM["phone"] != "" && rM["company"] != nil && rM["company"] != "" && rM["position"] != nil && rM["position"] != "" && rM["companyType"] != "" {
  629. if rM["position"] != "总裁" && rM["position"] != "总经理" && (rM["branch"] == nil || rM["branch"] == "") {
  630. return false
  631. }
  632. return true
  633. }
  634. return false
  635. }
  636. // 查看公告详情次数限制
  637. func SeeDetailLimit(obj map[string]interface{}, userId, sid string) bool {
  638. watchKey := fmt.Sprintf("article_count_%d_%s_%d_%s", time.Now().Year(), time.Now().Month(), time.Now().Day(), userId)
  639. subTypeStr, _ := obj["subtype"].(string)
  640. if strings.Contains(subTypeStr, "拟建") || strings.Contains(subTypeStr, "采购意向") {
  641. return false
  642. } else {
  643. //检验是否留资
  644. if CNode(userId) {
  645. return true
  646. }
  647. if seeRes := redis.Get("other", watchKey); seeRes != nil && seeRes != "" {
  648. if resVal, _ := seeRes.(string); resVal != "" {
  649. sidss := strings.Split(resVal, "_")
  650. canRead := config.Sysconfig["canReadNotice"]
  651. if len(sidss) < util.IntAll(canRead) {
  652. sidss = append(sidss, sid)
  653. arrs := RemoveDuplicatesAndEmpty(sidss)
  654. newVal := strings.Join(arrs, "_")
  655. redis.Put("other", watchKey, newVal, jy.GetExpire())
  656. return true
  657. } else {
  658. for _, v := range sidss {
  659. if sid == v {
  660. return true
  661. }
  662. }
  663. return false
  664. }
  665. }
  666. } else {
  667. redis.Put("other", watchKey, sid, jy.GetExpire())
  668. return true
  669. }
  670. }
  671. return false
  672. }
  673. func SwiDef(sid_openid []string) (string, string) {
  674. var shareopenid, sid string
  675. if len(sid_openid) > 1 {
  676. sid = sid_openid[0]
  677. shareopenid = sid_openid[1]
  678. } else {
  679. sid = sid_openid[0]
  680. }
  681. return shareopenid, sid
  682. }
  683. // user 权限获取
  684. func UserPermission(userId string, ssOpenid interface{}) (bool, bool, bool) {
  685. var (
  686. res *map[string]interface{}
  687. isVip, isMember, isEntniche, privatedata bool
  688. )
  689. if userId == "" && ssOpenid != nil {
  690. 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}`)
  691. userId = mg.BsonIdToSId((*res)["_id"])
  692. } else {
  693. //判断用户是否是vip
  694. res = jyutil.Compatible.Select(userId, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1}`)
  695. }
  696. isVip = util.IntAll((*res)["i_vip_status"]) == 1 || util.IntAll((*res)["i_vip_status"]) == 2
  697. isMember = util.IntAll((*res)["i_member_status"]) > 0
  698. if phone, _ := util.If(util.ObjToString((*res)["s_phone"]) != "", util.ObjToString((*res)["s_phone"]), util.ObjToString((*res)["s_m_phone"])).(string); phone != "" {
  699. 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
  700. privatedata = public.Mysql.CountBySql(`select count(1) from privatedata where phone = ?`, phone) > 0
  701. }
  702. if !isEntniche && privatedata {
  703. isEntniche = true
  704. }
  705. return isVip, isMember, isEntniche
  706. }
  707. // pc 移动共用字段处理
  708. func FieldProcessing(obj map[string]interface{}, ssOpenid interface{}, industry, id, from_userid, userId, stype string, b bool) {
  709. obj["industry"] = industry
  710. if ssOpenid != nil {
  711. obj["ucbsId"] = encrypt.EncodeArticleId2ByCheck("ucbs#" + ssOpenid.(string) + "#" + id)
  712. }
  713. //判断是否公开联系人信息
  714. if util.Int64All(obj["buyerhint"]) == 2 {
  715. obj["buyerperson"] = ""
  716. obj["buyertel"] = ""
  717. }
  718. if !b {
  719. href, _ := obj["href"].(string)
  720. href = strings.Replace(href, "\n", "", -1)
  721. if href != "" && !strings.HasPrefix(href, "http") {
  722. href = "http://" + href
  723. }
  724. obj["url"] = href
  725. }
  726. //大会员中标企业跳转至画像
  727. if obj["entidlist"] != nil {
  728. if s_winner := util.ObjToString(obj["s_winner"]); s_winner != "" {
  729. entIdArr, winnerMap := []string{}, map[string]interface{}{}
  730. swinnerArr := strings.Split(s_winner, ",")
  731. eidList, _ := obj["entidlist"].([]interface{})
  732. //先查询entlist 如果长度和s_winner不一致 根据企业名称查询id
  733. if len(eidList) != len(swinnerArr) {
  734. for _, v := range swinnerArr {
  735. winnerMap[v] = ""
  736. //临时更改为企业名称查询企业id
  737. 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))
  738. if rData != nil && len(*rData) == 1 {
  739. if entId := util.ObjToString((*rData)[0]["_id"]); entId != "" {
  740. entIdArr = append(entIdArr, encrypt.EncodeArticleId2ByCheck(util.ObjToString((*rData)[0]["_id"])))
  741. winnerMap[v] = encrypt.EncodeArticleId2ByCheck(util.ObjToString((*rData)[0]["_id"]))
  742. }
  743. }
  744. }
  745. } else {
  746. for k, v := range eidList {
  747. vstr := util.ObjToString(v)
  748. if vstr == "-" {
  749. continue
  750. }
  751. winnerMap[swinnerArr[k]] = encrypt.EncodeArticleId2ByCheck(vstr)
  752. }
  753. }
  754. obj["entId"] = entIdArr
  755. obj["winnerMap"] = winnerMap
  756. }
  757. }
  758. //移动端需要处理--剑鱼币
  759. if b && from_userid != "" && se.Decode4Hex(from_userid) != "" && se.Decode4Hex(from_userid) != userId && util.ObjToString(obj["subtype"]) != "拟建" { //分享开打的
  760. article_id := encrypt.CommonDecodeArticle(stype, id)[0]
  761. key := fmt.Sprintf("integral_article_%s_%s_%s", article_id, from_userid, userId)
  762. if redis.Incr("other", key) == 1 {
  763. redis.SetExpire("other", key, 60*60*24)
  764. 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)
  765. if err != nil {
  766. log.Println("nsq队列写入失败-->", jy.Jyweb_article_open, se.Decode4Hex(from_userid))
  767. }
  768. }
  769. }
  770. }
  771. // disWord 为空时处理
  772. func disWordNil(disWord, userId string) string {
  773. var from_userid string
  774. redisDis := redis.GetStr("other", "DIS_"+disWord[1:])
  775. if redisDis != "" {
  776. suffix := disWord[len(disWord)-3:]
  777. //公告三级页处理
  778. if suffix == suffix_msgt {
  779. effectiveTimeStr := strings.Split(redisDis, "##")[3]
  780. effectiveTime, _ := strconv.ParseInt(effectiveTimeStr, 10, 64)
  781. //是否计算佣金
  782. if time.Now().Unix() <= effectiveTime {
  783. belongUserId := strings.Split(redisDis, "##")[1]
  784. //if (belongUserId != userId) {
  785. public.Mysql.ExecTx("口号使用", func(tx *sql.Tx) bool {
  786. //口号是否使用过
  787. wordInfo := public.Mysql.Find("dis_word", map[string]interface{}{"userId": userId, "password": disWord}, "id", "", 0, 0)
  788. if len((*wordInfo)) == 0 {
  789. //新增口号使用
  790. start_time := time.Now().Format(DateFullLayout)
  791. termValidityInt, _ := strconv.Atoi(fmt.Sprint(config.Sysconfig["termValidity"]))
  792. stop_time := TimeProcessing(time.Now().Format(DateFullLayout), termValidityInt).Format(DateFullLayout)
  793. insert := map[string]interface{}{
  794. "password": disWord,
  795. "userId": userId,
  796. "belong_userid": belongUserId,
  797. "start_time": start_time,
  798. "stop_time": stop_time,
  799. }
  800. insert_1 := public.Mysql.InsertByTx(tx, "dis_word", insert) //口号使用表
  801. log.Println("插入口号使用表", insert_1)
  802. from_userid = se.Encode2Hex(belongUserId)
  803. }
  804. return true
  805. })
  806. }
  807. //}
  808. }
  809. }
  810. return from_userid
  811. }
  812. // 检查用户是否关注
  813. func CheckUserIsSubscribe(openid string) bool {
  814. user, ok := mongodb.FindOneByField("user", map[string]interface{}{
  815. "i_appid": 2,
  816. "s_m_openid": openid,
  817. "s_unionid": map[string]interface{}{"$ne": openid},
  818. }, `{"i_ispush":1}`)
  819. if ok && user != nil {
  820. if (*user)["_id"] == nil || util.IntAllDef((*user)["i_ispush"], 1) == 0 {
  821. return false
  822. } else {
  823. return true
  824. }
  825. }
  826. return false
  827. }
  828. func (s *Short) Qr(t, id string) error {
  829. w := s.ResponseWriter
  830. w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  831. w.Header().Set("Pragma", "no-cache")
  832. w.Header().Set("Expires", "0")
  833. w.Header().Set("Content-Type", "image/png")
  834. kds := s.GetString("kds")
  835. industry := s.GetString("industry")
  836. param := "?scan_source=pc"
  837. if t == "force" {
  838. param += "&ispcforceshare=1"
  839. }
  840. if kds != "" {
  841. param += "&keywords=" + kds
  842. }
  843. if industry != "" {
  844. param += "&industry=" + industry
  845. }
  846. data := config.Sysconfig["webdomain"].(string) + "/article/content/" + id + ".html" + param
  847. r, _ := qr.Encode(data, qr.M)
  848. pngdat := r.PNG()
  849. _, err := w.Write(pngdat)
  850. return err
  851. }
  852. func (s *Short) Replication() {
  853. userId, OK := s.GetSession("userId").(string)
  854. if OK && userId != "" {
  855. mongodb.Save("copyaction", map[string]interface{}{
  856. "userid": userId,
  857. "createtime": time.Now().Unix(),
  858. "url": s.Request.Referer(),
  859. "client": s.Header("User-Agent"),
  860. })
  861. }
  862. }
  863. func isbid(typ interface{}) bool {
  864. if typ != nil {
  865. subtype := util.ObjToString(typ)
  866. if subtype == "中标" || subtype == "合同" || subtype == "成交" {
  867. return true
  868. }
  869. }
  870. return false
  871. }
  872. // 中标企业库
  873. func getwinnertel(company interface{}) string {
  874. if company != nil {
  875. data, _ := public.Mgo_Ent.FindOne("winner_enterprise", map[string]interface{}{
  876. "company_name": util.ObjToString(company),
  877. })
  878. if (*data)["company_phone"] != nil {
  879. return util.ObjToString((*data)["company_phone"])
  880. }
  881. }
  882. return ""
  883. }
  884. func GetUserId(openid string) string {
  885. data, ok := public.MQFW.FindOne("user", map[string]interface{}{"s_m_openid": openid})
  886. if data != nil && len(*data) > 0 && ok {
  887. userid := mg.BsonIdToSId((*data)["_id"])
  888. return userid
  889. }
  890. return ""
  891. }
  892. func RemoveDuplicatesAndEmpty(a []string) (ret []string) {
  893. a_len := len(a)
  894. for i := 0; i < a_len; i++ {
  895. if (i > 0 && a[i-1] == a[i]) || len(a[i]) == 0 {
  896. continue
  897. }
  898. ret = append(ret, a[i])
  899. }
  900. return
  901. }
  902. // 该节点是否留资
  903. func hasRetainedCapital(uid, source string) bool {
  904. if count, err := mongodb.CountByErr("saleLeads", map[string]interface{}{"userid": uid, "source": source}); err != nil || count > 0 {
  905. return true
  906. }
  907. return false
  908. }
  909. func isInStringArr(arr []string, key string) bool {
  910. for _, v := range arr {
  911. if v == key {
  912. return true
  913. }
  914. }
  915. return false
  916. }
  917. func ReplaceStringByRegex(str, rule, replace string) (string, error) {
  918. reg, err := regexp.Compile(rule)
  919. if reg == nil || err != nil {
  920. return "", errors.New("正则MustCompile错误:" + err.Error())
  921. }
  922. return reg.ReplaceAllString(str, replace), nil
  923. }
  924. // 未登录用户进行数据过滤 name 配置文件
  925. func Filter(obj map[string]interface{}) map[string]interface{} {
  926. detail := fmt.Sprint(obj["detail"])
  927. mosaicText := fmt.Sprintf(`<span style="color:#2ABED1;">%s</span>`, util.ObjToString(config.Sysconfig["detailMosaic"]))
  928. detailText := fmt.Sprintf(`<span class="noLoginMosaic" style="color: #2ABED1;">%s</span>`, util.ObjToString(config.Sysconfig["detailMosaic"]))
  929. //for k, _ := range obj {
  930. // if ok, _ := detailNeedMosaic[k].(bool); ok {
  931. // if util.ObjToString(obj[k]) != "" {
  932. // detail = strings.ReplaceAll(detail, util.ObjToString(obj[k]), detailText)
  933. // }
  934. // //中标企业信息
  935. // if k == "winnerMap" && obj[k] != nil {
  936. // winnerNewMap := map[string]interface{}{}
  937. // winnerMap := util.ObjToMap(obj[k])
  938. // for _, wv := range *winnerMap {
  939. // winnerNewMap[mosaicText] = wv
  940. // }
  941. // obj[k] = winnerNewMap
  942. // } else {
  943. // obj[k] = mosaicText
  944. // }
  945. // }
  946. //}
  947. //
  948. for dk, dv := range detailNeedMosaic {
  949. if !dv.(bool) {
  950. continue
  951. }
  952. //if util.ObjToString(obj[dk]) != "" {
  953. // detail = strings.ReplaceAll(detail, util.ObjToString(obj[dk]), detailText)
  954. //}
  955. if util.InterfaceToStr(obj[dk]) != "" {
  956. value, b := obj[dk].(float64)
  957. if b {
  958. replaceStr := fmt.Sprintf("%v", int64(value))
  959. detail = strings.ReplaceAll(detail, replaceStr, detailText)
  960. } else {
  961. detail = strings.ReplaceAll(detail, util.InterfaceToStr(obj[dk]), detailText)
  962. }
  963. }
  964. //中标企业信息
  965. if dk == "winnerMap" {
  966. winnerNewMap := map[string]interface{}{}
  967. if obj[dk] != nil {
  968. winnerMap := util.ObjToMap(obj[dk])
  969. for _, wv := range *winnerMap {
  970. winnerNewMap[mosaicText] = wv
  971. }
  972. }
  973. obj[dk] = winnerNewMap
  974. } else {
  975. obj[dk] = mosaicText
  976. }
  977. }
  978. obj["detail"] = detail
  979. return obj
  980. }
  981. // 未登录用户进行数据过滤 name 配置文件
  982. func SearchFilter(obj map[string]interface{}) map[string]interface{} {
  983. //detail := fmt.Sprint(obj["detail"])
  984. //mosaicText := fmt.Sprintf(`<span style="cursor:pointer;">%s</span>`, util.ObjToString(config.Sysconfig["detailMosaic"]))
  985. //for k, _ := range obj {
  986. // needMosaic, _ := config.Sysconfig["detailNeedMosaic"].(map[string]interface{})
  987. // if ok, _ := needMosaic[k].(bool); ok {
  988. // //if util.ObjToString(obj[k]) != "" {
  989. // // detail = strings.ReplaceAll(detail, util.ObjToString(obj[k]), mosaicText)
  990. // // //敏感词过滤
  991. // //}
  992. // if k == "winnerMap" {
  993. // winnerMap, _ := obj[k].(map[string]interface{})
  994. // mosaicMap := map[string]interface{}{}
  995. // for i := 0; i < len(winnerMap); i++ {
  996. // mosaicMap[mosaicText] = mosaicText
  997. // }
  998. // obj["winnerMap"] = mosaicMap
  999. // } else {
  1000. // obj[k] = mosaicText
  1001. // }
  1002. //
  1003. // }
  1004. //}
  1005. //数字打码
  1006. //detail = RegDetail(detail)
  1007. //detail = fsw.Repl(detail)
  1008. //obj["detail"] = detail
  1009. if detailNeedMosaic == nil {
  1010. detailNeedMosaic, _ = config.Sysconfig["detailNeedMosaic"].(map[string]interface{})
  1011. }
  1012. for dk, dv := range detailNeedMosaic {
  1013. if !dv.(bool) {
  1014. continue
  1015. }
  1016. //中标企业信息
  1017. if dk == "winnerMap" {
  1018. winnerNewMap := map[string]interface{}{}
  1019. if obj[dk] != nil {
  1020. winnerMap := util.ObjToMap(obj[dk])
  1021. for _, wv := range *winnerMap {
  1022. winnerNewMap[util.ObjToString(config.Sysconfig["detailMosaic"])] = wv
  1023. }
  1024. }
  1025. obj[dk] = winnerNewMap
  1026. } else {
  1027. obj[dk] = util.ObjToString(config.Sysconfig["detailMosaic"])
  1028. }
  1029. }
  1030. return obj
  1031. }
  1032. func (s *Short) NologinArticle(stype, id string) error {
  1033. userId := util.ObjToString(s.GetSession("userId"))
  1034. sids := encrypt.CommonDecodeArticle(stype, id)
  1035. if len(sids) == 0 || (len(sids) > 0 && sids[0] == "") {
  1036. s.Redirect("/notin/page", 302)
  1037. return nil
  1038. }
  1039. if userId != "" { //已登录用户直接跳转至正常三级页
  1040. return s.LoginCommon(userId, stype, id)
  1041. }
  1042. if detailNeedMosaic == nil {
  1043. detailNeedMosaic, _ = config.Sysconfig["detailNeedMosaic"].(map[string]interface{})
  1044. }
  1045. return s.NologinCommon(userId, stype, id, sids[0])
  1046. }
  1047. func (s *Short) NologinCommon(userId, stype, id, sid string) error {
  1048. tg := &Tags{}
  1049. catchKey := fmt.Sprintf("jypcdetail_nologin_%s_%s", stype, sid)
  1050. if res := redis.Get("newother", catchKey); res == nil || res == "" {
  1051. industry := s.GetString("industry")
  1052. var shareid = s.GetString("id")
  1053. if len(shareid) == 0 {
  1054. shareid = "10"
  1055. }
  1056. s.T["logid"] = config.Seoconfig["jysskzy"].(string)
  1057. s.T["shareid"] = se.EncodeString(shareid)
  1058. //s.T["keywords"] = s.GetString("kds")
  1059. s.DisableHttpCache()
  1060. po, bo, wo, obj := pcVRT(sid, industry, stype, false)
  1061. if obj != nil && len(obj) > 0 {
  1062. if len(po) > 0 {
  1063. s.T["projectOther"] = po
  1064. }
  1065. if len(bo) > 0 {
  1066. s.T["buyerOther"] = bo
  1067. }
  1068. if len(wo) > 0 {
  1069. s.T["winnerOther"] = wo
  1070. }
  1071. FieldProcessing(obj, "", industry, id, "", userId, stype, false)
  1072. obj["urlpath"] = s.Uri()
  1073. obj["industry"] = industry
  1074. if userId == "" {
  1075. obj["winnerTitle"] = obj["winner"]
  1076. obj["buyerTitle"] = obj["buyer"]
  1077. obj["projectnameTitle"] = obj["projectname"]
  1078. obj["projectcodeTitle"] = obj["projectcode"]
  1079. log.Println(time.Now().UnixNano())
  1080. obj = Filter(obj)
  1081. //obj["description"] = fmt.Sprintf("%s,%s。", obj["title"], baseInfo(obj))
  1082. }
  1083. obj["agency"] = ""
  1084. if obj["publishtime"] != nil {
  1085. obj["publishtimeShorDate"] = time.Unix(util.Int64All(obj["publishtime"]), 0).Format(date.Date_Short_Layout)
  1086. }
  1087. obj["keywords"] = KeyWordHandle(obj)
  1088. obj["description"] = DescriptionHandle("nologin", obj)
  1089. s.T["obj"] = obj
  1090. s.T["url"] = s.Uri()
  1091. s.T["newBidInfoList"] = tg.GetNewBidInfo()
  1092. s.T["industryInfoList"] = tg.GetConsult()
  1093. s.T["hotLabelList"] = tg.GetHotLabel(30)
  1094. content, _ := s.Render4Cache("/pc/tags/detail.html", &s.T)
  1095. redis.Put("newother", catchKey, string(content), 60*2)
  1096. return s.SetBody(content)
  1097. }
  1098. } else {
  1099. return s.SetBody([]byte(res.(string)))
  1100. }
  1101. return nil
  1102. }
  1103. /*
  1104. TDK description
  1105. */
  1106. func baseInfo(obj map[string]interface{}) string {
  1107. info := ""
  1108. info += "省份:"
  1109. //{{if eq .T.obj.area "A"}}全国{{else}}{{.T.obj.area}}{{end}}
  1110. if area := util.ObjToString(obj["area"]); area == "A" {
  1111. info += "全国"
  1112. } else {
  1113. info += area
  1114. }
  1115. info += ",城市:" + util.ObjToString(obj["city"])
  1116. info += ",招标代理机构:" + util.ObjToString(obj["agency"])
  1117. info += ",项目名称:" + util.ObjToString(obj["projectname"])
  1118. info += ",采购单位:" + util.ObjToString(obj["buyer"])
  1119. info += ",采购联系人:" + util.ObjToString(obj["buyerperson"])
  1120. info += ",采购电话:" + util.ObjToString(obj["buyertel"])
  1121. if obj["package"] == nil {
  1122. info += ",项目预算(元):" + util.ObjToString(obj["budget"])
  1123. }
  1124. if util.ObjToString(obj["subtype"]) == "单一" && util.ObjToString(obj["package"]) == "" {
  1125. info += ",拟定单一来源采购供应商:" + util.ObjToString(obj["winner"])
  1126. }
  1127. subtype := util.ObjToString(obj["subtype"])
  1128. if subtype == "中标" || subtype == "成交" || subtype == "合同" {
  1129. if obj["winnerMap"] != nil {
  1130. info += ",中标单位:"
  1131. i := 0
  1132. for k, _ := range *util.ObjToMap(obj["winnerMap"]) {
  1133. i++
  1134. info += k
  1135. if i != len(*util.ObjToMap(obj["winnerMap"])) {
  1136. info += "、"
  1137. }
  1138. }
  1139. }
  1140. if obj["bidamount"] != nil {
  1141. info += ",中标金额(元):" + util.ObjToString(obj["bidamount"])
  1142. }
  1143. if obj["bidamount"] != nil {
  1144. info += ",联系方式:" + util.ObjToString(obj["bidamount"])
  1145. }
  1146. }
  1147. return info
  1148. }
  1149. // 分段匹配数字打码
  1150. func RegDetail(html string) string {
  1151. mosaicText := util.ObjToString(config.Sysconfig["detailMosaicTxt"])
  1152. reg := regexp.MustCompile("<[^<>]{1,1000}>") //分段正则
  1153. s := reg.FindAllStringIndex(html, -1) //全文匹配分段
  1154. if len(s) > 0 { //走分段替换
  1155. arr := []string{}
  1156. index := 0
  1157. for _, v := range s {
  1158. if len(v) == 2 {
  1159. // log.Println(html[index:v[0]])
  1160. txt, _ := ReplaceStringByRegex(html[index:v[0]], "[0-9]+", mosaicText)
  1161. arr = append(arr, txt) //替换
  1162. arr = append(arr, html[v[0]:v[1]])
  1163. index = v[1]
  1164. }
  1165. }
  1166. return strings.Join(arr, "")
  1167. }
  1168. return ""
  1169. }
  1170. func KeyWordHandle(obj map[string]interface{}) string {
  1171. keywordArr := []string{}
  1172. owner := util.InterfaceToStr(obj["owner"])
  1173. buyer := util.InterfaceToStr(obj["buyer"])
  1174. if buyer == "" {
  1175. buyer = owner
  1176. }
  1177. if buyer != "" && buyer != config.Sysconfig["detailMosaicTxt"] {
  1178. keywordArr = append(keywordArr, buyer)
  1179. }
  1180. if util.InterfaceToStr(obj["s_winner"]) != "" && util.InterfaceToStr(obj["s_winner"]) != config.Sysconfig["detailMosaicTxt"] {
  1181. keywordArr = append(keywordArr, util.InterfaceToStr(obj["s_winner"]))
  1182. }
  1183. if obj["purchasinglist"] != nil && obj["purchasinglist"] != "" {
  1184. i := 0
  1185. for _, v := range gconv.SliceMap(obj["purchasinglist"]) {
  1186. if i == 5 {
  1187. break
  1188. }
  1189. if util.InterfaceToStr(v["itemname"]) != "" && util.InterfaceToStr(obj["s_winner"]) != config.Sysconfig["detailMosaicTxt"] {
  1190. keywordArr = append(keywordArr, util.InterfaceToStr(v["itemname"]))
  1191. i++
  1192. }
  1193. }
  1194. }
  1195. if util.InterfaceToStr(obj["subtype"]) != "" && util.InterfaceToStr(obj["subtype"]) != "其它" {
  1196. keywordArr = append(keywordArr, TypeCodeMap[util.InterfaceToStr(obj["subtype"])])
  1197. }
  1198. if util.InterfaceToStr(obj["area"]) != "" {
  1199. keywordArr = append(keywordArr, util.InterfaceToStr(obj["area"])+"招标")
  1200. }
  1201. if util.InterfaceToStr(obj["city"]) != "" {
  1202. keywordArr = append(keywordArr, util.InterfaceToStr(obj["city"])+"招标")
  1203. }
  1204. keywordArr = append(keywordArr, "剑鱼标讯")
  1205. keyword := strings.Join(keywordArr, ",")
  1206. return keyword
  1207. }
  1208. func DescriptionHandle(stype string, obj map[string]interface{}) string {
  1209. description := ""
  1210. publishtime := util.Int64All(obj["l_publishtime"])
  1211. if publishtime == 0 {
  1212. publishtime = util.Int64All(obj["publishtime"])
  1213. }
  1214. pushTime := time.Unix(publishtime, 0)
  1215. title := util.InterfaceToStr(obj["title"])
  1216. owner := util.InterfaceToStr(obj["owner"])
  1217. buyer := util.InterfaceToStr(obj["buyer"])
  1218. if buyer == "" {
  1219. buyer = owner
  1220. }
  1221. s_winner := util.InterfaceToStr(obj["s_winner"])
  1222. area := util.InterfaceToStr(obj["area"])
  1223. city := util.InterfaceToStr(obj["city"])
  1224. if stype == "bdprivate" {
  1225. //bdprivate
  1226. //{项目标题},采购单位:{采购单位名称},成交供应商:{中标企业名称},公告日期:{公告日期}。
  1227. descriptionArr := []string{}
  1228. if title != "" {
  1229. descriptionArr = append(descriptionArr, title)
  1230. }
  1231. if buyer != "" {
  1232. descriptionArr = append(descriptionArr, fmt.Sprintf("采购单位:%s", buyer))
  1233. }
  1234. if s_winner != "" {
  1235. descriptionArr = append(descriptionArr, fmt.Sprintf("成交供应商:%s", s_winner))
  1236. }
  1237. if publishtime != 0 {
  1238. descriptionArr = append(descriptionArr, fmt.Sprintf("公告日期:%s", pushTime.Format("2006年01月02日")))
  1239. }
  1240. descriptionArr = append(descriptionArr, "查看该项目信息详情请访问剑鱼标讯官网。")
  1241. description = strings.Join(descriptionArr, ",")
  1242. } else {
  1243. //descriptionStr = "%s,项目所属地区是%s%s,项目采购单位是%s,项目发布时间是%s"
  1244. descriptionArr := []string{}
  1245. if title != "" {
  1246. descriptionArr = append(descriptionArr, title)
  1247. }
  1248. if area != "" || city != "" {
  1249. descriptionArr = append(descriptionArr, fmt.Sprintf("项目所属地区是%s%s", area, city))
  1250. }
  1251. if buyer != "" {
  1252. descriptionArr = append(descriptionArr, fmt.Sprintf("项目采购单位是%s", buyer))
  1253. }
  1254. if publishtime != 0 {
  1255. descriptionArr = append(descriptionArr, fmt.Sprintf("项目发布时间是%s", pushTime.Format("2006年01月02日")))
  1256. }
  1257. descriptionArr = append(descriptionArr, "查看该项目信息详情请访问剑鱼标讯官网。")
  1258. description = strings.Join(descriptionArr, ",")
  1259. }
  1260. return description
  1261. }