|
@@ -0,0 +1,177 @@
|
|
|
+package front
|
|
|
+
|
|
|
+import (
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "jfw/public"
|
|
|
+ "qfw/util"
|
|
|
+ "qfw/util/redis"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ "github.com/go-xweb/xweb"
|
|
|
+ "gopkg.in/mgo.v2/bson"
|
|
|
+)
|
|
|
+
|
|
|
+type WsDataExport struct {
|
|
|
+ *xweb.Action
|
|
|
+ searchExport xweb.Mapper `xweb:"/front/wx_dataExport/searchExport"` //微信数据导出
|
|
|
+ toCreateOrderPage xweb.Mapper `xweb:"/front/wx_dataExport/toCreateOrderPage/(.*)"` //微信数据导出-订单页面
|
|
|
+}
|
|
|
+
|
|
|
+func init() {
|
|
|
+ xweb.AddAction(&WsDataExport{})
|
|
|
+}
|
|
|
+
|
|
|
+func (w *WsDataExport) ToCreateOrderPage(_id string) error {
|
|
|
+ id := util.SE.Decode4Hex(_id)
|
|
|
+ openid := util.ObjToString(w.GetSession("s_m_openid"))
|
|
|
+ userId := util.ObjToString(w.GetSession("userId"))
|
|
|
+ if userId == "" {
|
|
|
+ return errors.New("未登录")
|
|
|
+ }
|
|
|
+ msgCount := public.GetDataExportSearchCountUseId(id)
|
|
|
+ if msgCount > public.ExConf.MsgMaxCount {
|
|
|
+ msgCount = public.ExConf.MsgMaxCount
|
|
|
+ }
|
|
|
+ if msgCount < 1 {
|
|
|
+ w.Render("/weixin/dataExport/404.html", &w.T)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ //订单数据存入session中
|
|
|
+ w.SetSession("dataexport_waitcreateorder", map[string]interface{}{
|
|
|
+ "id": id, //用户的筛选条件mongodb中的id string
|
|
|
+ "data_count": msgCount, //匹配到的数据总数 int
|
|
|
+ })
|
|
|
+ //邮箱验证
|
|
|
+ // w.DelSession("DataExportVerifyEmail_val")
|
|
|
+ // w.DelSession("DataExportVerifyPhone_val")
|
|
|
+ email := w.GetSession("DataExportVerifyEmail_val")
|
|
|
+ resPhone := w.GetSession("DataExportVerifyPhone_val")
|
|
|
+ if email != nil {
|
|
|
+ lastSendDEVerify := util.Int64All(w.GetSession("CreatEVerifyTime"))
|
|
|
+ timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
|
|
|
+ w.T["email"] = email
|
|
|
+ w.T["timeSpaceing"] = timeSpaceing
|
|
|
+ } else {
|
|
|
+ mail_phone := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ }, "user_mail,user_phone", "create_time desc")
|
|
|
+ if mail_phone != nil {
|
|
|
+ email = (*mail_phone)["user_mail"]
|
|
|
+ resPhone = (*mail_phone)["user_phone"]
|
|
|
+ }
|
|
|
+ if email == nil || email == "" {
|
|
|
+ userData, _ := mongodb.FindById("user", userId, `{"o_jy":1}`)
|
|
|
+ o_jy := util.ObjToMap((*userData)["o_jy"])
|
|
|
+ email = (*o_jy)["s_email"]
|
|
|
+ }
|
|
|
+ if email != nil && email != "" {
|
|
|
+ w.SetSession("EMVerifySucess", true)
|
|
|
+ w.SetSession("DataExportVerifyEmail_val", email)
|
|
|
+ }
|
|
|
+ w.T["email"] = email
|
|
|
+ }
|
|
|
+ //手机号
|
|
|
+ phone := w.GetSession("DataExportVerifyPhone_val")
|
|
|
+ if phone != nil && phone != "" {
|
|
|
+ w.T["phone"] = phone
|
|
|
+ } else {
|
|
|
+ //剑鱼助手手机号登录
|
|
|
+ if isPhone(openid) {
|
|
|
+ phone = openid
|
|
|
+ } else {
|
|
|
+ phone = resPhone
|
|
|
+ }
|
|
|
+ if phone != nil && phone != "" {
|
|
|
+ w.SetSession("DataExportVerifyPhone_val", phone)
|
|
|
+ }
|
|
|
+ w.T["phone"] = phone
|
|
|
+ }
|
|
|
+ w.T["_id"] = _id
|
|
|
+ w.T["msgCount"] = msgCount
|
|
|
+ w.T["msgMaxCount"] = public.ExConf.MsgMaxCount
|
|
|
+ w.T["discount"] = public.ExConf.Discount
|
|
|
+ w.T["discount10"] = public.ExConf.Discount * 10
|
|
|
+ w.T["unitPrice_normal"] = public.ExConf.UnitPrice_normal
|
|
|
+ w.T["unitPrice_senior"] = public.ExConf.UnitPrice_senior
|
|
|
+ w.T["unitPrice_normal_final"] = (public.ExConf.UnitPrice_normal * 100) * (public.ExConf.Discount * 100) / 10000
|
|
|
+ w.T["unitPrice_senior_final"] = (public.ExConf.UnitPrice_senior * 100) * (public.ExConf.Discount * 100) / 10000
|
|
|
+ w.T["orderMinPrice"] = public.ExConf.OrderMinPrice
|
|
|
+ incurKey := fmt.Sprintf("PreviewData_%s_%d", w.GetSession("userId"), time.Now().Day())
|
|
|
+ w.T["PreviewData"] = util.IntAll(redis.Get("other", incurKey))
|
|
|
+ w.Render("/weixin/dataExport/dataExport_payOrder.html", &w.T)
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+//微信数据导出
|
|
|
+func (w *WsDataExport) SearchExport() error {
|
|
|
+ openid := util.ObjToString(w.GetSession("s_m_openid"))
|
|
|
+ userId := util.ObjToString(w.GetSession("userId"))
|
|
|
+ if userId == "" {
|
|
|
+ return errors.New("未登录")
|
|
|
+ }
|
|
|
+ //接收超级搜索页面参数
|
|
|
+ keywords := w.GetString("searchvalue") //搜索词
|
|
|
+ publishtime := w.GetString("publishtime") //发布时间
|
|
|
+ area := w.GetString("scope") //地区
|
|
|
+ subtype := w.GetString("subtype") //信息类型
|
|
|
+ minprice := w.GetString("minprice") //最低价格
|
|
|
+ maxprice := w.GetString("maxprice") //最高价格
|
|
|
+ industry := strings.TrimSpace(w.GetString("industry")) //选中的行业
|
|
|
+ selectType := w.GetString("selectType") //标题 or 全文
|
|
|
+
|
|
|
+ //数据存库转换
|
|
|
+ areaSave := []string{}
|
|
|
+ if len(area) > 0 {
|
|
|
+ areaSave = strings.Split(area, ",")
|
|
|
+ }
|
|
|
+ industrySave := []string{}
|
|
|
+ if len(industry) > 0 {
|
|
|
+ industrySave = strings.Split(industry, ",")
|
|
|
+ }
|
|
|
+ //格式化keywords
|
|
|
+ KeyWordSave := []public.KeyWord{}
|
|
|
+
|
|
|
+ if len(keywords) > 0 {
|
|
|
+ isIntercept := false
|
|
|
+ if selectType == "all" {
|
|
|
+ isIntercept = true
|
|
|
+ }
|
|
|
+ _, _, keywords = public.InterceptSearchKW(keywords, isIntercept, len(industrySave) == 0)
|
|
|
+ KeyWordSave = append(KeyWordSave, public.KeyWord{Keyword: keywords})
|
|
|
+ }
|
|
|
+ //时间
|
|
|
+ now := time.Now()
|
|
|
+ if publishtime == "lately-7" { //最近7天
|
|
|
+ starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
|
|
|
+ publishtime = fmt.Sprintf("%s_%d", starttime, now.Unix())
|
|
|
+ } else if publishtime == "lately-30" { //最近30天
|
|
|
+ starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
|
|
|
+ publishtime = fmt.Sprintf("%s_%d", starttime, now.Unix())
|
|
|
+ } else if publishtime == "thisyear" { //去年
|
|
|
+ starttime := fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
|
|
|
+ endtime := fmt.Sprint(time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.Local).Unix())
|
|
|
+ publishtime = fmt.Sprintf("%s_%s", starttime, endtime)
|
|
|
+ }
|
|
|
+
|
|
|
+ data := map[string]interface{}{
|
|
|
+ "keywords": KeyWordSave,
|
|
|
+ "publishtime": publishtime,
|
|
|
+ "area": areaSave,
|
|
|
+ "subtype": subtype,
|
|
|
+ "minprice": minprice,
|
|
|
+ "maxprice": maxprice,
|
|
|
+ "industry": industrySave,
|
|
|
+ "selectType": selectType,
|
|
|
+ "comeintime": now.Unix(),
|
|
|
+ "s_openid": openid,
|
|
|
+ "comeinfrom": "supersearchPage",
|
|
|
+ "s_userid": userId,
|
|
|
+ }
|
|
|
+
|
|
|
+ //存入数据库
|
|
|
+ _id := mongodb.Save(public.ExportTable, data)
|
|
|
+ w.ServeJson(bson.M{"_id": util.SE.Encode2Hex(_id)})
|
|
|
+ return nil
|
|
|
+}
|