/// <summary> /// 获取客户端列表 /// </summary> public static List<Clients> GetClients(string keyWords,int type, string orderBy,int pageSize, int pageIndex, ref int totalCount, ref int pageCount) { string sqlWhere = "a.Status<>9"; if (!string.IsNullOrEmpty(keyWords)) { sqlWhere += " and ( a.CompanyName like '%" + keyWords + "%' or a.AliMemberID like '%" + keyWords + "%' or a.MobilePhone like '%" + keyWords + "%' or a.ClientCode like '%" + keyWords + "%')"; } if (type > -1) { if (type == 0) { sqlWhere += " and len(a.AliMemberID)=0 "; } else { sqlWhere += " and len(a.AliMemberID)>0 "; } } string sqlColumn = @" a.AutoID,a.ClientID,a.ClientCode,a.CompanyName,a.Logo,a.Industry, a.CityCode,a.Address,a.PostalCode,a.ContactName,a.MobilePhone,a.OfficePhone, a.Status,b.EndTime,b.UserQuantity,a.TotalIn,a.TotalOut,a.FreezeMoney, a.Description,a.AuthorizeType,a.IsDefault,a.AgentID,a.CreateTime,a.CreateUserID,a.AliMemberID "; bool isAsc=false; if (string.IsNullOrEmpty(orderBy)) { orderBy = "a.AutoID"; } else { isAsc=orderBy.IndexOf(" asc")>-1?true:false; orderBy = orderBy.Replace(" desc", "").Replace(" asc", ""); } DataTable dt = CommonBusiness.GetPagerData("Clients a join Agents b on a.ClientID=b.ClientID", sqlColumn, sqlWhere, orderBy, pageSize, pageIndex, out totalCount, out pageCount, isAsc); List<Clients> list = new List<Clients>(); Clients model; foreach (DataRow item in dt.Rows) { model = new Clients(); model.FillData(item); model.City = CommonBusiness.Citys.Where(c => c.CityCode == model.CityCode).FirstOrDefault(); // model.IndustryEntity =Manage.IndustryBusiness.GetIndustrys().Where(i => i.IndustryID.ToLower() == model.Industry.ToLower()).FirstOrDefault(); list.Add(model); } return list; }
/// <summary> /// 添加客户端 /// </summary> /// <param name="model">Clients 对象</param> /// <param name="loginName">账号</param> /// <param name="loginPwd">密码</param> /// <param name="userid">操作人</param> /// <param name="result">0:失败 1:成功 2:账号已存在 3:模块未选择</param> public static string InsertClient(Clients model, string loginname, string bindMobilePhone, string loginPwd, string userid, out int result, string email = "", string mduserid = "", string mdprojectid = "", string aliMemberID = "", string weiXinID = "") { loginPwd = CloudSalesTool.Encrypt.GetEncryptPwd(loginPwd, bindMobilePhone); string clientid = ClientDAL.BaseProvider.InsertClient(model.CompanyName, loginname, model.ContactName, model.MobilePhone, model.Industry, model.CityCode, model.Address, model.Description, bindMobilePhone, loginPwd, email, mduserid, mdprojectid, userid,aliMemberID,weiXinID, out result); return clientid; }
/// <summary> /// 更新客户信息 /// </summary> /// <param name="model"></param> /// <param name="userid"></param> /// <param name="result"></param> /// <returns></returns> public static bool UpdateClient(Clients model, string userid) { if (!string.IsNullOrEmpty(model.Logo) && model.Logo.IndexOf(TempPath) >= 0) { DirectoryInfo directory = new DirectoryInfo(HttpContext.Current.Server.MapPath(FILEPATH)); if (!directory.Exists) { directory.Create(); } if (model.Logo.IndexOf("?") > 0) { model.Logo = model.Logo.Substring(0, model.Logo.IndexOf("?")); } FileInfo file = new FileInfo(HttpContext.Current.Server.MapPath(model.Logo)); model.Logo = FILEPATH + file.Name; if (file.Exists) { file.MoveTo(HttpContext.Current.Server.MapPath(model.Logo)); } } bool flag= ClientDAL.BaseProvider.UpdateClient(model.ClientID, model.CompanyName , model.ContactName, model.MobilePhone, model.Industry , model.CityCode, model.Address, model.Description,model.Logo==null?"":model.Logo,model.OfficePhone , userid); if (flag) { if (Clients.ContainsKey(model.ClientID)) Clients[model.ClientID] = GetClientDetailBase(model.ClientID); //Clients[model.ClientID]=model; } return flag; }
/// <summary> /// 更新客户缓存 /// </summary> /// <param name="clientID"></param> /// <param name="client"></param> /// <returns></returns> public static bool UpdateClientCache(string clientID,Clients client) { if (Clients.ContainsKey(clientID)) { Clients[clientID] = client; } return true; }
public static Clients GetClientDetailBase(string clientID) { DataTable dt = ClientDAL.BaseProvider.GetClientDetail(clientID); Clients model = new Clients(); if (dt.Rows.Count == 1) { DataRow row = dt.Rows[0]; model.FillData(row); model.City = CommonBusiness.Citys.Where(c => c.CityCode == model.CityCode).FirstOrDefault(); //model.IndustryEntity = Manage.IndustryBusiness.GetIndustrys().Where(i => i.IndustryID.ToLower() == model.Industry.ToLower()).FirstOrDefault(); return model; } else { return null; } }
/// <summary> /// 主动注册客户端 /// </summary> /// <param name="name"></param> /// <param name="companyName"></param> /// <param name="loginName"></param> /// <param name="loginPWD"></param> /// <returns></returns> public JsonResult RegisterClient(string name, string companyName, string loginName, string loginPWD,string code) { int result = 0; Dictionary<string, object> JsonDictionary = new Dictionary<string, object>(); bool bl = OrganizationBusiness.IsExistLoginName(loginName); if (bl){ result = 2; } else { bl = Common.Common.ValidateMobilePhoneCode(loginName, code); if (!bl){ result = 3; } else { Clients client = new Clients() { CompanyName = companyName, ContactName = name, MobilePhone = loginName }; ClientBusiness.InsertClient(client, "", loginName, loginPWD, string.Empty, out result); if (result == 1) { string operateip = Common.Common.GetRequestIP(); int outResult; IntFactoryEntity.Users user = IntFactoryBusiness.OrganizationBusiness.GetUserByUserName(loginName, loginPWD, out outResult, operateip); if (user != null){ Session["ClientManager"] = user; } Common.Common.ClearMobilePhoneCode(loginName); } else result = 0; } } JsonDictionary.Add("Result", result); return new JsonResult() { Data = JsonDictionary, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
//微信账户注册 public ActionResult WinXinRegisterMember() { string operateip = Common.Common.GetRequestIP(); int result; if (Session["WeiXinTokenInfo"] != null) { string tokenInfo = Session["WeiXinTokenInfo"].ToString(); string[] tokenArr = tokenInfo.Split('|'); if (tokenArr.Length == 3) { string access_token = tokenArr[0]; string openid = tokenArr[1]; var memberResult = WeiXin.Sdk.Passport.GetUserInfo(access_token, openid); Clients clientModel = new Clients(); clientModel.CompanyName = memberResult.nickname; clientModel.ContactName = memberResult.nickname; clientModel.MobilePhone = string.Empty; var clientid = ClientBusiness.InsertClient(clientModel, "", "", "", "", out result, "", string.Empty, string.Empty,string.Empty,memberResult.unionid); if (!string.IsNullOrEmpty(clientid)) { var current = OrganizationBusiness.GetUserByWeiXinID(memberResult.unionid, operateip); current.MDToken = access_token; Session.Remove("WeiXinTokenInfo"); Session["ClientManager"] = current; return Redirect("/Home/Index"); } } } return Redirect("/Home/Login"); }
//阿里账户注册 public ActionResult AliRegisterMember() { string operateip = Common.Common.GetRequestIP(); int result; if (Session["AliTokenInfo"] != null) { string tokenInfo = Session["AliTokenInfo"].ToString(); string[] tokenArr = tokenInfo.Split('|'); if (tokenArr.Length == 3) { string access_token = tokenArr[0]; string refresh_token = tokenArr[1]; string memberId = tokenArr[2]; var memberResult = AlibabaSdk.UserBusiness.GetMemberDetail(access_token, memberId); var member = memberResult.result.toReturn[0]; Clients clientModel = new Clients(); clientModel.CompanyName = member.companyName ?? string.Empty; clientModel.ContactName = member.sellerName ?? string.Empty; clientModel.MobilePhone = string.Empty; var clientid = ClientBusiness.InsertClient(clientModel, "", "", "", "", out result, member.email, string.Empty, string.Empty, member.memberId); if (!string.IsNullOrEmpty(clientid)) { var current = OrganizationBusiness.GetUserByAliMemberID(member.memberId, operateip); AliOrderBusiness.BaseBusiness.AddAliOrderDownloadPlan(current.UserID, member.memberId, access_token, refresh_token, current.AgentID, current.ClientID); current.MDToken = access_token; Session.Remove("AliTokenInfo"); Session["ClientManager"] = current; return Redirect("/Home/Index"); } } } return Redirect("/Home/Login"); }