public ActionResult StorePermission(OneKeySearchModel searchModel) { Expression <Func <Stores, Boolean> > lbdWhere = null; if (searchModel.SearchStr != null) { searchModel.SearchStr = searchModel.SearchStr.Trim(); if (!string.IsNullOrWhiteSpace(searchModel.SearchStr)) { lbdWhere = t => t.StoreName.Contains(searchModel.SearchStr) || t.Phone.Contains(searchModel.SearchStr) || t.Adress.Contains(searchModel.SearchStr) || t.Shops.ShopName.Contains(searchModel.SearchStr); } } IStoresService storesService = ServiceFactory.Create <IStoresService>(); var stores = storesService.GetEntitiesByPage(searchModel.PageIndex, 10, lbdWhere, false, t => t.ID); //转换数据模型 var listData = stores.Models.Select(t => new StorePermissionListModel { ID = t.ID, ShopName = t.Shops.ShopName, StoreName = t.StoreName, Phone = t.Phone, Adress = t.Adress, IsShowWeiXin = t.IsShowWeiXin == true ? "显示" : "不显示", IsMainStore = t.IsMainStore == true ? "是" : "否"//是否总店 }); var listStore = new PageModel <StorePermissionListModel> { Models = listData.ToList(), pagingInfo = stores.pagingInfo }; ViewBag.SearchModel = searchModel; return(View(listStore)); }
/// <summary> /// 获取商家下的门店 /// </summary> /// <param name="pageSize"></param> /// <param name="username"></param> /// <param name="pageNumber"></param> /// <returns></returns> public ActionResult GetShopStores(int pageSize, string username, int pageNumber) { SearchModel <StoresParams> searchModel = new SearchModel <StoresParams> { PageIndex = pageNumber, PageSize = pageSize, Model = new StoresParams() { StoreName = username } }; //IShopsService shopsService = ServiceFactory.Create<IShopsService>(); //var shop = shopsService.GetFirstOrDefault(t => t.AdminUserID == CurrentInfo.CurrentUser.ID); DynamicLambda <Stores> bulider = new DynamicLambda <Stores>(); Expression <Func <Stores, Boolean> > expr = null; //如果是店铺管理员 if (CurrentInfo.IsShopAdmin) { Expression <Func <Stores, Boolean> > tmp = t => t.ShopId == CurrentInfo.CurrentUser.ShopsID && t.Disabled != true; expr = bulider.BuildQueryAnd(expr, tmp); } else { Expression <Func <Stores, Boolean> > tmp = t => t.ID == CurrentInfo.CurrentStore.ID; expr = bulider.BuildQueryAnd(expr, tmp); } ////如果是商家本人的账号,则显示商家自己的门店 //if (shop != null) //{ // Expression<Func<Stores, Boolean>> tmp = t => t.ShopId == shop.ID; // expr = bulider.BuildQueryAnd(expr, tmp); //} if (!string.IsNullOrWhiteSpace(username)) { username = username.Trim(); Expression <Func <Stores, Boolean> > tmp = t => t.StoreName.Contains(username); expr = bulider.BuildQueryAnd(expr, tmp); } IStoresService storesService = ServiceFactory.Create <IStoresService>(); int total; var data = storesService.GetEntitiesByPage(searchModel.PageIndex, searchModel.PageSize, out total, expr, false, t => t.ID).Select(t => new { ID = t.ID, ShopsName = t.Shops.ShopName, StoreName = t.StoreName, Adress = t.Adress, Phone = t.Phone, IsShowWeiXin = t.IsShowWeiXin == true ? "显示" : "不显示", IsMainStore = t.IsMainStore, Disabled = t.Disabled, AdminUserID = t.AdminUserID, /// AdminName = t.AdminUserID==null?"0":t.AdminUserID.ToString() //t.Users1 != null ? t.Users1.RealName : "" }).ToList(); return(Json(new { total = total, rows = data }, JsonRequestBehavior.AllowGet)); }