WH01243 2 жил өмнө
parent
commit
8043ec9806

+ 4 - 198
common/src/qfw/util/jy/bigVipPower.go

@@ -6,12 +6,9 @@ import (
 	m "app.yhyue.com/moapp/jybase/mongodb"
 	m "app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"app.yhyue.com/moapp/jybase/redis"
 	"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/pb"
-	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck"
-	"context"
 	"fmt"
 	"fmt"
-	"github.com/zeromicro/go-zero/core/discov"
-	"github.com/zeromicro/go-zero/zrpc"
 	"log"
 	"log"
 	"strings"
 	"strings"
 	"time"
 	"time"
@@ -149,13 +146,14 @@ func GetEntnicheState(userId string, mysql *mysql.Mysql, mg m.MongodbSim) *BigVi
 }
 }
 
 
 // 获取大会员个人基本信息
 // 获取大会员个人基本信息
-func GetBigVipUserBaseMsg(appid string, session *httpsession.Session, host, key string) *BigVipBaseMsg {
+func GetBigVipUserBaseMsg(appid string, session *httpsession.Session, middleground middleground.Middleground) *BigVipBaseMsg {
 	userId := qutil.ObjToString(session.Get("userId"))
 	userId := qutil.ObjToString(session.Get("userId"))
 	baseUserId := qutil.Int64All(session.Get("base_user_id"))
 	baseUserId := qutil.Int64All(session.Get("base_user_id"))
 	entId := qutil.Int64All(session.Get("entId"))
 	entId := qutil.Int64All(session.Get("entId"))
 	positionType := qutil.Int64All(session.Get("positionType"))
 	positionType := qutil.Int64All(session.Get("positionType"))
+	accountId := qutil.Int64All(session.Get("accountId"))
 	userPower := BigVipBaseMsg{}
 	userPower := BigVipBaseMsg{}
-	data := Check(appid, session, host, key)
+	data := middleground.PowerCheckCenter.Check(appid, userId, baseUserId, accountId, entId)
 	if positionType == 0 {
 	if positionType == 0 {
 		userId = qutil.InterfaceToStr(session.Get("userId"))
 		userId = qutil.InterfaceToStr(session.Get("userId"))
 	} else {
 	} else {
@@ -217,201 +215,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
 	userPower.Data = data
 	return &userPower
 	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) {
 func (this *BigVipBaseMsg) CheckBigVipFrontPower(reqFlag string) (pass bool) {

+ 2 - 3
middleground/middleground.go

@@ -6,12 +6,11 @@ type Middleground struct {
 	PowerCheckCenter *powerCheckCenter
 	PowerCheckCenter *powerCheckCenter
 }
 }
 
 
-func NewMiddleground(hosts []string) *Middleground {
+func NewMiddleground(hosts []string, key string) *Middleground {
 	return &Middleground{
 	return &Middleground{
-		hosts: hosts,
+		UserCenter: newUserCenter(hosts, key),
 	}
 	}
 }
 }
-
 func (m *Middleground) RegUserCenter(key string) *Middleground {
 func (m *Middleground) RegUserCenter(key string) *Middleground {
 	m.UserCenter = newUserCenter(m.hosts, key)
 	m.UserCenter = newUserCenter(m.hosts, key)
 	return m
 	return m

+ 21 - 2
middleground/powercheckcenter.go

@@ -1,10 +1,12 @@
 package middleground
 package middleground
 
 
 import (
 import (
-	"log"
-
+	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/pb"
+	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck"
+	"context"
 	"github.com/zeromicro/go-zero/core/discov"
 	"github.com/zeromicro/go-zero/core/discov"
 	"github.com/zeromicro/go-zero/zrpc"
 	"github.com/zeromicro/go-zero/zrpc"
+	"log"
 )
 )
 
 
 type powerCheckCenter struct {
 type powerCheckCenter struct {
@@ -32,3 +34,20 @@ func (p *powerCheckCenter) newClient() zrpc.Client {
 	}
 	}
 	return client
 	return client
 }
 }
+
+func (p *powerCheckCenter) Check(appid, userId string, baseUserId, accountId, entId int64) *pb.CheckResp {
+	client := p.newClient()
+	defer client.Conn().Close()
+	resp, err := powercheck.NewPowerCheck(client).Check(context.Background(), &pb.CheckReq{
+		Appid:      appid,
+		Userid:     userId,
+		BaseUserId: baseUserId,
+		AccountId:  accountId,
+		EntId:      entId,
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	return resp
+}