/// <summary>
        /// 查询今日待办事项,销售统计
        /// </summary>
        /// <returns></returns>
        public Task <ApiResult <BackLogReport> > GetBackLogReport()
        {
            var res = new ApiResult <BackLogReport>()
            {
                statusCode = (int)ApiEnum.Error
            };

            try
            {
                DateTime dayTime   = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " 00:00:00");
                string   startWeek = Utils.GetMondayDate().ToShortDateString();
                string   endWeek   = Utils.GetSundayDate().AddDays(1).ToShortDateString();
                //昨天销售额
                var yesterDayTime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " 00:00:00");
                var yesterDay     = Db.Queryable <ErpSaleOrder>().Where(m => SqlFunc.DateIsSame(m.AddDate, yesterDayTime)).Sum(m => m.RealMoney);
                //上周销售额
                var yesterWeekTimeStart = Utils.GetMondayDate().AddDays(-7).ToShortDateString();
                var yesterWeekTimeEnd   = Utils.GetMondayDate().AddDays(-1).ToShortDateString();
                var yesterWeek          = Db.Queryable <ErpSaleOrder>().Where(m => SqlFunc.Between(m.AddDate, yesterWeekTimeStart, yesterWeekTimeEnd)).Sum(m => m.RealMoney);
                //上个月销售额
                var yesterMonthTime = DateTime.Now.AddMonths(-1);
                var yesterMonth     = Db.Queryable <ErpSaleOrder>().Where(m => SqlFunc.DateIsSame(m.AddDate, yesterMonthTime, DateType.Month)).Sum(m => m.RealMoney);
                var model           = new BackLogReport
                {
                    //今日返货数量
                    ReturnCount = ErpReturnOrderDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime)),
                    //今日退货数量
                    BackCount = ErpBackGoodsDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime)),
                    //库存报警
                    StockPoliceCount = ErpGoodsSkuDb.Count(m => m.StockSum < 10),
                    //今日加入会员
                    JoinUserCount = ErpShopUserDb.Count(m => SqlFunc.DateIsSame(m.RegDate, dayTime)),
                    //今日销售金额
                    DaySaleMoney = Db.Queryable <ErpSaleOrder>().Where(m => SqlFunc.DateIsSame(m.AddDate, dayTime)).Sum(m => m.RealMoney),
                    //本周销售金额
                    WeekSaleMoney = Db.Queryable <ErpSaleOrder>().Where(m => SqlFunc.Between(m.AddDate, Utils.GetMondayDate(), Utils.GetMondayDate().AddDays(7))).Sum(m => m.RealMoney),
                    //本月销售金额
                    MonthSaleMoney = Db.Queryable <ErpSaleOrder>().Where(m => SqlFunc.DateIsSame(m.AddDate, dayTime, DateType.Month)).Sum(m => m.RealMoney)
                };
                //日同比  同比增长率=(本年的指标值-去年同期的值)÷去年同期的值*100%
                model.DayOnYear = yesterDay == 0?0:Convert.ToDouble((model.DaySaleMoney - yesterDay) / yesterDay * 100);
                //周同比
                model.WeekOnYear = yesterWeek == 0 ? 0 : Convert.ToDouble((model.WeekSaleMoney - yesterWeek) / yesterWeek * 100);
                //月同比
                model.MonthOnYear = yesterMonth == 0 ? 0 : Convert.ToDouble((model.MonthSaleMoney - yesterMonth) / yesterMonth * 100);

                res.data       = model;
                res.statusCode = (int)ApiEnum.Status;
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(Task.Run(() => res));
        }
