Browse Source

feat:会展活动

wangshan 2 years ago
parent
commit
eccdea7a41

+ 7 - 4
src/config.json

@@ -16,13 +16,13 @@
 	},
     "redis": {
     	"main": {
-			"address": "other=192.168.3.206:1712,session=192.168.3.206:1712"
+			"address": "other=192.168.3.11:1712,session=192.168.3.11:1713"
 		}
     },
     "mysql": {
 	    "main": {
 	        "dbName": "jianyu",
-	        "address": "192.168.3.11:3366",
+	        "address": "192.168.3.149:3366",
 	        "userName": "root",
 	        "passWord": "Topnet123",
 			"maxOpenConns": 5,
@@ -39,7 +39,7 @@
     },
 	"elasticsearch": {
 		"main": {
-			"address": "http://192.168.3.206:9800",
+			"address": "http://192.168.3.241:9205",
 	    	"size": 30,
 			"version": "v7",
 			"userName": "",
@@ -845,5 +845,8 @@
 			"maximum": 10,
 			"type": 4
 		}
-	]
+	],
+	"bindPopRedis": "merge",
+	"maxBindPop": 5,
+	"accountMergeOnline": "2015-03-30 00:00:00"
 }

+ 8 - 2
src/config.yaml

@@ -1,5 +1,11 @@
 etcd:
   hosts:
-  - 192.168.3.206:2379
+  - 192.168.3.149:2379
 powerCheckCenterKey: "powercheck.rpc" #权益校验中台
-userCenterKey: "usercenter.rpc" #用户中台rpc
+userCenterKey: "usercenter.rpc" #用户中台rpc
+
+appId: 10000
+userDoc:
+  key: jydocs.stdlib.rpc
+  address:
+    - 192.168.3.149:2379

+ 72 - 65
src/go.mod

@@ -1,125 +1,132 @@
 module salesLeads/src
 
