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

+ 1 - 0
entity/power.go

@@ -24,6 +24,7 @@ type Free struct {
 	IsUpgrade     bool  //是否是新免费用户
 	Registedate   int64 //注册时间
 	Mail          string
+	Phone         string
 }
 
 //超级订阅相关

+ 1 - 1
rpc/etc/powercheck.yaml

@@ -6,7 +6,7 @@ Etcd:
   Key: powercheck.rpc
 Timeout: 10000
 MysqlMain:
-  dbName: qfw
+  dbName: jianyu
   address: 192.168.3.11:3366
   userName: root
   passWord: Topnet123

+ 25 - 21
rpc/internal/logic/checklogic.go

@@ -34,23 +34,11 @@ func (l *CheckLogic) Check(in *pb.CheckReq) (*pb.CheckResp, error) {
 		BaseMysql: entity.BaseMysql,
 		MgoJy:     entity.MgoJy,
 	})
-	data := power.Power(in.Userid, in.BaseUserId, in.AccountId, in.EntId)
+	data := power.Power(in.Userid, in.BaseUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId)
 	if data == nil {
 		resp.ErrorMsg = "暂无数据"
 		resp.ErrorCode = -1
 	} else {
-		resp.Ent = &pb.Ent{
-			Name:                data.Ent.Name,
-			EntRoleId:           data.Ent.EntRoleId,
-			EntAuthStatus:       data.Ent.EntAuthStatus,
-			EntAuthReason:       data.Ent.EntAuthReason,
-			EntSubscribe:        data.Ent.EntSubscribe,
-			EntSubscribeManager: data.Ent.EntSubscribeManager,
-			PowerSource:         data.Entniche.PowerSource,
-			DeptSubscribe:       data.Ent.DeptSubscribe,
-			BuyVip:              data.Ent.BuyVip,
-			BuyMember:           data.Ent.BuyMember,
-		}
 		resp.Vip = &pb.Vip{
 			Status:          data.Vip.Status,
 			StartTime:       data.Vip.StartTime,
@@ -81,14 +69,6 @@ func (l *CheckLogic) Check(in *pb.CheckReq) (*pb.CheckResp, error) {
 			Pid:             data.Member.Pid,
 			Used:            data.Member.Used,
 		}
-		resp.Entniche = &pb.Entniche{
-			Status:      data.Entniche.Status,
-			StartTime:   data.Entniche.StartTime,
-			EndTime:     data.Entniche.EndTime,
-			PowerSource: data.Entniche.PowerSource,
-			IsEntPower:  data.Entniche.IsEntPower,
-			IsNew:       data.Entniche.IsNew,
-		}
 		resp.Free = &pb.Free{
 			IsFree:        data.Free.IsFree,
 			FreeHasKey:    data.Free.FreeHasKey,
@@ -98,6 +78,30 @@ func (l *CheckLogic) Check(in *pb.CheckReq) (*pb.CheckResp, error) {
 			Registedate:   data.Free.Registedate,
 			IsUpgrade:     data.Free.IsUpgrade,
 			Mail:          data.Free.Mail,
+			Phone:         data.Free.Phone,
+		}
+		//职位类型 0个人 1企业
+		if in.PositionType == 1 {
+			resp.Ent = &pb.Ent{
+				Name:                data.Ent.Name,
+				EntRoleId:           data.Ent.EntRoleId,
+				EntAuthStatus:       data.Ent.EntAuthStatus,
+				EntAuthReason:       data.Ent.EntAuthReason,
+				EntSubscribe:        data.Ent.EntSubscribe,
+				EntSubscribeManager: data.Ent.EntSubscribeManager,
+				PowerSource:         data.Entniche.PowerSource,
+				DeptSubscribe:       data.Ent.DeptSubscribe,
+				BuyVip:              data.Ent.BuyVip,
+				BuyMember:           data.Ent.BuyMember,
+			}
+			resp.Entniche = &pb.Entniche{
+				Status:      data.Entniche.Status,
+				StartTime:   data.Entniche.StartTime,
+				EndTime:     data.Entniche.EndTime,
+				PowerSource: data.Entniche.PowerSource,
+				IsEntPower:  data.Entniche.IsEntPower,
+				IsNew:       data.Entniche.IsNew,
+			}
 		}
 	}
 	return &pb.CheckResp{}, nil

+ 31 - 12
rpc/pb/powerCheck.pb.go

@@ -95,6 +95,7 @@ type CheckReq struct {
 	AccountId    int64  `protobuf:"varint,4,opt,name=accountId,proto3" json:"accountId,omitempty"`       //账户id
 	EntId        int64  `protobuf:"varint,5,opt,name=entId,proto3" json:"entId,omitempty"`               //
 	PositionType int64  `protobuf:"varint,6,opt,name=positionType,proto3" json:"positionType,omitempty"` //职位类型 0个人 1企业
+	PositionId   int64  `protobuf:"varint,7,opt,name=positionId,proto3" json:"positionId,omitempty"`     //职位id
 }
 
 func (x *CheckReq) Reset() {
@@ -171,6 +172,13 @@ func (x *CheckReq) GetPositionType() int64 {
 	return 0
 }
 
+func (x *CheckReq) GetPositionId() int64 {
+	if x != nil {
+		return x.PositionId
+	}
+	return 0
+}
+
 type CheckResp struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
@@ -782,8 +790,9 @@ type Free struct {
 	FreeBuyerPort int64  `protobuf:"varint,4,opt,name=freeBuyerPort,proto3" json:"freeBuyerPort,omitempty"` //免费用户可查看采购单位画像次数
 	FreeFile      int64  `protobuf:"varint,5,opt,name=freeFile,proto3" json:"freeFile,omitempty"`           //免费用户可以进行附件下载次数
 	Registedate   int64  `protobuf:"varint,6,opt,name=registedate,proto3" json:"registedate,omitempty"`     //注册时间
-	IsUpgrade     int64  `protobuf:"varint,7,opt,name=isUpgrade,proto3" json:"isUpgrade,omitempty"`         //是否是新免费用户
+	IsUpgrade     bool   `protobuf:"varint,7,opt,name=isUpgrade,proto3" json:"isUpgrade,omitempty"`         //是否是新免费用户
 	Mail          string `protobuf:"bytes,8,opt,name=mail,proto3" json:"mail,omitempty"`
+	Phone         string `protobuf:"bytes,9,opt,name=phone,proto3" json:"phone,omitempty"` //手机号
 }
 
 func (x *Free) Reset() {
@@ -860,11 +869,11 @@ func (x *Free) GetRegistedate() int64 {
 	return 0
 }
 
-func (x *Free) GetIsUpgrade() int64 {
+func (x *Free) GetIsUpgrade() bool {
 	if x != nil {
 		return x.IsUpgrade
 	}
-	return 0
+	return false
 }
 
 func (x *Free) GetMail() string {
@@ -874,6 +883,13 @@ func (x *Free) GetMail() string {
 	return ""
 }
 
+func (x *Free) GetPhone() string {
+	if x != nil {
+		return x.Phone
+	}
+	return ""
+}
+
 var File_powerCheck_proto protoreflect.FileDescriptor
 
 var file_powerCheck_proto_rawDesc = []byte{
@@ -883,7 +899,7 @@ var file_powerCheck_proto_rawDesc = []byte{
 	0x72, 0x72, 0x6f, 0x72, 0x4d, 0x73, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x72, 0x72, 0x6f, 0x72,
 	0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x65, 0x72, 0x72,
 	0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73,
-	0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0xb0,
+	0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0xd0,
 	0x01, 0x0a, 0x08, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x61,
 	0x70, 0x70, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x69,
 	0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
@@ -895,7 +911,9 @@ var file_powerCheck_proto_rawDesc = []byte{
 	0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x22, 0x0a,
 	0x0c, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x06, 0x20,
 	0x01, 0x28, 0x03, 0x52, 0x0c, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70,
-	0x65, 0x22, 0xda, 0x01, 0x0a, 0x09, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12,
+	0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18,
+	0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x49,
+	0x64, 0x22, 0xda, 0x01, 0x0a, 0x09, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12,
 	0x1b, 0x0a, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01,
 	0x28, 0x09, 0x52, 0x08, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x73, 0x67, 0x12, 0x1d, 0x0a, 0x0a,
 	0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03,
@@ -992,7 +1010,7 @@ var file_powerCheck_proto_rawDesc = []byte{
 	0x76, 0x61, 0x74, 0x65, 0x47, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x75, 0x79, 0x56, 0x69, 0x70,
 	0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x62, 0x75, 0x79, 0x56, 0x69, 0x70, 0x12, 0x1c,
 	0x0a, 0x09, 0x62, 0x75, 0x79, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x0b, 0x20, 0x01, 0x28,
-	0x03, 0x52, 0x09, 0x62, 0x75, 0x79, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x22, 0xf6, 0x01, 0x0a,
+	0x03, 0x52, 0x09, 0x62, 0x75, 0x79, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x8c, 0x02, 0x0a,
 	0x04, 0x46, 0x72, 0x65, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x46, 0x72, 0x65, 0x65, 0x18,
 	0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x46, 0x72, 0x65, 0x65, 0x12, 0x1e, 0x0a,
 	0x0a, 0x66, 0x72, 0x65, 0x65, 0x48, 0x61, 0x73, 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28,
@@ -1006,13 +1024,14 @@ var file_powerCheck_proto_rawDesc = []byte{
 	0x65, 0x12, 0x20, 0x0a, 0x0b, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x64, 0x61, 0x74, 0x65,
 	0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x64,
 	0x61, 0x74, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x73, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65,
-	0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x69, 0x73, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64,
+	0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64,
 	0x65, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52,
-	0x04, 0x6d, 0x61, 0x69, 0x6c, 0x32, 0x2c, 0x0a, 0x0a, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x43, 0x68,
-	0x65, 0x63, 0x6b, 0x12, 0x1e, 0x0a, 0x05, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x09, 0x2e, 0x43,
-	0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x1a, 0x0a, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52,
-	0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f,
-	0x74, 0x6f, 0x33,
+	0x04, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x09,
+	0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x32, 0x2c, 0x0a, 0x0a, 0x70,
+	0x6f, 0x77, 0x65, 0x72, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x1e, 0x0a, 0x05, 0x43, 0x68, 0x65,
+	0x63, 0x6b, 0x12, 0x09, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x1a, 0x0a, 0x2e,
+	0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70,
+	0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (

+ 3 - 1
rpc/powerCheck.proto

@@ -17,6 +17,7 @@ message CheckReq{
 	int64 accountId =4;//账户id
 	int64 entId =5;//
 	int64 positionType=6;//职位类型 0个人 1企业
+	int64 positionId  =7; //职位id
 }
 
 message CheckResp {
@@ -96,8 +97,9 @@ message Free {
     int64 freeBuyerPort = 4; //免费用户可查看采购单位画像次数
     int64 freeFile = 5; //免费用户可以进行附件下载次数
     int64 registedate = 6;//注册时间
-    int64 isUpgrade = 7;//是否是新免费用户
+    bool isUpgrade = 7;//是否是新免费用户
     string mail=8; 
+    string phone=9; //手机号
 }
 
 service powerCheck {

+ 210 - 100
service/power.go

@@ -23,81 +23,196 @@ func NewPower(conn *entity.Conn) *PowerService {
 	}
 }
 
-//权益相关 userid用户mongodbid baseUserId
-func (this *PowerService) Power(userid string, baseUserId, accountId, entId int64) *entity.Power {
-	//获取权益
-	//大会员状态
-	data, ok := this.Conn.MgoJy.FindById("user", userid, `{"s_myemail":1,"l_vip_starttime":1,"l_vip_endtime":1,"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 {
+var level_map = map[int64]string{
+	1: "专家版",
+	2: "智慧版",
+	3: "商机版",
+	4: "试用版",
+	5: "自定义",
+	6: "商机版2.0",
+	7: "专家版2.0",
+}
+
+/*
+	权益相关
+	userid  		//mongodb用户id
+	baseUserId 		//base_user用户id
+	accountId 		//账户id
+	entId =5;		//企业id
+	positionType    //职位类型 0个人 1企业
+	positionId		//职位id
+	切换到企业身份后,session中userId存的是企业雇员的职位id,个人身份,userId还是原来mgo库里的_id
+*/
+func (this *PowerService) Power(userid string, baseUserId, accountId, entId, positionType, positionId int64) *entity.Power {
+	ent := &entity.Ent{}
+	entniche := &entity.Entniche{}
+	vip := &entity.Vip{}
+	member := &entity.Member{}
+	free := &entity.Free{}
 
-		ent := &entity.Ent{}
-		entniche := &entity.Entniche{}
-		vip := &entity.Vip{}
-		member := &entity.Member{}
-		free := &entity.Free{}
-		registeDate := common.Int64All((*data)["l_registedate"]) //注册时间
-		free.Mail = common.ObjToString((*data)["s_myemail"])
+	//获取用户本身的注册时间和邮箱、这个与个人、企业无关
+	mgoUserFields := map[string]interface{}{
+		"s_myemail":     1,
+		"l_registedate": 1,
+		"s_phone":       1,
+		"s_m_phone":     1,
+		"base_user_id":  1,
+	}
+	//大会员权益表查询条件
+	bigmemberServiceUserQuery := map[string]interface{}{"s_userid": userid, "i_status": 0}
+	//个人身份 取user表中权益
+	if positionType == 0 {
+		mgoUserFields["i_vip_status"] = 1
+		mgoUserFields["l_vip_starttime"] = 1
+		mgoUserFields["l_vip_endtime"] = 1
+		mgoUserFields["o_vipjy"] = 1
+		mgoUserFields["i_member_status"] = 1
+		mgoUserFields["i_member_give"] = 1
+		mgoUserFields["s_member_mainid"] = 1
+		mgoUserFields["i_member_sub_status"] = 1
+		mgoUserFields["i_member_trial"] = 1
+		mgoUserFields["o_jy"] = 1
+	} else {
+		bigmemberServiceUserQuery["s_userid"] = positionId
+	}
+	data, ok := this.Conn.MgoJy.FindById("user", userid, mgoUserFields)
+	if ok && data != nil && len(*data) > 0 {
+		//基本信息
+		registeDate := common.Int64All((*data)["l_registedate"])                                            //注册时间
+		phone, _ := common.If((*data)["s_phone"] != nil, (*data)["s_phone"], (*data)["s_m_phone"]).(string) //
+		mail := common.ObjToString((*data)["s_myemail"])
+		free.Mail = mail
 		free.Registedate = registeDate
-		//VIP
-		vipStatus := common.Int64All((*data)["i_vip_status"])
-		vipStartTime := common.Int64All((*data)["l_vip_starttime"])
-		vipEndTime := common.Int64All((*data)["l_vip_endtime"])
-		ovipjy := common.ObjToMap((*data)["o_vipjy"])
-		oBuyset := common.ObjToMap((*ovipjy)["o_buyset"])
-		upgrade := common.Int64All((*oBuyset)["oBuyset"])
-		areacount := common.Int64All((*oBuyset)["areacount"])
-		buyerclasscount := common.Int64All((*oBuyset)["buyerclasscount"])
-		vip = &entity.Vip{
-			Status:          vipStatus,
-			StartTime:       vipStartTime,
-			EndTime:         vipEndTime,
-			Upgrade:         upgrade,
-			Areacount:       areacount,
-			Buyerclasscount: buyerclasscount,
-			MaxKeyLength:    300,
-			PowerType:       common.Int64All(common.If(vipStatus > 0, 1, 0)),
-			//TODO 附件下载次数
-		}
-		//免费相关
-		o_jy, _ := (*data)["o_jy"].(map[string]interface{})
-		a_key, _ := o_jy["a_key"].([]interface{})
-		free.FreeHasKey = len(a_key) > 0
-		//免费用户可查看企业画像次数//免费用户可查看采购单位画像次数//免费用户可以进行附件下载次数
-		freeEntPort, freeBuyerPort, freeFile := FreeExperience(userid)
-		free.FreeEntPort, free.FreeBuyerPort, free.FreeFile = int64(freeEntPort), int64(freeBuyerPort), int64(freeFile)
-		//
-		//子账号被启用
-		i_member_sub_status := common.IntAllDef((*data)["i_member_sub_status"], 0)
+		free.Phone = phone
+		//个人权益
+		if positionType == 0 {
+			o_jy, _ := (*data)["o_jy"].(map[string]interface{})
+			a_key, _ := o_jy["a_key"].([]interface{})
+			free.FreeHasKey = len(a_key) > 0
+			if common.IntAll((o_jy)["i_newfree"]) > 0 || entity.IsNewFreeTimeCell < registeDate { //IsNewFreeTimeCell dev3.6.4版本之前发了个紧急版本处理老用户订阅问题,i_newfree字段必须用户选择地区才能生成,不能作为判断是否是新用户得唯一标识,在此版本添加了常量:IsNewFreeTimeCell作为判断标准;--ws
+				free.IsUpgrade = true //新免费用户
+			}
+			//超级订阅
+			vipStatus := common.Int64All((*data)["i_vip_status"])
+			vipStartTime := common.Int64All((*data)["l_vip_starttime"])
+			vipEndTime := common.Int64All((*data)["l_vip_endtime"])
+			ovipjy := common.ObjToMap((*data)["o_vipjy"])
+			oBuyset := common.ObjToMap((*ovipjy)["o_buyset"])
+			upgrade := common.Int64All((*oBuyset)["oBuyset"])
+			areacount := common.Int64All((*oBuyset)["areacount"])
+			buyerclasscount := common.Int64All((*oBuyset)["buyerclasscount"])
+			vip = &entity.Vip{
+				Status:          vipStatus,
+				StartTime:       vipStartTime,
+				EndTime:         vipEndTime,
+				Upgrade:         upgrade,
+				Areacount:       areacount,
+				Buyerclasscount: buyerclasscount,
+				MaxKeyLength:    300,
+				PowerType:       common.Int64All(common.If(vipStatus > 0, 1, 0)),
+				//TODO 附件下载次数
+			}
+			//个人member
+			i_member_sub_status := common.IntAllDef((*data)["i_member_sub_status"], 0)
 
-		memberStatus := common.Int64All((*data)["i_member_status"])
-		memberStarttime := common.Int64All((*data)["i_member_starttime"])
-		memberEndtime := common.Int64All((*data)["i_member_endtime"])
-		member = &entity.Member{
-			Status:       memberStatus,
-			StartTime:    memberStarttime,
-			EndTime:      memberEndtime,
-			MaxKeyLength: 300, //最大关键词数量限制
-		}
-		if memberStatus > 0 {
-			member.MemberPower = 1 //是否分配了大会员;0:否 1:是
-		}
-		if (*data)["s_member_mainid"] != nil && common.ObjToString((*data)["s_member_mainid"]) != "" && i_member_sub_status > 0 {
-			member.Pid = common.ObjToString((*data)["s_member_mainid"])
-			member.IsSubCount = 1
-		}
-		if (member.Pid != "" && common.IntAllDef((*data)["i_member_sub_status"], 0) == 1) || this.Conn.MgoJy.Count("member", map[string]interface{}{"userid": userid}) > 0 {
-			member.Used = true
-		}
-		if (*data)["i_member_trial"] != nil {
-			member.IsMemberTrial = 1
-		}
-		//获取大会员版本名称 //TODO 自定义有问题
-		if combo := this.Conn.Mysql.SelectBySql(`select s_name from bigmember_combo where id=?`, memberStatus); combo != nil && len(*combo) > 0 {
-			member.MemberName = common.ObjToString((*combo)[0]["s_name"])
+			memberStatus := common.Int64All((*data)["i_member_status"])
+			memberStarttime := common.Int64All((*data)["i_member_starttime"])
+			memberEndtime := common.Int64All((*data)["i_member_endtime"])
+			member = &entity.Member{
+				Status:       memberStatus,
+				StartTime:    memberStarttime,
+				EndTime:      memberEndtime,
+				MaxKeyLength: 300, //最大关键词数量限制
+				PowerType:    common.Int64All(common.If(memberStatus > 0, 1, 0)),
+			}
+			if memberStatus > 0 {
+				member.MemberPower = 1 //是否分配了大会员;0:否 1:是
+			}
+			if (*data)["s_member_mainid"] != nil && common.ObjToString((*data)["s_member_mainid"]) != "" && i_member_sub_status > 0 {
+				member.Pid = common.ObjToString((*data)["s_member_mainid"])
+				member.IsSubCount = 1
+			}
+			if (member.Pid != "" && common.IntAllDef((*data)["i_member_sub_status"], 0) == 1) || this.Conn.MgoJy.Count("member", map[string]interface{}{"userid": userid}) > 0 {
+				member.Used = true
+			}
+			if (*data)["i_member_trial"] != nil {
+				member.IsMemberTrial = 1
+			}
+			//获取大会员版本名称
+			member.MemberName = level_map[memberStatus]
+		} else if positionType == 1 {
+			entnicheUserId := this.GetEntnicheUserId(entId, phone)
+			//免费
+			fdata, ok := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
+				"i_ent":    entId,
+				"i_userid": entnicheUserId,
+				"i_type":   2, //0:商机管理 1:超级订阅/大会员 2:免费
+			})
+			o_jy, _ := (*fdata)["o_entniche"].(map[string]interface{})
+			a_key, _ := o_jy["a_key"].([]interface{})
+			free.FreeHasKey = len(a_key) > 0
+			if common.IntAll((o_jy)["i_newfree"]) > 0 || entity.IsNewFreeTimeCell < registeDate { //IsNewFreeTimeCell dev3.6.4版本之前发了个紧急版本处理老用户订阅问题,i_newfree字段必须用户选择地区才能生成,不能作为判断是否是新用户得唯一标识,在此版本添加了常量:IsNewFreeTimeCell作为判断标准;--ws
+				free.IsUpgrade = true //新免费用户
+			}
+			//企业
+			edata, ok := this.Conn.MgoJy.FindOne("entniche_rule", map[string]interface{}{
+				"i_ent":    entId,
+				"i_userid": entnicheUserId,
+				"i_type":   1, //0:商机管理 1:超级订阅/大会员
+				"l_endtime": map[string]interface{}{
+					"$gt": time.Now().Unix(),
+				},
+			})
+			if ok && edata != nil && len(*edata) > 0 {
+				status := common.Int64All((*edata)["i_status"])
+				starttime := common.Int64All((*edata)["l_starttime"])
+				endtime := common.Int64All((*edata)["l_endtime"])
+				o_entniche := common.ObjToMap((*edata)["o_entniche"])
+				//获取用户是什么版本权益
+				//用于判断是否含有企业主体的超级订阅、大会员服务
+				epowerData := this.Conn.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 b.ent_id=? AND c.end_time >?`, phone, entId, time.Now().Format(date.Date_Full_Layout))
+
+				if epowerData != nil && len(*epowerData) > 0 {
+					for _, v := range *epowerData {
+						product_type := common.ObjToString(v["product_type"])
+						if strings.Contains(product_type, entity.ProductType_vip) {
+							oBuyset := common.ObjToMap((*o_entniche)["o_buyset"])
+							upgrade := common.Int64All((*oBuyset)["oBuyset"])
+							areacount := common.Int64All((*oBuyset)["areacount"])
+							buyerclasscount := common.Int64All((*oBuyset)["buyerclasscount"])
+							vip = &entity.Vip{
+								Status:          status,
+								StartTime:       starttime,
+								EndTime:         endtime,
+								Upgrade:         upgrade,
+								Areacount:       areacount,
+								Buyerclasscount: buyerclasscount,
+								MaxKeyLength:    300,
+								PowerType:       2,
+							}
+						} else if strings.Contains(product_type, entity.ProductType_member) {
+							member.PowerType = 2
+							member = &entity.Member{
+								Status:     status,
+								StartTime:  starttime,
+								EndTime:    endtime,
+								MemberName: level_map[status],
+								PowerType:  2,
+							}
+							//是否试用
+							if this.Conn.MgoJy.Count("member", map[string]interface{}{"userid": positionId}) > 0 {
+								member.Used = true
+							}
+						}
+					}
+				}
+			}
 		}
+		//大会员相关权益数量
 		memberServiceMap := map[int64]bool{}
-		//获取大会员相关操作
-		serviceList := this.Conn.Mysql.Find("bigmember_service_user", map[string]interface{}{"s_userid": userid, "i_status": 0}, "DISTINCT(s_serviceid),i_frequency", "", -1, -1)
+		serviceList := this.Conn.Mysql.Find("bigmember_service_user", bigmemberServiceUserQuery, "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 {
@@ -123,28 +238,7 @@ func (this *PowerService) Power(userid string, baseUserId, accountId, entId int6
 			member.Customers = int64(customers)
 		}
 		//
-		phone, _ := common.If((*data)["s_phone"] != nil, (*data)["s_phone"], (*data)["s_m_phone"]).(string)
 		if phone != "" {
-			//用于判断是否含有企业主体的超级订阅、大会员服务
-			epowerData := this.Conn.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.Date_Full_Layout))
-			if epowerData != nil && len(*epowerData) > 0 {
-				for _, v := range *epowerData {
-					product_type := common.ObjToString(v["product_type"])
-					if strings.Contains(product_type, entity.ProductType_vip) {
-						vip.PowerType = 2
-					} else if strings.Contains(product_type, entity.ProductType_member) {
-						member.PowerType = 2
-					}
-				}
-			}
-			//免费用户画像和附件下载权限
-			o_jy := common.ObjToMap((*data)["o_jy"])
-			//IsNewFreeTimeCell dev3.6.4版本之前发了个紧急版本处理老用户订阅问题,i_newfree字段必须用户选择地区才能生成,不能作为判断是否是新用户得唯一标识,在此版本添加了常量:IsNewFreeTimeCell作为判断标准;--ws
-			if common.IntAll((*o_jy)["i_newfree"]) > 0 || entity.IsNewFreeTimeCell < registeDate {
-				free.IsUpgrade = true //新免费用户
-			}
 			//查询是否是商机管理付费用户
 			res := this.Conn.Mysql.SelectBySql(`SELECT i. STATUS AS status, i.isNew, i.power_source, r.role_id, u.power, i.name,i.id,i.startdate,i.enddate,i.auth_status,i.auth_reason,i.dept_subscribe 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 = ? and i.id = ? ORDER BY i. STATUS DESC, i.auth_status DESC`, phone, entId)
 			if res != nil && len(*res) > 0 {
@@ -158,9 +252,8 @@ func (this *PowerService) Power(userid string, baseUserId, accountId, entId int6
 					entniche.PowerSource = common.Int64All(v["power_source"])
 					entniche.StartTime = common.Int64All(v["startdate"])
 					entniche.EndTime = common.Int64All(v["enddate"])
-
 					//
-					ent.Name = common.ObjToString((*res)[0]["name"])
+					ent.Name = common.ObjToString(v["name"])
 					ent.EntRoleId = common.Int64All(v["role_id"])
 					ent.EntAuthStatus = common.Int64All(v["auth_status"])
 					ent.EntAuthReason = common.ObjToString(v["auth_reason"])
@@ -202,13 +295,13 @@ func (this *PowerService) Power(userid string, baseUserId, accountId, entId int6
 		} else {
 			free.IsFree = false
 		}
-		return &entity.Power{
-			Vip:      vip,
-			Member:   member,
-			Free:     free,
-			Ent:      ent,
-			Entniche: entniche,
-		}
+	}
+	return &entity.Power{
+		Vip:      vip,
+		Member:   member,
+		Free:     free,
+		Ent:      ent,
+		Entniche: entniche,
 	}
 	return nil
 }
@@ -220,3 +313,20 @@ func FreeExperience(userId string) (int, int, int) {
 		redis.GetInt(entity.PowerCacheDb, fmt.Sprintf(entity.PowerCacheBuyerPortKey, userId)),
 		redis.GetInt(entity.PowerCacheDb, fmt.Sprintf(entity.PowerCacheFileKey, userId))
 }
+
+/*
+判断是企业或个人
+1.企业
+ entniche_rule
+ 查询 vip/member  free ent entniche
+2.个人
+  查询vip member free
+*/
+
+func (this *PowerService) GetEntnicheUserId(entId int64, phone string) int64 {
+	data := this.Conn.Mysql.SelectBySql(`select id from entniche_user where phone =? and ent_id =?`, phone, entId)
+	if data != nil && len(*data) > 0 {
+		return common.Int64All((*data)[0]["id"])
+	}
+	return -1
+}