Exemplo n.º 1
0
        /// <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());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 取商品销售分类统计
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="shopId"></param>
        /// <returns></returns>
        public static IEnumerable <ProductCategoryStatisticModel> GetProductCategorySales(DateTime startDate, DateTime endDate, long shopId = 0)
        {
            ProductStatisticQuery query = new ProductStatisticQuery()
            {
                StartDate = startDate,
                EndDate   = endDate
            };

            if (shopId > 0)
            {//如果不等于0,增加店铺ID条件
                query.ShopId = shopId;
            }
            //销售记录
            var productSales = _StatisticsService.GetProductAllVisits(query);
            var pids         = productSales.Select(e => e.ProductId).Distinct();
            //商品信息,分类
            var products  = ProductManagerApplication.GetAllStatusProductByIds(pids);
            var categorys = CategoryApplication.GetMainCategory();
            //补充分类
            var productCateInfo = productSales.Select(e =>
            {
                var mainCategoryId = products.FirstOrDefault(item => item.Id == e.ProductId).CategoryTopId;
                var mainCategory   = categorys.FirstOrDefault(c => c.Id == mainCategoryId);
                return(new
                {
                    CategoryId = mainCategoryId,
                    CategoryName = mainCategory == null?string.Empty:mainCategory.Name,
                    ProductId = e.ProductId,
                    ShopId = e.ShopId,
                    SaleAmounts = e.SaleAmounts,
                    SaleCounts = e.SaleCounts
                });
            });
            var totalAmount = productCateInfo.Sum(e => e.SaleAmounts);
            var totalCount  = productCateInfo.Sum(e => e.SaleCounts);
            //根据分类统计
            var productCateStat = productCateInfo.GroupBy(e => e.CategoryId).Select(e => new ProductCategoryStatisticModel
            {
                CategoryId   = e.Key,
                CategoryName = e.FirstOrDefault().CategoryName,
                SaleAmounts  = e.Sum(item => item.SaleAmounts),
                SaleCounts   = e.Sum(item => item.SaleCounts),
                EndDate      = endDate.ToString("yyyy-MM-dd"),
                StartDate    = startDate.ToString("yyyy-MM-dd"),
                AmountRate   = 0.0M,
                CountRate    = 0.0M
            });

            //计算比率
            totalAmount = totalAmount == 0 ? 1 : totalAmount;
            totalCount  = totalCount == 0 ? 1 : totalCount;
            foreach (var cate in productCateStat)
            {
                cate.AmountRate = (decimal)cate.SaleAmounts / totalAmount;
                cate.CountRate  = (decimal)cate.SaleCounts / totalCount;
            }
            return(productCateStat);
        }