Browse Source

数据导出回显手机号和邮箱

wangkaiyue 4 years ago
parent
commit
3475ace621

+ 7 - 9
src/jfw/front/dataExport.go

@@ -418,17 +418,15 @@ func (d *DataExport) ToCreateOrderPage(_id string) error {
 
 	if resEmail == "" || resPhone == "" {
 		lastEmail, lastPhone := "", ""
-		if lastOrder := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
-			"user_id":      userId,
-			"product_type": "历史数据",
-		}, "user_mail,user_phone", "create_time desc"); lastOrder != nil && len(*lastOrder) > 0 { //若有上一个订单,邮箱和手机号则取上个订单中的
-			lastEmail, _ = (*lastOrder)["user_mail"].(string)
-			lastPhone, _ = (*lastOrder)["user_phone"].(string)
-		} else { //若无上个订单,则取用户账户中设置的手机号和邮箱
+		if lastPhone, lastEmail = dataexport.GetLastExportPhoneAndMail(public.Mysql, userId, util.ObjToString(d.GetSession("entUserId"))); lastPhone == "" || lastEmail == "" {
 			userData, _ := mongodb.FindById("user", userId, `{"s_myemail":1,"s_phone":1,"s_m_phone":1}`)
 			if userData != nil && len(*userData) > 0 {
-				lastEmail, _ = (*userData)["s_myemail"].(string)
-				lastPhone, _ = util.If((*userData)["s_phone"] != nil, (*userData)["s_phone"], (*userData)["s_m_phone"]).(string)
+				if lastEmail == "" {
+					lastEmail, _ = (*userData)["s_myemail"].(string)
+				}
+				if lastPhone == "" {
+					lastPhone, _ = util.If((*userData)["s_phone"] != nil, (*userData)["s_phone"], (*userData)["s_m_phone"]).(string)
+				}
 			}
 		}
 		if resEmail == "" && lastEmail != "" {

+ 7 - 9
src/jfw/front/ws_dataExport.go

@@ -321,17 +321,15 @@ func (w *WsDataExport) SubmitOrder() error {
 
 	if resEmail == "" || resPhone == "" {
 		lastEmail, lastPhone := "", ""
-		if lastOrder := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
-			"user_id":      userId,
-			"product_type": "历史数据",
-		}, "user_mail,user_phone", "create_time desc"); lastOrder != nil && len(*lastOrder) > 0 { //若有上一个订单,邮箱和手机号则取上个订单中的
-			lastEmail, _ = (*lastOrder)["user_mail"].(string)
-			lastPhone, _ = (*lastOrder)["user_phone"].(string)
-		} else { //若无上个订单,则取用户账户中设置的手机号和邮箱
+		if lastPhone, lastEmail = dataexport.GetLastExportPhoneAndMail(public.Mysql, userId, util.ObjToString(w.GetSession("entUserId"))); lastPhone == "" || lastEmail == "" {
 			userData, _ := mongodb.FindById("user", userId, `{"s_myemail":1,"s_phone":1,"s_m_phone":1}`)
 			if userData != nil && len(*userData) > 0 {
-				lastEmail, _ = (*userData)["s_myemail"].(string)
-				lastPhone, _ = util.If((*userData)["s_phone"] != nil, (*userData)["s_phone"], (*userData)["s_m_phone"]).(string)
+				if lastEmail == "" {
+					lastEmail, _ = (*userData)["s_myemail"].(string)
+				}
+				if lastPhone == "" {
+					lastPhone, _ = util.If((*userData)["s_phone"] != nil, (*userData)["s_phone"], (*userData)["s_m_phone"]).(string)
+				}
 			}
 		}
 		if resEmail == "" && lastEmail != "" {

+ 8 - 12
src/jfw/modules/app/src/app/front/ws_dataExport.go

@@ -266,9 +266,7 @@ func (w *WsDataExport) ToCreateOrderPage() error {
 		w.Render("/dataExport/404.html", &w.T)
 		return nil
 	}
-	//邮箱验证
-	//	w.DelSession("DataExportVerifyEmail_val")
-	//	w.DelSession("DataExportVerifyPhone_val")
+
 	resEmail, _ := w.GetSession("DataExportVerifyEmail_val").(string)
 	resPhone, _ := w.GetSession("DataExportVerifyPhone_val").(string)
 	if resEmail != "" {
@@ -283,17 +281,15 @@ func (w *WsDataExport) ToCreateOrderPage() error {
 
 	if resEmail == "" || resPhone == "" {
 		lastEmail, lastPhone := "", ""
-		if lastOrder := public.Mysql.FindOne("dataexport_order", map[string]interface{}{
-			"user_id":      userId,
-			"product_type": "历史数据",
-		}, "user_mail,user_phone", "create_time desc"); lastOrder != nil && len(*lastOrder) > 0 { //若有上一个订单,邮箱和手机号则取上个订单中的
-			lastEmail, _ = (*lastOrder)["user_mail"].(string)
-			lastPhone, _ = (*lastOrder)["user_phone"].(string)
-		} else { //若无上个订单,则取用户账户中设置的手机号和邮箱
+		if lastPhone, lastEmail = dataexport.GetLastExportPhoneAndMail(public.Mysql, userId, util.ObjToString(w.GetSession("entUserId"))); lastPhone == "" || lastEmail == "" {
 			userData, _ := mongodb.FindById("user", userId, `{"s_myemail":1,"s_phone":1,"s_m_phone":1}`)
 			if userData != nil && len(*userData) > 0 {
-				lastEmail, _ = (*userData)["s_myemail"].(string)
-				lastPhone, _ = util.If((*userData)["s_phone"] != nil, (*userData)["s_phone"], (*userData)["s_m_phone"]).(string)
+				if lastEmail == "" {
+					lastEmail, _ = (*userData)["s_myemail"].(string)
+				}
+				if lastPhone == "" {
+					lastPhone, _ = util.If((*userData)["s_phone"] != nil, (*userData)["s_phone"], (*userData)["s_m_phone"]).(string)
+				}
 			}
 		}
 		if resEmail == "" && lastEmail != "" {

+ 38 - 0
src/jfw/modules/common/src/qfw/util/dataexport/common.go

@@ -0,0 +1,38 @@
+package dataexport
+
+import (
+	"fmt"
+	"qfw/util/mysql"
+	"strings"
+)
+
+//GetLastExportPhoneAndMail 数据导出联想上次导出手机号和邮箱查询
+func GetLastExportPhoneAndMail(mysqlSess *mysql.Mysql, userId, entUserId string) (phone, email string) {
+	var searchSql []string
+	var searchValue []interface{}
+
+	if userId != "" {
+		//个人直接支付数据导出
+		searchSql = append(searchSql, `(SELECT user_phone AS phone,user_mail AS mail,UNIX_TIMESTAMP(service_time) AS exportDate FROM dataexport_order where user_mail  IS NOT NULL and user_phone is NOT NULL AND user_id =? AND product_type ='历史数据' ORDER BY create_time DESC LIMIT 1)`)
+		searchValue = append(searchValue, userId)
+
+		//每日限量包和个人线上数据包
+		searchSql = append(searchSql, `(SELECT phone,mail,date AS exportDate FROM datapacket_record WHERE  phone IS NOT NULL AND mail IS NOT NULL AND useid = ? ORDER BY id DESC LIMIT 1)`)
+		searchValue = append(searchValue, userId)
+
+	}
+
+	//企业数据导出查询
+	if entUserId != "" {
+		searchSql = append(searchSql, `(SELECT export_phone AS phone,export_mail AS mail,UNIX_TIMESTAMP(export_time) AS exportDate FROM entniche_export_log WHERE export_phone IS NOT NULL AND export_mail IS NOT NULL AND user_id =? ORDER BY id desc limit 1)`)
+		searchValue = append(searchValue, entUserId)
+	}
+
+	//log.Println(fmt.Sprintf(`SELECT phone,mail FROM ( %s ) AS allData ORDER BY exportDate DESC limit 1`, strings.Join(searchSql, ` UNION ALL `)))
+	res := mysqlSess.Query(fmt.Sprintf(`SELECT phone,mail FROM ( %s ) AS allData ORDER BY exportDate DESC limit 1`, strings.Join(searchSql, ` UNION ALL `)), searchValue...)
+	if res != nil && len(*res) > 0 {
+		phone, _ = (*res)[0]["phone"].(string)
+		email, _ = (*res)[0]["mail"].(string)
+	}
+	return
+}