Ver Fonte

fenzhihebing

123456 há 1 ano atrás
pai
commit
dae1898021
2 ficheiros alterados com 117 adições e 6 exclusões
  1. 97 4
      ent/entity/user.go
  2. 20 2
      public/db.go

+ 97 - 4
ent/entity/user.go

@@ -31,8 +31,12 @@ type User struct {
 	Dept_name string //部门名称
 	Role      string //角色
 	Power     int    //权限
+<<<<<<< HEAD
 	NicheDis  int    //商机分配权限
 	Role_id   int
+=======
+	User_name string
+>>>>>>> feature/v1.0.3
 }
 
 type CompletionUserInfo struct {
@@ -71,7 +75,7 @@ func (u *User) GetByPhone(phone string) *[]*User {
 
 //根据id获取带有角色的员工信息
 func (u *User) GetAllInfoById(entId, userId int) *User {
-	r := Mysql.SelectBySql(`SELECT a.id,a.name,a.phone,a.mail,c.name as dept_name,c.id as dept_id,e.name as role from entniche_user a 
+	r := Mysql.SelectBySql(`SELECT a.id,a.name,a.user_name,a.phone,a.mail,c.name as dept_name,c.id as dept_id,e.name as role from entniche_user a 
 		INNER JOIN entniche_department_user b on (a.id=? and a.ent_id=? and a.id=b.user_id) 
 		INNER JOIN entniche_department c on (b.dept_id=c.id)
 		LEFT JOIN entniche_user_role d on (a.id=d.user_id) 
@@ -143,11 +147,13 @@ func (u *User) Add(tx *sql.Tx, entId int, user *User, paymentAddress, source, ns
 		"ent_id":     entId,
 		"createtime": nowFormat,
 		"timestamp":  nowFormat,
+		"user_name":  user.User_name,
 	})
 	dept_user_id := Mysql.InsertByTx(tx, Entniche_department_user, map[string]interface{}{
 		"dept_id": user.Dept_id,
 		"user_id": user_id,
 	})
+
 	if user_id <= 0 || dept_user_id < 0 {
 		return user_id, false
 	}
@@ -182,7 +188,37 @@ func (u *User) Add(tx *sql.Tx, entId int, user *User, paymentAddress, source, ns
 			})
 
 		}
+		//entniche_user表,用户名字段 user_name
+		//base_user表,用户名字段 user_name
+		//mog库user表,用户名字段 user_name
+		if user.User_name != "" && len(user.User_name) > 0 {
+			Mysql.UpdateOrDeleteBySqlByTx(tx, `update entniche_user set user_name=? where phone=? and  ent_id!=?`, user.User_name, user.Phone, entId)
+			data, _ := MQFW.Find("user", map[string]interface{}{
+				"i_appid": 2,
+				"$or": []map[string]interface{}{
+					{"s_phone": user.Phone},
+					{"s_m_phone": user.Phone},
+				},
+			}, `{"s_phone":-1}`, `{"_id":1,"base_user_id":1}`, false, 0, 1)
+			if data != nil && len(*data) > 0 {
+				for _, v := range *data {
+					userId := BsonIdToSId(v["_id"])
+					baseUserId := v["base_user_id"]
+					MQFW.UpdateById("user", userId, map[string]interface{}{
+						"$set": map[string]interface{}{
+							"user_name": user.User_name,
+						},
+					})
+					Base.Update("base_user", map[string]interface{}{
+						"id": baseUserId,
+					}, map[string]interface{}{
+						"user_name": user.User_name,
+					})
+				}
+			}
+		}
 	}
+
 	return user_id, respData.Fool
 }
 
