소스 검색

数据导出 userid

wangshan 6 년 전
부모
커밋
14610ba55e
4개의 변경된 파일76개의 추가작업 그리고 57개의 파일을 삭제
  1. 41 29
      src/jfw/front/dataExport.go
  2. 31 25
      src/jfw/pay/weixin.go
  3. 3 2
      src/jfw/public/dataexport.go
  4. 1 1
      src/web/templates/weixin/dataExport/dataExport_price.html

+ 41 - 29
src/jfw/front/dataExport.go

@@ -143,6 +143,9 @@ func (d *DataExport) SieveData() error {
 	if d.GetSession("s_m_openid") != nil {
 		sieveCondition["s_openid"] = d.GetSession("s_m_openid").(string)
 	}
+	if d.GetSession("userId") != nil {
+		sieveCondition["s_userid"] = d.GetSession("userId").(string)
+	}
 	_id := mongodb.Save(public.ExportTable, sieveCondition)
 	if _id != "" {
 		d.T["success"] = true
@@ -163,11 +166,11 @@ func (d *DataExport) ToMyOrder() error {
 func (d *DataExport) QueryOrder() error {
 	typ := d.GetString("type") //0-全部 1-待支付 2-已支付
 	query := map[string]interface{}{}
-	if openid := d.GetSession("s_m_openid"); openid != nil {
-		query["user_openid"] = openid.(string)
-		log.Println("QueryOrder -- openid====================", openid)
+	if userId := d.GetSession("userId"); userId != nil {
+		query["user_id"] = userId.(string)
+		log.Println("QueryOrder -- userId====================", userId)
 	} else {
-		log.Println("QueryOrder -- session openid does not exist")
+		log.Println("QueryOrder -- session userId does not exist")
 		return nil
 	}
 	if typ != "0" && typ != "" {
@@ -210,7 +213,7 @@ func (d *DataExport) QueryOrder() error {
 				v["order_money"] = float64(orderMoney.(int64)) / 100
 			}
 			if v["id"] != nil && orderMoney != nil && v["order_code"] != nil {
-				v["token"] = public.GetWaitPayToken(v["id"].(int64), int(orderMoney.(int64)), v["order_code"].(string), query["user_openid"].(string))
+				v["token"] = public.GetWaitPayToken(v["id"].(int64), int(orderMoney.(int64)), v["order_code"].(string), query["user_id"].(string))
 			}
 		}
 	}
@@ -227,10 +230,11 @@ func (d *DataExport) QueryOrder() error {
 根据 id+openid 删除
 */
 func (d *DataExport) DeleteOrder() error {
-	if openid := d.GetSession("s_m_openid"); openid != nil {
+	if userId := d.GetSession("userId"); userId != nil {
+		//	if openid := d.GetSession("s_m_openid"); openid != nil {
 		queryMap := map[string]interface{}{
-			"id":          d.GetString("id"),
-			"user_openid": openid.(string),
+			"id":      d.GetString("id"),
+			"user_id": userId.(string),
 		}
 		boo := public.Mysql.Update(tableName_order, queryMap, map[string]interface{}{"order_status": -1})
 		d.ServeJson(map[string]interface{}{"success": boo})
@@ -239,20 +243,21 @@ func (d *DataExport) DeleteOrder() error {
 }
 
 /**
-根据 订单编号+openid 查询
+根据 订单编号+userId 查询
 */
 func (d *DataExport) ToOrderDetail(orderCode string) error {
-	myOpenid := ""
-	if openid := d.GetSession("s_m_openid"); openid != nil {
-		myOpenid = openid.(string)
+	myUserId := ""
+	if userId := d.GetSession("userId"); userId != nil {
+		//	if openid := d.GetSession("s_m_openid"); openid != nil {
+		myUserId = userId.(string)
 	} else {
 		return nil
 	}
 	orderDetail := map[string]interface{}{}
 	filter := public.SieveCondition{}
 	queryMap := map[string]interface{}{
-		"order_code":  orderCode,
-		"user_openid": myOpenid,
+		"order_code": orderCode,
+		"user_id":    myUserId,
 	}
 	if orderCode != "" {
 		orderDetail = *public.Mysql.FindOne(tableName_order, queryMap, "", "")
@@ -376,7 +381,8 @@ func (d *DataExport) ApplyInvoice() error {
 //---------------------------生成订单预览----------------------------------
 func (d *DataExport) SuperSearchExport() error {
 	openid := util.ObjToString(d.GetSession("s_m_openid"))
-	if openid == "" {
+	userId := util.ObjToString(d.GetSession("userId"))
+	if userId == "" {
 		return errors.New("未登录")
 	}
 	//接收超级搜索页面参数
@@ -446,6 +452,7 @@ func (d *DataExport) SuperSearchExport() error {
 		"comeintime":  now.Unix(),
 		"s_openid":    openid,
 		"comeinfrom":  "supersearchPage",
+		"s_userid":    userId,
 	}
 
 	//存入数据库
@@ -457,7 +464,8 @@ func (d *DataExport) SuperSearchExport() error {
 func (d *DataExport) ToCreateOrderPage(_id string) error {
 	id := util.SE.Decode4Hex(_id)
 	openid := util.ObjToString(d.GetSession("s_m_openid"))
-	if openid == "" {
+	userId := util.ObjToString(d.GetSession("userId"))
+	if userId == "" {
 		return errors.New("未登录")
 	}
 	msgCount := public.GetDataExportSearchCountUseId(id)
@@ -486,14 +494,14 @@ func (d *DataExport) ToCreateOrderPage(_id string) error {
 		d.T["timeSpaceing"] = timeSpaceing
 	} else {
 		mail_phone := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
-			"user_openid": openid,
+			"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.FindOneByField("user", `{"s_m_openid":"`+openid+`"}`, `{"o_jy":1}`)
+			userData, _ := mongodb.FindById("user", userId, `{"o_jy":1}`)
 			o_jy := util.ObjToMap((*userData)["o_jy"])
 			email = (*o_jy)["s_email"]
 		}
@@ -508,6 +516,7 @@ func (d *DataExport) ToCreateOrderPage(_id string) error {
 	if phone != nil && phone != "" {
 		d.T["phone"] = phone
 	} else {
+		//剑鱼助手手机号登录
 		if isPhone(openid) {
 			phone = openid
 		} else {
@@ -528,7 +537,7 @@ func (d *DataExport) ToCreateOrderPage(_id string) error {
 	d.T["unitPrice_normal_final"] = (public.ExConf.UnitPrice_normal * 100) * (public.ExConf.Discount * 100) / 10000
 	d.T["unitPrice_senior_final"] = (public.ExConf.UnitPrice_senior * 100) * (public.ExConf.Discount * 100) / 10000
 	d.T["orderMinPrice"] = public.ExConf.OrderMinPrice
-	incurKey := fmt.Sprintf("PreviewData_%s_%d", d.GetSession("s_m_openid"), time.Now().Day())
+	incurKey := fmt.Sprintf("PreviewData_%s_%d", d.GetSession("userId"), time.Now().Day())
 	d.T["PreviewData"] = util.IntAll(redis.Get("other", incurKey))
 	//	go func() {
 	//		orderdata := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
@@ -543,12 +552,13 @@ func (d *DataExport) ToCreateOrderPage(_id string) error {
 }
 
 func (d *DataExport) PreviewData(_id string) error {
-	openid := util.ObjToString(d.GetSession("s_m_openid"))
-	if openid == "" {
+	userId := util.ObjToString(d.GetSession("userId"))
+	//	openid := util.ObjToString(d.GetSession("s_m_openid"))
+	if userId == "" {
 		return errors.New("未登录")
 	}
 	//数据预览每天限制50次
-	incurKey := fmt.Sprintf("PreviewData_%s_%d", d.GetSession("s_m_openid"), time.Now().Day())
+	incurKey := fmt.Sprintf("PreviewData_%s_%d", d.GetSession("userId"), time.Now().Day())
 	times := util.IntAll(redis.Get("other", incurKey))
 	if times >= 50 {
 		return errors.New("超出预览次数")
@@ -634,10 +644,11 @@ func (d *DataExport) SendMailVerify() {
 		var email_used = true
 		if email != d.GetSession("DataExportVerifyEmail") {
 			d.DelSession("CreatEVerifyTime")
-			openid := util.ObjToString(d.GetSession("s_m_openid"))
+			//			openid := util.ObjToString(d.GetSession("s_m_openid"))
+			userId := util.ObjToString(d.GetSession("userId"))
 			emails := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
-				"user_mail":   email,
-				"user_openid": openid,
+				"user_mail": email,
+				"user_id":   userId,
 			}, "user_mail", "")
 			if emails != nil && util.ObjToString((*emails)["user_mail"]) != "" {
 				email_used = false
@@ -651,7 +662,7 @@ func (d *DataExport) SendMailVerify() {
 		if email_used {
 			lastSendDEVerify := util.Int64All(d.GetSession("CreatEVerifyTime"))
 			timeSpaceing := lastSendDEVerify - time.Now().Unix() + 60*5
-			incurKey := fmt.Sprintf("SendEmail_%s_%d", d.GetSession("s_m_openid"), time.Now().Day())
+			incurKey := fmt.Sprintf("SendEmail_%s_%d", d.GetSession("userId"), time.Now().Day())
 			//log.Println(incurKey)
 			if lastSendDEVerify == 0 || timeSpaceing < 0 {
 				//每日限制10次
@@ -735,12 +746,13 @@ func isEmail(value string) bool {
 }
 func (d *DataExport) Paysuccess() error {
 	code := d.GetString("code")
-	openid, _ := d.GetSession("s_m_openid").(string)
+	//	openid, _ := d.GetSession("s_m_openid").(string)
+	userId, _ := d.GetSession("userId").(string)
 	data := map[string]interface{}{}
-	if code != "" && openid != "" {
+	if code != "" && userId != "" {
 		data_ := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
 			"order_code":   code,
-			"user_openid":  openid,
+			"user_id":      userId,
 			"order_status": 1,
 		}, "pay_way,user_mail,pay_time,pay_money,order_money", "")
 

+ 31 - 25
src/jfw/pay/weixin.go

@@ -296,12 +296,15 @@ func (c *WxPayAction) Qr(code string) error {
 	_, err := w.Write(pngdat)
 	return err
 }
+
+//20190719移动端数据导出 openid改成userid
 func (p *WxPayAction) SacnPay_CreateOrder() {
 	defer util.Catch()
 	openId, _ := p.GetSession("s_m_openid").(string)
+	userId, _ := p.GetSession("userId").(string)
 	id := util.SE.Decode4Hex(p.GetString("id"))
-	if openId == "" || id == "" {
-		log.Println("openId,id错误", openId, id)
+	if userId == "" || id == "" {
+		log.Println("userId,id错误", userId, id)
 		p.ServeJson(map[string]interface{}{
 			"status": "n",
 		})
@@ -323,22 +326,22 @@ func (p *WxPayAction) SacnPay_CreateOrder() {
 	}
 	//先看有没有创建过预支付订单
 	oldOrder := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
-		"user_openid": openId,
-		"filter_id":   id,
+		"user_id":   userId,
+		"filter_id": id,
 	}, "id,order_status,order_code,order_money,user_mail,user_phone,data_spec,prepay_time", "")
 	if oldOrder != nil {
 		if user_mail != "" && user_mail != util.ObjToString((*oldOrder)["user_mail"]) {
 			public.Mysql.Update("dataexport_order", map[string]interface{}{
-				"user_openid": openId,
-				"filter_id":   id,
+				"user_id":   userId,
+				"filter_id": id,
 			}, map[string]interface{}{
 				"user_mail": user_mail,
 			})
 		}
 		if user_phone != "" && user_phone != util.ObjToString((*oldOrder)["user_phone"]) {
 			public.Mysql.Update("dataexport_order", map[string]interface{}{
-				"user_openid": openId,
-				"filter_id":   id,
+				"user_id":   userId,
+				"filter_id": id,
 			}, map[string]interface{}{
 				"user_phone": user_phone,
 			})
@@ -367,8 +370,8 @@ func (p *WxPayAction) SacnPay_CreateOrder() {
 			prepayTime, _ := time.ParseInLocation(util.Date_Full_Layout, util.ObjToString((*oldOrder)["prepay_time"]), time.Local)
 			surplus_second := prepayTime.Unix() - 7200 //价格变动  支付二维码更新成超时状态--重新生订单二维码
 			public.Mysql.Update("dataexport_order", map[string]interface{}{
-				"user_openid": openId,
-				"filter_id":   id,
+				"user_id":   userId,
+				"filter_id": id,
 			}, map[string]interface{}{
 				"data_spec":      data_spec,
 				"order_money":    order_money,
@@ -381,11 +384,11 @@ func (p *WxPayAction) SacnPay_CreateOrder() {
 			p.ServeJson(map[string]interface{}{
 				"status": "y",
 				"code":   util.ObjToString((*oldOrder)["order_code"]),
-				"token":  public.GetWaitPayToken(util.Int64All((*oldOrder)["id"]), util.IntAll((*oldOrder)["order_money"]), util.ObjToString((*oldOrder)["order_code"]), openId),
+				"token":  public.GetWaitPayToken(util.Int64All((*oldOrder)["id"]), util.IntAll((*oldOrder)["order_money"]), util.ObjToString((*oldOrder)["order_code"]), userId),
 			})
 			return
 		} else {
-			log.Println("该订单已存在,订单状态不允许支付!", openId)
+			log.Println("该订单已存在,订单状态不允许支付!", userId)
 			p.ServeJson(map[string]interface{}{
 				"status": "n",
 			})
@@ -439,7 +442,7 @@ func (p *WxPayAction) SacnPay_CreateOrder() {
 			filterByte, _ := json.Marshal(userfilter)
 			filter = string(filterByte)
 		} else {
-			log.Println("id is not find in mongodb", openId, id)
+			log.Println("id is not find in mongodb", userId, id)
 			return false
 		}
 		return true
@@ -478,12 +481,13 @@ func (p *WxPayAction) SacnPay_CreateOrder() {
 					"filter_publishtime": filter_publishtime,
 					"filter_keys":        filter_keys,
 					"filter_id":          id,
+					"user_id":            userId, //20190719 移动端数据导出 生订单添加用户id
 				})
 				if orderid > 0 {
 					p.SetSession("DataExportVerifyPhone_val", user_phone)
 					result["status"] = "y"
 					result["code"] = ordercode
-					result["token"] = public.GetWaitPayToken(orderid, order_money, ordercode, openId)
+					result["token"] = public.GetWaitPayToken(orderid, order_money, ordercode, userId)
 				}
 			} else {
 				log.Println("生成预支付交易单失败", ret)
@@ -495,33 +499,34 @@ func (p *WxPayAction) SacnPay_CreateOrder() {
 func (p *WxPayAction) SacnPay_WaitPay() error {
 	defer util.Catch()
 	openid, _ := p.GetSession("s_m_openid").(string)
+	userid, _ := p.GetSession("userId").(string)
 	code := p.GetString("code")
 	token := p.GetString("token")
 	surplus, money, qrcode := func() (int64, int, string) {
-		if openid == "" || code == "" || token == "" {
+		if userid == "" || code == "" || token == "" {
 			return 0, 0, ""
 		}
-		data := public.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": code, "user_openid": openid}, "id,code_url,prepay_time,order_money,order_status", "")
+		data := public.Mysql.FindOne("dataexport_order", map[string]interface{}{"order_code": code, "user_id": userid}, "id,code_url,prepay_time,order_money,order_status", "")
 		if data == nil {
-			log.Println("订单号不存在!", openid)
+			log.Println("订单号不存在!", userid)
 			return 0, 0, ""
 		}
 		if util.IntAll((*data)["order_status"]) != 0 {
-			log.Println("订单状态不允许支付!", openid)
+			log.Println("订单状态不允许支付!", userid)
 			return 0, 0, ""
 		}
 		orderid := util.Int64All((*data)["id"])
 		orderMoney := util.IntAll((*data)["order_money"])
-		realToken := public.GetWaitPayToken(orderid, orderMoney, code, openid)
+		realToken := public.GetWaitPayToken(orderid, orderMoney, code, userid)
 		if realToken != token {
-			log.Println("token错误!", openid, realToken, token)
+			log.Println("token错误!", userid, realToken, token)
 			return 0, 0, ""
 		}
 		prepayTime, err := time.ParseInLocation(util.Date_Full_Layout, util.ObjToString((*data)["prepay_time"]), time.Local)
 		surplus_second := prepayTime.Unix() + 7200 - time.Now().Unix()
 		codeUrl := util.ObjToString((*data)["code_url"])
 		if err == nil && surplus_second <= 0 {
-			log.Println("二维码已失效,重新生成预订单!", openid)
+			log.Println("二维码已失效,重新生成预订单!", userid)
 			surplus_second = 0
 			//重新生成预订单
 			tradeno, ret := public.WxStruct.CreatePrepayOrder(config.Sysconfig["weixinrpc"].(string), "b", p.IP(), openid, "", orderMoney)
@@ -553,12 +558,13 @@ func (p *WxPayAction) SacnPay_WaitPay() error {
 func (p *WxPayAction) IsPaySuccess() {
 	defer util.Catch()
 	code := p.GetString("code")
-	openid, _ := p.GetSession("s_m_openid").(string)
+	//	openid, _ := p.GetSession("s_m_openid").(string)
+	userId, _ := p.GetSession("userId").(string)
 	status := "n"
-	if code != "" || openid != "" {
+	if code != "" || userId != "" {
 		data := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
-			"order_code":  code,
-			"user_openid": openid,
+			"order_code": code,
+			"user_id":    userId,
 		}, "order_status", "")
 		if data != nil && util.IntAll((*data)["order_status"]) == 1 {
 			status = "y"

+ 3 - 2
src/jfw/public/dataexport.go

@@ -75,6 +75,7 @@ func (w *WeixinStruct) GetTradeno(tp string) string {
 }
 
 //tradeno a 打赏 b pc端数据导出
+//20190719 移动端数据导出开发需要把openid改成userid 发现数据导出生订单并没有用openid字段 暂不作改变。-王山
 func (w *WeixinStruct) CreatePrepayOrder(weixinrpc, tradeno, ip, openid, detailmsg string, totalfee int) (string, *map[string]string) {
 	defer util.Catch()
 	attachmsg, bodymsg := "", ""
@@ -524,8 +525,8 @@ func SendMailToPayUser(order *map[string]interface{}, order_money float64, pay_t
 		}
 	}
 }
-func GetWaitPayToken(orderid int64, order_money int, ordercode, openId string) string {
-	return util.GetMd5String(fmt.Sprintf("%d_%d_%s_%s", orderid, order_money, ordercode, openId))
+func GetWaitPayToken(orderid int64, order_money int, ordercode, userid string) string {
+	return util.GetMd5String(fmt.Sprintf("%d_%d_%s_%s", orderid, order_money, ordercode, userid))
 }
 func GetOrderCode(id string) string {
 	return fmt.Sprintf("%s%s", time.Now().Format("150405"), util.GetRandom(6))

+ 1 - 1
src/web/templates/weixin/dataExport/dataExport_price.html

@@ -65,7 +65,7 @@
             window.location.href = "/front/wx_dataExport/toSieve"
         });
         //
-        if(localStorage.price !== ""){
+        if(localStorage.price !== ""&&localStorage.price!=undefined){
             var price = localStorage.price.replace("-","").split("万元");
             var prices = price.filter(function (e) {
                 return e !== "";