-go 1.18
+go 1.20
 
 require (
-	app.yhyue.com/moapp/jybase v0.0.0-20230511020847-9b0fbc33ff1c
-	app.yhyue.com/moapp/jypkg v0.0.0-20230227093354-3184be71dc03
-	github.com/gogf/gf/v2 v2.3.1
+	app.yhyue.com/moapp/jybase v0.0.0-20230629025419-641ebbfdeaeb
+	app.yhyue.com/moapp/jypkg v0.0.0-20230712091846-607abb6659b8
+	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.13
+	github.com/gogf/gf/v2 v2.4.4
 )
 
 require (
 	app.yhyue.com/moapp/esv1 v0.0.0-20220414031211-3da4123e648d // indirect
+	app.yhyue.com/moapp/jyMarketing v0.0.2-0.20230304035551-21bb1eedf547 // indirect
 	app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae // indirect
 	bp.jydev.jianyu360.cn/BaseService/entManageApplication v0.0.0-20230214091519-89a98c01ab0e // indirect
 	bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20230222052351-9d6fad062447 // indirect
 	bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.7 // indirect
-	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.13 // indirect
 	github.com/BurntSushi/toml v1.1.0 // indirect
 	github.com/beorn7/perks v1.0.1 // indirect
-	github.com/cenkalti/backoff/v4 v4.1.3 // indirect
+	github.com/cenkalti/backoff/v4 v4.2.1 // indirect
 	github.com/cespare/xxhash/v2 v2.2.0 // indirect
 	github.com/clbanning/mxj/v2 v2.5.5 // indirect
-	github.com/coreos/go-semver v0.3.0 // indirect
-	github.com/coreos/go-systemd/v22 v22.3.2 // indirect
+	github.com/coreos/go-semver v0.3.1 // indirect
+	github.com/coreos/go-systemd/v22 v22.5.0 // indirect
 	github.com/davecgh/go-spew v1.1.1 // indirect
-	github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f // indirect
 	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
-	github.com/fatih/color v1.13.0 // indirect
-	github.com/felixge/fgprof v0.9.3 // indirect
-	github.com/fsnotify/fsnotify v1.5.4 // indirect
+	github.com/emicklei/go-restful/v3 v3.9.0 // indirect
+	github.com/fatih/color v1.15.0 // indirect
+	github.com/fsnotify/fsnotify v1.6.0 // indirect
 	github.com/garyburd/redigo v1.6.2 // indirect
-	github.com/go-logr/logr v1.2.3 // indirect
+	github.com/go-logr/logr v1.2.4 // indirect
 	github.com/go-logr/stdr v1.2.2 // indirect
+	github.com/go-openapi/jsonpointer v0.19.6 // indirect
+	github.com/go-openapi/jsonreference v0.20.1 // indirect
+	github.com/go-openapi/swag v0.22.3 // indirect
 	github.com/go-redis/redis/v8 v8.11.5 // indirect
-	github.com/go-sql-driver/mysql v1.7.0 // indirect
+	github.com/go-sql-driver/mysql v1.7.1 // indirect
 	github.com/gogo/protobuf v1.3.2 // indirect
-	github.com/golang-jwt/jwt/v4 v4.4.3 // indirect
+	github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
 	github.com/golang/mock v1.6.0 // indirect
-	github.com/golang/protobuf v1.5.2 // indirect
+	github.com/golang/protobuf v1.5.3 // indirect
 	github.com/golang/snappy v0.0.4 // indirect
-	github.com/gomodule/redigo v1.8.9 // indirect
+	github.com/gomodule/redigo v2.0.0+incompatible // indirect
+	github.com/google/gnostic v0.5.7-v3refs // indirect
 	github.com/google/go-cmp v0.5.9 // indirect
 	github.com/google/gofuzz v1.2.0 // indirect
-	github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
-	github.com/googleapis/gnostic v0.5.5 // indirect
 	github.com/gorilla/websocket v1.5.0 // indirect
 	github.com/grokify/html-strip-tags-go v0.0.1 // indirect
-	github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
+	github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect
 	github.com/howeyc/fsnotify v0.9.0 // indirect
 	github.com/jinzhu/inflection v1.0.0 // indirect
 	github.com/jinzhu/now v1.1.1 // indirect
 	github.com/josharian/intern v1.0.0 // indirect
 	github.com/json-iterator/go v1.1.12 // indirect
-	github.com/klauspost/compress v1.13.6 // indirect
-	github.com/magiconair/properties v1.8.6 // indirect
+	github.com/klauspost/compress v1.15.15 // indirect
+	github.com/magiconair/properties v1.8.7 // indirect
 	github.com/mailru/easyjson v0.7.7 // indirect
-	github.com/mattn/go-colorable v0.1.9 // indirect
-	github.com/mattn/go-isatty v0.0.14 // indirect
+	github.com/mattn/go-colorable v0.1.13 // indirect
+	github.com/mattn/go-isatty v0.0.17 // indirect
 	github.com/mattn/go-runewidth v0.0.13 // indirect
-	github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
+	github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
+	github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
 	github.com/nsqio/go-nsq v1.1.0 // indirect
 	github.com/olekukonko/tablewriter v0.0.5 // indirect
 	github.com/olivere/elastic v6.2.37+incompatible // indirect
 	github.com/olivere/elastic/v7 v7.0.22 // indirect
-	github.com/openzipkin/zipkin-go v0.4.0 // indirect
-	github.com/pelletier/go-toml/v2 v2.0.6 // indirect
+	github.com/openzipkin/zipkin-go v0.4.1 // indirect
+	github.com/pelletier/go-toml/v2 v2.0.8 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
-	github.com/prometheus/client_golang v1.13.0 // indirect
-	github.com/prometheus/client_model v0.2.0 // indirect
-	github.com/prometheus/common v0.37.0 // indirect
-	github.com/prometheus/procfs v0.8.0 // indirect
+	github.com/prometheus/client_golang v1.15.1 // indirect
+	github.com/prometheus/client_model v0.3.0 // indirect
+	github.com/prometheus/common v0.42.0 // indirect
+	github.com/prometheus/procfs v0.9.0 // indirect
 	github.com/rivo/uniseg v0.2.0 // indirect
 	github.com/spaolacci/murmur3 v1.1.0 // indirect
 	github.com/xdg-go/pbkdf2 v1.0.0 // indirect
 	github.com/xdg-go/scram v1.1.1 // indirect
 	github.com/xdg-go/stringprep v1.0.3 // indirect
 	github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
-	github.com/zeromicro/go-zero v1.4.4 // indirect
-	go.etcd.io/etcd/api/v3 v3.5.5 // indirect
-	go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
-	go.etcd.io/etcd/client/v3 v3.5.5 // indirect
-	go.mongodb.org/mongo-driver v1.11.1 // indirect
-	go.opentelemetry.io/otel v1.11.0 // indirect
-	go.opentelemetry.io/otel/exporters/jaeger v1.11.0 // indirect
-	go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.0 // indirect
-	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.0 // indirect
-	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.0 // indirect
-	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.10.0 // indirect
-	go.opentelemetry.io/otel/exporters/zipkin v1.11.0 // indirect
-	go.opentelemetry.io/otel/sdk v1.11.0 // indirect
-	go.opentelemetry.io/otel/trace v1.11.0 // indirect
+	github.com/zeromicro/go-zero v1.5.3 // indirect
+	go.etcd.io/etcd/api/v3 v3.5.9 // indirect
+	go.etcd.io/etcd/client/pkg/v3 v3.5.9 // indirect
+	go.etcd.io/etcd/client/v3 v3.5.9 // indirect
+	go.mongodb.org/mongo-driver v1.11.6 // indirect
+	go.opentelemetry.io/otel v1.15.1 // indirect
+	go.opentelemetry.io/otel/exporters/jaeger v1.15.1 // indirect
+	go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.15.1 // indirect
+	go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.15.1 // indirect
+	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.15.1 // indirect
+	go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.15.1 // indirect
+	go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0 // indirect
+	go.opentelemetry.io/otel/exporters/zipkin v1.15.1 // indirect
+	go.opentelemetry.io/otel/sdk v1.15.1 // indirect
+	go.opentelemetry.io/otel/trace v1.15.1 // indirect
 	go.opentelemetry.io/proto/otlp v0.19.0 // indirect
-	go.uber.org/atomic v1.9.0 // indirect
-	go.uber.org/automaxprocs v1.5.1 // indirect
-	go.uber.org/multierr v1.8.0 // indirect
-	go.uber.org/zap v1.21.0 // indirect
-	golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
-	golang.org/x/net v0.5.0 // indirect
-	golang.org/x/oauth2 v0.4.0 // indirect
+	go.uber.org/atomic v1.10.0 // indirect
+	go.uber.org/automaxprocs v1.5.2 // indirect
+	go.uber.org/multierr v1.9.0 // indirect
+	go.uber.org/zap v1.24.0 // indirect
+	golang.org/x/crypto v0.6.0 // indirect
+	golang.org/x/net v0.10.0 // indirect
+	golang.org/x/oauth2 v0.7.0 // indirect
 	golang.org/x/sync v0.1.0 // indirect
-	golang.org/x/sys v0.4.0 // indirect
-	golang.org/x/term v0.4.0 // indirect
-	golang.org/x/text v0.6.0 // indirect
+	golang.org/x/sys v0.8.0 // indirect
+	golang.org/x/term v0.8.0 // indirect
+	golang.org/x/text v0.9.0 // indirect
 	golang.org/x/time v0.3.0 // indirect
 	google.golang.org/appengine v1.6.7 // indirect
-	google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
-	google.golang.org/grpc v1.53.0 // indirect
-	google.golang.org/protobuf v1.28.1 // indirect
+	google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
+	google.golang.org/grpc v1.56.1 // indirect
+	google.golang.org/protobuf v1.31.0 // indirect
 	gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
 	gopkg.in/inf.v0 v0.9.1 // indirect
 	gopkg.in/yaml.v2 v2.4.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 	gorm.io/driver/mysql v1.0.5 // indirect
 	gorm.io/gorm v1.21.3 // indirect
-	k8s.io/api v0.22.9 // indirect
-	k8s.io/apimachinery v0.22.9 // indirect
-	k8s.io/client-go v0.22.9 // indirect
-	k8s.io/klog/v2 v2.80.1 // indirect
-	k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2 // indirect
-	sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
-	sigs.k8s.io/yaml v1.2.0 // indirect
+	jygit.jydev.jianyu360.cn/ApplicationCenter/publicService v0.0.0-20230630032508-eefb06a4588e // indirect
+	k8s.io/api v0.26.3 // indirect
+	k8s.io/apimachinery v0.27.0-alpha.3 // indirect
+	k8s.io/client-go v0.26.3 // indirect
+	k8s.io/klog/v2 v2.90.1 // indirect
+	k8s.io/kube-openapi v0.0.0-20230307230338-69ee2d25a840 // indirect
+	k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
+	sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
+	sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
+	sigs.k8s.io/yaml v1.3.0 // indirect
 )

