Ver Fonte

feat:根据账户id获取用户身份

wangchuanjin há 1 ano atrás
pai
commit
b25dd296c9
1 ficheiros alterados com 23 adições e 7 exclusões
  1. 23 7
      identity/identity.go

+ 23 - 7
identity/identity.go

@@ -5,6 +5,7 @@ import (
 	"strings"
 
 	. "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/mongodb"
 	. "app.yhyue.com/moapp/jybase/mysql"
 	. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
 )
@@ -120,16 +121,31 @@ func IdentityByPositionId(msl *Mysql, positionId int64) *Identity {
 }
 
 //根据企业员工id获取身份信息
-func IdentityByEntUserId(msl *Mysql, entUserId int64) *Identity {
+func IdentityByEntUserId(msl *Mysql, mgo *MongodbSim, entUserId int64) *Identity {
 	ents := msl.SelectBySql(`SELECT a.id,a.name,a.phone,a.ent_id,a.niche_dis,b.name as ent_name,c.role_id,d.dept_id  from jianyu.entniche_user a inner join jianyu.entniche_info b on (a.id=? and a.ent_id=b.id) left join jianyu.entniche_user_role c on (a.id=c.user_id) LEFT JOIN jianyu.entniche_department_user d ON (d.user_id=a.id) limit 1`, entUserId)
 	if ents == nil || len(*ents) == 0 {
 		return nil
 	}
-	if entId := Int64All((*ents)[0]["ent_id"]); entId > 0 {
-		list := msl.SelectBySql(`SELECT a.id as position_id,c.person_id,a.person_name,a.account_id,a.type as position_type,d.id as user_id,b.id as ent_account_id from base_service.base_user d
-		inner join base_service.base_position a on (d.phone=? and a.ent_id=? and a.type=1 and d.id=a.user_id)
-		inner join base_service.base_account c on (c.ent_id=? and c.type=1 and a.account_id=c.id)
-		inner join base_service.base_account b on (b.type=1 and b.person_id=0 and b.ent_id=?) order by a.id desc limit 1`, ObjToString((*ents)[0]["phone"]), entId, entId, entId)
+	if entId, phone := Int64All((*ents)[0]["ent_id"]), ObjToString((*ents)[0]["phone"]); entId > 0 && phone != "" {
+		users, ok := mgo.Find(Mgo_User, map[string]interface{}{
+			"$or": []map[string]interface{}{
+				map[string]interface{}{
+					"s_phone": phone,
+				},
+				map[string]interface{}{
+					"s_m_phone": phone,
+				},
+			},
+		}, `{"s_phone":-1}`, map[string]interface{}{
+			"base_user_id": 1,
+		}, false, 0, 1)
+		if !ok || users == nil {
+			return nil
+		}
+		userId := Int64All((*users)[0]["base_user_id"])
+		list := msl.SelectBySql(`SELECT a.id as position_id,c.person_id,a.person_name,a.account_id,a.type as position_type,b.id as ent_account_id from base_service.base_position a
+		inner join base_service.base_account c on (a.user_id=? and a.ent_id=? and a.type=1 and c.ent_id=? and c.type=1 and a.account_id=c.id)
+		inner join base_service.base_account b on (b.type=1 and b.person_id=0 and b.ent_id=?) order by a.id desc limit 1`, userId, entId, entId, entId)
 		if list != nil && len(*list) > 0 {
 			identity := &Identity{
 				PersonId:     Int64All((*list)[0]["person_id"]),
@@ -138,7 +154,7 @@ func IdentityByEntUserId(msl *Mysql, entUserId int64) *Identity {
 				EntAccountId: Int64All((*list)[0]["ent_account_id"]),
 				PositionId:   Int64All((*list)[0]["position_id"]),
 				PositionType: Int64All((*list)[0]["position_type"]),
-				UserId:       Int64All((*list)[0]["user_id"]),
+				UserId:       userId,
 				EntId:        entId,
 				EntUserId:    Int64All((*ents)[0]["id"]),
 				EntUserName:  ObjToString((*ents)[0]["name"]),