/// <summary> /// /// </summary> /// <param name="user_id"></param> /// <param name="user_name"></param> /// <returns></returns> public BUser GetSubUser(string user_id, string user_name) { BUser user=null; SubuserFullinfoGetRequest req = new SubuserFullinfoGetRequest(); req.Fields = "subuser_email,user_email"; req.SubNick = user_name; SubuserFullinfoGetResponse response = client.Execute(req, this.Access_Token.Access_Token1); if (response.IsError) { throw new KMJXCException("在"+this.MallType.Name+"没有找到用户"+user_name,ExceptionLevel.ERROR); } if (response.SubFullinfo != null) { user = new BUser(); user.Mall_Name = user_name; user.Mall_ID = response.SubFullinfo.SubId.ToString(); user.Type = this.MallType; user.Parent = new BUser(); user.Parent.Mall_ID = response.SubFullinfo.UserId.ToString(); user.Parent.Mall_Name = response.SubFullinfo.UserNick; user.Parent.Type = this.MallType; user.Parent.Parent = null; BEmployee employee = new BEmployee(); user.EmployeeInfo = employee; employee.Department = response.SubFullinfo.DepartmentName; employee.Duty = response.SubFullinfo.DutyName; employee.Email = response.SubFullinfo.SubuserEmail; employee.Gendar = response.SubFullinfo.Sex.ToString(); employee.Name = response.SubFullinfo.EmployeeName; employee.Phone = response.SubFullinfo.OfficePhone; } return user; }
/// <summary> /// /// </summary> /// <param name="user"></param> /// <returns></returns> public List<Product_Class> GetCategories(BUser user) { List<Product_Class> categories = new List<Product_Class>(); SellercatsListGetRequest req = new SellercatsListGetRequest(); req.Nick = user.Mall_Name; SellercatsListGetResponse response = client.Execute(req); if (response.IsError) { throw new KMJXCException(response.ErrMsg); } if (response.SellerCats != null) { foreach (TB.SellerCat cat in response.SellerCats) { Product_Class category = new Product_Class(); category.Create_Time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); category.Create_User_ID = user.ID; category.Enabled = true; category.Mall_CID = cat.Cid.ToString(); category.Mall_PCID = cat.ParentCid.ToString(); category.Name = cat.Name; category.Parent_ID = 0; category.Product_Class_ID = 0; categories.Add(category); } } return categories; }
public BBaseManager(BUser user, Shop shop, Permission permission) { this.CurrentUser = user; GetUserById(user.ID); this.Shop = shop; this.GetShops(); permissionManager = new PermissionManager(this.Shop.Shop_ID); this.CurrentUserPermission = permission; this.GetUserPermission(); }
public BBaseManager(BUser user,int shop_id,Permission permission) { this.CurrentUser = user; GetUserById(user.ID); this.Shop_Id = shop_id; if (this.Shop_Id == 0) { this.GetShops(); } permissionManager = new PermissionManager(shop_id); this.CurrentUserPermission = permission; this.GetUserPermission(); }
/// <summary> /// Create new user /// </summary> /// <param name="user"></param> /// <returns></returns> public BUser CreateNewUser(BUser user) { if (user == null) { throw new UserException("用户实体不能为空引用"); } if (string.IsNullOrEmpty(user.Name)) { throw new UserException("用户名不能为空"); } if (this.CurrentUserPermission.ADD_USER == 0) { throw new UserException("没有权限创建新用户"); } KuanMaiEntities dba = new KuanMaiEntities(); try { if (GetUser(user) != null) throw new UserException("用户名已经存在"); User dbUser = new User(); dbUser.User_ID = user.ID; dbUser.Mall_ID = user.Mall_ID; dbUser.Mall_Name = user.Mall_Name; dbUser.Name = user.Name; dbUser.Mall_Type = user.Type.ID; if (user.Parent != null) { dbUser.Parent_Mall_ID = user.Parent.Mall_ID; dbUser.Parent_Mall_Name = user.Parent.Mall_Name; dbUser.Parent_User_ID = user.Parent.ID; } dba.User.Add(dbUser); dba.SaveChanges(); return user; } catch (Exception ex) { throw ex; } finally { if (dba != null) { dba.Dispose(); } } }
/// <summary> /// Get all actions /// </summary> /// <param name="user"></param> /// <returns></returns> public List<Admin_Action> GetActions(BUser user) { List<Admin_Action> actions = new List<Admin_Action>(); List<Admin_Action> all_actions = new List<Admin_Action>(); using (KuanMaiEntities db = new KuanMaiEntities()) { if (user != null) { actions = this.GetUserActions(user); } var ps = from a in db.Admin_Action select a; all_actions = ps.ToList<Admin_Action>(); } foreach (Admin_Action action in all_actions) { bool found = false; foreach (Admin_Action uaction in actions) { if (action.action_name == uaction.action_name && action.id == uaction.id) { found = true; break; } } if (found) { action.enable = true; } else { action.enable = false; } } return all_actions; }
/// <summary> /// Get user actions /// </summary> /// <param name="user"></param> /// <returns></returns> public List<Admin_Action> GetUserActions(BUser user) { List<Admin_Action> actions = new List<Admin_Action>(); using (KuanMaiEntities db = new KuanMaiEntities()) { var ps = from a in db.Admin_Action join c in db.Admin_Role_Action on a.id equals c.action_id join d in db.Admin_User_Role on c.role_id equals d.role_id join b in db.Admin_Role on d.role_id equals b.id where d.user_id==user.ID && b.enabled==true orderby a.id ascending select a; actions = ps.ToList<Admin_Action>(); } return actions; }
/// <summary> /// Update user object /// </summary> /// <param name="newUser"></param> public void UpdateUser(BUser user) { if (this.CurrentUserPermission.UPDATE_USER == 0) { throw new UserException("没有权限创建新用户"); } using (KuanMaiEntities db = new KuanMaiEntities()) { var old = from ou in db.User where ou.User_ID == user.ID select ou; User dbUser = old.FirstOrDefault<User>(); if (dbUser != null) { dbUser.User_ID = user.ID; dbUser.Mall_ID = user.Mall_ID; dbUser.Mall_Name = user.Mall_Name; dbUser.Name = user.Name; dbUser.Password = user.Password; //dbUser.Mall_Type = user.Type.Mall_Type_ID; if (user.Parent != null) { dbUser.Parent_Mall_ID = user.Parent.Mall_ID; dbUser.Parent_Mall_Name = user.Parent.Mall_Name; dbUser.Parent_User_ID = user.Parent.ID; } Employee employee = (from em in db.Employee where em.User_ID == dbUser.User_ID select em).FirstOrDefault<Employee>(); if (employee != null) { base.UpdateProperties(employee, user.EmployeeInfo); } } db.SaveChanges(); } }
public UserActionLogManager(BUser user) { this.CurrentUser = user; }
public ShopCategoryManager(BUser user, Shop shop, Permission permission) : base(user, shop, permission) { mallShopManager = new TaoBaoShopManager(this.AccessToken, this.Shop.Mall_Type_ID); }
/// <summary> /// Get user by user object /// </summary> /// <param name="user"></param> /// <returns></returns> public BUser GetUser(BUser user) { return this.GetUser(user.ID); }
/// <summary> /// /// </summary> /// <param name="mall_name"></param> /// <returns></returns> public BUser GetSubUserFullInfo(string mall_name) { BUser user = new BUser(); return user; }
/// <summary> /// /// </summary> /// <param name="user"></param> /// <param name="shop_id"></param> /// <returns></returns> public bool ShopUserVerification(BUser user, int shop_id) { bool result = false; return result; }
/// <summary> /// Get user information from mall /// </summary> /// <param name="user_id"></param> /// <param name="user_name"></param> /// <returns></returns> public BUser GetUser(string user_id, string user_name) { UserGetRequest req = new UserGetRequest(); req.Fields = "user_id,uid,nick"; req.Nick = ""; UserGetResponse response = client.Execute(req, this.Access_Token.Access_Token1); if (response.IsError || response.User==null) { throw new KMJXCException(response.ErrMsg); } BUser user = new BUser(); user.ID = 0; user.Mall_ID = response.User.Uid; user.Mall_Name = response.User.Nick; user.Type = new BMallType() { ID=this.Mall_Type_ID}; user.Parent = null; user.Password = ""; return user; }
/// <summary> /// /// </summary> /// <param name="user"></param> /// <param name="shop"></param> /// <returns></returns> public List<BMallProduct> GetOnSaleProducts(BUser user, Shop shop, long pageIndex,long pageSize, out long total) { List<BMallProduct> products = new List<BMallProduct>(); total = 0; if (pageIndex <= 0) { pageIndex = 1; } if (pageSize <= 0) { pageSize = 50; } List<TB.Item> items = GetItems(out total, pageIndex, pageSize); if (items == null) { return products; } string num_idd = ""; foreach (TB.Item item in items) { if (num_idd == "") { num_idd = item.NumIid.ToString(); } else { num_idd +=","+ item.NumIid.ToString(); } BMallProduct product = new BMallProduct(); if (!string.IsNullOrEmpty(item.Created)) { product.Created = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(item.Created)); } product.ID = item.NumIid.ToString(); if (!string.IsNullOrEmpty(item.Modified)) { product.Modified = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(item.Modified)); } if (!string.IsNullOrEmpty(item.OuterId)) { int tmpId = 0; int.TryParse(item.OuterId, out tmpId); product.OuterID = tmpId; } product.PicUrl = item.PicUrl; if (!string.IsNullOrEmpty(item.Price)) { product.Price = double.Parse(item.Price); } product.Quantity = item.Num; if (!string.IsNullOrEmpty(item.Desc)) { product.Description = item.Desc; } product.Shop = new BShop { ID=shop.Shop_ID }; product.Title = item.Title; if (product.Skus == null) { product.Skus = new List<BMallSku>(); } products.Add(product); } List<TB.Sku> skus = this.GetSuks(num_idd); if (skus != null) { foreach (BMallProduct pdt in products) { List<TB.Sku> tmpskus = (from sku in skus where sku.NumIid == long.Parse(pdt.ID) select sku).ToList<TB.Sku>(); foreach (TB.Sku sku in tmpskus) { BMallSku msku = new BMallSku(); int tmpId = 0; int.TryParse(sku.OuterId, out tmpId); msku.OuterID = tmpId; msku.MallProduct_ID = pdt.ID; msku.PropertiesName = sku.PropertiesName; msku.Quantity = sku.Quantity; msku.SkuID = sku.SkuId.ToString(); msku.Properities = sku.Properties; if (!string.IsNullOrEmpty(sku.Price)) { msku.Price = double.Parse(sku.Price); } pdt.Skus.Add(msku); } } } return products; }
public PermissionManagement(BUser user, Shop shop, Permission permission) : base(user, shop, permission) { PermissionManager = new PermissionManager(shop.Shop_ID); }
public SupplierManager(BUser user, int shop_id, Permission permission) : base(user, shop_id,permission) { }
public BBaseManager(BUser user, Permission permission) { GetUserById(user.ID); permissionManager = new PermissionManager(); this.GetShops(); this.CurrentUserPermission = permission; this.CurrentUser = user; this.GetUserPermission(); }
/// <summary> /// Get user permission /// </summary> /// <param name="user">User object, must has User_ID field</param> /// <returns>Permissions Object</returns> public Permission GetUserPermission(BUser user) { Permission permissions = new Permission(); List<Admin_Action> actions = this.GetUserActions(user); Type type = typeof(Permission); foreach (Admin_Action action in actions) { FieldInfo field = type.GetField(action.action_name); if (field != null) { field.SetValue(permissions, 1); } } return permissions; }
/// <summary> /// Get sub accounts from mall /// </summary> /// <param name="mainUser"></param> /// <returns></returns> public List<BUser> GetSubUsers(BUser mainUser) { List<BUser> users = new List<BUser>(); SubusersGetRequest req = new SubusersGetRequest(); req.UserNick = mainUser.Mall_Name; SubusersGetResponse response = client.Execute(req, this.Access_Token.Access_Token1); if (response.IsError) { throw new KMJXCException(response.ErrMsg); } if (response.Subaccounts != null && response.Subaccounts.Count > 0) { foreach (Top.Api.Domain.SubAccountInfo subaccount in response.Subaccounts) { BUser u = new BUser(); u = this.GetSubUser(subaccount.SubId.ToString(), subaccount.SubNick); u.Parent = mainUser; users.Add(u); } } return users; }
/// <summary> /// /// </summary> /// <param name="userId"></param> /// <returns></returns> public Access_Token GetAccessToken(BUser loginUser) { Access_Token token = null; token = this.GetLocalToken(loginUser.ID, this.Mall_Type_ID); if (token != null) { long timeNow = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); //last access token is expried if (timeNow >= token.Expirse_In + token.Request_Time) { return null; } else { return token; } } return null; }
public SalesManager(BUser user, int shop_id, Permission permission) : base(user, shop_id, permission) { tradeManager = new TaobaoTradeManager(this.AccessToken, this.Shop.Mall_Type_ID); }
/// <summary> /// Calback from Mall Open API Authorization, it will verify if current login user has access to the system /// </summary> /// <param name="code">returns by Mall Open API Authorization</param> /// <returns></returns> public Access_Token AuthorizationCallBack(string code) { Access_Token request_token = null; BUser requester = new BUser(); //must get access token after mall authorization to identify user request_token = TokenManager.RequestAccessToken(code); if (request_token == null) { throw new KMJXCException("没有获取到Access token", ExceptionLevel.SYSTEM); } requester.Type = new BMallType() { ID = this.Mall_Type_ID }; requester.Mall_ID = request_token.Mall_User_ID; requester.Mall_Name = request_token.Mall_User_Name; requester.Parent_ID = 0; requester.Parent = null; KuanMaiEntities db = new KuanMaiEntities(); try { var db_user = from u in db.User where u.Mall_ID == requester.Mall_ID && u.Mall_Name == requester.Mall_Name && u.Mall_Type == this.Mall_Type_ID select new BUser { ID = u.User_ID, Name = u.Name, Mall_Name = u.Mall_Name, Mall_ID = u.Mall_ID, Password = u.Password, Parent_ID = (int)u.Parent_User_ID, }; List<BUser> users = db_user.ToList<BUser>(); //Create user in local db with mall owner id if (users.Count == 0) { this.InitializeMallManagers(request_token); if (this.ShopManager == null) { throw new KMJXCException("IShopManager 实例为null", ExceptionLevel.SYSTEM); } //check if current user's shop is ready in system Shop shop = this.ShopManager.GetShop(requester); if (shop == null) { BUser subUser = this.MallUserManager.GetSubUser(requester.Mall_ID, requester.Mall_Name); if (subUser == null) { throw new KMJXCException("用户:" + requester.Mall_Name + " 没有对应的" + ((KM.JXC.BL.Open.OBaseManager)this.ShopManager).MallType.Description + ",并且不属于任何店铺的子账户", ExceptionLevel.ERROR); } else { // if (subUser.Parent == null || string.IsNullOrEmpty(subUser.Parent.Mall_Name)) { throw new KMJXCException("用户:" + requester.Mall_Name + " 没有对应的" + ((KM.JXC.BL.Open.OBaseManager)this.ShopManager).MallType.Description + ",并且不属于任何店铺的子账户", ExceptionLevel.ERROR); } BUser mainUser = null; var u = from us in db.User where us.Mall_ID == subUser.Parent.Mall_ID && us.Mall_Type == requester.Type.ID && us.Mall_Name == subUser.Parent.Mall_Name select new BUser { ID = us.User_ID, Name = us.Name, Mall_Name = us.Mall_Name, Mall_ID = us.Mall_ID, Password = us.Password, Parent_ID = (int)us.Parent_User_ID, Type = new BMallType { ID = us.Mall_Type } }; if (u.ToList<BUser>().Count() == 1) { mainUser = u.ToList<BUser>()[0]; } if (mainUser == null) { throw new KMJXCException("主账户:" + subUser.Parent.Mall_Name + " 还没有初始化店铺信息,所有子账户无法登录系统", ExceptionLevel.ERROR); } requester.Parent_ID = mainUser.ID; requester.Parent = mainUser; requester.EmployeeInfo = subUser.EmployeeInfo; } } //create user in local db requester.Name = requester.Mall_Name; requester.Password = Guid.NewGuid().ToString(); User dbUser = new User(); dbUser.User_ID = requester.ID; dbUser.Mall_ID = requester.Mall_ID; dbUser.Mall_Name = requester.Mall_Name; dbUser.NickName = ""; dbUser.Name = requester.Name; dbUser.Mall_Type = requester.Type.ID; dbUser.Parent_Mall_ID = ""; dbUser.Parent_Mall_Name = ""; dbUser.Parent_User_ID = 0; dbUser.Password = ""; dbUser.Name = dbUser.Mall_Name; dbUser.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); dbUser.Modified = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); dbUser.Modified_By = 0; if (requester.Parent != null) { dbUser.Parent_Mall_ID = requester.Parent.Mall_ID; dbUser.Parent_Mall_Name = requester.Parent.Mall_Name; dbUser.Parent_User_ID = requester.Parent.ID; } db.User.Add(dbUser); db.SaveChanges(); //create access token for the new user request_token.User_ID = dbUser.User_ID; requester.ID = dbUser.User_ID; db.Access_Token.Add(request_token); //save employee if (requester.Parent_ID > 0 && requester.EmployeeInfo != null) { requester.EmployeeInfo.User_ID = requester.ID; Employee employee = new Employee(); employee.Name = requester.EmployeeInfo.Name; employee.IdentityCard = requester.EmployeeInfo.IdentityCard; employee.MatureDate = requester.EmployeeInfo.MatureDate; employee.Phone = requester.EmployeeInfo.Phone; employee.User_ID=requester.EmployeeInfo.User_ID; employee.HireDate = requester.EmployeeInfo.HireDate; employee.Gendar = requester.EmployeeInfo.Gendar; employee.Duty = requester.EmployeeInfo.Duty; employee.Email = requester.EmployeeInfo.Email; employee.Department = requester.EmployeeInfo.Department; employee.BirthDate = requester.EmployeeInfo.BirthDate; employee.Address = requester.EmployeeInfo.Address; db.Employee.Add(employee); } if (shop != null) { //create local shop information for the new main user shop.User_ID = requester.ID; shop.Parent_Shop_ID = 0; shop.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); shop.Synced = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); db.Shop.Add(shop); db.SaveChanges(); //save shop user Shop_User shop_User = new Shop_User(); shop_User.User_ID = requester.ID; shop_User.Shop_ID = shop.Shop_ID; db.Shop_User.Add(shop_User); //update dbuser dbUser.Shop_ID = shop.Shop_ID; db.SaveChanges(); //create default stock house Store_House shouse = new Store_House(); shouse.Shop_ID = shop.Shop_ID; shouse.Title = "默认仓库"; shouse.User_ID = requester.ID; shouse.Create_Time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); db.Store_House.Add(shouse); db.SaveChanges(); } if (shop != null && requester.Parent_ID == 0) { //sync mall sub users to system //List<BUser> subUsers = this.MallUserManager.GetSubUsers(requester); //if (subUsers != null && subUsers.Count > 0 && shop.Shop_ID > 0) //{ // foreach (BUser user in subUsers) // { // User db1User = new User(); // db1User.Parent_Mall_ID = requester.Mall_ID; // db1User.Parent_Mall_Name = requester.Mall_Name; // db1User.Parent_User_ID = (int)requester.ID; // db1User.Mall_Name = user.Mall_Name; // db1User.Mall_ID = user.Mall_ID; // db1User.Mall_Type = user.Type.Mall_Type_ID; // db1User.Name = user.Name; // db1User.Password = ""; // db.User.Add(db1User); // db.SaveChanges(); // if (db1User.User_ID > 0) // { // //add shop user // Shop_User shop_User1 = new Shop_User(); // shop_User1.User_ID = requester.ID; // shop_User1.Shop_ID = shop.Shop_ID; // db.Shop_User.Add(shop_User1); // if (user.EmployeeInfo != null) // { // user.EmployeeInfo.User_ID = db1User.User_ID; // db.Employee.Add(user.EmployeeInfo); // //db.SaveChanges(); // } // } // } // db.SaveChanges(); //} } } else { //Verify if local db has non expried accesstoken requester = users[0]; Access_Token local_token = GetLocalToken(requester.ID, this.Mall_Type_ID); if (local_token != null) { long timeNow = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); //last access token is expried if (timeNow >= local_token.Expirse_In + local_token.Request_Time) { request_token = TokenManager.RequestAccessToken(code); request_token.User_ID = requester.ID; UpdateLocalAccessToken(request_token); } else { request_token = local_token; } } } } catch (DbEntityValidationException dbex) { throw new KMJXCException("登录失败,请联系管理员"); } catch (Exception ex) { throw new KMJXCException(ex.Message, ExceptionLevel.SYSTEM); } finally { if (db != null) { db.Dispose(); } } return request_token; }
public ProductManager(BUser user, Shop shop, Permission permission) : base(user, shop, permission) { stockManager = new StockManager(user, shop, permission); }
public PropertyManager(BUser user, int shop_id, Permission permission) : base(user,shop_id,permission) { }
public BugManager(BUser user) { this.currentUser = user; }
public UserManager(BUser user, Permission permission) : base(user,permission) { }
private void GetUser(int uid) { using (KuanMaiEntities db = new KuanMaiEntities()) { this.currentUser = (from user in db.User where user.User_ID == uid select new BUser { ID=user.User_ID, Mall_Name=user.Mall_Name, Name=user.Name }).FirstOrDefault<BUser>(); } }
public SalesManager(BUser user, Shop shop, Permission permission) : base(user, shop, permission) { stockManager = new StockManager(user, shop, permission); tradeManager = new TaobaoTradeManager(this.AccessToken, this.Shop.Mall_Type_ID); }
public SupplierManager(BUser user, Shop shop, Permission permission) : base(user, shop, permission) { }