Эх сурвалжийг харах

Merge branch 'master' of https://app.yhyue.com/moapp/jypkg into master

zhangxinlei1996 2 жил өмнө
parent
commit
e4d33621d3

+ 4 - 4
common/src/qfw/util/bidsearch/search.go

@@ -1,6 +1,8 @@
 package bidsearch
 
 import (
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+	"app.yhyue.com/moapp/jypkg/middleground"
 	"fmt"
 	"log"
 	"net/http"
@@ -389,12 +391,11 @@ func GetSearchQuery(keyword, industry, minprice, maxprice, hasBuyerTel, hasWinne
 	return
 }
 
-func PublicSearch(userId, selectType, publishtime string, bidSearchOldUserLimit int64, currentPage, pageSize int) (bool, string, []string, int, int) {
+func PublicSearch(userId, selectType, publishtime string, bidSearchOldUserLimit int64, currentPage, pageSize int, session *httpsession.Session, middleground middleground.Middleground) (bool, string, []string, int, int) {
 	var start int
-	vipStatus := jy.GetVipState(public.Mysql, public.MQFW, userId)
+	vipStatus := jy.GetVipState(session, middleground, userId)
 	isPayedUser := vipStatus.IsPayedUser()
 	queryItems := vipStatus.GetQueryItems(selectType, bidSearchOldUserLimit)
-
 	if publishtime == "" {
 		if isPayedUser {
 			publishtime = "fiveyear"
@@ -402,7 +403,6 @@ func PublicSearch(userId, selectType, publishtime string, bidSearchOldUserLimit
 			publishtime = "thisyear"
 		}
 	}
-
 	if isPayedUser {
 		//if currentPage > SearchMaxPageCount_PAYED {
 		//	currentPage = SearchMaxPageCount_PAYED

+ 7 - 199
common/src/qfw/util/jy/bigVipPower.go

@@ -6,12 +6,9 @@ import (
 	m "app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"app.yhyue.com/moapp/jybase/redis"
+	"app.yhyue.com/moapp/jypkg/middleground"
 	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/pb"
-	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck"
-	"context"
 	"fmt"
-	"github.com/zeromicro/go-zero/core/discov"
-	"github.com/zeromicro/go-zero/zrpc"
 	"log"
 	"strings"
 	"time"
@@ -149,13 +146,16 @@ func GetEntnicheState(userId string, mysql *mysql.Mysql, mg m.MongodbSim) *BigVi
 }
 
 // 获取大会员个人基本信息
-func GetBigVipUserBaseMsg(appid string, session *httpsession.Session, host, key string) *BigVipBaseMsg {
+func GetBigVipUserBaseMsg(session *httpsession.Session, middleground middleground.Middleground) *BigVipBaseMsg {
 	userId := qutil.ObjToString(session.Get("userId"))
 	baseUserId := qutil.Int64All(session.Get("base_user_id"))
 	entId := qutil.Int64All(session.Get("entId"))
 	positionType := qutil.Int64All(session.Get("positionType"))
+	accountId := qutil.Int64All(session.Get("accountId"))
+	positionId := qutil.Int64All(session.Get("positionId"))
 	userPower := BigVipBaseMsg{}
-	data := Check(appid, session, host, key)
+	log.Println("userId:", userId, "-baseUserId:", baseUserId, "-accountId:", accountId, "-entId:", entId, "-positionType:", positionType, "-baseUserId:", baseUserId, "-accountId:", accountId, "-entId:", entId, "-positionType:", positionType, "-positionId:", positionId)
+	data := middleground.PowerCheckCenter.Check("10000", userId, baseUserId, accountId, entId, positionType, positionId)
 	if positionType == 0 {
 		userId = qutil.InterfaceToStr(session.Get("userId"))
 	} else {
@@ -164,7 +164,7 @@ func GetBigVipUserBaseMsg(appid string, session *httpsession.Session, host, key
 	if data != nil {
 		power := make(map[int]bool)
 		for k, _ := range data.Member.MemberPowerList {
-			userPower.PowerMap[k] = true
+			power[k] = true
 		}
 		isEnt := 0
 		if data.Entniche.PowerSource != 1 && data.Entniche.Status == 1 {
@@ -217,201 +217,9 @@ func GetBigVipUserBaseMsg(appid string, session *httpsession.Session, host, key
 			}
 		}
 	}
-
-	/*userPower.PowerMap = make(map[int]bool)
-	  if userId == "" {
-	  	return &userPower
-	  }
-	  userPower.IsUpgrade = false
-	  userPower.Uid = userId
-	  cacheKey := fmt.Sprintf(PowerCacheKey, userId)
-
-	  if bytes, err := redis.GetBytes(BaseInfoCacheDb, cacheKey); err == nil && bytes != nil {
-	  	if err := json.Unmarshal(*bytes, &userPower); err == nil {
-	  		return &userPower
-	  	}
-	  }
-	  //大会员状态
-	  data, ok := mg.FindById("user", userId, `{"s_phone":1,"s_m_phone":1,i_member_status":1,"i_member_give":1,"s_member_mainid":1,"i_member_sub_status":1,"i_member_trial":1,"i_vip_status":1,"o_vipjy":1,"o_jy":1,"l_registedate":1,"s_myemail":1,"base_user_id":1}`)
-	  if ok && *data != nil && len(*data) > 0 {
-	  	userPower.Email = qutil.ObjToString((*data)["s_myemail"])
-	  	userPower.BaseUserId = qutil.IntAll((*data)["base_user_id"])
-	  	userPower.Registedate = qutil.Int64All((*data)["l_registedate"])
-	  	userPower.Status = qutil.IntAllDef((*data)["i_member_status"], 0)
-	  	//子账号被启用
-	  	i_member_sub_status := qutil.IntAllDef((*data)["i_member_sub_status"], 0)
-	  	if (*data)["s_member_mainid"] != nil && qutil.ObjToString((*data)["s_member_mainid"]) != "" && i_member_sub_status > 0 {
-	  		userPower.Pid = qutil.ObjToString((*data)["s_member_mainid"])
-	  	}
-	  	if (userPower.Pid != "" && qutil.IntAllDef((*data)["i_member_sub_status"], 0) == 1) || mg.Count("member", map[string]interface{}{"userid": userId}) > 0 {
-	  		userPower.Used = true
-	  	}
-	  	if (*data)["i_member_trial"] != nil {
-	  		userPower.HasTrial = true
-	  	}
-	  	if vipStatus := qutil.IntAll((*data)["i_vip_status"]); vipStatus > 0 {
-	  		userPower.VipStatus = vipStatus
-	  		if o_vipjy := qutil.ObjToMap((*data)["o_vipjy"]); o_vipjy != nil {
-	  			if o_buyset := qutil.ObjToMap((*o_vipjy)["o_buyset"]); o_buyset != nil {
-	  				userPower.Vip_BuySet = BuySet{
-	  					Upgrade:         qutil.IntAll((*o_buyset)["upgrade"]),
-	  					AreaCount:       qutil.IntAll((*o_buyset)["areacount"]),
-	  					BuyerclassCount: qutil.IntAll((*o_buyset)["buyerclasscount"]),
-	  				}
-	  			}
-	  		}
-	  		userPower.VipPowerType = 1
-	  	}
-	  	if userPower.Status > 0 {
-	  		userPower.MemberPowerType = 1
-	  	}
-	  	//免费用户画像和附件下载权限
-	  	//if userPower.Status <= 0 && userPower.VipStatus <= 0 {
-	  	o_jy := qutil.ObjToMap((*data)["o_jy"])
-	  	//"i_newfree":    1, //新免费用户=>新订阅设置页面 20211122
-	  	//IsNewFreeTimeCell dev3.6.4版本之前发了个紧急版本处理老用户订阅问题,i_newfree字段必须用户选择地区才能生成,不能作为判断是否是新用户得唯一标识,在此版本添加了常量:IsNewFreeTimeCell作为判断标准;--ws
-	  	if qutil.IntAll((*o_jy)["i_newfree"]) > 0 || IsNewFreeTimeCell < userPower.Registedate {
-	  		userPower.IsUpgrade = true
-	  	}
-	  	//}
-	  	//查询是否是商机管理付费用户
-	  	//userPower.EntnicheStatus = 0
-	  	phone, _ := qutil.If((*data)["s_phone"] != nil, (*data)["s_phone"], (*data)["s_m_phone"]).(string)
-	  	if phone != "" {
-	  		res := mysql.SelectBySql(`SELECT i. STATUS AS status, i.isNew, i.power_source, r.role_id, u.power, i.name,i.id FROM (entniche_user u LEFT JOIN entniche_user_role r ON r.user_id = u.id ) LEFT JOIN entniche_info i ON u.ent_id = i.id WHERE u.phone = ? ORDER BY i. STATUS DESC, i.auth_status DESC`, phone)
-	  		if res != nil && len(*res) > 0 {
-	  			userPower.EntInfo = map[int]*EntInfoStruct{}
-	  			//商机管理
-	  			userPower.EntName = qutil.ObjToString((*res)[0]["name"])
-	  			//已购买企业未过期-商机管理用户
-	  			for _, v := range *res {
-	  				if qutil.IntAll(v["id"]) == 0 {
-	  					continue
-	  				}
-	  				entId := qutil.IntAll(v["id"])
-	  				userPower.EntInfo[entId] = &EntInfoStruct{
-	  					IsNew:     qutil.IntAll(v["isNew"]) > 0,
-	  					IsPower:   qutil.IntAll(v["power"]) > 0,
-	  					Status:    qutil.IntAll(v["status"]),
-	  					Name:      qutil.ObjToString(v["name"]),
-	  					IsService: qutil.IntAll(v["power_source"]) > 0,
-	  					RoleId:    qutil.IntAll(v["role_id"]),
-	  				}
-	  				// 判断是否是新商机管理
-	  				if qutil.IntAll(v["status"]) == 1 && qutil.IntAll(v["power"]) == 1 {
-	  					userPower.EntnicheStatus = 1
-	  					if qutil.IntAll(v["isNew"]) == 1 {
-	  						userPower.EntIsNew = true
-	  						// if userPower.EntIsNew && userPower.IsEntService {
-	  						// 	break
-	  						// }
-	  					}
-	  				}
-	  				// 判断是否是商机管理服务 (在超级订阅或者大会员、医械通(暂无)的基础上才会有的)
-	  				// if qutil.IntAll(v["power_source"]) == 1 {
-	  				// 	userPower.IsEntService = true
-	  				// 	break
-	  				// }
-
-	  			}
-	  		}
-	  		// 如果是商机管理服务用户,则不能是旧版商机管理及新版商机管理
-	  		// if userPower.IsEntService {
-	  		// 	userPower.EntnicheStatus = 0 // 商机管理状态
-	  		// 	userPower.EntIsNew = false   // 新版商机管理
-	  		// }
-	  		//if count := mysql.CountBySql(`SELECT count(1) FROM entniche_user u LEFT JOIN entniche_info i ON u.ent_id=i.id WHERE u.phone=? and u.power=1 and i.status=1`, phone); count > 0 {
-	  		//	userPower.EntnicheStatus = 1
-	  		//}
-	  		//广东移动DICT 用户
-	  		userPower.PrivateGD = mysql.CountBySql(`select count(1) from privatedata where phone = ?`, phone) > 0
-
-	  		//用于判断是否含有企业主体的超级订阅、大会员服务
-	  		epowerData := mysql.SelectBySql(`SELECT c.product_type FROM entniche_user a INNER JOIN entniche_power b
-	  	 									INNER JOIN entniche_wait_empower c
-	  	 									ON a.id =b.ent_user_id  AND c.id = b.wait_empower_id WHERE a.phone =? AND c.end_time >?`, phone, time.Now().Format(Date_Full_Layout))
-	  		if epowerData != nil && len(*epowerData) > 0 {
-	  			for _, v := range *epowerData {
-	  				product_type := qutil.ObjToString(v["product_type"])
-	  				if strings.Contains(product_type, "VIP订阅") {
-	  					userPower.MemberPowerType = 2
-	  				} else if strings.Contains(product_type, "大会员") {
-	  					userPower.MemberPowerType = 2
-	  				}
-	  			}
-	  		}
-	  	}
-	  }
-
-	  //子账号查询父节点权限
-	  queryId := qutil.If(userPower.Pid == "", userId, userPower.Pid).(string)
-	  //用户购买的服务
-	  serviceList := mysql.Find(BigmemberUserPowerTable, map[string]interface{}{"s_userid": queryId, "i_status": 0}, "DISTINCT(s_serviceid),i_frequency", "", -1, -1)
-	  if serviceList != nil && len(*serviceList) != 0 {
-	  	pCount, eCount, dailyNum, customers := 0, 0, 0, 10
-	  	for _, item := range *serviceList {
-	  		serviceid := qutil.IntAll(item["s_serviceid"])
-	  		userPower.PowerMap[serviceid] = true
-	  		if serviceid == 14 { //项目数量
-	  			pCount = qutil.IntAll(item["i_frequency"])
-	  		} else if serviceid == 4 || serviceid == 12 || serviceid == 13 { //企业情报监控 企业中标动态
-	  			tEcount := qutil.IntAll(item["i_frequency"])
-	  			if tEcount > eCount {
-	  				eCount = tEcount
-	  			}
-	  		} else if serviceid == 17 || serviceid == 18 { //每日数据包
-	  			dailyNum = qutil.IntAll(item["i_frequency"])
-	  		} else if serviceid == 7 { //潜在客户 关注客户
-	  			customers = qutil.IntAll(item["i_frequency"])
-	  		}
-	  	}
-	  	userPower.EntNum = eCount
-	  	userPower.ProNum = pCount
-	  	userPower.DailyNum = dailyNum
-	  	userPower.Customers = customers
-	  }
-
-	  //存储缓存
-	  go func() {
-	  	if bytes, err := json.Marshal(userPower); err == nil && bytes != nil {
-	  		oneDayMore := OneDay + rand.Intn(60*60)
-	  		_ = redis.PutBytes(BaseInfoCacheDb, cacheKey, &bytes, oneDayMore)
-	  	}
-	  }()*/
 	userPower.Data = data
 	return &userPower
 }
-func Check(appid string, session *httpsession.Session, host, key string) *pb.CheckResp {
-	userId := qutil.ObjToString(session.Get("userId"))
-	baseUserId := qutil.Int64All(session.Get("base_user_id"))
-	entId := qutil.Int64All(session.Get("entId"))
-	accountId := qutil.Int64All(session.Get("accountId"))
-	positionType := qutil.Int64All(session.Get("positionType"))
-	client, err := zrpc.NewClient(zrpc.RpcClientConf{
-		Etcd: discov.EtcdConf{
-			Hosts: []string{host},
-			Key:   key,
-		},
-	})
-	if positionType == 0 {
-		userId = qutil.InterfaceToStr(session.Get("userId"))
-	} else {
-		userId = qutil.InterfaceToStr(session.Get("mgoUserId"))
-	}
-	if err != nil {
-		log.Println(err)
-		return nil
-	}
-	defer client.Conn().Close()
-	resp, err := powercheck.NewPowerCheck(client).Check(context.Background(), &pb.CheckReq{
-		Appid:      appid,
-		Userid:     userId,
-		BaseUserId: baseUserId,
-		AccountId:  accountId,
-		EntId:      entId,
-	})
-	return resp
-}
 
 // 权限判断
 func (this *BigVipBaseMsg) CheckBigVipFrontPower(reqFlag string) (pass bool) {

+ 17 - 42
common/src/qfw/util/jy/payUser.go

@@ -10,10 +10,10 @@ import (
 	"net/http"
 	"strings"
 
-	"app.yhyue.com/moapp/jybase/mongodb"
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+	"app.yhyue.com/moapp/jypkg/middleground"
 
 	qu "app.yhyue.com/moapp/jybase/common"
-	"app.yhyue.com/moapp/jybase/mysql"
 )
 
 //是否是付费用户
@@ -24,39 +24,26 @@ type VipState struct {
 	registerData int64 //注册时间
 }
 
-func GetVipState(mysql *mysql.Mysql, mg mongodb.MongodbSim, userId string) (vs *VipState) {
+func GetVipState(session *httpsession.Session, middleground middleground.Middleground, userId string) (vs *VipState) {
 	vs = &VipState{}
 	if userId == "" {
 		return
 	}
-	phone := ""
-	data, ok := mg.FindById("user", userId, `"i_member_status":1,"i_vip_status":1,"s_m_phone":1,"s_phone":1,"o_vipjy":1,"l_registedate":1`)
-	if data != nil && len(*data) > 0 && ok {
-		i_vip_status := qu.IntAll((*data)["i_vip_status"])
+	//data, ok := mg.FindById("user", userId, `"i_member_status":1,"i_vip_status":1,"s_m_phone":1,"s_phone":1,"o_vipjy":1,"l_registedate":1`)
+	data := GetBigVipUserBaseMsg(session, middleground)
+	if data != nil {
+		i_vip_status := data.Data.Vip.Status
 		if i_vip_status > 1 {
 			vs.VipState = 1
-			ovipjy, _ := (*data)["o_vipjy"].(map[string]interface{})
-			if ovipjy["o_buyset"] != nil {
-				o_buyset := ovipjy["o_buyset"].(map[string]interface{})
-				if o_buyset["upgrade"] != nil {
-					vs.VipState = 2
-				}
+			if data.Data.Vip.Upgrade > 0 {
+				vs.VipState = 2
 			}
 		}
-		if i_member_status := qu.IntAllDef((*data)["i_member_status"], 0); i_member_status > 0 {
-			vs.BigMember = i_member_status
+		if i_member_status := data.Data.Member.Status; i_member_status > 0 {
+			vs.BigMember = qu.IntAll(i_member_status)
 		}
-		if s_phone, _ := (*data)["s_phone"].(string); s_phone != "" {
-			phone = s_phone
-		} else if s_m_phone, _ := (*data)["s_m_phone"].(string); s_m_phone != "" {
-			phone = s_m_phone
-		}
-		if phone != "" {
-			if mysql.CountBySql(`select count(1) from entniche_user where phone = ? and power =1`, phone) > 0 {
-				vs.EntMember = 1
-			}
-		}
-		vs.registerData, _ = ((*data)["l_registedate"]).(int64)
+		vs.EntMember = qu.IntAll(data.Data.Entniche.Status)
+		vs.registerData = data.Data.Free.Registedate
 	}
 	return
 }
@@ -108,22 +95,10 @@ func (vs *VipState) GetQueryItems(selectType string, limitOldTime int64) (items
 }
 
 // HasBidFieldPower 获取用户是否有领域化数据权限
-func HasBidFieldPower(url string, userId string, functionCode string) bool {
-	// 是否开通过权益
-	header := map[string]string{
-		"newUserId": userId,
-	}
-	byJson, err := PostByJson(url, []byte(""), header)
-	if err != nil || byJson == nil {
-		log.Println("查询用户权益", url, userId, functionCode, err)
-		return false
-	}
-	if byJson != nil {
-		powerList := byJson["data"].([]interface{})
-		for i := 0; i < len(powerList); i++ {
-			if powerList[i] == functionCode {
-				return true
-			}
+func HasBidFieldPower(m *middleground.Middleground, userId int64, functionCode string) bool {
+	for _, v := range m.ResourceCenter.Haspowers(userId).Powers {
+		if v == functionCode {
+			return true
 		}
 	}
 	return false

+ 2 - 3
common/src/qfw/util/jy/subScribe.go

@@ -37,12 +37,10 @@ func GetSubScribeInfo(session *httpsession.Session, mg mongodb.MongodbSim, types
 		} else {
 			jyData = EntnicheSub(entUserId, entId, 1, mg)
 		}
-
 	case EntnicheFlag:
 		//商机管理
 		jyData = EntnicheSub(entUserId, entId, 0, mg)
 		log.Println("~~~", jyData)
-
 	case SubVipFlag:
 		//超级订阅
 		if positionType == 0 {
@@ -53,12 +51,12 @@ func GetSubScribeInfo(session *httpsession.Session, mg mongodb.MongodbSim, types
 		} else {
 			jyData = EntnicheSub(entUserId, entId, 1, mg)
 		}
-
 	case SubFreeFlag:
 		if positionType == 0 {
 			//个人
 			if (*data)["o_jy"] != nil {
 				ojy := common.ObjToMap((*data)["o_jy"])
+				object = ojy
 				if (*ojy)["a_key"] != nil {
 					akey := common.ObjArrToMapArr((*ojy)["a_key"].([]interface{}))
 					(*object)["a_items"] = []map[string]interface{}{ //转换至和其它结构一致
@@ -95,6 +93,7 @@ func EntnicheSub(entUserId, entId int64, types int64, mg mongodb.MongodbSim) *ma
 	if types == 2 {
 		if (*res)["o_entniche"] != nil {
 			ojy := common.ObjToMap((*res)["o_jy"])
+			object = ojy
 			if (*ojy)["a_key"] != nil {
 				akey := common.ObjArrToMapArr((*ojy)["a_key"].([]interface{}))
 				(*object)["a_items"] = []map[string]interface{}{ //转换至和其它结构一致

+ 28 - 29
common/src/qfw/util/jy/switchService.go

@@ -1,11 +1,8 @@
 package jy
 
 import (
-	util "app.yhyue.com/moapp/jybase/common"
-	. "app.yhyue.com/moapp/jybase/mongodb"
-	"app.yhyue.com/moapp/jybase/mysql"
-
 	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+	"app.yhyue.com/moapp/jypkg/middleground"
 )
 
 var SwitchService = &switchService{
@@ -30,14 +27,15 @@ type switchService struct {
  * @param mongodb
  * @return string 服务类型
  */
-func (s *switchService) Get(session *httpsession.Session, m MongodbSim) string {
-	userId, _ := session.Get("userId").(string)
+func (s *switchService) Get(session *httpsession.Session, middleground middleground.Middleground) string {
+	//userId, _ := session.Get("userId").(string)
 	v, _ := session.Get(s.SessionKey).(string)
-	u, ok := m.FindById("user", userId, `{"i_member_status":1,"i_vip_status":1}`)
-	if ok && u != nil {
-		if i_member_status := util.IntAll((*u)["i_member_status"]); v == s.Member && i_member_status > 0 {
+	data := GetBigVipUserBaseMsg(session, middleground)
+	//u, ok := m.FindById("user", userId, `{"i_member_status":1,"i_vip_status":1}`)
+	if data != nil {
+		if i_member_status := data.Status; v == s.Member && i_member_status > 0 {
 			return s.Member
-		} else if i_vip_status := util.IntAll((*u)["i_vip_status"]); v == s.Vip && i_vip_status > 0 {
+		} else if i_vip_status := data.VipStatus; v == s.Vip && i_vip_status > 0 {
 			return s.Vip
 		} else if i_member_status > 0 {
 			session.Set(s.SessionKey, s.Member)
@@ -51,24 +49,25 @@ func (s *switchService) Get(session *httpsession.Session, m MongodbSim) string {
 	return s.Free
 }
 
-func (s *switchService) GetEntniche(session *httpsession.Session, m MongodbSim, sql *mysql.Mysql) string {
+func (s *switchService) GetEntniche(session *httpsession.Session, middleground middleground.Middleground) string {
 	sessMap := session.GetMultiple()
-	userId, _ := sessMap["userId"].(string)
+	//userId, _ := sessMap["userId"].(string)
 	v, _ := sessMap[s.SessionKey].(string)
-	u, ok := m.FindById("user", userId, `{"i_member_status":1,"i_vip_status":1}`)
-	entniche := false
-	if entId, entUserId := util.IntAll(sessMap["entId"]), util.IntAll(sessMap["entUserId"]); entId > 0 && entUserId > 0 {
-		//当前企业是否购买商机管理
-		if sql.CountBySql(`SELECT count(1) as count FROM entniche_info a inner join entniche_user b on (a.id=? and a.status=1 and ifnull(a.power_source,0)=0 and b.id=? and b.power=1)`, entId, entUserId) > 0 {
-			entniche = true
-		}
-	}
-	if ok && u != nil {
-		if i_member_status := util.IntAll((*u)["i_member_status"]); v == s.Member && i_member_status > 0 {
+	//u, ok := m.FindById("user", userId, `{"i_member_status":1,"i_vip_status":1}`)
+	data := GetBigVipUserBaseMsg(session, middleground)
+	/* if entId, entUserId := util.IntAll(sessMap["entId"]), util.IntAll(sessMap["entUserId"]); entId > 0 && entUserId > 0 {
+		      //当前企业是否购买商机管理
+		      if sql.CountBySql(`SELECT count(1) as count FROM entniche_info a inner join entniche_user b on (a.id=? and a.status=1 and ifnull(a.power_source,0)=0 and b.id=? and b.power=1)`, entId, entUserId) > 0 {
+			    entniche = true
+		      }
+	        }*/
+	entniche := data.Data.Entniche.Status > 0
+	if data != nil {
+		if i_member_status := data.Status; v == s.Member && i_member_status > 0 {
 			return s.Member
 		} else if v == s.Entniche && entniche {
 			return s.Entniche
-		} else if i_vip_status := util.IntAll((*u)["i_vip_status"]); v == s.Vip && i_vip_status > 0 {
+		} else if i_vip_status := data.VipStatus; v == s.Vip && i_vip_status > 0 {
 			return s.Vip
 		} else if i_member_status > 0 {
 			session.Set(s.SessionKey, s.Member)
@@ -86,16 +85,16 @@ func (s *switchService) GetEntniche(session *httpsession.Session, m MongodbSim,
 }
 
 //所选服务是否是大会员
-func (s *switchService) IsMember(session *httpsession.Session, m MongodbSim, sql *mysql.Mysql) bool {
-	return s.GetEntniche(session, m, sql) == s.Member
+func (s *switchService) IsMember(session *httpsession.Session, middleground middleground.Middleground) bool {
+	return s.GetEntniche(session, middleground) == s.Member
 }
 
 //所选服务是否是超级订阅
-func (s *switchService) IsVip(session *httpsession.Session, m MongodbSim) bool {
-	return s.Get(session, m) == s.Vip
+func (s *switchService) IsVip(session *httpsession.Session, middleground middleground.Middleground) bool {
+	return s.Get(session, middleground) == s.Vip
 }
 
 //所选服务是否是免费
-func (s *switchService) IsFree(session *httpsession.Session, m MongodbSim) bool {
-	return s.Get(session, m) == s.Free
+func (s *switchService) IsFree(session *httpsession.Session, middleground middleground.Middleground) bool {
+	return s.Get(session, middleground) == s.Free
 }

+ 16 - 15
ent/entity/entity.go

@@ -194,21 +194,22 @@ func (c *CurrentUser) PhoneIsOccupy(userId, phone string) (bool, int, string) {
 
 //绑定手机号
 func (c *CurrentUser) BindPhone(userId, phone, email string) (bool, int) {
-	isOccupy, appid, relationPhoneId := c.PhoneIsOccupy(userId, phone)
-	if isOccupy {
-		return false, appid
-	}
-	if appid == 2 {
-		//商机管理绑定手机号需要和剑鱼保持一致,建立双向绑定关系
-		err := jy.NewPhoneUtil(MQFW).BindPhone(userId, relationPhoneId, phone, email, nil)
-		if err == nil {
-			return true, appid
-		}
-		return false, appid
-	}
-	return MQFW.UpdateById("user", userId, map[string]interface{}{
-		"$set": map[string]interface{}{"s_m_phone": phone},
-	}), appid
+        isOccupy, appid, _ := c.PhoneIsOccupy(userId, phone)
+        if isOccupy {
+	      return false, appid
+        }
+        if appid == 2 {
+	      //商机管理绑定手机号需要和剑鱼保持一致,建立双向绑定关系
+	      //err := jy.NewPhoneUtil(MQFW).BindPhone(userId, relationPhoneId, phone, email, nil)\
+                var err error
+	      if err == nil {
+		    return true, appid
+	      }
+	      return false, appid
+        }
+        return MQFW.UpdateById("user", userId, map[string]interface{}{
+	      "$set": map[string]interface{}{"s_m_phone": phone},
+        }), appid
 }
 
 //更换手机号

+ 3 - 2
go.mod

@@ -5,8 +5,9 @@ go 1.18
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20230117032034-ad7c00ffe11a
 	app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae
-	bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20230128033309-a6b26e74a68c
-	bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20230128064517-23fe8581b7f1
+	bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20230207054315-b05f3dd4c4d3
+	bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.4
+	bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20230129060002-f69424aa14ba
 	github.com/nsqio/go-nsq v1.1.0
 	github.com/robfig/cron v1.2.0
 	github.com/tealeg/xlsx v1.0.5

+ 5 - 4
go.sum

@@ -18,19 +18,20 @@ app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae/go.mod h1:b0zZHev
 bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698/go.mod h1:ojo/AUH9Yr1wzarEjOaNMkj1Cet/9r8IgLyba64Z52E=
 bp.jydev.jianyu360.cn/BaseService/gateway v0.0.0-20220419090715-88ddb32961be/go.mod h1:Yj4oabIGItuMoF0BXYLz2XAnF581kxgXBrvlUtIJrkI=
 bp.jydev.jianyu360.cn/BaseService/gateway v1.3.4/go.mod h1:BMLd/5wb3BIEGhnEgF9y1sJN9P5/Dw9kYsoiE9V8I9g=
-bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20230128033309-a6b26e74a68c h1:g49jOlhZlBCJ3IgJA0rotfNf2Gh22pISffUtqxB8XtY=
-bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20230128033309-a6b26e74a68c/go.mod h1:5nimT8GJh46AyfeeDeyRlDQygMlO7TRM8Pwm41Gxemc=
+bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20230207054315-b05f3dd4c4d3 h1:jeItQ6RM1T6yPWc/5i4R6h3kViD+Rm2VnIEsc1gCFJA=
+bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20230207054315-b05f3dd4c4d3/go.mod h1:5nimT8GJh46AyfeeDeyRlDQygMlO7TRM8Pwm41Gxemc=
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.0-20220418005748-8ba5d936dd53/go.mod h1:E5lcDI3k4FESLxiAetCfWQTq8qfpy9cv0yN1oKoEO34=
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.0-20220419023723-0b32d4a41751/go.mod h1:6KL5LMEku83uRbre0W/bj5kXG2I6pJGBFtktmtp51yM=
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.0-20220419063004-233fc7ce006c/go.mod h1:6KL5LMEku83uRbre0W/bj5kXG2I6pJGBFtktmtp51yM=
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.0-20220420075831-0b59892e9982/go.mod h1:wsHNO91h37H+xE4ZNny0yd7mtpODeDJxbVYhIRMR+qw=
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.3/go.mod h1:Z353aucNO5hH4ZYjeKST3kE1PN3W8/uPc4J8s0Upz40=
+bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.4 h1:LXD8woSkDDtqCQ19S9TGvx7GVir300nGszoIidBTlGM=
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.4/go.mod h1:rRiGzKG4F/fmkNxXQCxrkxNWc8yf1SmW8qWCKfGIQSM=
 bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20220418072311-2062bed1e700/go.mod h1:KjcrxTzM96tBc6G4B8tlLBn1lrVy5UJYF8+eTdP4xAE=
 bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20220421015128-4a36f3eac5c5/go.mod h1:GT0QC4aaKDuXxAvaU4G02XjCc31TU1ctqBGqxQYOfC4=
 bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20220905055615-8540037e1b06/go.mod h1:LS21iwbgP8i3ZHJ1n4yNpLXQ/nzEudUOk0klC6VM2dQ=
-bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20230128064517-23fe8581b7f1 h1:LH/gm2iRShZ64FEuF7LTzF62iJhOVVD9AxGVHFd0ORI=
-bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20230128064517-23fe8581b7f1/go.mod h1:m7/aZ1r1FapNT2h3gqmCFVb0EV+CaJaNKNPHMzLHx8Y=
+bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20230129060002-f69424aa14ba h1:WATZdho/2XJ8DP3EuaSo10WiFrXRgxeLpmYoGEcSdMw=
+bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20230129060002-f69424aa14ba/go.mod h1:m7/aZ1r1FapNT2h3gqmCFVb0EV+CaJaNKNPHMzLHx8Y=
 cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
 cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
 cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw=

+ 22 - 3
middleground/middleground.go

@@ -1,11 +1,30 @@
 package middleground
 
 type Middleground struct {
-	UserCenter *userCenter
+	hosts            []string
+	UserCenter       *userCenter
+	ResourceCenter   *resourceCenter
+	PowerCheckCenter *powerCheckCenter
 }
 
-func NewMiddleground(hosts []string, key string) *Middleground {
+func NewMiddleground(hosts []string) *Middleground {
 	return &Middleground{
-		UserCenter: newUserCenter(hosts, key),
+		hosts: hosts,
 	}
 }
+func (m *Middleground) RegUserCenter(key string) *Middleground {
+	m.UserCenter = newUserCenter(m.hosts, key)
+	return m
+}
+func (m *Middleground) RegResourceCenter(key string) *Middleground {
+	m.ResourceCenter = newResourceCenter(m.hosts, key)
+	return m
+}
+func (m *Middleground) RegPowerCheckCenter(key string) *Middleground {
+	m.PowerCheckCenter = newPowerCheckCenter(m.hosts, key)
+	return m
+}
+func main() {
+	//userId: 63d498bb6ae0e1ea2170e03d -baseUserId: 366251 -accountId: 13485 -entId: 15419 -positionType: 0 -baseUserId: 366251 -accountId: 13485 -entId: 15419 -positionType: 0 -positionId: 932
+	NewMiddleground([]string{"192.168.3.206:2379"}).RegPowerCheckCenter("powercheck.rpc")
+}

+ 59 - 0
middleground/powercheckcenter.go

@@ -0,0 +1,59 @@
+package middleground
+
+import (
+	"context"
+	"log"
+
+	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/pb"
+	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck"
+	"github.com/zeromicro/go-zero/core/discov"
+	"github.com/zeromicro/go-zero/zrpc"
+)
+
+type powerCheckCenter struct {
+	hosts []string
+	key   string
+}
+
+func newPowerCheckCenter(hosts []string, key string) *powerCheckCenter {
+	return &powerCheckCenter{
+		hosts: hosts,
+		key:   key,
+	}
+}
+
+func (p *powerCheckCenter) newClient() zrpc.Client {
+	client, err := zrpc.NewClient(zrpc.RpcClientConf{
+		Etcd: discov.EtcdConf{
+			Hosts: p.hosts,
+			Key:   p.key,
+		},
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	return client
+}
+
+func (p *powerCheckCenter) Check(appid, userId string, baseUserId, accountId, entId, positionType, positionId int64) *pb.CheckResp {
+	client := p.newClient()
+	if client == nil {
+		return nil
+	}
+	defer client.Conn().Close()
+	resp, err := powercheck.NewPowerCheck(client).Check(context.Background(), &pb.CheckReq{
+		Appid:        appid,
+		Userid:       userId,
+		BaseUserId:   baseUserId,
+		AccountId:    accountId,
+		EntId:        entId,
+		PositionType: positionType,
+		PositionId:   positionId,
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	return resp
+}

+ 55 - 0
middleground/resourcecenter.go

@@ -0,0 +1,55 @@
+package middleground
+
+import (
+	"context"
+	"log"
+
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
+	"github.com/zeromicro/go-zero/core/discov"
+	"github.com/zeromicro/go-zero/zrpc"
+)
+
+type resourceCenter struct {
+	hosts []string
+	key   string
+}
+
+func newResourceCenter(hosts []string, key string) *resourceCenter {
+	return &resourceCenter{
+		hosts: hosts,
+		key:   key,
+	}
+}
+
+func (r *resourceCenter) newClient() zrpc.Client {
+	client, err := zrpc.NewClient(zrpc.RpcClientConf{
+		Etcd: discov.EtcdConf{
+			Hosts: r.hosts,
+			Key:   r.key,
+		},
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	return client
+}
+
+//
+func (r *resourceCenter) Haspowers(userId int64) *pb.HaspowersResp {
+	client := r.newClient()
+	if client == nil {
+		return nil
+	}
+	defer client.Conn().Close()
+	resp, err := resource.NewResource(client).Haspowers(context.Background(), &pb.HaspowersReq{
+		Appid:  "10000",
+		UserId: userId,
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	return resp
+}

+ 12 - 0
middleground/usercenter.go

@@ -39,6 +39,9 @@ func (u *userCenter) newClient() zrpc.Client {
 //获取身份列表
 func (u *userCenter) IdentityList(userId int64) []*pb.Identity {
 	client := u.newClient()
+	if client == nil {
+		return nil
+	}
 	defer client.Conn().Close()
 	resp, err := usercenter.NewUserCenter(client).IdentityList(context.Background(), &pb.IdentityReq{
 		Id: userId,
@@ -53,6 +56,9 @@ func (u *userCenter) IdentityList(userId int64) []*pb.Identity {
 //获取账号id获取个人身份信息
 func (u *userCenter) IdentityByUserId(userId int64) *pb.Identity {
 	client := u.newClient()
+	if client == nil {
+		return nil
+	}
 	defer client.Conn().Close()
 	resp, err := usercenter.NewUserCenter(client).IdentityByUserId(context.Background(), &pb.IdentityReq{
 		Id: userId,
@@ -67,6 +73,9 @@ func (u *userCenter) IdentityByUserId(userId int64) *pb.Identity {
 //根据职位id获取身份信息
 func (u *userCenter) IdentityByPositionId(positionId int64) *pb.Identity {
 	client := u.newClient()
+	if client == nil {
+		return nil
+	}
 	defer client.Conn().Close()
 	resp, err := usercenter.NewUserCenter(client).IdentityByPositionId(context.Background(), &pb.IdentityReq{
 		Id: positionId,
@@ -81,6 +90,9 @@ func (u *userCenter) IdentityByPositionId(positionId int64) *pb.Identity {
 //根据企业员工id获取身份信息
 func (u *userCenter) IdentityByEntUserId(entUserId int64) *pb.Identity {
 	client := u.newClient()
+	if client == nil {
+		return nil
+	}
 	defer client.Conn().Close()
 	resp, err := usercenter.NewUserCenter(client).IdentityByEntUserId(context.Background(), &pb.IdentityReq{
 		Id: entUserId,

+ 54 - 0
public/public.go

@@ -277,3 +277,57 @@ func isEmail(value string) bool {
 	var emailPattern = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$")
 	return emailPattern.MatchString(value)
 }
+
+func GetCompatibleUser(mgo *MongodbSim, userId string, field map[string]int) *map[string]interface{} {
+	user := map[string]interface{}{}
+	if field == nil || len(field) == 0 {
+		return &user
+	}
+	field["_id"] = 0
+	if IsObjectIdHex(userId) {
+		temp, ok := mgo.FindById("user", userId, field)
+		if ok && temp != nil && len(*temp) > 0 {
+			user = *temp
+		}
+	} else {
+		if field["o_entniche"] > 0 || field["o_vipjy"] > 0 || field["o_member_jy"] > 0 || field["o_jy"] > 0 {
+			entniche_rule, ok := mgo.Find("entniche_rule", map[string]interface{}{
+				"i_userid": util.IntAll(userId),
+			}, nil, `{"o_entniche":1}`, false, -1, -1)
+			if ok && entniche_rule != nil && len(*entniche_rule) > 0 {
+				for _, v := range *entniche_rule {
+					i_type := util.IntAll(v["i_type"])
+					if i_type == 0 {
+						if field["o_entniche"] > 0 {
+							user["o_entniche"] = v["o_entniche"]
+						}
+					} else if i_type == 1 {
+						if field["o_vipjy"] > 0 {
+							user["o_vipjy"] = v["o_entniche"]
+						}
+						if field["o_member_jy"] > 0 {
+							user["o_member_jy"] = v["o_entniche"]
+						}
+					} else if i_type == 2 {
+						if field["o_jy"] > 0 {
+							user["o_jy"] = v["o_entniche"]
+						}
+					}
+				}
+			}
+		}
+		delete(field, "o_jy")
+		delete(field, "o_vipjy")
+		delete(field, "o_member_jy")
+		delete(field, "o_entniche")
+		ent_user, ok := mgo.FindOneByField("ent_user", map[string]interface{}{
+			"i_userid": util.IntAll(userId),
+		}, field)
+		if ok && ent_user != nil && len(*ent_user) > 0 {
+			for k, v := range *ent_user {
+				user[k] = v
+			}
+		}
+	}
+	return &user
+}