ws_dataExport.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package front
  2. import (
  3. "errors"
  4. "fmt"
  5. "jfw/public"
  6. "qfw/util"
  7. "qfw/util/redis"
  8. "strings"
  9. "time"
  10. "github.com/go-xweb/xweb"
  11. "gopkg.in/mgo.v2/bson"
  12. )
  13. type WsDataExport struct {
  14. *xweb.Action
  15. searchExport xweb.Mapper `xweb:"/front/wx_dataExport/searchExport"` //微信数据导出
  16. toCreateOrderPage xweb.Mapper `xweb:"/front/wx_dataExport/toCreateOrderPage/(.*)"` //微信数据导出-订单页面
  17. }
  18. func init() {
  19. xweb.AddAction(&WsDataExport{})
  20. }
  21. func (w *WsDataExport) ToCreateOrderPage(_id string) error {
  22. id := util.SE.Decode4Hex(_id)
  23. openid := util.ObjToString(w.GetSession("s_m_openid"))
  24. userId := util.ObjToString(w.GetSession("userId"))
  25. if userId == "" {
  26. return errors.New("未登录")
  27. }
  28. msgCount := public.GetDataExportSearchCountUseId(id)
  29. if msgCount > public.ExConf.MsgMaxCount {
  30. msgCount = public.ExConf.MsgMaxCount
  31. }
  32. if msgCount < 1 {
  33. w.Render("/weixin/dataExport/404.html", &w.T)
  34. return nil
  35. }
  36. //订单数据存入session中
  37. w.SetSession("dataexport_waitcreateorder", map[string]interface{}{
  38. "id": id, //用户的筛选条件mongodb中的id string
  39. "data_count": msgCount, //匹配到的数据总数 int
  40. })
  41. //邮箱验证
  42. // w.DelSession("DataExportVerifyEmail_val")
  43. // w.DelSession("DataExportVerifyPhone_val")
  44. email := w.GetSession("DataExportVerifyEmail_val")
  45. resPhone := w.GetSession("DataExportVerifyPhone_val")
  46. if email != nil {
  47. lastSendDEVerify := util.Int64All(w.GetSession("CreatEVerifyTime"))
  48. timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
  49. w.T["email"] = email
  50. w.T["timeSpaceing"] = timeSpaceing
  51. } else {
  52. mail_phone := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
  53. "user_id": userId,
  54. }, "user_mail,user_phone", "create_time desc")
  55. if mail_phone != nil {
  56. email = (*mail_phone)["user_mail"]
  57. resPhone = (*mail_phone)["user_phone"]
  58. }
  59. if email == nil || email == "" {
  60. userData, _ := mongodb.FindById("user", userId, `{"o_jy":1}`)
  61. o_jy := util.ObjToMap((*userData)["o_jy"])
  62. email = (*o_jy)["s_email"]
  63. }
  64. if email != nil && email != "" {
  65. w.SetSession("EMVerifySucess", true)
  66. w.SetSession("DataExportVerifyEmail_val", email)
  67. }
  68. w.T["email"] = email
  69. }
  70. //手机号
  71. phone := w.GetSession("DataExportVerifyPhone_val")
  72. if phone != nil && phone != "" {
  73. w.T["phone"] = phone
  74. } else {
  75. //剑鱼助手手机号登录
  76. if isPhone(openid) {
  77. phone = openid
  78. } else {
  79. phone = resPhone
  80. }
  81. if phone != nil && phone != "" {
  82. w.SetSession("DataExportVerifyPhone_val", phone)
  83. }
  84. w.T["phone"] = phone
  85. }
  86. w.T["_id"] = _id
  87. w.T["msgCount"] = msgCount
  88. w.T["msgMaxCount"] = public.ExConf.MsgMaxCount
  89. w.T["discount"] = public.ExConf.Discount
  90. w.T["discount10"] = public.ExConf.Discount * 10
  91. w.T["unitPrice_normal"] = public.ExConf.UnitPrice_normal
  92. w.T["unitPrice_senior"] = public.ExConf.UnitPrice_senior
  93. w.T["unitPrice_normal_final"] = (public.ExConf.UnitPrice_normal * 100) * (public.ExConf.Discount * 100) / 10000
  94. w.T["unitPrice_senior_final"] = (public.ExConf.UnitPrice_senior * 100) * (public.ExConf.Discount * 100) / 10000
  95. w.T["orderMinPrice"] = public.ExConf.OrderMinPrice
  96. incurKey := fmt.Sprintf("PreviewData_%s_%d", w.GetSession("userId"), time.Now().Day())
  97. w.T["PreviewData"] = util.IntAll(redis.Get("other", incurKey))
  98. w.Render("/weixin/dataExport/dataExport_payOrder.html", &w.T)
  99. return nil
  100. }
  101. //微信数据导出
  102. func (w *WsDataExport) SearchExport() error {
  103. openid := util.ObjToString(w.GetSession("s_m_openid"))
  104. userId := util.ObjToString(w.GetSession("userId"))
  105. if userId == "" {
  106. return errors.New("未登录")
  107. }
  108. //接收超级搜索页面参数
  109. keywords := w.GetString("searchvalue") //搜索词
  110. publishtime := w.GetString("publishtime") //发布时间
  111. area := w.GetString("scope") //地区
  112. subtype := w.GetString("subtype") //信息类型
  113. minprice := w.GetString("minprice") //最低价格
  114. maxprice := w.GetString("maxprice") //最高价格
  115. industry := strings.TrimSpace(w.GetString("industry")) //选中的行业
  116. selectType := w.GetString("selectType") //标题 or 全文
  117. //数据存库转换
  118. areaSave := []string{}
  119. if len(area) > 0 {
  120. areaSave = strings.Split(area, ",")
  121. }
  122. industrySave := []string{}
  123. if len(industry) > 0 {
  124. industrySave = strings.Split(industry, ",")
  125. }
  126. //格式化keywords
  127. KeyWordSave := []public.KeyWord{}
  128. if len(keywords) > 0 {
  129. isIntercept := false
  130. if selectType == "all" {
  131. isIntercept = true
  132. }
  133. _, _, keywords = public.InterceptSearchKW(keywords, isIntercept, len(industrySave) == 0)
  134. KeyWordSave = append(KeyWordSave, public.KeyWord{Keyword: keywords})
  135. }
  136. //时间
  137. now := time.Now()
  138. if publishtime == "lately-7" { //最近7天
  139. starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
  140. publishtime = fmt.Sprintf("%s_%d", starttime, now.Unix())
  141. } else if publishtime == "lately-30" { //最近30天
  142. starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
  143. publishtime = fmt.Sprintf("%s_%d", starttime, now.Unix())
  144. } else if publishtime == "thisyear" { //去年
  145. starttime := fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
  146. endtime := fmt.Sprint(time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.Local).Unix())
  147. publishtime = fmt.Sprintf("%s_%s", starttime, endtime)
  148. }
  149. data := map[string]interface{}{
  150. "keywords": KeyWordSave,
  151. "publishtime": publishtime,
  152. "area": areaSave,
  153. "subtype": subtype,
  154. "minprice": minprice,
  155. "maxprice": maxprice,
  156. "industry": industrySave,
  157. "selectType": selectType,
  158. "comeintime": now.Unix(),
  159. "s_openid": openid,
  160. "comeinfrom": "supersearchPage",
  161. "s_userid": userId,
  162. }
  163. //存入数据库
  164. _id := mongodb.Save(public.ExportTable, data)
  165. w.ServeJson(bson.M{"_id": util.SE.Encode2Hex(_id)})
  166. return nil
  167. }