File diff suppressed because it is too large
+ 172 - 429
src/go.sum


+ 246 - 0
src/service/action/exhibition.go

@@ -0,0 +1,246 @@
+package action
+
+import (
+	util "app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+	"app.yhyue.com/moapp/jybase/mongodb"
+	"app.yhyue.com/moapp/jybase/redis"
+	"app.yhyue.com/moapp/jybase/usercenter"
+	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
+	"fmt"
+	"log"
+	. "salesLeads/src/service/config"
+	. "salesLeads/src/service/util"
+	"strings"
+	"time"
+)
+
+var (
+	ExhibitionMap = map[string]bool{}
+	MergeUrl      = "/weixin/frontPage/userMerge/free/index"
+)
+
+type ExhibitionStruct struct{}
+
+var exh = ExhibitionStruct{}
+
+// 提交留资信息后 处理会展跳转地址
+func (w *ExhibitionStruct) GetExhibitionActiveHref(email, phone, source string, session *httpsession.Session) (href string) {
+	if !ExhibitionMap[source] {
+		return
+	}
+	//是否需要账号合并--未绑定手机号
+	var (
+		mgoUserId = session.Get("mgoUserId").(string)
+		token     = ""
+	)
+	//phone  绑定此手机号
+	if thisPhone, _ := session.Get("phone").(string); thisPhone == "" {
+		//进行手机号绑定-1、新用户绑定手机号后强制合并;2、老用户绑定手机号让用户自己选择账号合并
+		token = AccountMerge(phone, email, mgoUserId, session)
+	}
+	fmt.Println(phone, "------")
+	//留资福利 及 留资后跳转地址
+	if res := w.ExhibitionActive("", source, session, "second_ad_code,guide_page,welfare_type,welfare_content"); res != nil {
+		href = util.ObjToString(res["toDirect"])
+	}
+	if token != "" {
+		href = fmt.Sprintf("%s?%stoDirect=%s", MergeUrl, fmt.Sprintf("token=%s&", token), href)
+	}
+	session.Del("relationPhoneId")
+	return
+}
+
+// 活动展会接口
+func (w *ExhibitionStruct) ExhibitionActive(host, source string, session *httpsession.Session, params string) map[string]interface{} {
+	var res = map[string]interface{}{}
+	sql := fmt.Sprintf(`SELECT %s FROM exhibition_active WHERE ex_code = ? AND state = 0;`, params)
+	if activeInfos := Base.SelectBySql(sql, source); activeInfos != nil && len(*activeInfos) > 0 {
+		ExhibitionMap[source] = true
+		activeInfo := (*activeInfos)[0]
+		switch {
+		case strings.Contains("first_ad_code", params):
+			res["bindOrNot"] = false
+			if session.Get("phone") == "" {
+				res["bindOrNot"] = true
+			}
+			res["adList"] = w.GetJyAdList(host, util.ObjToString(activeInfo["first_ad_code"]))
+		case strings.Contains("second_ad_code", params):
+			//福利
+			go ExhibitionWelfare(session, util.Int64All(activeInfo["welfare_type"]), util.ObjToString(activeInfo["welfare_content"]))
+			res["toDirect"] = fmt.Sprintf("%s?ad=%s", util.ObjToString("guide_page"), util.ObjToString("second_ad_code"))
+		}
+	}
+	return res
+}
+
+// 福利
+func ExhibitionWelfare(session *httpsession.Session, welfareType int64, welfareContent string) {
+	if welfareContent != "" {
+		switch welfareType {
+		case 0: //文库
+			for _, docId := range strings.Split(welfareContent, ",") {
+				go func(userId, docId string) {
+					//resp, err := UserDocLib.DocDownload(context.Background(), &userlib.UserCollectRequest{
+					//	AppId:  AppId,
+					//	UserId: userId,
+					//	DocId:  docId,
+					//})
+					//if err != nil {
+					//	log.Printf("%s userDocLib call error %v\n", userId, err)
+					//}
+					//if resp.Code != 1 {
+					//	log.Printf("%s getDoc fail Message %v\n", userId, resp.Message)
+					//}
+				}(session.Get("mgoUserId").(string), docId)
+			}
+		}
+	}
+}
+
+// GetJyAdList 广告位
+func (w *ExhibitionStruct) GetJyAdList(host, code string) (adInfo []jy.AdInfo) {
+	obj := redis.Get("other", "ad_"+code)
+	if obj != nil {
+		adInfo = jy.Handle(obj.([]interface{}), host)
+	} else {
+		res, ok := MQFW.FindOneByField("ad", `{"s_code":"`+code+`"}`, `{"a_son":1}`)
+		if ok && res != nil && (*res)["a_son"] != nil {
+			son := (*res)["a_son"].([]interface{})
+			if len(son) > 0 {
+				redis.Put("other", "ad_"+code, son, int(jy.GetLastTime()))
+			}
+			adInfo = jy.Handle(son, host)
+		}
+	}
+	return adInfo
+}
+
+// AccountMerge 账号合并
+func AccountMerge(phone, email, mgoUserId string, sess *httpsession.Session) (token string) {
+	if userinfo := Compatible.Select(mgoUserId, `{"s_unionid":1,"s_name":1,"s_nickname":1,"s_headimageurl":1,"l_registedate":1,"i_ispush":1,"i_applystatus":1,"i_sex":1,"s_country":1,"s_province":1,"s_city":1,"s_m_openid":1,"a_m_openid":1,"base_user_id":1,"s_newsource":1,"l_registedate":1}`); userinfo != nil && len(*userinfo) > 0 {
+		//新用户时间
+		onLineTime, _ := time.ParseInLocation(date.Date_Full_Layout, Sysconfig.AccountMergeOnline, time.Local)
+		registerDate := util.Int64All((*userinfo)["l_registedate"])
+		reg := time.Unix(registerDate, 0)
+		relationPhoneId, _ := sess.Get("relationPhoneId").(string)
+		//新账号
+		if relationPhoneId == "" {
+			data := map[string]interface{}{
+				"s_unionid":      (*userinfo)["s_unionid"],
+				"s_name":         (*userinfo)["s_name"],
+				"s_nickname":     (*userinfo)["s_nickname"],
+				"s_headimageurl": (*userinfo)["s_headimageurl"],
+			}
+			if jy.IsEmail(email) {
+				data["s_email"] = email
+			}
+			//建立关联关系
+			if bindErr := jy.NewPhoneUtil(MQFW).BindPhone(mgoUserId, relationPhoneId, phone, email, &data); bindErr != nil {
+				log.Println("bind link err :", bindErr)
+			} else {
+				//用户中台存储  开始
+				if uinfo := jy.GetInfoForBaseUser(MQFW, mgoUserId); uinfo != nil {
+					jy.UpdateUser(MQFW, mgoUserId, *uinfo, *Middleground)
+				} else {
+					log.Println("--用户中台存储 异常--")
+				}
+				//用户中台存储  结束
+				jy.CreateUserMerge(MQFW, Mysql, sess, Middleground).FlushSession(mgoUserId) //刷新session
+			}
+		} else if onLineTime.Before(reg) { //新微信用户直接绑定
+			data := map[string]interface{}{
+				"s_unionid":      (*userinfo)["s_unionid"],
+				"s_name":         (*userinfo)["s_name"],
+				"s_nickname":     (*userinfo)["s_nickname"],
+				"s_headimageurl": (*userinfo)["s_headimageurl"],
+				"i_ispush":       (*userinfo)["i_ispush"],
+				"i_applystatus":  (*userinfo)["i_applystatus"],
+				"i_sex":          (*userinfo)["i_sex"],
+				"s_country":      (*userinfo)["s_country"],
+				"s_province":     (*userinfo)["s_province"],
+				"s_city":         (*userinfo)["s_country"],
+				"s_m_openid":     (*userinfo)["s_m_openid"],
+				"a_m_openid":     (*userinfo)["a_m_openid"],
+				"o_jy.i_wxpush":  1,
+			}
+			if jy.IsEmail(email) {
+				data["s_email"] = email
+			}
+			if Compatible.Update(relationPhoneId, map[string]interface{}{
+				"$set": data,
+			}) {
+				//用户中台存储  开始
+				if uinfo := jy.GetInfoForBaseUser(MQFW, mongodb.BsonIdToSId(relationPhoneId)); uinfo != nil {
+					jy.UpdateUser(MQFW, mongodb.BsonIdToSId(relationPhoneId), *uinfo, *Middleground)
+				}
+				//删除user
+				base_userid_del := usercenter.GetBaseUserId(MQFW, mgoUserId)
+				jy.DelUser(MQFW, mgoUserId, pb.UserIdReq{
+					Appid: "10000",
+					Id:    base_userid_del,
+				}, *Middleground)
+				//备份用户
+				if backUser, _ := MQFW.FindById("user", mgoUserId, nil); backUser != nil && len(*backUser) > 0 {
+					backData := map[string]interface{}{
+						"l_mergeData":   time.Now().Unix(),
+						"s_userId":      mgoUserId,
+						"s_save_userId": relationPhoneId,
+						"mergeType":     "autoMerge",
+					}
+					for k, v := range *backUser {
+						if k == "_id" {
+							continue
+						}
+						backData[k] = v
+					}
+					if MQFW.Save("user_merge", backData) != "" {
+						MQFW.Del("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(mgoUserId)})
+						jy.CreateUserMerge(MQFW, Mysql, sess, Middleground).FlushSession(relationPhoneId)
+						redis.Put("session", fmt.Sprintf("usermerge_delete_%s", mgoUserId), relationPhoneId, 7*24*60*60)
+					} else {
+						log.Println("备份用户查询异常")
+					}
+				} else {
+					log.Println("没有备份用户或备份用户查询异常")
+				}
+			} else {
+				log.Println("账号 中台 更新异常")
+			}
+			log.Println(fmt.Errorf("账号自动合并异常"))
+		} else { //老微信用户选择合并
+			go CollectPhone(mgoUserId, phone) //增加user表验证手机号
+			token = jy.MergeEncrypt.Encode2Hex(mgoUserId + "&&" + relationPhoneId)
+		}
+	}
+	return
+}
+
+// 是否需要强制合并账号
+func NeedBind(uid string) bool {
+	if uid != "" {
+		if userinfo, ok := MQFW.FindById("user", uid, `{"s_phone":1,"s_m_phone":1,"l_registedate":1}`); userinfo != nil && ok && len(*userinfo) > 0 {
+			s_phone := util.ObjToString((*userinfo)["s_phone"])
+			if s_phone == "" {
+				s_phone = util.ObjToString((*userinfo)["s_m_phone"])
+			}
+			if s_phone != "" {
+				return false
+			}
+			registedate := util.Int64All((*userinfo)["l_registedate"])
+			reg := time.Unix(registedate, 0)
+			//新用户时间
+			onLineTime, _ := time.ParseInLocation(date.Date_Full_Layout, Sysconfig.AccountMergeOnline, time.Local)
+			if onLineTime.Before(reg) { //新用户
+				return true
+			}
+			key := fmt.Sprintf("bindPop_new_%s", uid)
+			if redis.GetInt(Sysconfig.BindPopRedis, key) >= Sysconfig.MaxBindPop {
+				return true
+			}
+		}
+	}
+	return false
+}

+ 70 - 41
src/service/action/info.go

@@ -51,11 +51,13 @@ type NewResultSales struct {
 	Error_msg  string      `json:"error_msg"`
 	Data       interface{} `json:"data"`
 	Url        string      `json:"url"`
+	ActiveHref string      `json:"activeHref"`
 }
 
 type FuncResult struct {
 	Data       interface{}            `json:"data"`
 	Info       map[string]interface{} `json:"info"`
+	Active     map[string]interface{} `json:"active"`
 	Error_code int                    `json:"error_code"`
 	Error_msg  string                 `json:"error_msg"`
 }
@@ -78,10 +80,20 @@ func (i *Info) CollectInfo() {
 			return NewResultSales{Data: nil, Error_msg: Error_msg_1002}
 		}
 		//验证
-		phone := qu.ObjToString(infoMap["phone"])   //手机号
-		mail := qu.ObjToString(infoMap["mail"])     //邮箱
-		source := qu.ObjToString(infoMap["source"]) //来源
+		phone := qu.ObjToString(infoMap["phone"]) //手机号
+		if !phoneReg.MatchString(phone) {
+			return NewResultSales{Error_code: -1, Error_msg: "手机号格式有误", Data: false}
+		}
 		i.Session().Set("sales_MyPhone", phone)
+		mail := qu.ObjToString(infoMap["mail"]) //邮箱
+		if mail != "" && !emailReg.MatchString(mail) {
+			return NewResultSales{Error_code: -1, Error_msg: "邮箱格式有误", Data: false}
+		}
+		//获取用户id
+		userid, _ := i.GetSession("userId").(string)
+		if userid != "" {
+			infoMap["userid"] = userid
+		}
 		if infoMap["code"] != nil {
 			phoneCode := qu.ObjToString(infoMap["code"])
 			i.Session().Set("sales_MsgCode", phoneCode)
@@ -89,6 +101,7 @@ func (i *Info) CollectInfo() {
 		if publishId := qu.ObjToString(infoMap["publish_id"]); publishId != "" {
 			infoMap["publish_id"] = strings.Join(encrypt.DecodeArticleId2ByCheck(publishId), ",")
 		}
+		source := qu.ObjToString(infoMap["source"]) //来源
 		//企业验证
 		if Sysconfig.Source[source] != nil && Sysconfig.Source[source].EntValidation {
 			entName := qu.ObjToString(infoMap["company"])
@@ -98,16 +111,17 @@ func (i *Info) CollectInfo() {
 		}
 		//三级页面留资带有发布id时解密
 		//手机号验证码验证
-		if Sysconfig.Source[source] != nil && Sysconfig.Source[source].CheckCode {
+		if Sysconfig.Source[source] != nil && Sysconfig.Source[source].CheckCode || ExhibitionMap[source] { //展会活动 需要验证手机号
 			code := qu.ObjToString(infoMap["code"]) //手机号验证码
 			var checkCodeBool = false
-			//非绑定手机号需要验证
+			//已绑定手机号 判断 当前手机号是否已绑定手机号
 			log.Println(phone, "-------", i.Session().Get("sales_MyPhone"))
 			if i.Session().Get("sales_MyPhone") != nil && phone == i.Session().Get("sales_MyPhone").(string) {
 				checkCodeBool = true
 			}
-			//验证短信验证码
+			//非绑定手机号需要验证
 			if !checkCodeBool && i.Session().Get("sales_phoneNum") != nil && i.Session().Get("sales_MsgCode") != nil {
+				//验证短信验证码
 				if phone == i.Session().Get("sales_phoneNum").(string) && code == i.Session().Get("sales_MsgCode").(string) {
 					checkCodeBool = true
 				}
@@ -117,17 +131,6 @@ func (i *Info) CollectInfo() {
 			}
 		}
 		infoMap["createtime"] = time.Now().Unix()
-		//获取用户id
-		userid, _ := i.GetSession("userId").(string)
-		if !phoneReg.MatchString(phone) {
-			return NewResultSales{Error_code: -1, Error_msg: "手机号格式有误", Data: false}
-		}
-		if mail != "" && !emailReg.MatchString(mail) {
-			return NewResultSales{Error_code: -1, Error_msg: "邮箱格式有误", Data: false}
-		}
-		if userid != "" {
-			infoMap["userid"] = userid
-		}
 
 		href := ""
 		now := time.Now()
@@ -154,8 +157,7 @@ func (i *Info) CollectInfo() {
 			if strings.HasSuffix(source, "_freeuser") && len(strings.Split(source, "_")) > 2 && Free_users(source, userid) {
 				FreeuserManage(source, userid)
 			}
-
-			return NewResultSales{Error_code: 1, Error_msg: "", Data: true, Url: href}
+			return NewResultSales{Error_code: 1, Error_msg: "", Data: true, Url: href, ActiveHref: exh.GetExhibitionActiveHref(mail, phone, source, i.Session())} //会展活动---
 		}
 		return NewResultSales{Error_code: -1, Error_msg: "保存失败", Data: false}
 	}()
@@ -233,45 +235,72 @@ func (i *Info) RetainedCapital() {
 	userId, _ := sessVal["userId"].(string)
 	mgoUserId, _ := sessVal["mgoUserId"].(string)
 	data, phone := Whether.CNode(mgoUserId, userId, i.Session())
-	i.SetSession("sales_MyPhone", phone)
+	if phone != nil {
+		i.SetSession("sales_MyPhone", phone)
+	}
 	i.ServeJson(FuncResult{Data: M{
 		"retainedCapital": Whether.Do(userId, source, i.Session()),
 		"fource":          Sysconfig.Source[source] != nil && Sysconfig.Source[source].Force,
-	}, Info: data})
+	}, Info: data, Active: exh.ExhibitionActive(i.Request.Host, source, i.Session(), "first_ad_code")})
 }
 
 // 发送验证码
 func (i *Info) SendMsg() error {
 	defer qu.Catch()
-	userid := qu.ObjToString(i.GetSession("userId"))
+	userId := qu.ObjToString(i.GetSession("mgoUserId"))
 	var returnMap = map[string]interface{}{}
 	returnMap["success"] = false
-	if userid != "" {
+	if userId != "" {
 		session := i.Session()
 		phoneNum := i.GetString("phoneNum")
-		lastSendMsgTime := qu.Int64All(session.Get("sales_lastSendMsgTime"))
-		//当前时间-上次发送时间>60s
-		if time.Now().Unix()-lastSendMsgTime > 60 {
-			if phoneReg.MatchString(phoneNum) {
-				returnMap["success"] = true
-				//生成随机验证码
-				MsgCode := qu.GetRandom(6)
-				session.Set("sales_MsgCode", MsgCode)
-				session.Set("sales_phoneNum", phoneNum)
-				session.Set("sales_lastSendMsgTime", time.Now().Unix())
-				go func() {
-					jy.SendSMS(Sysconfig.SmsServiceRpc, phoneNum, MsgCode)
+		msg := ""
+		if source := i.GetString("source"); source != "" && ExhibitionMap[source] {
+			//session中没有手机号,未绑定手机号,才判断当然手机号phoneNum是否已被占用
+			//未绑定手机号,在留资信息提交的时候 进行绑定手机号
+			if phone, _ := i.GetSession("phone").(string); phone == "" {
+				msg = func() string {
+					user, ok := MQFW.FindById("user", userId, `{"s_unionid":1}`)
+					if !ok || user == nil {
+						return "账号异常"
+					}
+					unionId, _ := (*user)["s_unionid"].(string)
+					if unionId == "" {
+						return "账号异常"
+					}
+					exists, relationPhoneId := jy.NewPhoneUtil(MQFW).BindPhoneIsOccupy(unionId, phoneNum)
+					if exists { //校验是否使用
+						return "手机号已被绑定"
+					}
+					i.Session().Set("relationPhoneId", relationPhoneId)
+					return ""
 				}()
-				fmt.Println("手机号码", phoneNum, "验证码", MsgCode)
+			}
+		}
+		if msg == "" {
+			lastSendMsgTime := qu.Int64All(session.Get("sales_lastSendMsgTime"))
+			//当前时间-上次发送时间>60s
+			if time.Now().Unix()-lastSendMsgTime > 60 {
+				if phoneReg.MatchString(phoneNum) {
+					returnMap["success"] = true
+					//生成随机验证码
+					MsgCode := qu.GetRandom(6)
+					session.Set("sales_MsgCode", MsgCode)
+					session.Set("sales_phoneNum", phoneNum)
+					session.Set("sales_lastSendMsgTime", time.Now().Unix())
+					go func() {
+						jy.SendSMS(Sysconfig.SmsServiceRpc, phoneNum, MsgCode)
+					}()
+					fmt.Println("手机号码", phoneNum, "验证码", MsgCode)
+				} else {
+					returnMap["msg"] = "phoneErr"
+				}
 			} else {
-				returnMap["msg"] = "phoneErr"
+				returnMap["msg"] = "sended"
+				returnMap["second"] = 60 - (time.Now().Unix() - lastSendMsgTime)
 			}
 		} else {
-			returnMap["msg"] = "sended"
-			returnMap["second"] = 60 - (time.Now().Unix() - lastSendMsgTime)
+			returnMap["msg"] = "outTime"
 		}
-	} else {
-		returnMap["msg"] = "outTime"
 	}
 	i.ServeJson(Result{Data: returnMap})
 	return nil

+ 1 - 2
src/service/action/whether.go

@@ -10,9 +10,8 @@ import (
 	"time"
 
 	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
-	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
-
 	"app.yhyue.com/moapp/jybase/redis"
+	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
 
 	qu "app.yhyue.com/moapp/jybase/common"
 	util "app.yhyue.com/moapp/jybase/common"

+ 16 - 0
src/service/config/config.go

@@ -5,6 +5,7 @@ import (
 
 	util "app.yhyue.com/moapp/jybase/common"
 	//elastic "app.yhyue.com/moapp/jybase/esv1"
+	//"app.yhyue.com/moapp/jy_docs/rpc/userlib/userlibclient"
 	elastic "app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jybase/mail"
 	mg "app.yhyue.com/moapp/jybase/mongodb"
@@ -69,6 +70,9 @@ type config struct {
 		Describe string `json:"describe,omitempty"`
 		Maximum  int    `json:"maximum,omitempty"`
 	} `json:"appNewSales"`
+	BindPopRedis       string
+	MaxBindPop         int
+	AccountMergeOnline string
 }
 
 type esConf struct {
@@ -120,6 +124,8 @@ var (
 	GmailAuth    []*mail.GmailAuth
 	Middleground *middleground.Middleground
 	Compatible   *compatible.Compatible
+	//UserDocLib   userlibclient.UserLib
+	AppId string
 )
 
 func init() {
@@ -202,4 +208,14 @@ func init() {
 		RegPowerCheckCenter(g.Cfg().MustGet(ctx, "powerCheckCenterKey").String()).
 		RegUserCenter(g.Cfg().MustGet(ctx, "userCenterKey").String())
 	Compatible = compatible.NewCompatible(&MQFW, Base, Mysql, Middleground)
+	//文库中台
+	//UserDocLib = userlibclient.NewUserLib(zrpc.MustNewClient(zrpc.RpcClientConf{
+	//	Etcd: discov.EtcdConf{
+	//		Key:   g.Cfg().MustGet(ctx, "userDoc.key").String(),
+	//		Hosts: g.Cfg().MustGet(ctx, "userDoc.address").Strings(),
+	//	},
+	//}))
+	//
+	AppId = g.Cfg().MustGet(ctx, "appId").String()
+	//
 }

+ 19 - 0
src/service/util/merge.go

@@ -0,0 +1,19 @@
+package util
+
+import (
+	. "salesLeads/src/service/config"
+)
+
+func CollectPhone(userId, phone string) bool {
+	if userId == "" || phone == "" {
+		return false
+	}
+	if !Compatible.Update(userId, map[string]interface{}{
+		"$addToSet": map[string]interface{}{
+			"a_collect_phone": phone,
+		},
+	}) {
+		return false
+	}
+	return true
+}

Some files were not shown because too many files changed in this diff