index.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*首页模块
  2. *包括首页内容展示、顶部用户登录状态功能
  3. *@Author 王传进
  4. */
  5. package front
  6. import (
  7. "encoding/base64"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/go-xweb/xweb"
  11. . "gopkg.in/mgo.v2/bson"
  12. "log"
  13. coreconfig "qfw/coreconfig"
  14. . "qfw/member"
  15. util "qfw/util"
  16. . "qfw/util/mongodb"
  17. msg "qfw/util/msg"
  18. "qfw/util/redis"
  19. "strings"
  20. "time"
  21. )
  22. type Index struct {
  23. *xweb.Action
  24. loadIndex xweb.Mapper `xweb:"/"` //访问首页
  25. getWebSiteTop xweb.Mapper `xweb:"/front/getWebSiteTop"` //获取网站顶部内容
  26. advertAjaxRqe xweb.Mapper `xweb:"/front/advertAjaxRqe"` //首页ajax请求
  27. reurl xweb.Mapper `xweb:"/front/reurl"` //跳转服务产品页面
  28. }
  29. //加载首页
  30. func (i *Index) LoadIndex() error {
  31. id := i.GetString("id")
  32. if id != "" && len(id) == 10 {
  33. c := i.GetString("c")
  34. if len(c) > 10 {
  35. //此为推广活动
  36. i.Session().Set("promotion_id", id)
  37. i.Session().Set("promotion_c", c)
  38. }
  39. }
  40. //读取cookie信息,自动登录
  41. userInfo, err := i.GetCookie(COOKIE_USER_INFO)
  42. if err == nil {
  43. ui := make(map[string]string)
  44. if v, e := base64.StdEncoding.DecodeString(userInfo.Value); e == nil && json.Unmarshal(v, &ui) == nil {
  45. r := *FindById("user", ui["loginId"], nil)
  46. if r[ui["loginType"]] != nil {
  47. UpdateCookieSession(i.Action, ui["loginType"], false, r)
  48. }
  49. }
  50. }
  51. if ret := redis.Get("other", "/"); ret != nil {
  52. return i.SetBody([]byte(ret.(string)))
  53. } else {
  54. i.T["serviceClassify"] = coreconfig.ServiceClassify
  55. //企业快报
  56. querymap := map[string]string{
  57. "perPage": i.GetString("perPage"),
  58. "currentPage": i.GetString("currentPage"),
  59. "contentType": "qykb",
  60. "query": i.GetString("query")}
  61. data, pagination := searhWebContent(querymap)
  62. //知识库
  63. zkquerymap := map[string]string{
  64. "perPage": "8",
  65. "currentPage": i.GetString("currentPage"),
  66. "contentType": "zhsk",
  67. "query": i.GetString("query")}
  68. zkdata, _ := searhWebContent(zkquerymap)
  69. if zkdata != nil {
  70. for _, v := range *zkdata {
  71. release := v["releasetime"].(string)
  72. v["releasetime"] = release[:4] + "." + release[5:7] + "." + release[8:10]
  73. }
  74. }
  75. //认证企业
  76. entquery := `{"i_identificationstatus":1,"i_freeze":{"$ne":2},"i_identificationtype":{"$in":[1,5]}}`
  77. entdata := *Find("identification", entquery, []string{"-l_auditdate"}, `{"s_enterprisename":1,"l_auditdate":1,"s_enterpriseid":1}`, false, 0, 8)
  78. if entdata != nil {
  79. for _, v := range entdata {
  80. auditdate := v["l_auditdate"].(int64)
  81. v["l_auditdate"] = time.Unix(auditdate, 0).Format("2006.01.02")
  82. }
  83. }
  84. //剑鱼最新消息
  85. now := time.Now()
  86. unix := time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-2, now.Minute(), now.Second(), now.Nanosecond(), time.Local).Unix()
  87. sfdata := *Find("bidding", M{"comeintime": M{"$lte": unix}}, `{"comeintime":-1}`, `{"title":1,"href":1,"publishtime":1}`, false, 0, 8)
  88. if sfdata != nil {
  89. for _, v := range sfdata {
  90. publishtime := v["publishtime"].(int64)
  91. //:= util.FormatDateWithObj(&data_2, util.Date_Short_Layout)
  92. v["publishtime"] = time.Unix(publishtime, 0).Format("2006.01.02")
  93. }
  94. }
  95. //
  96. content, _ := i.Render4Cache("/index.html", &xweb.T{"data": data, "pagination": pagination, "zkdata": zkdata, "entdata": entdata, "sfdata": sfdata})
  97. redis.Put("other", "/", string(content), 60*60*2) //设置首页缓存
  98. return i.SetBody(content)
  99. }
  100. }
  101. //获取网站顶部内容
  102. func (i *Index) GetWebSiteTop() error {
  103. var result = make(M)
  104. if i.GetSession("userType") != nil && util.IntAll(i.GetSession("userType")) > 0 { //用户类型
  105. result["status"] = "y"
  106. if nickName := i.GetSession("nickName"); nickName != nil { //昵称
  107. result["nickName"] = nickName.(string)
  108. }
  109. if loginType := i.GetSession("loginType"); loginType != nil { //登录类型
  110. result["loginType"] = loginType.(string)
  111. }
  112. if userId := i.GetSession("userId"); userId != nil {
  113. result["msgCount"] = msg.GetMsgCount(userId.(string))
  114. }
  115. userInfo := i.GetSession("userInfo").(*map[string]interface{})
  116. if avatar := (*userInfo)["s_avatar"]; avatar != nil {
  117. result["avatar"] = avatar.(string)
  118. }
  119. if audittype := i.GetSession("audittype"); audittype != nil && audittype == "y" {
  120. i.DelSession("audittype")
  121. result["auditType"] = audittype.(string)
  122. result["entId"] = i.GetSession("entid")
  123. result["entName"] = i.GetSession("entname")
  124. result["comAuthentType"] = util.IntAll(i.GetSession("comauthenttype"))
  125. result["identType"] = util.IntAll(i.GetSession("identType"))
  126. }
  127. }
  128. i.ServeJson(result)
  129. return nil
  130. }
  131. //查询评论个数、投标状态
  132. func (i *Index) AdvertAjaxRqe() error {
  133. position := i.GetString("position")
  134. result := make(M)
  135. var serviceResult []map[string]interface{}
  136. if position == "index" || position == "hotService" {
  137. serviceIds := i.GetSlice("serviceId")
  138. var sIds []ObjectId
  139. for _, v := range serviceIds {
  140. sIds = append(sIds, ObjectIdHex(v))
  141. }
  142. services := *Find("service", M{"_id": M{"$in": sIds}}, nil, `{"i_comments":1,"s_enterpriseid":1}`, false, -1, -1)
  143. for _, id := range serviceIds {
  144. var comments int
  145. online := "y"
  146. for _, service := range services {
  147. if strings.Split(fmt.Sprintf("%s", service["_id"]), `"`)[1] == id {
  148. if service["i_comments"] != nil {
  149. comments = util.IntAll(service["i_comments"])
  150. }
  151. break
  152. }
  153. }
  154. s := make(M)
  155. s["id"] = id
  156. s["comments"] = comments
  157. s["online"] = online
  158. serviceResult = append(serviceResult, s)
  159. }
  160. result["service"] = serviceResult
  161. }
  162. if position == "index" || position == "hotDemand" {
  163. demandIds := i.GetSlice("demandId")
  164. var dIds []ObjectId
  165. for _, v := range demandIds {
  166. dIds = append(dIds, ObjectIdHex(v))
  167. }
  168. demands := *Find("demand", M{"_id": M{"$in": dIds}}, nil, `{"i_status":1,"s_enterpriseid":1,"l_enddate":1}`, false, -1, -1)
  169. var demandResult []map[string]interface{}
  170. for _, id := range demandIds {
  171. status := 1
  172. online := "y"
  173. for _, demand := range demands {
  174. if strings.Split(fmt.Sprintf("%s", demand["_id"]), `"`)[1] == id {
  175. status = util.IntAll(demand["i_status"])
  176. if status == 1 {
  177. if enddate := time.Unix(demand["l_enddate"].(int64), 0).AddDate(0, 0, 1); enddate.Before(time.Now()) {
  178. status = 3
  179. }
  180. }
  181. break
  182. }
  183. }
  184. d := make(M)
  185. d["id"] = id
  186. d["status"] = status
  187. d["online"] = online
  188. demandResult = append(demandResult, d)
  189. }
  190. result["demand"] = demandResult
  191. }
  192. i.ServeJson(result)
  193. return nil
  194. }
  195. func (i *Index) Reurl() error {
  196. log.Println(i.GetSession("entid"))
  197. if i.GetSession("entid") == nil || i.GetSession("entid").(string) == "" {
  198. i.Redirect("/member/show/memberindex")
  199. } else {
  200. str := "/member/yellowpage/show/showService/" + i.GetSession("entid").(string)
  201. i.Redirect(str)
  202. }
  203. return nil
  204. }