@@ -276,12 +312,67 @@ func (u *User) ResetPasswords(power_virtual_account int, virtual_account_rule, p
 func (u *User) PhoneExist(phone string, entId int) *[]map[string]interface{} {
 	return Mysql.SelectBySql("select id from entniche_user where phone=? and ent_id=?", phone, entId)
 }
+func (u *User) UserNameExist(userName, phone string) bool {
+	user, ok := MQFW.FindOne("user", map[string]interface{}{
+		"i_appid":   2,
+		"user_name": userName,
+	})
+	if ok && user != nil && len(*user) > 0 {
+		s_phone := qutil.InterfaceToStr((*user)["s_phone"])
+		s_m_phone := qutil.InterfaceToStr((*user)["s_m_phone"])
+		if s_phone != "" {
+			if s_phone == phone {
+				return true
+			}
+			return false
+		}
+		if s_m_phone != "" {
+			if s_phone == phone {
+				return true
+			}
+			return false
+		}
+	}
+	return true
+}
+
+func (u *User) UpdateUserName(tx *sql.Tx, entId, userId int, user_name, phone string) {
+	//entniche_user表,用户名字段 user_name
+	//base_user表,用户名字段 user_name
+	//mog库user表,用户名字段 user_name
+	if user_name != "" && len(user_name) > 0 {
+		Mysql.UpdateOrDeleteBySqlByTx(tx, `update entniche_user set user_name=? where phone=? and  ent_id!=?`, user_name, phone, entId)
+		data, _ := MQFW.Find("user", map[string]interface{}{
+			"i_appid": 2,
+			"$or": []map[string]interface{}{
+				{"s_phone": phone},
+				{"s_m_phone": phone},
+			},
+		}, `{"s_phone":-1}`, `{"_id":1,"base_user_id":1}`, false, 0, 1)
+		if data != nil && len(*data) > 0 {
+			for _, v := range *data {
+				userId := BsonIdToSId(v["_id"])
+				baseUserId := v["base_user_id"]
+				MQFW.UpdateById("user", userId, map[string]interface{}{
+					"$set": map[string]interface{}{
+						"user_name": user_name,
+					},
+				})
+				Base.Update("base_user", map[string]interface{}{
+					"id": baseUserId,
+				}, map[string]interface{}{
+					"user_name": user_name,
+				})
+			}
+		}
+	}
+}
 
 // 修改用户信息包括用户名和手机号  20210429海康威视需求新增的
-func (u *User) UpdateInfo(mail string, phone string, name string, userId, deptId, entId int, entPhone string, entName string, isAdmin bool) bool {
+func (u *User) UpdateInfo(mail string, phone string, name string, userId, deptId, entId int, entPhone string, entName, user_name string, isAdmin bool) bool {
 	if isAdmin {
 		ok := Mysql.ExecTx("修改员工", func(tx *sql.Tx) bool {
-			ok_1 := Mysql.UpdateOrDeleteBySqlByTx(tx, `update entniche_user set mail=?,phone=?,name=?,timestamp=? where id=? and ent_id=?`, mail, phone, name, NowFormat(Date_Full_Layout), userId, entId)
+			ok_1 := Mysql.UpdateOrDeleteBySqlByTx(tx, `update entniche_user set mail=?,phone=?,name=?,timestamp=? ,user_name=? where id=? and ent_id=?`, mail, phone, name, NowFormat(Date_Full_Layout), user_name, userId, entId)
 			MQFW.Update("ent_user", map[string]interface{}{"i_entid": entId, "i_userid": userId}, map[string]interface{}{
 				"$set": map[string]interface{}{
 					"o_pushset.s_email": mail,
@@ -289,6 +380,7 @@ func (u *User) UpdateInfo(mail string, phone string, name string, userId, deptId
 			}, true, false)
 			ok_2 := Mysql.UpdateOrDeleteBySqlByTx(tx, "update entniche_info set admin=?,phone=? where id=?", name, phone, entId)
 			ok_3 := VarUser.Move(tx, entId, deptId, fmt.Sprint(userId))
+			u.UpdateUserName(tx, entId, userId, user_name, phone)
 			return ok_1 != -1 && ok_3 && ok_2 != -1
 		})
 		if ok {
@@ -303,13 +395,14 @@ func (u *User) UpdateInfo(mail string, phone string, name string, userId, deptId
 		}
 	} else {
 		return Mysql.ExecTx("修改员工", func(tx *sql.Tx) bool {
-			ok_1 := Mysql.UpdateOrDeleteBySqlByTx(tx, `update entniche_user set mail=?,phone=?,name=?,timestamp=? where id=? and ent_id=?`, mail, phone, name, NowFormat(Date_Full_Layout), userId, entId)
+			ok_1 := Mysql.UpdateOrDeleteBySqlByTx(tx, `update entniche_user set mail=?,phone=?,name=?,timestamp=? ,user_name=? where id=? and ent_id=?`, mail, phone, name, NowFormat(Date_Full_Layout), user_name, userId, entId)
 			MQFW.Update("ent_user", map[string]interface{}{"i_entid": entId, "i_userid": userId}, map[string]interface{}{
 				"$set": map[string]interface{}{
 					"o_pushset.s_email": mail,
 				},
 			}, true, false)
 			ok_2 := VarUser.Move(tx, entId, deptId, fmt.Sprint(userId))
+			u.UpdateUserName(tx, entId, userId, user_name, phone)
 			return ok_1 == 1 && ok_2
 		})
 	}

+ 20 - 2
public/db.go

@@ -35,8 +35,9 @@ type dbConf struct {
 		Seo     *mgoConf
 	}
 	Elasticsearch struct {
-		Main *esConf
-		Doc  *esConf
+		Main  *esConf
+		Doc   *esConf
+		Other *esConf
 	}
 	Redis struct {
 		Main  *redisConf
@@ -79,6 +80,10 @@ type mysqlConf struct {
 	MaxIdleConns int
 }
 
+var (
+	Other elastic.Es
+)
+
 func init() {
 	util.ReadConfig("./db.json", &DbConf)
 	if DbConf != nil {
@@ -93,6 +98,19 @@ func init() {
 			log.Println("初始化 doc elasticsearch")
 		}
 
+		if DbConf.Elasticsearch.Other != nil {
+			Other = &elastic.EsV7{
+				Address:  DbConf.Elasticsearch.Other.Address,
+				UserName: DbConf.Elasticsearch.Other.UserName,
+				Password: DbConf.Elasticsearch.Other.Password,
+				Size:     DbConf.Elasticsearch.Other.Size,
+			}
+			Other.Init()
+			//es.InitElasticSizeByAuth(DbConf.Elasticsearch.Other.Address, DbConf.Elasticsearch.Other.Size,
+			//	DbConf.Elasticsearch.Other.UserName, DbConf.Elasticsearch.Other.Password)
+			log.Println("初始化 Other elasticsearch")
+		}
+
 		//初始化redis
 		if DbConf.Redis.Main != nil {
 			log.Println("初始化 redis")