index.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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/common/src/qfw/util/bidsearch"
  9. "app.yhyue.com/moapp/jypkg/public"
  10. "context"
  11. "encoding/json"
  12. "fmt"
  13. "github.com/gogf/gf/v2/frame/g"
  14. "github.com/gogf/gf/v2/os/gctx"
  15. "github.com/gogf/gf/v2/util/gconv"
  16. "jy/src/jfw/config"
  17. "jy/src/jfw/jyutil"
  18. "jy/src/jfw/site/jySchool"
  19. "math/rand"
  20. "time"
  21. )
  22. type NewIndex struct {
  23. *xweb.Action
  24. newIndex xweb.Mapper `xweb:"/"` //首页改版
  25. entServerTransfer xweb.Mapper `xweb:"/front/entServerTransfer/(.*)"` //企业服务中转
  26. appDownload xweb.Mapper `xweb:"/front/appDownload"` //新app下载页面
  27. }
  28. var (
  29. entServerTransferMap map[string]map[bool]string
  30. BiddingTypeUrl = map[int]string{
  31. 1: "/list/stype/ZBYG.html",
  32. 2: "/list/stype/ZBJG.html",
  33. 3: "/list/stype/CGYX.html",
  34. 6: "/list/stype/XMFB.html",
  35. 13: "/list/rmxm/",
  36. 14: "/list/xxxm/",
  37. 15: "/list/gjxm/",
  38. 16: "/list/sjxm/",
  39. }
  40. )
  41. func init() {
  42. xweb.AddAction(&NewIndex{})
  43. entServerTransferMap = map[string]map[bool]string{
  44. "yxgl": map[bool]string{ //【营销管理】根据code判断是否有权限 bi_yx
  45. true: fmt.Sprintf("/page_workDesktop/work-bench/page?link=%s/succbi/crm_system/app/crm.app/sales_clues.spg", config.Sysconfig["webdomain"].(string)),
  46. false: "/swordfish/frontPage/digitalMarketing/free/index",
  47. },
  48. "yxt": map[bool]string{ //【医械通】根据code判断是否有权限 lyh_yl_yldy
  49. true: "/page_workDesktop/work-bench/app/big/medical/Credentials",
  50. false: "http://clpages.cn/yxtsjgwyxy",
  51. },
  52. "khgl": map[bool]string{ //【客户管理】根据code判断是否有权限 bi_yx
  53. true: fmt.Sprintf("/page_workDesktop/work-bench/page?link=%s/succbi/crm_system/app/crm.app/sales_clues.spg", config.Sysconfig["webdomain"].(string)),
  54. false: "/swordfish/frontPage/customanage/free/index",
  55. },
  56. "tbxmgl": map[bool]string{ //【投标项目管理】根据code判断是否有权限 cb_zy_code
  57. true: "/big/attend_bidding/mine",
  58. false: "/swordfish/frontPage/biddingProject/free/index",
  59. },
  60. "nzbg": map[bool]string{ //【年终报告】根据code判断是否有权限
  61. true: fmt.Sprintf("/page_workDesktop/work-bench/page?link=%s/succbi/nzbg/app/nzbg.app/nzbg_entrance_pc.spg", config.Sysconfig["webdomain"].(string)),
  62. false: "/swordfish/frontPage/AnnualReport/free/index",
  63. },
  64. }
  65. }
  66. // NewIndex 新版首页改版
  67. func (nIndex *NewIndex) NewIndex() error {
  68. sessVal := nIndex.Session().GetMultiple()
  69. userId := util.ObjToString(sessVal["userId"])
  70. nIndex.T["hasLogin"] = userId != ""
  71. nIndex.T["hotkey"] = hotKeyArrLoginEd
  72. nIndex.T["hotKeyArrUnLogin"] = hotKeyArrUnLogin
  73. if userId != "" {
  74. nickname, vipType := gconv.String(sessVal["userName"]), "注册用户"
  75. var endTime int64
  76. if nickname == "" {
  77. nickname = gconv.String(sessVal["s_nickname"])
  78. }
  79. if nickname == "" {
  80. nickname = gconv.String(sessVal["s_jyname"])
  81. }
  82. if nickname == "" {
  83. nickname = gconv.String(sessVal["phone"])
  84. }
  85. 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"]))
  86. if powerRes.Vip.Status > 0 && powerRes.Vip.GetEndTime() > endTime {
  87. vipType, endTime = "超级订阅", powerRes.Vip.GetEndTime()
  88. }
  89. if powerRes.Member.Status > 0 && powerRes.Member.GetEndTime() > endTime {
  90. vipType, endTime = "大会员", powerRes.Member.GetEndTime()
  91. }
  92. if powerRes.Entniche.Status > 0 && powerRes.Entniche.GetEndTime() > endTime {
  93. vipType, endTime = "商机管理", powerRes.Entniche.GetEndTime()
  94. }
  95. if powerRes.Free.PpStatus > 0 && powerRes.Free.PpEndTime > endTime {
  96. vipType, endTime = "省份订阅包", powerRes.Free.GetPpEndTime()
  97. }
  98. nIndex.T["vipType"] = vipType
  99. nIndex.T["nickname"] = nickname
  100. if endTime > 0 {
  101. nIndex.T["vipEntTime"] = time.Unix(endTime, 0).Format("2006-01-02")
  102. }
  103. }
  104. //顶部菜单
  105. nIndex.T["topMenu"] = g.Cfg("index").MustGet(context.Background(), "topMenu").Maps()
  106. //招标公告
  107. nIndex.T["newbids"] = map[string]interface{}{
  108. "biddingList": NewIndexbids(nIndex.Session(), nIndex.Request),
  109. "more": fmt.Sprintf("%s", "/list/stype/ZBGG.html"),
  110. }
  111. //推荐标讯专区
  112. rangeInfoType := []int{1, 2, 3}
  113. //招标动态
  114. bidTrends := []map[string]interface{}{}
  115. for _, v := range rangeInfoType { //1招标预告 2 中标成交 3采购意向 4 拟建项目
  116. listData, types := GetRecommendBidZone(v, 5)
  117. bidTrends = append(bidTrends, map[string]interface{}{
  118. "listData": listData,
  119. "types": types,
  120. "url": fmt.Sprintf("%s", BiddingTypeUrl[v]),
  121. })
  122. }
  123. //项目分包
  124. projectPage, typesName := GetIndexProjectList(6, 5)
  125. bidTrends = append(bidTrends, map[string]interface{}{
  126. "listData": projectPage,
  127. "types": typesName,
  128. "url": fmt.Sprintf("%s", BiddingTypeUrl[6]),
  129. })
  130. nIndex.T["bidTrends"] = bidTrends
  131. //项目专区
  132. projectZoneType := []int{13, 14, 15, 16}
  133. projectZone := []map[string]interface{}{}
  134. for _, val := range projectZoneType {
  135. listData, types := GetIndexProjectList(val, 5)
  136. projectZone = append(projectZone, map[string]interface{}{
  137. "listData": listData,
  138. "types": types,
  139. "url": fmt.Sprintf("%s", BiddingTypeUrl[val]),
  140. })
  141. }
  142. nIndex.T["projectZone"] = projectZone
  143. //中标喜报
  144. nIndex.T["winnerGlad"] = WinnerGladTidings()
  145. //热门行业 ////重点招标
  146. nIndex.T["hotIndustry"] = GetHotIndustry()
  147. //热门中标企业
  148. nIndex.T["hotWinner"] = NewHotEnt(true, 10)
  149. //热门采购单位
  150. nIndex.T["hotBuyers"] = NewHotEnt(false, 5)
  151. //供应商
  152. nIndex.T["supplyEnt"] = GetBidInfoPublishEnt()
  153. //招投标攻略
  154. nIndex.T["strategyList"] = GetStrategyList()
  155. //剑鱼课堂
  156. nIndex.T["jySchool"] = jyutil.Course(6, 3)
  157. //政府招标
  158. nIndex.T["governmentBidding"] = GovernmentTender(15)
  159. nIndex.T["importBidding"] = GetImportBidding()
  160. nIndex.T["biddingTrend"] = HomeBiddingTrends()
  161. nIndex.T["hotBuyerData"] = PurchasingData()
  162. nIndex.T["simpleTemplateData"] = map[string]interface{}{"XwebVer": nIndex.T["XwebVer"]}
  163. return nIndex.Render("/pc/newIndex.html", &nIndex.T)
  164. }
  165. func (nIndex *NewIndex) EntServerTransfer(code string) {
  166. toUrl := func() string {
  167. sessVal := nIndex.Session().GetMultiple()
  168. accountId := common.Int64All(sessVal["accountId"])
  169. if accountId <= 0 { //未登录
  170. return entServerTransferMap[code][false]
  171. }
  172. if code == "nzbg" {
  173. return entServerTransferMap[code][true]
  174. }
  175. entAccountId := common.Int64All(sessVal["entAccountId"])
  176. entId := common.Int64All(sessVal["entId"])
  177. entUserId := common.Int64All(sessVal["entUserId"])
  178. res := config.Middleground.ResourceCenter.Haspowers(accountId, entAccountId, entId, entUserId)
  179. powerPass := false
  180. switch code {
  181. case "yxgl", "khgl":
  182. for _, pCode := range res.Powers {
  183. if pCode == "bi_yx" {
  184. powerPass = true
  185. break
  186. }
  187. }
  188. case "yxt":
  189. for _, pCode := range res.Powers {
  190. if pCode == "lyh_yl_yldy" {
  191. powerPass = true
  192. break
  193. }
  194. }
  195. case "tbxmgl":
  196. for _, pCode := range res.Powers {
  197. if pCode == "cb_zy_code" {
  198. powerPass = true
  199. break
  200. }
  201. }
  202. }
  203. return entServerTransferMap[code][powerPass]
  204. }()
  205. _ = nIndex.Redirect(toUrl)
  206. }
  207. func (nIndex *NewIndex) AppDownload() {
  208. nIndex.T["includedInfo"] = GetIncludedInfo()
  209. nIndex.Render("/frontRouter/pc/AppDownload/free/index.html", &nIndex.T)
  210. }
  211. // 推荐标讯专区
  212. func GetRecommendBidZone(typ int, pageSize int) (list []map[string]interface{}, typs string) {
  213. if typ == 0 {
  214. typ = 1
  215. }
  216. rediskey := fmt.Sprintf("pcIndexRecommendBidZone_%d", typ)
  217. subtype := ""
  218. switch typ {
  219. case 1:
  220. //招标预告
  221. subtype = "预告"
  222. typs = "招标预告"
  223. case 2:
  224. //招标中标成交
  225. subtype = "中标,成交"
  226. typs = "中标成交"
  227. case 3:
  228. //采购意向
  229. subtype = "采购意向"
  230. typs = "采购意向"
  231. case 4:
  232. //拟建
  233. subtype = "拟建"
  234. typs = "拟建项目"
  235. }
  236. if l, ok := redis.Get("newother", rediskey).([]interface{}); ok && l != nil && len(l) > 0 {
  237. list = common.ObjArrToMapArr(l)
  238. } else {
  239. _, _, lists := bidsearch.GetPcBidSearchData("", "", "", "", subtype, "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", pageSize, "")
  240. if lists != nil && len(*lists) >= 5 {
  241. *lists = (*lists)[0:5]
  242. for _, v := range *lists {
  243. v["_id"] = encrypt.CommonEncodeArticle("indexcontent", v["_id"].(string))
  244. delete(v, "toptype")
  245. delete(v, "s_subscopeclass")
  246. tmpdate := v["publishtime"]
  247. v["publish_time"] = time.Unix(common.Int64All(tmpdate.(float64)), 0).Format("2006-01-02")
  248. /*if v["budget"] != nil {
  249. v["budget"] = ConversionMoeny(v["budget"])
  250. } else if v["bidamount"] != nil {
  251. v["budget"] = ConversionMoeny(v["bidamount"])
  252. }*/
  253. }
  254. list = *lists
  255. redis.Put("other", rediskey, list, 2*60*60)
  256. }
  257. }
  258. return list, typs
  259. }
  260. // GetStrategyList 招投标攻略
  261. func GetStrategyList() (strategyList []map[string]interface{}) {
  262. if l, ok := redis.Get("newother", "pcIndexStrategyList").([]interface{}); ok && l != nil && len(l) > 0 {
  263. strategyList = common.ObjArrToMapArr(l)
  264. } else {
  265. for _, item := range jySchool.GuidelineColumn().SeedData {
  266. if res := jySchool.Guideline(item.Code, 15); res != nil && len(*res) > 0 {
  267. strategyList = append(strategyList, map[string]interface{}{
  268. "name": item.Name,
  269. "code": item.Code,
  270. "list": res,
  271. })
  272. }
  273. }
  274. }
  275. return strategyList
  276. }
  277. func GetIndexProjectList(typ, pageSize int) (data []map[string]interface{}, types string) {
  278. switch typ {
  279. case 6:
  280. types = "项目分包"
  281. case 13:
  282. types = "热门项目"
  283. case 14:
  284. types = "新兴项目"
  285. case 15:
  286. types = "国家级项目"
  287. case 16:
  288. types = "省级项目"
  289. }
  290. redidKey := fmt.Sprintf("pcIndexProjectZone_%d", typ)
  291. redisArr, _ := redis.Get("newother", redidKey).([]interface{})
  292. if len(redisArr) > 0 {
  293. data = common.ObjArrToMapArr(redisArr)
  294. return
  295. }
  296. res, err := g.DB().Query(gctx.New(), fmt.Sprintf(`SELECT nbl.bid_id as bid_id,nbl.title as title,nbl.publish_time as publish_time FROM jyseo_test.new_bid_sign nbs LEFT JOIN jyseo_test.new_bidList nbl ON nbs.bid_id = nbl.bid_id WHERE bitmapContains(sign, %d) ORDER BY publish_time DESC LIMIT %d `, typ, pageSize))
  297. if err != nil || res.IsEmpty() {
  298. return nil, types
  299. }
  300. for _, v := range res.List() {
  301. v["_id"] = encrypt.EncodeArticleId2ByCheck(common.InterfaceToStr(v["bid_id"]))
  302. v["publish_time"] = time.Unix(common.Int64All(v["publish_time"]), 0).Format("2006-01-02")
  303. data = append(data, v)
  304. }
  305. return data, types
  306. }
  307. // 优秀供应商
  308. func GetBidInfoPublishEnt() (res [][]map[string]interface{}) {
  309. if l, ok := redis.Get("newother", "pcIndexBidInfoGoodPublishEnt").([]interface{}); ok && l != nil && len(l) > 0 {
  310. for _, v := range l {
  311. res = append(res, common.ObjArrToMapArr(v.([]interface{})))
  312. }
  313. } else {
  314. data := public.Mysql.Find("entniche_info", map[string]interface{}{"auth_status": 1}, "id,name", "auth_time DESC", -1, -1)
  315. if data != nil && len(*data) > 0 {
  316. entData := []map[string]interface{}{}
  317. if len(*data) > 60 {
  318. r := rand.Intn(len(*data) - 60)
  319. entData = (*data)[r : r+60]
  320. } else {
  321. entData = *data
  322. }
  323. if len(entData) > 0 {
  324. once := []map[string]interface{}{}
  325. for _, val := range entData {
  326. if len(once) <= 15 {
  327. once = append(once, val)
  328. } else {
  329. res = append(res, once)
  330. once = []map[string]interface{}{}
  331. once = append(once, val)
  332. }
  333. }
  334. if len(once) > 0 {
  335. res = append(res, once)
  336. }
  337. }
  338. redis.Put("newother", "pcIndexBidInfoGoodPublishEnt", res, 3600*24*7)
  339. }
  340. }
  341. return res
  342. }
  343. func GetImportBidding() []*hotKeyWord {
  344. redisData := redis.Get(RedisNameNew, "pcIndexImportBidding")
  345. if redisData != nil {
  346. if d, err := json.Marshal(redisData); err == nil {
  347. var hotKW []*hotKeyWord
  348. json.Unmarshal(d, &hotKW)
  349. return hotKW
  350. }
  351. }
  352. randomNumber := rand.Intn(len(subjectMatter) - 30)
  353. res := subjectMatter[randomNumber : randomNumber+30]
  354. redis.Put(RedisNameNew, "pcIndexImportBidding", res, 3600*6)
  355. return res
  356. }