123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- /*首页模块
- *包括首页内容展示、顶部用户登录状态功能
- *@Author 王传进
- */
- package front
- import (
- "encoding/base64"
- "encoding/json"
- "fmt"
- "github.com/go-xweb/xweb"
- . "gopkg.in/mgo.v2/bson"
- "log"
- coreconfig "qfw/coreconfig"
- . "qfw/member"
- util "qfw/util"
- . "qfw/util/mongodb"
- msg "qfw/util/msg"
- "qfw/util/redis"
- "strings"
- "time"
- )
- type Index struct {
- *xweb.Action
- loadIndex xweb.Mapper `xweb:"/"` //访问首页
- getWebSiteTop xweb.Mapper `xweb:"/front/getWebSiteTop"` //获取网站顶部内容
- advertAjaxRqe xweb.Mapper `xweb:"/front/advertAjaxRqe"` //首页ajax请求
- reurl xweb.Mapper `xweb:"/front/reurl"` //跳转服务产品页面
- }
- //加载首页
- func (i *Index) LoadIndex() error {
- id := i.GetString("id")
- if id != "" && len(id) == 10 {
- c := i.GetString("c")
- if len(c) > 10 {
- //此为推广活动
- i.Session().Set("promotion_id", id)
- i.Session().Set("promotion_c", c)
- }
- }
- //读取cookie信息,自动登录
- userInfo, err := i.GetCookie(COOKIE_USER_INFO)
- if err == nil {
- ui := make(map[string]string)
- if v, e := base64.StdEncoding.DecodeString(userInfo.Value); e == nil && json.Unmarshal(v, &ui) == nil {
- r := *FindById("user", ui["loginId"], nil)
- if r[ui["loginType"]] != nil {
- UpdateCookieSession(i.Action, ui["loginType"], false, r)
- }
- }
- }
- if ret := redis.Get("other", "/"); ret != nil {
- return i.SetBody([]byte(ret.(string)))
- } else {
- i.T["serviceClassify"] = coreconfig.ServiceClassify
- //企业快报
- querymap := map[string]string{
- "perPage": i.GetString("perPage"),
- "currentPage": i.GetString("currentPage"),
- "contentType": "qykb",
- "query": i.GetString("query")}
- data, pagination := searhWebContent(querymap)
- //知识库
- zkquerymap := map[string]string{
- "perPage": "8",
- "currentPage": i.GetString("currentPage"),
- "contentType": "zhsk",
- "query": i.GetString("query")}
- zkdata, _ := searhWebContent(zkquerymap)
- if zkdata != nil {
- for _, v := range *zkdata {
- release := v["releasetime"].(string)
- v["releasetime"] = release[:4] + "." + release[5:7] + "." + release[8:10]
- }
- }
- //认证企业
- entquery := `{"i_identificationstatus":1,"i_freeze":{"$ne":2},"i_identificationtype":{"$in":[1,5]}}`
- entdata := *Find("identification", entquery, []string{"-l_auditdate"}, `{"s_enterprisename":1,"l_auditdate":1,"s_enterpriseid":1}`, false, 0, 8)
- if entdata != nil {
- for _, v := range entdata {
- auditdate := v["l_auditdate"].(int64)
- v["l_auditdate"] = time.Unix(auditdate, 0).Format("2006.01.02")
- }
- }
- //剑鱼最新消息
- now := time.Now()
- unix := time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-2, now.Minute(), now.Second(), now.Nanosecond(), time.Local).Unix()
- sfdata := *Find("bidding", M{"comeintime": M{"$lte": unix}}, `{"comeintime":-1}`, `{"title":1,"href":1,"publishtime":1}`, false, 0, 8)
- if sfdata != nil {
- for _, v := range sfdata {
- publishtime := v["publishtime"].(int64)
- //:= util.FormatDateWithObj(&data_2, util.Date_Short_Layout)
- v["publishtime"] = time.Unix(publishtime, 0).Format("2006.01.02")
- }
- }
- //
- content, _ := i.Render4Cache("/index.html", &xweb.T{"data": data, "pagination": pagination, "zkdata": zkdata, "entdata": entdata, "sfdata": sfdata})
- redis.Put("other", "/", string(content), 60*60*2) //设置首页缓存
- return i.SetBody(content)
- }
- }
- //获取网站顶部内容
- func (i *Index) GetWebSiteTop() error {
- var result = make(M)
- if i.GetSession("userType") != nil && util.IntAll(i.GetSession("userType")) > 0 { //用户类型
- result["status"] = "y"
- if nickName := i.GetSession("nickName"); nickName != nil { //昵称
- result["nickName"] = nickName.(string)
- }
- if loginType := i.GetSession("loginType"); loginType != nil { //登录类型
- result["loginType"] = loginType.(string)
- }
- if userId := i.GetSession("userId"); userId != nil {
- result["msgCount"] = msg.GetMsgCount(userId.(string))
- }
- userInfo := i.GetSession("userInfo").(*map[string]interface{})
- if avatar := (*userInfo)["s_avatar"]; avatar != nil {
- result["avatar"] = avatar.(string)
- }
- if audittype := i.GetSession("audittype"); audittype != nil && audittype == "y" {
- i.DelSession("audittype")
- result["auditType"] = audittype.(string)
- result["entId"] = i.GetSession("entid")
- result["entName"] = i.GetSession("entname")
- result["comAuthentType"] = util.IntAll(i.GetSession("comauthenttype"))
- result["identType"] = util.IntAll(i.GetSession("identType"))
- }
- }
- i.ServeJson(result)
- return nil
- }
- //查询评论个数、投标状态
- func (i *Index) AdvertAjaxRqe() error {
- position := i.GetString("position")
- result := make(M)
- var serviceResult []map[string]interface{}
- if position == "index" || position == "hotService" {
- serviceIds := i.GetSlice("serviceId")
- var sIds []ObjectId
- for _, v := range serviceIds {
- sIds = append(sIds, ObjectIdHex(v))
- }
- services := *Find("service", M{"_id": M{"$in": sIds}}, nil, `{"i_comments":1,"s_enterpriseid":1}`, false, -1, -1)
- for _, id := range serviceIds {
- var comments int
- online := "y"
- for _, service := range services {
- if strings.Split(fmt.Sprintf("%s", service["_id"]), `"`)[1] == id {
- if service["i_comments"] != nil {
- comments = util.IntAll(service["i_comments"])
- }
- break
- }
- }
- s := make(M)
- s["id"] = id
- s["comments"] = comments
- s["online"] = online
- serviceResult = append(serviceResult, s)
- }
- result["service"] = serviceResult
- }
- if position == "index" || position == "hotDemand" {
- demandIds := i.GetSlice("demandId")
- var dIds []ObjectId
- for _, v := range demandIds {
- dIds = append(dIds, ObjectIdHex(v))
- }
- demands := *Find("demand", M{"_id": M{"$in": dIds}}, nil, `{"i_status":1,"s_enterpriseid":1,"l_enddate":1}`, false, -1, -1)
- var demandResult []map[string]interface{}
- for _, id := range demandIds {
- status := 1
- online := "y"
- for _, demand := range demands {
- if strings.Split(fmt.Sprintf("%s", demand["_id"]), `"`)[1] == id {
- status = util.IntAll(demand["i_status"])
- if status == 1 {
- if enddate := time.Unix(demand["l_enddate"].(int64), 0).AddDate(0, 0, 1); enddate.Before(time.Now()) {
- status = 3
- }
- }
- break
- }
- }
- d := make(M)
- d["id"] = id
- d["status"] = status
- d["online"] = online
- demandResult = append(demandResult, d)
- }
- result["demand"] = demandResult
- }
- i.ServeJson(result)
- return nil
- }
- func (i *Index) Reurl() error {
- log.Println(i.GetSession("entid"))
- if i.GetSession("entid") == nil || i.GetSession("entid").(string) == "" {
- i.Redirect("/member/show/memberindex")
- } else {
- str := "/member/yellowpage/show/showService/" + i.GetSession("entid").(string)
- i.Redirect(str)
- }
- return nil
- }
|