/// <summary> /// 导入部门 /// </summary> /// <param name="storeId"></param> public void ImportDepartment(int storeId) { var permanentCode = WorkWeChats.GetAccessToken(storeId); var list = WorkWeiXinSDK.GetDepartmentList(permanentCode.access_token, string.Empty); var oldList = DepartmentManager.GetList(storeId); //导入微信通讯录的部门 foreach (var item in list.department) { //部门不存在,创建部门 var old = oldList.Find(x => x.Name.ToLower().Equals(item.name.ToLower())); if (old == null) { var newModel = new Department() { StoreId = storeId, Name = item.name, Parentid = item.parentid, Sort = item.order, wxDepartmentId = item.id, AddTime = DateTime.Now }; DepartmentManager.Add(newModel); //Response.Write($"{item.name} 导入成功 (新增)<br/>"); } else { old.Name = item.name; old.Parentid = item.parentid; old.Sort = item.order; old.wxDepartmentId = item.id; DepartmentManager.Update(old); //Response.Write($"{item.name} 导入成功 (更新)<br/>"); } } }
/// <summary> /// 员工列表 /// </summary> /// <param name="storeId"></param> public void UserList(int storeId, int deptId = 0) { var permanentCode = WorkWeChats.GetAccessToken(storeId); var list = WorkWeiXinSDK.GetUserList(permanentCode.access_token, deptId.ToString()); foreach (var item in list.userlist) { Response.Write(item.name + "<br/>"); } }
/// <summary> /// 部门列表 /// </summary> /// <param name="storeId"></param> public void DepartmentList(int storeId) { var permanentCode = WorkWeChats.GetAccessToken(storeId); var list = WorkWeiXinSDK.GetDepartmentList(permanentCode.access_token, string.Empty); foreach (var item in list.department) { Response.Write(item.name + "<br/>"); } }
public void GetUserDetail(int storeId, string userid, string access_token = "") { if (string.IsNullOrEmpty(access_token)) { var permanentCode = WorkWeChats.GetAccessToken(storeId); access_token = permanentCode.access_token; } var model = WorkWeiXinSDK.GetUser(access_token, userid); if (model != null) { Response.Write(JsonConvert.SerializeObject(model)); } }
public void CreateDepartment(int storeId, string name = "销售二部") { var permanentCode = WorkWeChats.GetAccessToken(storeId); Response.Write(WorkWeiXinSDK.CreateDepartment(permanentCode.access_token, name, 3, 19)); }
public void ImportUser(int storeId) { var permanentCode = WorkWeChats.GetAccessToken(storeId); //已存在的成员 var oldUserList = StaffManager.GetListByStoreId(storeId); //已存在的部门 var oldDeptList = DepartmentManager.GetList(storeId); //已存在的员工部门关系 var oldUnionList = StaffDepartmentManager.GetListByStoreId(storeId); var wxDeptId = oldDeptList.Find(x => x.wxDepartmentId > 0 && x.Parentid == 0); var list = WorkWeiXinSDK.GetUserList(permanentCode.access_token, wxDeptId.wxDepartmentId.ToString()); //导入微信通讯录的成员 foreach (var item in list.userlist) { //成员不存在,创建成员 var old = oldUserList.Find(x => x.Name.ToLower().Equals(item.name.ToLower())); if (old == null) { //创建用户 var userInfo = Staffs.CreateUser(storeId, item.name); //开通聊天的用户 WebIMUtil.ImportUser(userInfo); old = new Staff() { StoreId = storeId, Uid = userInfo.Uid, Name = item.name, wxUserId = item.userid, Wxid = string.Empty, Avater = string.Empty, AiState = 0, BossState = 0, MobileState = "1", Company = permanentCode.corp_full_name, ClickCount = 0, SignUpCount = 0, UpCount = 0, ShareCount = 0, QrCode = "", Sign = string.Empty, Mobile = string.Empty, Phone = string.Empty, Email = string.Empty, wxMobile = string.Empty, Address = string.Empty, Position = string.Empty, Department = string.Empty, Addtime = DateTime.Now }; StaffManager.Add(old); //Response.Write($"{item.name} 导入成功 (新增) " + userInfo.Uid + "<br/>"); } else { //创建用户 if (old.Uid < 1) { //创建用户 var userInfo = Staffs.CreateUser(storeId, item.name); //开通聊天的用户 WebIMUtil.ImportUser(userInfo); old.Uid = userInfo.Uid; } StaffManager.Update(old); //Response.Write($"{item.name} 导入成功 (更新)<br/>"); } //导入所属部门 foreach (var departmentId in item.department) { //用微信的部门ID,找到系统的部门ID var dept = oldDeptList.Find(x => x.wxDepartmentId == departmentId); var deptId = dept != null ? dept.Id : 0; //判断 员工ID,系统部门ID是否相同 var oldUnion = oldUnionList.Find(x => x.StaffId == old.Id && x.DepartmentId == deptId); if (oldUnion == null) { StaffDepartment newUnion = new StaffDepartment() { DepartmentId = deptId, StaffId = old.Id, StoreId = storeId }; StaffDepartmentManager.Add(newUnion); } } } }