/// <summary> /// 分佣首页诊疗项目实体转换 /// </summary> /// <param name="models"></param> /// <returns></returns> private static List <Himall.DTO.DistributionProducts> ChangeDistributionProductsModels(List <Himall.Model.DistributionProductsInfo> models, long?userId = 0) { List <long> canAgentIds = new List <long>(); if (userId.HasValue) { List <long> proids = _iDistributionService.GetDistributionProducts().Select(item => item.Himall_ProductBrokerage.ProductId.Value).ToList(); canAgentIds = _iDistributionService.GetCanAgentProductId(proids, userId.Value).ToList(); } IQueryable <Himall.DTO.DistributionProducts> returnsql = models.Select(a => { //品牌 var brand = _iBrandService.GetBrand(a.Himall_ProductBrokerage.Himall_Products.BrandId); //分佣价格 decimal Commission = 0; decimal rate = a.Himall_ProductBrokerage.rate; if (rate > 0) { Commission = (a.Himall_ProductBrokerage.Himall_Products.MinSalePrice * rate / 100); int _tmp = (int)(Commission * 100); //保留两位小数,但不四舍五入 Commission = (decimal)(((decimal)_tmp) / (decimal)100); } //成交数 long SaleNum = 0; SaleNum = a.Himall_ProductBrokerage.Himall_Products.Himall_ProductVistis.Sum(item => item.SaleCounts); //是否代理 bool isHasAgent = false; if (userId.HasValue) { isHasAgent = !canAgentIds.Contains(a.Himall_ProductBrokerage.ProductId.Value); } return(new Himall.DTO.DistributionProducts { Id = a.ID, Brand = brand == null ? "" : brand.Name, CategoryName = CategoryApplication.GetCategory(long.Parse(CategoryApplication.GetCategory(a.Himall_ProductBrokerage.Himall_Products.CategoryId).Path.Split('|').Last())).Name, Image = Himall.Core.HimallIO.GetProductSizeImage(a.Himall_ProductBrokerage.Himall_Products.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_100), Price = a.Himall_ProductBrokerage.Himall_Products.MinSalePrice, ProductbrokerageId = a.Himall_ProductBrokerage.Id, ProductId = a.Himall_ProductBrokerage.ProductId.Value, ProductName = a.Himall_ProductBrokerage.Himall_Products.ProductName, ShortDescription = a.Himall_ProductBrokerage.Himall_Products.ShortDescription, Sequence = a.Sequence, Status = a.Himall_ProductBrokerage.Status, Commission = Commission, AgentNum = a.Himall_ProductBrokerage.AgentNum.HasValue ? a.Himall_ProductBrokerage.AgentNum.Value : 0, SaleNum = SaleNum, isHasAgent = isHasAgent }); } ).AsQueryable(); return(returnsql.ToList()); }
public JsonResult ProductList(string skey, int page, long categoryId = 0, long shopId = 0, int sort = 0) { //查询条件 ProductBrokerageQuery query = new ProductBrokerageQuery(); query.skey = skey; query.PageSize = 5; query.PageNo = page; query.ProductBrokerageState = ProductBrokerageInfo.ProductBrokerageStatus.Normal; query.OnlyShowNormal = true; if (categoryId != 0) { query.CategoryId = categoryId; } if (shopId != 0) { query.ShopId = shopId; } query.Sort = ProductBrokerageQuery.EnumProductSort.AgentNum; switch (sort) { case 1: query.Sort = ProductBrokerageQuery.EnumProductSort.SalesNumber; break; case 3: query.Sort = ProductBrokerageQuery.EnumProductSort.Brokerage; break; case 4: query.Sort = ProductBrokerageQuery.EnumProductSort.PriceAsc; break; case 5: query.Sort = ProductBrokerageQuery.EnumProductSort.PriceDesc; break; case 2: query.Sort = ProductBrokerageQuery.EnumProductSort.AgentNum; break; case 6: query.Sort = ProductBrokerageQuery.EnumProductSort.MonthDesc; break; case 7: query.Sort = ProductBrokerageQuery.EnumProductSort.WeekDesc; break; } ObsoletePageModel <ProductBrokerageInfo> datasql = _iDistributionService.GetDistributionProducts(query); List <ProductBrokerageInfo> datalist = new List <ProductBrokerageInfo>(); List <DistributionProductListModel> result = new List <DistributionProductListModel>(); if (datasql.Models != null) { datalist = datasql.Models.ToList(); List <long> proids = datalist.Select(d => d.ProductId.Value).ToList(); List <long> canAgentIds = _iDistributionService.GetCanAgentProductId(proids, curUserId).ToList(); result = datalist.Select(d => new DistributionProductListModel { ShopId = d.ShopId, ProductId = d.ProductId, ProductName = d.Product.ProductName, ShortDescription = d.Product.ShortDescription, Image = d.Product.GetImage(ImageSize.Size_350), CategoryId = d.Product.CategoryId, CategoryName = d.CategoryName, DistributorRate = d.rate, ProductBrokerageState = d.Status, ProductSaleState = d.Product.SaleStatus, SellPrice = d.Product.MinSalePrice, ShowProductBrokerageState = d.Status.ToDescription(), ShowProductSaleState = d.Product.SaleStatus.ToDescription(), SaleNum = d.SaleNum, AgentNum = d.AgentNum, ForwardNum = d.ForwardNum, isHasAgent = (!canAgentIds.Contains(d.ProductId.Value)) }).ToList(); } return(Json(result)); }