index.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. package front
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. util "app.yhyue.com/moapp/jybase/common"
  5. "app.yhyue.com/moapp/jybase/encrypt"
  6. "app.yhyue.com/moapp/jybase/go-xweb/xweb"
  7. "app.yhyue.com/moapp/jybase/redis"
  8. "app.yhyue.com/moapp/jypkg/public"
  9. "context"
  10. "encoding/json"
  11. "fmt"
  12. "github.com/gogf/gf/v2/frame/g"
  13. "github.com/gogf/gf/v2/os/gctx"
  14. "github.com/gogf/gf/v2/util/gconv"
  15. "jy/src/jfw/config"
  16. "jy/src/jfw/jyutil"
  17. "jy/src/jfw/site/jySchool"
  18. "log"
  19. "math/rand"
  20. "regexp"
  21. "strings"
  22. "time"
  23. )
  24. type NewIndex struct {
  25. *xweb.Action
  26. newIndex xweb.Mapper `xweb:"/"` //首页改版
  27. routerRelay xweb.Mapper `xweb:"/front/routerRelay/(.*)"` //企业服务中转
  28. appDownload xweb.Mapper `xweb:"/front/appDownload"` //新app下载页面
  29. }
  30. var (
  31. RedisTimeout = 2 * 3600
  32. routerRelayMap map[string]map[bool]string
  33. BiddingTypeUrl = map[int]string{
  34. 1: "/list/stype/ZBYG.html",
  35. 2: "/list/stype/ZBJG.html",
  36. 5: "/list/stype/CGYX.html",
  37. 6: "/list/stype/XMFB.html",
  38. 10: "/list/spxm/",
  39. 11: "/list/tjxm/",
  40. 13: "/list/rmxm/",
  41. 14: "/list/xxxm/",
  42. 15: "/list/gjxm/",
  43. 16: "/list/sjxm/",
  44. 8: "/list/stype/ZFCG.html",
  45. 20: "/list/nzjxm/",
  46. }
  47. )
  48. func init() {
  49. xweb.AddAction(&NewIndex{})
  50. routerRelayMap = map[string]map[bool]string{
  51. "yxgl": { //【营销管理】根据code判断是否有权限 bi_yx
  52. true: fmt.Sprintf("/page_workDesktop/work-bench/page?link=%s/succbi/crm_system/app/crm.app/sales_clues.spg", config.Sysconfig["webdomain"].(string)),
  53. false: "/swordfish/frontPage/digitalMarketing/free/index",
  54. },
  55. "yxt": { //【医械通】根据code判断是否有权限 lyh_yl_yldy
  56. true: "/page_workDesktop/work-bench/app/big/medical/Credentials",
  57. false: "http://clpages.cn/yxtsjgwyxy",
  58. },
  59. "khgl": { //【客户管理】根据code判断是否有权限 bi_yx
  60. true: fmt.Sprintf("/page_workDesktop/work-bench/page?link=%s/succbi/crm_system/app/crm.app/sales_clues.spg", config.Sysconfig["webdomain"].(string)),
  61. false: "/swordfish/frontPage/customanage/free/index",
  62. },
  63. "tbxmgl": { //【投标项目管理】根据code判断是否有权限 cb_zy_code
  64. true: "/page_workDesktop/work-bench/app/big/attend_bidding/mine",
  65. false: "/swordfish/frontPage/biddingProject/free/index",
  66. },
  67. "nzbg": { //【年终报告】根据code判断是否有权限
  68. true: fmt.Sprintf("/page_workDesktop/work-bench/page?link=%s/succbi/nzbg/app/nzbg.app/nzbg_entrance_pc.spg", config.Sysconfig["webdomain"].(string)),
  69. false: "http://clpages.cn/nzbg",
  70. },
  71. "xxfb": { //【信息发布】根据登录否判断
  72. true: fmt.Sprintf("/page_workDesktop/work-bench/page?link=%s/swordfish/page_web_pc/issued/info", config.Sysconfig["webdomain"].(string)),
  73. false: "/swordfish/frontPage/InformationDistribution/free/index",
  74. },
  75. "scfx": { //【市场分析报告】 根据登录否判断
  76. true: "/page_workDesktop/work-bench/app/big/desktop/report_analysis",
  77. false: "/big/page/sc",
  78. },
  79. "qdkz": { //【渠道扩展】 根据大会员权益7判断
  80. true: "/swordfish/page_big_pc/potential_cor_list/c",
  81. false: "/big/page/yw",
  82. },
  83. "tbjc": { //【投标决策分析】 根据大会员权益6判断
  84. true: "/page_workDesktop/work-bench/app/big/analysis_result",
  85. false: "/big/page/tb",
  86. },
  87. }
  88. }
  89. func (nIndex *NewIndex) RouterRelay(code string) {
  90. toUrl := func() string {
  91. sessVal := nIndex.Session().GetMultiple()
  92. accountId := common.Int64All(sessVal["accountId"])
  93. if accountId <= 0 { //未登录
  94. return routerRelayMap[code][false]
  95. }
  96. if code == "nzbg" || code == "xxfb" || code == "scfx" {
  97. return routerRelayMap[code][true]
  98. }
  99. entAccountId := common.Int64All(sessVal["entAccountId"])
  100. entId := common.Int64All(sessVal["entId"])
  101. entUserId := common.Int64All(sessVal["entUserId"])
  102. res := config.Middleground.ResourceCenter.Haspowers(accountId, entAccountId, entId, entUserId)
  103. powerPass := false
  104. switch code {
  105. case "yxgl", "khgl":
  106. for _, pCode := range res.Powers {
  107. if pCode == "bi_yx" {
  108. powerPass = true
  109. break
  110. }
  111. }
  112. case "yxt":
  113. for _, pCode := range res.Powers {
  114. if pCode == "lyh_yl_yldy" {
  115. powerPass = true
  116. break
  117. }
  118. }
  119. case "tbxmgl":
  120. for _, pCode := range res.Powers {
  121. if pCode == "cb_zy_code" {
  122. powerPass = true
  123. break
  124. }
  125. }
  126. case "tbjc", "qdkz": //大会员权益判断
  127. powerRes := config.Middleground.PowerCheckCenter.Check("10000", gconv.String(sessVal["mgoUserId"]), gconv.Int64(sessVal["base_user_id"]), gconv.Int64(sessVal["accountId"]), gconv.Int64(sessVal["entId"]), gconv.Int64(sessVal["positionType"]), gconv.Int64(sessVal["positionId"]))
  128. for _, pInt := range powerRes.Member.MemberPowerList {
  129. if code == "tbjc" && pInt == 6 {
  130. powerPass = true
  131. break
  132. }
  133. if code == "qdkz" && pInt == 7 {
  134. powerPass = true
  135. break
  136. }
  137. }
  138. }
  139. return routerRelayMap[code][powerPass]
  140. }()
  141. _ = nIndex.Redirect(toUrl)
  142. }
  143. // NewIndex 新版首页改版
  144. func (nIndex *NewIndex) NewIndex() error {
  145. sessVal := nIndex.Session().GetMultiple()
  146. userId := util.ObjToString(sessVal["userId"])
  147. nIndex.T["hasLogin"] = userId != ""
  148. nIndex.T["hotkey"] = hotKeyArrLoginEd
  149. nIndex.T["hotKeyArrUnLogin"] = hotKeyArrUnLogin
  150. if userId != "" {
  151. nickname, vipType := gconv.String(sessVal["userName"]), "注册用户"
  152. var endTime int64
  153. //来源于接口/user/getSimpleData
  154. phone, _ := sessVal["phone"].(string)
  155. nickname, _ = common.If(sessVal["s_nickname"] != nil, sessVal["s_nickname"], sessVal["app_name"]).(string)
  156. if nickname == "" {
  157. var PhoneReg = regexp.MustCompile(`^(100\d{8}|1[3-9]\d{9})$`)
  158. if PhoneReg.MatchString(phone) {
  159. nickname = string(phone[0:3]) + "****" + string(phone[(len(phone)-4):])
  160. }
  161. }
  162. powerRes := config.Middleground.PowerCheckCenter.Check("10000", gconv.String(sessVal["mgoUserId"]), gconv.Int64(sessVal["base_user_id"]), gconv.Int64(sessVal["accountId"]), gconv.Int64(sessVal["entId"]), gconv.Int64(sessVal["positionType"]), gconv.Int64(sessVal["positionId"]))
  163. if powerRes.Vip.Status > 0 && powerRes.Vip.GetEndTime() > endTime {
  164. vipType, endTime = "超级订阅", powerRes.Vip.GetEndTime()
  165. }
  166. if powerRes.Member.Status > 0 && powerRes.Member.GetEndTime() > endTime {
  167. vipType, endTime = "大会员", powerRes.Member.GetEndTime()
  168. }
  169. if powerRes.Entniche.Status > 0 && powerRes.Entniche.GetEndTime() > endTime {
  170. vipType, endTime = "商机管理", powerRes.Entniche.GetEndTime()
  171. }
  172. if powerRes.Free.PpStatus > 0 && powerRes.Free.PpEndTime > endTime {
  173. vipType, endTime = "省份订阅包", powerRes.Free.GetPpEndTime()
  174. }
  175. nIndex.T["vipType"] = vipType
  176. nIndex.T["nickname"] = nickname
  177. if endTime > 0 {
  178. nIndex.T["vipEntTime"] = time.Unix(endTime, 0).Format("2006-01-02")
  179. }
  180. }
  181. //顶部菜单
  182. nIndex.T["topMenu"] = g.Cfg("index").MustGet(context.Background(), "topMenu").Maps()
  183. //招标公告
  184. biddingList, _ := GetRecommendBidZone(5, 16)
  185. nIndex.T["newbids"] = map[string]interface{}{
  186. "biddingList": biddingList,
  187. "more": fmt.Sprintf("%s", "/list/stype/ZBGG.html"),
  188. }
  189. //推荐标讯专区
  190. rangeInfoType := []int{1, 2}
  191. //招标动态
  192. bidTrends := []map[string]interface{}{}
  193. for _, v := range rangeInfoType { //1招标预告 2 中标成交 3采购意向 4 拟建项目
  194. listData, types := GetRecommendBidZone(v, 10)
  195. bidTrends = append(bidTrends, map[string]interface{}{
  196. "listData": listData,
  197. "types": types,
  198. "url": fmt.Sprintf("%s", BiddingTypeUrl[v]),
  199. })
  200. }
  201. //采购意向
  202. procure, procureName := GetIndexProjectListRedis(5, 10)
  203. bidTrends = append(bidTrends, map[string]interface{}{
  204. "listData": procure,
  205. "types": procureName,
  206. "url": fmt.Sprintf("%s", BiddingTypeUrl[5]),
  207. })
  208. //项目分包
  209. projectPage, typesName := GetIndexProjectListRedis(6, 10)
  210. bidTrends = append(bidTrends, map[string]interface{}{
  211. "listData": projectPage,
  212. "types": typesName,
  213. "url": fmt.Sprintf("%s", BiddingTypeUrl[6]),
  214. })
  215. nIndex.T["bidTrends"] = bidTrends
  216. //项目专区
  217. projectZone := []map[string]interface{}{}
  218. //拟在建项目
  219. nzjProject := IndexNzjProject(5)
  220. projectZone = append(projectZone, map[string]interface{}{
  221. "listData": nzjProject,
  222. "types": "拟在建项目",
  223. "url": fmt.Sprintf("%s", BiddingTypeUrl[20]),
  224. })
  225. projectZoneType := []int{10, 11}
  226. for _, val := range projectZoneType {
  227. listData, types := GetIndexRecommendProjectList(val, 5)
  228. projectZone = append(projectZone, map[string]interface{}{
  229. "listData": listData,
  230. "types": types,
  231. "url": fmt.Sprintf("%s", BiddingTypeUrl[val]),
  232. })
  233. }
  234. //热门项目
  235. listData, types := GetIndexProjectListRedis(13, 10)
  236. projectZone = append(projectZone, map[string]interface{}{
  237. "listData": listData,
  238. "types": types,
  239. "url": fmt.Sprintf("%s", BiddingTypeUrl[13]),
  240. })
  241. nIndex.T["projectZone"] = projectZone
  242. //中标喜报
  243. nIndex.T["winnerGlad"] = WinnerGladTidings(10)
  244. //热门行业 ////重点招标
  245. nIndex.T["hotIndustry"] = GetHotIndustry()
  246. //热门中标企业
  247. nIndex.T["hotWinner"] = NewHotEnt(true, 10)
  248. //热门采购单位
  249. nIndex.T["hotBuyers"] = NewHotEnt(false, 5)
  250. //供应商
  251. nIndex.T["supplyEnt"] = GetBidInfoPublishEnt()
  252. //行业分析简报
  253. nIndex.T["industryReport"] = GetIndustryAnalysisReport()
  254. //招投标攻略
  255. nIndex.T["strategyList"] = GetStrategyList()
  256. //剑鱼课堂
  257. nIndex.T["jySchool"] = jyutil.Course(6, 3)
  258. // 政府招标
  259. nIndex.T["governmentBidding"] = GovernmentTender(15)
  260. //区县招标
  261. nIndex.T["districtsBidding"] = DistrictsTender(15)
  262. nIndex.T["importBidding"] = GetImportBidding()
  263. //nIndex.T["biddingTrend"] = HomeBiddingTrends()
  264. nIndex.T["hotBuyerData"] = PurchasingData()
  265. nIndex.T["simpleTemplateData"] = map[string]interface{}{"XwebVer": nIndex.T["XwebVer"]}
  266. //文库
  267. nIndex.T["docsClass"], nIndex.T["docsData"] = GetDocsData()
  268. return nIndex.Render("/pc/newIndex.html", &nIndex.T)
  269. }
  270. func GetDocsData() (docClass []string, indexDocs [][]map[string]interface{}) {
  271. cacheDocsInfoKey := "jy_index_docs_info"
  272. cacheDocsClassKey := "jy_index_docs_class"
  273. if bytes, err := redis.GetBytes(RedisNameNew, cacheDocsInfoKey); err == nil && bytes != nil {
  274. if err := json.Unmarshal(*bytes, &indexDocs); err != nil {
  275. log.Printf("[MANAGER-ERR]jy_index_docs_info GetData Error %v \n", err)
  276. return []string{}, nil
  277. }
  278. classNames := redis.GetStr(RedisNameNew, cacheDocsClassKey)
  279. if classNames == "" {
  280. return []string{}, nil
  281. }
  282. docClass = strings.Split(classNames, ",")
  283. return
  284. }
  285. //浏览量前十的一级分类
  286. var (
  287. ossUrl = common.InterfaceToStr(config.Sysconfig["ossUrl"]) // "https://jydocs-previewimg.oss-cn-beijing.aliyuncs.com/%s"
  288. docinUrl = common.InterfaceToStr(config.Sysconfig["docinUrl"]) //"https://img3.douding.cn/docin_%s_90x80.jpg"
  289. )
  290. //浏览量前十的一级分类
  291. docClassNames := config.Sysconfig["indexDocClass"].([]interface{})
  292. if docClassNames != nil && len(docClassNames) > 0 {
  293. indexDoc := []map[string]interface{}{}
  294. //docSql := `SELECT d.id,d.docName,d.docFileSuffix,d.docTags,d.previewImgId,d.productType,d.source FROM jydocs.doc d LEFT JOIN jydocs.doc_statistics ds ON d.id=ds.docId WHERE FIND_IN_SET(?,d.docTags) ORDER BY ds.viewTimes DESC LIMIT 10 `
  295. var docFormatFunc = func(docs *[]map[string]interface{}) {
  296. for dock, docv := range *docs {
  297. if dock > 7 {
  298. break
  299. }
  300. previewImg := fmt.Sprintf(ossUrl, common.InterfaceToStr(docv["previewImgId"]))
  301. if common.IntAll(docv["source"]) == 2 {
  302. previewImg = fmt.Sprintf(docinUrl, common.InterfaceToStr(docv["previewImgId"]))
  303. }
  304. fileSuffix := common.InterfaceToStr(docv["docFileSuffix"])
  305. //文件类型,1 doc 2 pdf 3 xls 4 ppt 5 txt 6 其他
  306. docFileType := common.IntAll(docv["docFileType"])
  307. switch docFileType {
  308. case 1:
  309. fileSuffix = "doc"
  310. case 2:
  311. fileSuffix = "pdf"
  312. case 3:
  313. fileSuffix = "xls"
  314. case 4:
  315. fileSuffix = "ppt"
  316. case 5:
  317. fileSuffix = "txt"
  318. default:
  319. fileSuffix = "其他"
  320. }
  321. //if strings.HasPrefix(fileSuffix, ".") {
  322. // fileSuffix = strings.ReplaceAll(fileSuffix, ".", "")
  323. //}
  324. indexDoc = append(indexDoc, map[string]interface{}{
  325. "id": common.InterfaceToStr(docv["id"]),
  326. "docName": common.InterfaceToStr(docv["docName"]),
  327. "docFileSuffix": fileSuffix,
  328. "previewImg": previewImg,
  329. "productType": common.IntAll(docv["productType"]),
  330. })
  331. }
  332. }
  333. for _, dv := range docClassNames {
  334. tmpClass := common.ObjToMap(dv)
  335. if tmpClass == nil {
  336. continue
  337. }
  338. name := common.InterfaceToStr((*tmpClass)["class"])
  339. search := common.InterfaceToStr((*tmpClass)["search"])
  340. code := common.InterfaceToStr((*tmpClass)["code"])
  341. //2.0 推荐表数据
  342. var docByTidb = func() {
  343. docSql := fmt.Sprintf(`SELECT d.id, d.docName, d.docFileType, d.docFileSuffix, d.previewImgId, d.productType, d.source FROM doc d LEFT JOIN doc_recommend dr ON d.id = dr.doc_id WHERE dr.region_state = 1 AND dr.doc_class_code = '%s' ORDER BY dr.create_date DESC;`, code)
  344. docs := public.BaseMysql.SelectBySql(docSql)
  345. if docs != nil && len(*docs) > 0 {
  346. docFormatFunc(docs)
  347. }
  348. }
  349. docByTidb()
  350. //1.0 查es
  351. var docByEs = func() {
  352. query := fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"docTags":"%s"}}]}},"size":10,"sort":[{"viewTimes":"desc"}]}`, search)
  353. docs := public.Doc.Get("jydoc", "jydoc", query)
  354. //docs := public.BaseMysql.SelectBySql(docSql, search)
  355. if docs != nil && len(*docs) > 0 {
  356. docFormatFunc(docs)
  357. }
  358. }
  359. if len(indexDoc) == 0 {
  360. docByEs()
  361. }
  362. if len(indexDoc) > 0 {
  363. docClass = append(docClass, name)
  364. indexDocs = append(indexDocs, indexDoc)
  365. //
  366. indexDoc = []map[string]interface{}{}
  367. }
  368. }
  369. }
  370. if len(indexDocs) > 0 {
  371. b, err := json.Marshal(indexDocs)
  372. if err == nil && len(b) > 0 {
  373. err = redis.PutBytes(RedisNameNew, cacheDocsInfoKey, &b, 12*60*60)
  374. if err != nil {
  375. log.Println(fmt.Sprintf("首页 文库数据 缓存 %s,保存异常:%s", cacheDocsInfoKey, err.Error()))
  376. }
  377. }
  378. if len(docClass) > 0 {
  379. if b := redis.Put(RedisNameNew, cacheDocsClassKey, strings.Join(docClass, ","), 12*60*60); !b {
  380. log.Println(fmt.Sprintf("首页 文库分类 缓存 %s,保存异常", cacheDocsClassKey))
  381. }
  382. }
  383. }
  384. return
  385. }
  386. func (nIndex *NewIndex) AppDownload() {
  387. nIndex.T["includedInfo"] = GetIncludedInfo()
  388. nIndex.Render("/frontRouter/pc/AppDownload/free/index.html", &nIndex.T)
  389. }
  390. // 推荐标讯专区
  391. func GetRecommendBidZone(typ int, pageSize int) (list []map[string]interface{}, typs string) {
  392. if typ == 0 {
  393. typ = 1
  394. }
  395. sql := ""
  396. switch typ {
  397. case 1:
  398. //招标预告
  399. typs = "招标预告"
  400. sql = fmt.Sprintf(" AND toptype = '%s' ", "预告")
  401. case 2:
  402. //招标中标成交
  403. typs = "中标成交"
  404. sql = fmt.Sprintf(" AND subtype = '%s' or subtype = '%s' ", "中标", "成交")
  405. /*case 3:
  406. //采购意向
  407. typs = "采购意向"
  408. sql = fmt.Sprintf(" AND toptype = '%s' ", "采购意向")*/
  409. case 4:
  410. //拟建
  411. typs = "拟建项目"
  412. sql = fmt.Sprintf(" AND toptype = '%s' ", "拟建")
  413. case 5:
  414. typs = "招标公告"
  415. sql = fmt.Sprintf(" AND toptype = '%s' ", "招标")
  416. }
  417. rediskey := fmt.Sprintf("pcIndexRecommendBidZone_%d", typ)
  418. if l, ok := redis.Get(RedisNameNew, rediskey).([]interface{}); ok && l != nil && len(l) > 0 {
  419. list = common.ObjArrToMapArr(l)
  420. return list, typs
  421. }
  422. queryRes, err := g.DB().Query(gctx.New(), fmt.Sprintf(`SELECT b.bid_id
  423. FROM new_areaClass b
  424. WHERE 1=1 %s
  425. ORDER BY b.publish_time DESC
  426. LIMIT 0,?`, sql), pageSize)
  427. if err != nil || queryRes.IsEmpty() {
  428. return nil, ""
  429. }
  430. finalArr := FillingBiddingBaseFields(gctx.New(), queryRes.List(), typs)
  431. if finalArr != nil && len(finalArr) > 0 {
  432. redis.Put(RedisNameNew, rediskey, finalArr, g.Cfg("index").MustGet(context.Background(), "indexBiddingCacheTime", 1800).Int())
  433. }
  434. return finalArr, typs
  435. }
  436. func FillingBiddingBaseFields(ctx context.Context, res []map[string]interface{}, typs string) []map[string]interface{} {
  437. bidIdStrings := make([]string, 0, len(res))
  438. for _, m := range res {
  439. if bidId := gconv.String(m["bid_id"]); bidId != "" {
  440. bidIdStrings = append(bidIdStrings, bidId)
  441. }
  442. }
  443. bidRes, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT * FROM new_bidList WHERE toptype !='拟建' AND bid_id IN ('%s')`, strings.Join(bidIdStrings, "','")))
  444. if bidRes.IsEmpty() {
  445. return nil
  446. }
  447. bidMap := map[string]map[string]interface{}{}
  448. titleReduction := map[string]bool{}
  449. for _, m := range bidRes.List() {
  450. if bidIdStr := gconv.String(m["bid_id"]); bidIdStr != "" {
  451. //重复标题加数字后缀
  452. if titleReduction[gconv.String(m["title"])] {
  453. continue
  454. }
  455. titleReduction[gconv.String(m["title"])] = true
  456. m["_id"] = encrypt.EncodeArticleId2ByCheck(common.ObjToString(m["bid_id"]))
  457. if typs == "招标公告" {
  458. m["publish_time"] = time.Unix(common.Int64All(m["publish_time"]), 0).Format("01-02")
  459. } else {
  460. m["publish_time"] = time.Unix(common.Int64All(m["publish_time"]), 0).Format("2006-01-02")
  461. }
  462. bidMap[bidIdStr] = m
  463. }
  464. }
  465. var finalArr []map[string]interface{}
  466. for i := 0; i < len(res); i++ {
  467. if tBid := gconv.String(res[i]["bid_id"]); tBid != "" && bidMap[tBid] != nil && len(bidMap[tBid]) > 0 {
  468. for k, v := range bidMap[tBid] {
  469. res[i][k] = v
  470. }
  471. finalArr = append(finalArr, res[i])
  472. }
  473. }
  474. return finalArr
  475. }
  476. // GetStrategyList 招投标攻略
  477. func GetStrategyList() (strategyList []map[string]interface{}) {
  478. /*if l, ok := redis.Get(RedisNameNew, "pcIndexStrategyList").([]interface{}); ok && l != nil && len(l) > 0 {
  479. strategyList = common.ObjArrToMapArr(l)
  480. } else {*/
  481. for _, item := range jySchool.GuidelineColumn().SeedData {
  482. if res := jySchool.Guideline(item.Code, 15); res != nil && len(*res) > 0 {
  483. strategyList = append(strategyList, map[string]interface{}{
  484. "name": item.Name,
  485. "code": item.Code,
  486. "list": res,
  487. })
  488. }
  489. }
  490. //}
  491. return strategyList
  492. }
  493. func GetIndexProjectList(typ, pageSize int, resArr []map[string]interface{}) (data []map[string]interface{}, types string) {
  494. if len(resArr) > 5 {
  495. return resArr[:5], types
  496. }
  497. res, err := g.DB().Query(gctx.New(), fmt.Sprintf(`SELECT bid_id,publish_time,bitmapToArray(sign) FROM new_bid_sign WHERE bitmapContains(sign, %d) ORDER BY publish_time DESC LIMIT %d, %d`, typ, pageSize-10, 10))
  498. if err != nil || res.IsEmpty() {
  499. return nil, types
  500. }
  501. finalArr := FillingBiddingBaseFields(gctx.New(), res.List(), types)
  502. if len(finalArr) > 5 {
  503. finalArr = finalArr[:5]
  504. }
  505. resArr = append(resArr, finalArr...)
  506. return GetIndexProjectList(typ, pageSize+10, resArr)
  507. }
  508. func GetIndexProjectListRedis(typ, pageSize int) (data []map[string]interface{}, types string) {
  509. switch typ {
  510. case 5:
  511. types = "采购意向"
  512. case 6:
  513. types = "项目分包"
  514. case 13:
  515. types = "热门项目"
  516. case 14:
  517. types = "新兴项目"
  518. case 15:
  519. types = "国家级项目"
  520. case 16:
  521. types = "省级项目"
  522. case 8:
  523. types = "政府采购"
  524. }
  525. redidKey := fmt.Sprintf("pcIndexProjectZone_%d", typ)
  526. redisArr, _ := redis.Get(RedisNameNew, redidKey).([]interface{})
  527. if len(redisArr) > 0 {
  528. data = common.ObjArrToMapArr(redisArr)
  529. return
  530. }
  531. data, _ = GetIndexProjectList(typ, pageSize, []map[string]interface{}{})
  532. if data != nil && len(data) > 0 {
  533. redis.Put(RedisNameNew, redidKey, data, RedisTimeout+rand.Intn(100))
  534. }
  535. return data, types
  536. }
  537. // GetIndexRecommendProjectList 审批项目、推荐项目
  538. func GetIndexRecommendProjectList(typ, pageSize int) (data []map[string]interface{}, types string) {
  539. switch typ {
  540. case 10:
  541. types = "审批项目"
  542. case 11:
  543. types = "推荐项目"
  544. }
  545. redidKey := fmt.Sprintf("pcIndexProjectZone_%d", typ)
  546. redisArr, _ := redis.Get(RedisNameNew, redidKey).([]interface{})
  547. if len(redisArr) > 0 {
  548. data = common.ObjArrToMapArr(redisArr)
  549. return
  550. }
  551. res, err := g.DB().Query(gctx.New(), fmt.Sprintf(`SELECT bid_id,title,publish_time FROM new_project_sign WHERE bitmapContains(sign, %d) ORDER BY publish_time DESC LIMIT 0, %d`, typ, pageSize))
  552. if err != nil || res.IsEmpty() {
  553. return nil, types
  554. }
  555. for _, v := range res.List() {
  556. v["proposed_id"] = encrypt.SE2.Encode2Hex(common.ObjToString(v["bid_id"]))
  557. v["publish_time"] = strings.Split(common.InterfaceToStr(v["publish_time"]), " ")[0]
  558. data = append(data, v)
  559. }
  560. if data != nil && len(data) > 0 {
  561. redis.Put(RedisNameNew, redidKey, data, RedisTimeout+rand.Intn(100))
  562. }
  563. return data, types
  564. }
  565. // 优秀供应商
  566. func GetBidInfoPublishEnt() (res [][]map[string]interface{}) {
  567. if l, ok := redis.Get(RedisNameNew, "pcIndexBidInfoGoodPublishEnt").([]interface{}); ok && l != nil && len(l) > 0 {
  568. for _, v := range l {
  569. res = append(res, common.ObjArrToMapArr(v.([]interface{})))
  570. }
  571. } else {
  572. data := public.Mysql.Query("SELECT id,name FROM `entniche_info` WHERE auth_status = 1 ORDER BY auth_startTime DESC")
  573. if data != nil && len(*data) > 0 {
  574. resData := []map[string]interface{}{}
  575. for _, val := range *data {
  576. if strings.Contains(common.ObjToString(val["name"]), "测试") || strings.Contains(common.ObjToString(val["name"]), "账号") {
  577. continue
  578. } else {
  579. resData = append(resData, val)
  580. }
  581. }
  582. entData := []map[string]interface{}{}
  583. if len(resData) > 110 {
  584. r := rand.Intn(len(resData) - 110)
  585. entData = (resData)[r : r+110]
  586. } else {
  587. entData = resData
  588. }
  589. if len(entData) > 0 {
  590. once := []map[string]interface{}{}
  591. for _, val := range entData {
  592. if len(once) <= 10 {
  593. once = append(once, val)
  594. } else {
  595. res = append(res, once)
  596. once = []map[string]interface{}{}
  597. once = append(once, val)
  598. }
  599. }
  600. if len(once) > 0 {
  601. res = append(res, once)
  602. }
  603. }
  604. redis.Put(RedisNameNew, "pcIndexBidInfoGoodPublishEnt", res, RedisTimeout+rand.Intn(100))
  605. }
  606. }
  607. return res
  608. }
  609. func GetImportBidding() []*hotKeyWord {
  610. redisData := redis.Get(RedisNameNew, "pcIndexImportBidding")
  611. if redisData != nil {
  612. if d, err := json.Marshal(redisData); err == nil {
  613. var hotKW []*hotKeyWord
  614. json.Unmarshal(d, &hotKW)
  615. return hotKW
  616. }
  617. }
  618. randomNumber := rand.Intn(len(subjectMatter) - 30)
  619. res := subjectMatter[randomNumber : randomNumber+30]
  620. if len(res) > 0 {
  621. redis.Put(RedisNameNew, "pcIndexImportBidding", res, RedisTimeout+rand.Intn(100))
  622. }
  623. return res
  624. }
  625. func GetIndustryAnalysisReport() (data []map[string]interface{}) {
  626. redidKey := "pcIndexIndustryReport"
  627. redisArr, _ := redis.Get(RedisNameNew, redidKey).([]interface{})
  628. if len(redisArr) > 0 {
  629. data = common.ObjArrToMapArr(redisArr)
  630. return
  631. }
  632. res, err := g.DB().Query(gctx.New(), `SELECT * FROM analysis_report WHERE 1=1 ORDER BY show_time DESC limit 4`)
  633. if err != nil || res.IsEmpty() {
  634. return nil
  635. }
  636. for _, v := range res.List() {
  637. info := formatRow(v)
  638. data = append(data, map[string]interface{}{
  639. "url": info.Url,
  640. "area": info.Area,
  641. "detail": info.Detail,
  642. "keyword": info.Keyword,
  643. "industry": info.Industry,
  644. "title": info.Title,
  645. })
  646. }
  647. if len(data) > 0 {
  648. redis.Put(RedisNameNew, redidKey, data, RedisTimeout)
  649. }
  650. return data
  651. }
  652. type InfoList struct {
  653. Url string
  654. Area string
  655. Detail string
  656. Keyword string
  657. Industry string
  658. Title string
  659. }
  660. func formatRow(row map[string]interface{}, isDetail ...bool) *InfoList {
  661. bl := &InfoList{
  662. Url: fmt.Sprintf("/hybg/%s.html", gconv.String(row["id"])),
  663. Area: gconv.String(row["area"]),
  664. //Detail: gconv.String(row["desc"]),
  665. Keyword: gconv.String(row["key_word"]),
  666. Industry: gconv.String(row["industry"]),
  667. }
  668. var title string //河南省建筑工程行业2024年第2周行业分
  669. showTime, classify := time.Unix(gconv.Int64(row["show_time"]), 0), gconv.Int(row["classify"])
  670. var finalImages []string
  671. for _, imgUrl := range gconv.Strings(row["imags"]) {
  672. finalImages = append(finalImages, fmt.Sprintf("%s%s", g.Cfg().MustGet(context.Background(), "analysisReport.images.requestPrefix").String(), imgUrl))
  673. }
  674. expandMap := map[string]interface{}{
  675. "classify": classify,
  676. "images": finalImages,
  677. }
  678. switch classify { //1周报 2月报
  679. case 1: //1周报
  680. year, week := showTime.ISOWeek()
  681. expandMap["year"], expandMap["date"] = year, week
  682. title = fmt.Sprintf("%s%s行业%d年第%d周市场分析简报", common.If(bl.Area == "", "全国", bl.Area), bl.Industry, year, week)
  683. case 2: //2月报
  684. year, month := showTime.Year(), int(showTime.Month())
  685. expandMap["year"], expandMap["date"] = year, month
  686. title = fmt.Sprintf("%s%s行业%d年%d月份市场分析简报", common.If(bl.Area == "", "全国", bl.Area), bl.Industry, year, month)
  687. }
  688. bl.Title = title
  689. if len(isDetail) > 0 {
  690. bl.Detail = fmt.Sprintf(gconv.String(row["content"]), gconv.Interfaces(finalImages)...)
  691. }
  692. return bl
  693. }