Exemplo n.º 1
0
        /// <summary>
        /// 查询多条记录
        /// </summary>
        /// <returns></returns>
        public Task <ApiResult <Page <SaleOrderDto> > > GetPagesAsync(PageParm parm, AppSearchParm searchParm)
        {
            var res = new ApiResult <Page <SaleOrderDto> >();

            try
            {
                var query = Db.Queryable <ErpSaleOrder, ErpShops>((eso, es) => new object[] { JoinType.Left, eso.ShopGuid == es.Guid })
                            .WhereIF(!string.IsNullOrEmpty(parm.guid), (eso, es) => eso.ShopGuid == parm.guid)
                            .WhereIF(parm.types != 0, (eso, es) => eso.ActivityTypes == parm.types)
                            .WhereIF(searchParm.saleType != 0, (eso, es) => eso.SaleType == searchParm.saleType)
                            .WhereIF(searchParm.activityTypes != 0, (eso, es) => eso.ActivityTypes == searchParm.activityTypes)
                            .WhereIF(!string.IsNullOrEmpty(searchParm.btime) && !string.IsNullOrEmpty(searchParm.etime),
                                     (eso, es) => eso.AddDate >= Convert.ToDateTime(searchParm.btime) && eso.AddDate <= Convert.ToDateTime(searchParm.etime))
                            .OrderBy((eso, es) => eso.AddDate, OrderByType.Desc)
                            .Select((eso, es) => new SaleOrderDto()
                {
                    Number        = eso.Number,
                    ShopName      = es.ShopName,
                    ActivityTypes = SqlFunc.ToString(eso.ActivityTypes),
                    SaleType      = SqlFunc.ToString(eso.SaleType),
                    Counts        = eso.Counts,
                    ActivityName  = eso.ActivityName,
                    Money         = eso.Money,
                    RealMoney     = eso.RealMoney,
                    AddDate       = eso.AddDate
                })
                            .ToPage(parm.page, parm.limit);
                //循环商品订单,查询订单下面的商品
                var orderNumbers = query.Items?.Select(m => m.Number).ToList();
                var orderGood    = ErpSaleOrderGoodsDb.GetList(m => orderNumbers.Contains(m.OrderNumber));
                foreach (var item in query.Items)
                {
                    var list = new List <SaleOrderGoodsDto>();
                    foreach (var row in orderGood)
                    {
                        if (item.Number == row.OrderNumber)
                        {
                            var goodSku = ErpGoodsSkuDb.GetById(row.GoodsGuid);
                            list.Add(new SaleOrderGoodsDto()
                            {
                                Counts    = row.Counts,
                                Code      = goodSku.Code,
                                GoodsName = SysCodeDb.GetById(goodSku.BrankGuid).Name + SysCodeDb.GetById(goodSku.StyleGuid).Name
                            });
                        }
                    }
                    item.Goods = list;
                }
                res.success = true;
                res.message = "获取成功!";
                res.data    = query;
            }
            catch (Exception ex)
            {
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
                res.statusCode = (int)ApiEnum.Error;
            }
            return(Task.Run(() => res));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 查询库存剩余数量和销售数量
        /// 可根据店铺查询,日期,品牌
        /// </summary>
        /// <returns></returns>
        public Task <ApiResult <Page <StockSaleNum> > > GetStockNumByShopAsync(PageParm parm, AppSearchParm searchParm)

        {
            var res = new ApiResult <Page <StockSaleNum> >();

            try
            {
                var query = Db.Queryable <ErpShopSku, ErpGoodsSku>((t1, t2) => new object[] { JoinType.Left, t1.SkuGuid == t2.Guid })
                            .Where((t1, t2) => t1.ShopGuid == parm.guid)
                            .WhereIF(!string.IsNullOrEmpty(searchParm.brand), (t1, t2) => t2.BrankGuid == searchParm.brand)
                            .OrderByIF(parm.orderType == 1, (t1, t2) => t1.Sale, OrderByType.Desc)
                            .OrderByIF(parm.orderType == 2, (t1, t2) => t1.Stock, OrderByType.Desc)
                            .Select((t1, t2) => new StockSaleNum()
                {
                    Guid      = t2.Guid,
                    Code      = t2.Code,
                    Brand     = SqlFunc.Subqueryable <SysCode>().Where(g => g.Guid == t2.BrankGuid).Select(g => g.Name),
                    Style     = SqlFunc.Subqueryable <SysCode>().Where(g => g.Guid == t2.StyleGuid).Select(g => g.Name),
                    Stock     = t1.Stock,
                    returnSum = SqlFunc.Subqueryable <ErpReturnGoods>().Where(g => g.GoodsGuid == t1.SkuGuid && g.ShopGuid == parm.guid).Sum(g => g.ReturnCount)
                }).ToPage(parm.page, parm.limit);

                //根据日期查询
                var guidList = query.Items.Select(m => m.Guid).ToList();
                if (parm.types == 0)
                {
                    //所有
                    var dayList = ErpSaleOrderGoodsDb.GetList(m => guidList.Contains(m.GoodsGuid) && m.ShopGuid == parm.guid);
                    foreach (var item in query.Items)
                    {
                        item.Sale = dayList.Where(m => m.GoodsGuid == item.Guid).Sum(m => m.Counts) - dayList.Where(m => m.GoodsGuid == item.Guid).Sum(m => m.BackCounts);
                    }
                }
                if (parm.types == 1)
                {
                    DateTime dayTime = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " 00:00:00");
                    //本日
                    var dayList = ErpSaleOrderGoodsDb.GetList(m => guidList.Contains(m.GoodsGuid) && m.ShopGuid == parm.guid &&
                                                              SqlFunc.DateIsSame(SqlFunc.Subqueryable <ErpSaleOrder>().Where(g => g.Number == m.OrderNumber).Select(g => g.AddDate), dayTime));
                    foreach (var item in query.Items)
                    {
                        item.Sale = dayList.Where(m => m.GoodsGuid == item.Guid).Sum(m => m.Counts) - dayList.Where(m => m.GoodsGuid == item.Guid).Sum(m => m.BackCounts);
                    }
                }
                if (parm.types == 2)
                {
                    //本月
                    DateTime now     = DateTime.Now;
                    DateTime d1      = new DateTime(now.Year, now.Month, 1);
                    DateTime d2      = d1.AddMonths(1);
                    var      dayList = ErpSaleOrderGoodsDb.GetList(m => guidList.Contains(m.GoodsGuid) && m.ShopGuid == parm.guid &&
                                                                   SqlFunc.Between(SqlFunc.Subqueryable <ErpSaleOrder>().Where(g => g.Number == m.OrderNumber).Select(g => g.AddDate), d1, d2));
                    foreach (var item in query.Items)
                    {
                        item.Sale = dayList.Where(m => m.GoodsGuid == item.Guid).Sum(m => m.Counts) - dayList.Where(m => m.GoodsGuid == item.Guid).Sum(m => m.BackCounts);
                    }
                }
                if (parm.types == 3)
                {
                    //自定义时间
                    var dayList = ErpSaleOrderGoodsDb.GetList(m => guidList.Contains(m.GoodsGuid) && m.ShopGuid == parm.guid &&
                                                              SqlFunc.Between(SqlFunc.Subqueryable <ErpSaleOrder>().Where(g => g.Number == m.OrderNumber).Select(g => g.AddDate), Convert.ToDateTime(searchParm.btime), Convert.ToDateTime(searchParm.etime)));
                    foreach (var item in query.Items)
                    {
                        item.Sale = dayList.Where(m => m.GoodsGuid == item.Guid).Sum(m => m.Counts) - dayList.Where(m => m.GoodsGuid == item.Guid).Sum(m => m.BackCounts);
                    }
                }
                res.data = query;
            }
            catch (Exception ex)
            {
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
                res.statusCode = (int)ApiEnum.Error;
            }
            return(Task.Run(() => res));
        }