Exemple #2
0
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(ErpBackGoods parm)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = (int)ApiEnum.Error
            };

            try
            {
                DateTime dayTime = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " 00:00:00");
                parm.Guid = Guid.NewGuid().ToString();
                //查询今天退货数量
                var dayCount = ErpBackGoodsDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime));
                parm.Number = "BO-" + DateTime.Now.ToString("yyyyMMdd") + "-" + (1001 + dayCount);
                //根据条形码查询唯一编号
                var goodSku = ErpGoodsSkuDb.GetSingle(m => m.Code == parm.GoodsGuid);
                if (goodSku != null)
                {
                    parm.GoodsGuid = goodSku.Guid;
                }
                else
                {
                    res.message = "商品不存在~";
                    return(await Task.Run(() => res));
                }
                //判断退货商品,金额是否大于订单金额,   以及商品数量,是否大于订单出售数量
                var orderModel = ErpSaleOrderDb.GetSingle(m => m.Number == parm.OrderNumber);
                if (orderModel == null)
                {
                    res.message = "订单不存在~";
                    return(await Task.Run(() => res));
                }
                //跨月不允许退货
                if (orderModel.AddDate.Month != DateTime.Now.Month)
                {
                    res.message = "跨月不允许退货~";
                    return(await Task.Run(() => res));
                }
                //查询活动,是否买一赠一活动,如果是,需要单独处理下
                var activityModel = new ErpShopActivity();
                if (!string.IsNullOrEmpty(orderModel.ActivityGuid))
                {
                    activityModel = ErpShopActivityDb.GetSingle(m => m.Guid == orderModel.ActivityGuid);
                }
                //if (parm.BackMoney>orderModel.RealMoney)
                //{
                //    res.message = "退货金额不能大于订单金额~";
                //    return await Task.Run(() => res);
                //}
                //判断是否存在
                var egbCount = ErpBackGoodsDb.Count(m => m.ShopGuid == parm.ShopGuid && m.GoodsGuid == parm.GoodsGuid && m.OrderNumber == parm.OrderNumber);
                if (egbCount > 0)
                {
                    //买一增一,最多可以退货2次
                    if (activityModel != null && activityModel.Method == 3)
                    {
                        if (egbCount > 1)
                        {
                            res.message = "该退货信息已存在~";
                            return(await Task.Run(() => res));
                        }
                    }
                    else
                    {
                        res.message = "该退货信息已存在~";
                        return(await Task.Run(() => res));
                    }
                }
                //根据订单查询商品数量是否满足
                var orderGoodsModel = new ErpSaleOrderGoods();
                if (activityModel != null && activityModel.Method == 3)
                {
                    //如果是买一赠一,第一次差=0的,第二次差!=0的
                    if (egbCount == 0)
                    {
                        orderGoodsModel = ErpSaleOrderGoodsDb.GetSingle(m => m.OrderNumber == parm.OrderNumber && m.GoodsGuid == parm.GoodsGuid && m.ShopGuid == parm.ShopGuid && m.Money == 0);
                    }
                    else
                    {
                        orderGoodsModel = ErpSaleOrderGoodsDb.GetSingle(m => m.OrderNumber == parm.OrderNumber && m.GoodsGuid == parm.GoodsGuid && m.ShopGuid == parm.ShopGuid && m.Money != 0);
                    }
                }
                else
                {
                    orderGoodsModel = ErpSaleOrderGoodsDb.GetSingle(m => m.OrderNumber == parm.OrderNumber && m.GoodsGuid == parm.GoodsGuid && m.ShopGuid == parm.ShopGuid);
                }
                if (orderGoodsModel == null)
                {
                    res.message = "该商品在该订单号中不存在~";
                    return(await Task.Run(() => res));
                }
                if (orderGoodsModel.Counts < parm.BackCount)
                {
                    res.message = "退货商品数量不能大于订单购买数量~";
                    return(await Task.Run(() => res));
                }
                //获取订单销售的金额  客户端不需要手动输入, 注意需要判断下是否买一赠一活动
                parm.BackMoney = orderGoodsModel.Money;
                //构建积分变动记录

                var result = Db.Ado.UseTran(() =>
                {
                    //修改加盟商条形码里面的库存 退货=加盟商库存增加
                    Db.Updateable <ErpShopSku>()
                    .UpdateColumns(m => new ErpShopSku()
                    {
                        Stock = m.Stock + parm.BackCount, Sale = m.Sale - parm.BackCount
                    })
                    .Where(m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == goodSku.Guid)
                    .ExecuteCommand();
                    //根据商品编号,修改平台的销售数量
                    Db.Updateable <ErpGoodsSku>().UpdateColumns(m => new ErpGoodsSku()
                    {
                        SaleSum = m.SaleSum - parm.BackCount
                    })
                    .Where(m => m.Guid == goodSku.Guid).ExecuteCommand();
                    //修改订单-商品详情表中的退货数量   增加
                    orderGoodsModel.BackCounts = orderGoodsModel.BackCounts + parm.BackCount;
                    Db.Updateable(orderGoodsModel).ExecuteCommand();
                    //增加一条退货信息
                    Db.Insertable(parm).ExecuteCommand();
                    //判断是否存在用户信息
                    if (!string.IsNullOrEmpty(orderModel.UserGuid))
                    {
                        var pointLogModel = new ErpUserPointLog()
                        {
                            Guid        = Guid.NewGuid().ToString(),
                            UserGuid    = orderModel.UserGuid,
                            OperateGuid = parm.Guid,
                            Types       = 1,
                            Point       = orderGoodsModel.Money != 0?Convert.ToInt32((orderGoodsModel.Money / orderGoodsModel.Counts) / 10):0,
                            Summary     = "[减少]-退货积分变更"
                        };
                        Db.Insertable(pointLogModel).ExecuteCommand();
                        //用户积分减少
                        Db.Updateable <ErpShopUser>().UpdateColumns(m => m.Points == m.Points - pointLogModel.Point)
                        .Where(m => m.Guid == orderModel.UserGuid).ExecuteCommand();
                    }
                });
                res.statusCode = (int)ApiEnum.Status;
                if (!result.IsSuccess)
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.message    = result.ErrorMessage;
                }
            }
            catch (Exception ex)
            {
                res.statusCode = (int)ApiEnum.Error;
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Exemple #3
0
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(ErpBackGoods parm)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = (int)ApiEnum.Error
            };

            try
            {
                DateTime dayTime = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " 00:00:00");
                parm.Guid = Guid.NewGuid().ToString();
                //查询今天退货数量
                var dayCount = ErpBackGoodsDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime));
                parm.Number = "BO-" + DateTime.Now.ToString("yyyyMMdd") + "-" + (1001 + dayCount);
                //根据条形码查询唯一编号
                var goodSku = ErpGoodsSkuDb.GetSingle(m => m.Code == parm.GoodsGuid);
                if (goodSku != null)
                {
                    parm.GoodsGuid = goodSku.Guid;
                }
                else
                {
                    res.message = "商品不存在~";
                    return(await Task.Run(() => res));
                }
                //判断退货商品,金额是否大于订单金额,   以及商品数量,是否大于订单出售数量
                var orderModel = ErpSaleOrderDb.GetSingle(m => m.Number == parm.OrderNumber);
                if (orderModel == null)
                {
                    res.message = "订单不存在~";
                    return(await Task.Run(() => res));
                }
                if (parm.BackMoney > orderModel.RealMoney)
                {
                    res.message = "退货金额不能大于订单金额~";
                    return(await Task.Run(() => res));
                }
                //判断是否存在
                var isExt = ErpBackGoodsDb.IsAny(m => m.ShopGuid == parm.ShopGuid && m.GoodsGuid == parm.GoodsGuid && m.OrderNumber == parm.OrderNumber);
                if (isExt)
                {
                    res.message = "该退货信息已存在~";
                    return(await Task.Run(() => res));
                }
                //根据订单查询商品数量是否满足
                var orderGoodsModel = ErpSaleOrderGoodsDb.GetSingle(m => m.OrderNumber == parm.OrderNumber && m.GoodsGuid == parm.GoodsGuid && m.ShopGuid == parm.ShopGuid);
                if (orderGoodsModel == null)
                {
                    res.message = "该商品在该订单号中不存在~";
                    return(await Task.Run(() => res));
                }
                if (orderGoodsModel.Counts < parm.BackCount)
                {
                    res.message = "退货商品数量不能大于订单购买数量~";
                    return(await Task.Run(() => res));
                }
                var result = Db.Ado.UseTran(() =>
                {
                    //修改加盟商条形码里面的库存 退货=加盟商库存增加
                    Db.Updateable <ErpShopSku>()
                    .UpdateColumns(m => new ErpShopSku()
                    {
                        Stock = m.Stock + parm.BackCount, Sale = m.Sale - parm.BackCount
                    })
                    .Where(m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == goodSku.Guid)
                    .ExecuteCommand();
                    //根据商品编号,修改平台的销售数量
                    Db.Updateable <ErpGoodsSku>().UpdateColumns(m => new ErpGoodsSku()
                    {
                        SaleSum = m.SaleSum - parm.BackCount
                    })
                    .Where(m => m.Guid == goodSku.Guid).ExecuteCommand();
                    //修改订单-商品详情表中的退货数量   增加
                    orderGoodsModel.BackCounts = orderGoodsModel.BackCounts + parm.BackCount;
                    Db.Updateable(orderGoodsModel).ExecuteCommand();
                    //增加一条退货信息
                    Db.Insertable(parm).ExecuteCommand();
                });
                res.statusCode = (int)ApiEnum.Status;
                if (!result.IsSuccess)
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.message    = result.ErrorMessage;
                }
            }
            catch (Exception ex)
            {
                res.statusCode = (int)ApiEnum.Error;
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }