public ActionResult List() { GridRequest rq = new GridRequest(Request); var pred = FilterHelper.GetExpression <Inventory>(rq.FilterGroup); int cou = CacheAccess.GetAccessibleInventorys(_inventoryContract, _storeContract).Count(pred); var inves = CacheAccess.GetAccessibleInventorys(_inventoryContract, _storeContract).Where(pred).OrderByDescending(c => c.CreatedTime).Skip(rq.PageCondition.PageIndex).Take(rq.PageCondition.PageSize).Select(c => new { c.Id, c.Store.StoreName, c.Product.ProductOriginNumber.Brand.BrandName, c.Product.ProductOriginNumber.Category.CategoryName, c.Product.ProductOriginNumber.Season.SeasonName, c.Product.Size.SizeName, c.Product.Color.ColorName, c.Product.Color.IconPath, c.Storage.StorageName, c.Product.ThumbnailPath, c.ProductBarcode, c.CreatedTime, c.Operator.Member.MemberName }).ToList <object>(); GridData <object> ojbdat = new GridData <object>(inves, cou, Request); return(Json(ojbdat)); }
public ActionResult ExportInventory(int?recordId, string Ids) { try { var inventoryIds = new List <int>(); if (recordId.HasValue && recordId != -1) { //导出记录下所有库存数据 inventoryIds.AddRange(CacheAccess.GetInventoryRecords(_inventoryRecordContract, _storeContract) .Where(r => r.Id == recordId.Value) .SelectMany(r => r.Inventories) .Where(i => !i.IsDeleted && i.IsEnabled) .Select(i => i.Id).ToList()); } else { //导出选中的数据 inventoryIds.AddRange(Ids.Split(',').Select(id => int.Parse(id))); } var path = Path.Combine(HttpRuntime.AppDomainAppPath, EnvironmentHelper.TemplatePath(this.RouteData)); var list = CacheAccess.GetAccessibleInventorys(_inventoryContract, _storeContract) .Where(i => inventoryIds.Contains(i.Id)) .OrderByDescending(c => c.CreatedTime) .Select(c => new { c.Id, c.Store.StoreName, c.Product.ProductOriginNumber.Brand.BrandName, c.Product.ProductOriginNumber.Category.CategoryName, c.Product.ProductOriginNumber.Season.SeasonName, c.Product.Size.SizeName, c.Product.Color.ColorName, c.Product.Color.IconPath, c.Storage.StorageName, c.Product.ThumbnailPath, c.ProductBarcode, c.CreatedTime, c.Operator.Member.MemberName }).ToList(); var group = new StringTemplateGroup("all", path, typeof(TemplateLexer)); var st = group.GetInstanceOf("ExporterInventory"); st.SetAttribute("list", list); var str = st.ToString(); var buffer = Encoding.UTF8.GetBytes(str); var stream = new MemoryStream(buffer); return(File(stream, "application/ms-excel", "入库记录明细.xls")); } catch (Exception e) { return(Json(new OperationResult(OperationResultType.Error, e.Message), JsonRequestBehavior.AllowGet)); } }
public ActionResult GetBitchProduct() { GridRequest rq = new GridRequest(Request); Expression <Func <Inventory, bool> > exp = FilterHelper.GetExpression <Inventory>(rq.FilterGroup); var allprod = CacheAccess.GetAccessibleInventorys(_inventoryContract, _StoreContract).Where(exp).GroupBy(x => x.Product.ProductNumber); var data = allprod.Select(x => new { x.FirstOrDefault().Id, x.FirstOrDefault().Product.ProductName, x.FirstOrDefault().Product.ProductNumber, x.FirstOrDefault().Product.ThumbnailPath, x.FirstOrDefault().Product.ProductOriginNumber.Season.SeasonName, x.FirstOrDefault().Product.Color.ColorName, x.FirstOrDefault().Product.Size.SizeName, x.FirstOrDefault().Storage.StorageName, x.FirstOrDefault().Product.ProductOriginNumber.Brand.BrandName, //Quantity = x.Select(g => g.IsLock ? g.Quantity - g.LockCoun : g.Quantity).Sum() }).ToList(); GridData <object> obj = new GridData <object>(data, allprod.Count(), Request); return(Json(obj)); }
/// <summary> /// 获取入库记录关联的库存信息 /// </summary> /// <param name="RecordId">入库记录id</param> /// <returns></returns> public ActionResult GetInventoryList(int RecordId) { GridRequest rq = new GridRequest(Request); Expression <Func <Inventory, bool> > predicate; try { predicate = FilterHelper.GetExpression <Inventory>(rq.FilterGroup); var source = CacheAccess.GetAccessibleInventorys(_inventoryContract, _storeContract) .Where(i => i.InventoryRecordId.Value == RecordId) .Where(predicate); int count = source.Count(); var inventoryList = source.OrderByDescending(c => c.CreatedTime) .Skip(rq.PageCondition.PageIndex) .Take(rq.PageCondition.PageSize).Select(c => new { c.Id, c.Store.StoreName, c.Product.ProductOriginNumber.Brand.BrandName, c.Product.ProductOriginNumber.Category.CategoryName, c.Product.ProductOriginNumber.Season.SeasonName, c.Product.Size.SizeName, c.Product.Color.ColorName, c.Product.Color.IconPath, c.Storage.StorageName, ThumbnailPath = c.Product.ThumbnailPath ?? c.Product.ProductOriginNumber.ThumbnailPath, c.ProductBarcode, c.CreatedTime, c.Operator.Member.MemberName }).ToList <object>(); GridData <object> ojbdat = new GridData <object>(inventoryList, count, Request); return(Json(ojbdat)); } catch (Exception ex) { return(Json(new GridData <object>(new List <string>(), 0, rq.RequestInfo))); } }
/// <summary> /// 入库记录数据 /// </summary> /// <returns></returns> public async Task <ActionResult> List(string txtBarcode, string txtBrandName) { GridRequest request = new GridRequest(Request); Expression <Func <InventoryRecord, bool> > predicate; try { //权限检查 var inventoryQuery = CacheAccess.GetAccessibleInventorys(_inventoryContract, _storeContract); var inventoryRecordQuery = CacheAccess.GetInventoryRecords(_inventoryRecordContract, _storeContract); predicate = FilterHelper.GetExpression <InventoryRecord>(request.FilterGroup); var data = await Task.Run(() => { // 根据identifyId或者商品productbarcode 查询 List <int> inventoryRecordIds = new List <int>(); string identifyId = string.Empty; if (!string.IsNullOrEmpty(txtBarcode)) { if (txtBarcode.Length == 14) //productbarcode { // 根据商品条码查找所有的库存信息,然后找到与之关联的库存记录id inventoryRecordIds = inventoryQuery.Where(i => i.ProductBarcode == txtBarcode && i.InventoryRecordId.HasValue) .Select(i => i.InventoryRecordId.Value) .Distinct() .ToList(); } else if (txtBarcode.Length == 17) //identifyId { identifyId = txtBarcode; } } // 多条件查询 var count = 0; var source = inventoryRecordQuery; if (inventoryRecordIds.Count > 0) { source = source.Where(i => inventoryRecordIds.Contains(i.Id)); } if (!string.IsNullOrEmpty(identifyId)) { source = source.Where(i => i.IdentifyId == identifyId); } if (!string.IsNullOrEmpty(txtBrandName)) { source = source.Where(i => i.Inventories.Count(j => j.Product.ProductOriginNumber.Brand.BrandName == txtBrandName) > 0); } source = source.Where <InventoryRecord>(predicate); count = source.Count(); // 组装分页数据 var list = source.OrderByDescending(i => i.CreatedTime) .Skip(request.PageCondition.PageIndex) .Take(request.PageCondition.PageSize) .Select(i => new { i.Id, i.RecordOrderNumber, i.IdentifyId, i.Store.StoreName, i.Storage.StorageName, i.TagPrice, i.Quantity, i.Operator.Member.MemberName, i.CreatedTime, i.IsDeleted, i.IsEnabled, BrandCount = i.Inventories.Count(j => j.Product.ProductOriginNumber.Brand.BrandName == txtBrandName), TotalBrandCount = i.Inventories.Select(j => j.Product.ProductOriginNumber.Brand.BrandName).Distinct().Count() }).ToList(); return(new GridData <object>(list, count, request.RequestInfo)); }); return(Json(data, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new GridData <object>(new List <string>(), 0, request.RequestInfo))); } }
public ActionResult SetRecommend(int type, int storeId, string bigProdNum) { try { List <string> bigProdNums = new List <string>(); var arr = bigProdNum.Split(','); for (int i = 0; i < arr.Length; i++) { bigProdNums.Add(arr[i]); } //校验权限 var inventoryQuery = CacheAccess.GetAccessibleInventorys(_inventoryContract, _storeContract) .Where(i => i.IsDeleted == false && i.IsEnabled == true); var availableStoreIds = inventoryQuery.Select(i => i.StoreId).Distinct().ToList(); if (!availableStoreIds.Contains(storeId)) { return(Json(new OperationResult(OperationResultType.Error, "权限不足"))); } //校验当前商店库存所有的品类中是否包含要操作的品类 var bigProdNumberInStore = inventoryQuery.Where(i => i.StoreId == storeId).Select(i => i.Product.BigProdNum).Distinct().ToList(); if (bigProdNums.Any(i => !bigProdNumberInStore.Contains(i))) { return(Json(new OperationResult(OperationResultType.Error, "商铺下未找到所有选中的分类"))); } //查看记录是否已经存在 var existDataList = _storeRecommendContract.StoreRecommends.Where(s => s.StoreId == storeId && bigProdNums.Contains(s.BigProdNum)).ToList(); if (type == 1) //设置推荐 { if (existDataList != null && existDataList.Count > 0 && existDataList.Count == arr.Length) //所有要推荐的品类都已经存在于数据表中了 { //修改推荐状态 foreach (var item in existDataList) { item.IsEnabled = true; item.IsDeleted = false; } //更新 var res = _storeRecommendContract.Update(existDataList.ToArray()); return(Json(res)); } //取出数据库中尚未插入过的记录 var arr2 = existDataList.Select(i => i.BigProdNum).ToList(); var dataToInsert = bigProdNums.Where(i => !arr2.Contains(i)).ToList(); //插入新记录 List <StoreRecommendDto> dtos = new List <StoreRecommendDto>(); foreach (var item in dataToInsert) { var dto = new StoreRecommendDto() { BigProdNum = item, StoreId = storeId }; dtos.Add(dto); } var result = _storeRecommendContract.Insert(dtos.ToArray()); return(Json(result)); } else //取消推荐 { if (existDataList == null) { return(Json(new OperationResult(OperationResultType.Success))); } var res = _storeRecommendContract.Disable(existDataList.Select(i => i.Id).ToArray()); return(Json(res)); } } catch (Exception e) { return(Json(new OperationResult(OperationResultType.Error, "系统错误"))); } }
/// <summary> /// 查询数据 /// </summary> /// <returns></returns> public ActionResult List(string BrandName, int?CategoryId, int?storeId, int?storageId, int?seasonId) { GridRequest request = new GridRequest(Request); var storeIds = _storeContract.FilterStoreId(AuthorityHelper.OperatorId, _administratorContract, storeId); var storageIds = _storageContract.FilterStorageId(AuthorityHelper.OperatorId, _administratorContract, storageId); Expression <Func <Inventory, bool> > predicate; CacheAccess.SaveHttpContextState(); try { predicate = FilterHelper.GetExpression <Inventory>(request.FilterGroup); var inventoryQuery = CacheAccess.GetAccessibleInventorys(_inventoryContract, _storeContract) .Where(i => !i.IsLock && i.Status == InventoryStatus.Default) .Where(i => storeIds.Contains(i.StoreId)) .Where(i => storageIds.Contains(i.StorageId)) .Where(predicate) .Include(i => i.Product) .Include(i => i.Product.Size) .Include(i => i.Product.Color) .Include(i => i.Product.ProductOriginNumber) .Include(i => i.Product.ProductOriginNumber.Season) .Include(i => i.Product.ProductOriginNumber.Category) .Include(i => i.Product.ProductOriginNumber.Brand); if (!string.IsNullOrEmpty(BrandName)) { inventoryQuery = inventoryQuery.Where(i => i.Product.ProductOriginNumber.Brand.BrandName == BrandName); } if (CategoryId.HasValue) { inventoryQuery = inventoryQuery.Where(i => i.Product.ProductOriginNumber.Category.ParentId == CategoryId.Value); } if (seasonId.HasValue) { inventoryQuery = inventoryQuery.Where(i => i.Product.ProductOriginNumber.SeasonId == seasonId.Value); } //获取分页信息 var groupQuery = inventoryQuery.GroupBy(i => i.Product.ProductOriginNumber.BigProdNum); var inventoryTotalCount = groupQuery.Count(); var groupedDataList = groupQuery.OrderBy(g => g.Key) .Skip(request.PageCondition.PageIndex) .Take(request.PageCondition.PageSize) .ToList(); var li = new List <object>(); var index = 0; foreach (var groupItem in groupedDataList) { //构造父节点 li.Add(new { ParentId = "", Id = "par" + index, BigProdNum = groupItem.Key, BrandName = groupItem.First().Product.ProductOriginNumber.Brand.BrandName, CategoryName = groupItem.First().Product.ProductOriginNumber.Category.CategoryName, ColorName = string.Empty, IconPath = string.Empty, ThumbnailPath = groupItem.First().Product.ProductOriginNumber.ThumbnailPath, SizeName = string.Empty, Quantity = groupItem.Count(), StoreName = "", StorageName = "", ProductName = "", TagPrice = "", RetailPrice = "", WholesalePrice = "", PurchasePrice = "", IsDeleted = "", IsEnabled = "", UpdatedTime = "", CreatedTime = "", SeasonName = groupItem.First().Product.ProductOriginNumber.Season.SeasonName }); // 构造子节点 li.AddRange( groupItem.GroupBy(h => h.ProductNumber).Select(c => new { ParentId = "par" + index, Id = c.First().Id, BigProdNum = "", ProductNumber = c.Key, StoreName = c.First().Store.StoreName, StorageName = c.First().Storage.StorageName, ProductName = c.First().Product.ProductName, BrandName = c.First().Product.ProductOriginNumber.Brand.BrandName, CategoryName = c.First().Product.ProductOriginNumber.Category.CategoryName, SeasonName = string.Empty, ColorName = c.First().Product.Color.ColorName, SizeName = c.First().Product.Size.SizeName, IconPath = c.First().Product.Color.IconPath, Quantity = c.Count(), TagPrice = c.First().Product.ProductOriginNumber.TagPrice, ThumbnailPath = c.First().Product.ThumbnailPath ?? c.First().Product.ProductOriginNumber.ThumbnailPath, IsDeleted = c.First().IsDeleted, IsEnabled = c.First().IsEnabled, UpdatedTime = c.First().UpdatedTime, CreatedTime = c.First().CreatedTime })); index++; } var data = new GridDataResul <object>(li, inventoryTotalCount, request.RequestInfo) { Other = inventoryQuery.Count().ToString() + "|" + groupedDataList.Sum(g => g.Count()) }; return(Json(data, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new GridData <object>(new List <string>(), 0, request.RequestInfo))); } }