Ejemplo n.º 1
0
        /// <summary>
        /// 修改一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > ModifyAsync(ErpInOutLog parm)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = 200
            };

            try
            {
                //判断条形码是否存在
                var isExt = ErpGoodsSkuDb.IsAny(m => m.Guid == parm.GoodsGuid && !m.IsDel);
                if (!isExt)
                {
                    res.statusCode = (int)ApiEnum.ParameterError;
                    res.message    = "该条形码不存在~";
                }
                else
                {
                    var dbres = ErpInOutLogDb.Update(parm);
                    if (!dbres)
                    {
                        res.statusCode = (int)ApiEnum.Error;
                        res.message    = "修改数据失败~";
                    }
                }
            }
            catch (Exception ex)
            {
                res.statusCode = (int)ApiEnum.Error;
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 删除一条或多条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > DeleteAsync(string parm)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = 200
            };

            try
            {
                var list  = Utils.StrToListString(parm);
                var dbres = ErpGoodsSkuDb.Update(m => new ErpGoodsSku()
                {
                    IsDel = true
                }, m => list.Contains(m.Guid));
                if (!dbres)
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.message    = "删除数据失败~";
                }
            }
            catch (Exception ex)
            {
                res.statusCode = (int)ApiEnum.Error;
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        /// <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));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 修改一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > ModifyAsync(ErpSkuLoss parm)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = (int)ApiEnum.Error
            };

            try
            {
                //根据条形码,查询条形码信息
                var skuModel = ErpGoodsSkuDb.GetSingle(m => m.Code == parm.SkuGuid);
                if (skuModel == null)
                {
                    res.message = "条形码不存在~";
                    return(await Task.Run(() => res));
                }
                var oldLoss = ErpSkuLossDb.GetSingle(m => m.Guid == parm.Guid);
                if (oldLoss == null)
                {
                    res.message = "报损信息不存在~";
                    return(await Task.Run(() => res));
                }
                //判断库存数量是否满足报损数量
                if (oldLoss.Counts < parm.Counts)
                {
                    res.message = "数量不能大于原报损数量~";
                    return(await Task.Run(() => res));
                }
                //修改原报损数量
                oldLoss.Counts -= parm.Counts;
                //减少库存
                skuModel.StockSum += parm.Counts;
                //事务,保证数据一致性
                var result = Db.Ado.UseTran(() =>
                {
                    //执行添加报损信息
                    Db.Updateable(oldLoss).ExecuteCommand();
                    //修改条形码库存
                    Db.Updateable(skuModel).ExecuteCommand();
                });
                res.statusCode = (int)ApiEnum.Status;
                if (!result.IsSuccess)
                {
                    res.message = result.ErrorMessage;
                }
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获得一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <ErpGoodsSku> > GetByGuidAsync(string parm)
        {
            var model = ErpGoodsSkuDb.GetById(parm);
            var res   = new ApiResult <ErpGoodsSku>
            {
                statusCode = 200,
                data       = model ?? new ErpGoodsSku()
                {
                }
            };

            return(await Task.Run(() => res));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(ErpInOutLog parm)
        {
            var res = new ApiResult <string>()
            {
                statusCode = 200
            };

            try
            {
                //判断条形码是否存在
                var skuModel = ErpGoodsSkuDb.GetSingle(m => m.Code == parm.GoodsSku && !m.IsDel);
                if (skuModel == null)
                {
                    res.statusCode = (int)ApiEnum.ParameterError;
                    res.message    = "该条形码不存在~";
                    return(await Task.Run(() => res));
                }
                if (parm.Types == 2)
                {
                    //出库  需要判断库存是否足够
                    if (skuModel.StockSum < parm.GoodsSum)
                    {
                        res.statusCode = (int)ApiEnum.ParameterError;
                        res.message    = "库存不足,只剩下" + skuModel.StockSum + "件~";
                        return(await Task.Run(() => res));
                    }
                }
                parm.Guid      = Guid.NewGuid().ToString();
                parm.GoodsGuid = skuModel.Guid;
                //开启事务
                Db.Ado.BeginTran();
                if (parm.Types == 1)
                {
                    //更新该条形码的库存
                    ErpGoodsSkuDb.Update(m => new ErpGoodsSku()
                    {
                        StockSum = m.StockSum + parm.GoodsSum
                    }, m => m.Guid == parm.GoodsGuid);
                }
                else
                {
                    //更新平台的库存,减少
                    ErpGoodsSkuDb.Update(m => new ErpGoodsSku()
                    {
                        StockSum = m.StockSum - parm.GoodsSum
                    }, m => m.Guid == parm.GoodsGuid);
                    //增加到店铺条形码表中
                    var shopSku = ErpShopSkuDb.GetSingle(m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == parm.GoodsGuid);
                    if (shopSku != null)
                    {
                        //修改,增加库存
                        ErpShopSkuDb.Update(m => new ErpShopSku()
                        {
                            Stock = m.Stock + parm.GoodsSum, UpdateDate = DateTime.Now
                        }, m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == parm.GoodsGuid);
                    }
                    else
                    {
                        //增加一条库存
                        var shopSkuModel = new ErpShopSku()
                        {
                            SkuGuid  = skuModel.Guid,
                            SkuCode  = skuModel.Code,
                            ShopGuid = parm.ShopGuid,
                            Stock    = parm.GoodsSum
                        };
                        ErpShopSkuDb.Insert(shopSkuModel);
                    }
                }
                ErpInOutLogDb.Insert(parm);
                Db.Ado.CommitTran();
            }
            catch (Exception ex)
            {
                Db.Ado.CommitTran();
                res.statusCode = (int)ApiEnum.Error;
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 删除一条或多条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > DeleteAsync(string parm)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = (int)ApiEnum.Error
            };

            try
            {
                var list = Utils.StrToListString(parm);
                //根据主键查询详细
                var inoutList = ErpInOutLogDb.GetList(m => list.Contains(m.Guid));
                //获得条形码数据
                var codeList = inoutList.Select(m => m.GoodsGuid).ToList();
                var skuList  = ErpGoodsSkuDb.GetList(m => codeList.Contains(m.Guid));
                //定义一个值,判断条形码里面没有的数据数量
                var noSkuCount = 0;
                //获得打包日志的ID
                var packGuid = "";
                //循环平台数据,减少相应的库存
                foreach (var item in skuList)
                {
                    var goodsModel = inoutList.Find(m => m.GoodsGuid == item.Guid);
                    packGuid = goodsModel.PackGuid;
                    if (goodsModel != null && goodsModel.Types == 2)
                    {
                        item.StockSum = item.StockSum + goodsModel.GoodsSum;
                    }
                    else if (goodsModel != null && goodsModel.Types == 1)
                    {
                        item.StockSum = item.StockSum - goodsModel.GoodsSum;
                    }
                    else
                    {
                        noSkuCount++;
                    }
                }
                if (noSkuCount != 0)
                {
                    res.message = "删除的商品在平台没有查询到~";
                    return(await Task.Run(() => res));
                }

                var result = Db.Ado.UseTran(() =>
                {
                    //删除出入库信息
                    Db.Deleteable(inoutList).ExecuteCommand();
                    //修改平台库存数量
                    Db.Updateable(skuList).ExecuteCommand();
                    //根据打包ID获得下面商品的总数
                    var packInOutCount = Db.Queryable <ErpInOutLog>().Where(m => m.PackGuid == packGuid).Sum(m => m.GoodsSum);
                    //更新打包日志数量
                    Db.Updateable <ErpPackLog>().UpdateColumns(m => new ErpPackLog()
                    {
                        GoodsSum = packInOutCount
                    }).Where(m => m.Guid == packGuid).ExecuteCommand();
                });
                res.statusCode = (int)ApiEnum.Status;
                if (!result.IsSuccess)
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.message    = result.ErrorMessage;
                }
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 批量添加数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddBatchAsync(string guid, string json, string adminGuid)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = (int)ApiEnum.Error
            };

            try
            {
                if (string.IsNullOrEmpty(json))
                {
                    res.message = "商品不能为空~";
                    return(await Task.Run(() => res));
                }
                var packModel = ErpPackLogDb.GetById(guid);
                //解析字符串转换成List对象
                var goodsList = JsonConvert.DeserializeObject <List <ErpInOutLog> >(json);
                //根据条形码查询平台库存的数据
                var codeList = goodsList.Select(m => m.GoodsGuid).ToList();
                var skuList  = ErpGoodsSkuDb.GetList(m => codeList.Contains(m.Guid));
                //定义一个值,判断条形码里面没有的数据数量
                var noSkuCount = 0;
                //根据条形码,查询商家库存信息
                var shopSkuList = new List <ErpShopSku>();
                //一个新的商家库存信息
                var newShopSkuList = new List <ErpShopSku>();
                //只有在出库的时候查询,入库不处理
                if (packModel.Types == 2)
                {
                    shopSkuList = ErpShopSkuDb.GetList(m => codeList.Contains(m.SkuGuid) && m.ShopGuid == packModel.ShopGuid);
                }
                //循环平台数据,减少相应的库存
                foreach (var item in skuList)
                {
                    var goodsModel = goodsList.Find(m => m.GoodsGuid == item.Guid);
                    //出库
                    if (goodsModel != null && packModel.Types == 2)
                    {
                        item.StockSum = item.StockSum - goodsModel.GoodsSum;
                        //根据条形码判断商家库存是否存在,如果存在,修改库存信息,不存在增加一条新的库存信息
                        if (shopSkuList.Count > 0)
                        {
                            var shopSkuModel = shopSkuList.Find(m => m.SkuGuid == item.Guid);
                            if (shopSkuModel != null)
                            {
                                shopSkuList.Find(m => m.SkuGuid == item.Guid).Stock = shopSkuModel.Stock + goodsModel.GoodsSum;
                            }
                            else
                            {
                                newShopSkuList.Add(new ErpShopSku()
                                {
                                    Guid     = Guid.NewGuid().ToString(),
                                    SkuGuid  = item.Guid,
                                    SkuCode  = item.Code,
                                    ShopGuid = packModel.ShopGuid,
                                    Stock    = goodsModel.GoodsSum
                                });
                            }
                        }
                        else
                        {
                            newShopSkuList.Add(new ErpShopSku()
                            {
                                Guid     = Guid.NewGuid().ToString(),
                                SkuGuid  = item.Guid,
                                SkuCode  = item.Code,
                                ShopGuid = packModel.ShopGuid,
                                Stock    = goodsModel.GoodsSum
                            });
                        }
                    }
                    //入库
                    else if (goodsModel != null && packModel.Types == 1)
                    {
                        item.StockSum = item.StockSum + goodsModel.GoodsSum;
                    }
                    else
                    {
                        noSkuCount++;
                    }
                }
                if (noSkuCount != 0)
                {
                    res.message = "添加的商品在平台没有查询到~";
                    return(await Task.Run(() => res));
                }
                //循环构造出入库详情数据
                foreach (var item in goodsList)
                {
                    item.Guid      = Guid.NewGuid().ToString();
                    item.Types     = packModel.Types;
                    item.InTypes   = 1;
                    item.PackGuid  = packModel.Guid;
                    item.ShopGuid  = packModel.ShopGuid;
                    item.AdminGuid = adminGuid;
                    item.AddDate   = DateTime.Now;
                }
                packModel.GoodsSum += goodsList.Sum(m => m.GoodsSum);
                var result = Db.Ado.UseTran(() =>
                {
                    //修改打包的数量
                    Db.Updateable(packModel).ExecuteCommand();
                    //添加该打包日志下面的商品
                    Db.Insertable(goodsList).ExecuteCommand();
                    //修改平台库存数量
                    Db.Updateable(skuList).ExecuteCommand();
                    if (packModel.Types == 2)
                    {
                        if (shopSkuList.Count > 0)
                        {
                            Db.Updateable(shopSkuList).ExecuteCommand();
                        }
                        if (newShopSkuList.Count > 0)
                        {
                            Db.Insertable(newShopSkuList).ExecuteCommand();
                        }
                    }
                });
                res.statusCode = (int)ApiEnum.Status;
                if (!result.IsSuccess)
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.message    = result.ErrorMessage;
                }
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(ErpTransferGoods parm, List <TransferGoods> list)
        {
            var res = new ApiResult <string>()
            {
                statusCode = (int)ApiEnum.Error
            };

            try
            {
                //根据调拨单,查询入库信息
                var transferModel = ErpTransferDb.GetById(parm.TransferGuid);
                if (transferModel == null)
                {
                    res.message = "调拨单不存在~";
                    return(await Task.Run(() => res));
                }
                //增加调拨商品日志
                var listModel = new List <ErpTransferGoods>();
                //增加调拨的入库
                var inOutLogList = new List <ErpInOutLog>();
                //查询调拨的商品唯一编号
                var skuArray = list.Select(m => m.guid).ToList();
                //根据条形码编号,查询条形码信息
                var goodsSkuList = ErpGoodsSkuDb.GetList(m => skuArray.Contains(m.Guid));
                //查询调拨出库的商家条形码列表
                var outStockSkuList = ErpShopSkuDb.GetList(m => m.ShopGuid == transferModel.OutShopGuid && skuArray.Contains(m.SkuGuid));
                //查询调拨入库的商家条形码列表
                var inStockSkuList = ErpShopSkuDb.GetList(m => m.ShopGuid == transferModel.InShopGuid && skuArray.Contains(m.SkuGuid));

                var newShopSkuList = new List <ErpShopSku>();

                //创建一个出库到加盟商的打包日志
                var packModel = new ErpPackLog()
                {
                    Guid     = Guid.NewGuid().ToString(),
                    Types    = 2,
                    Mode     = 1,
                    Number   = "DB" + Utils.GetOrderNumber(),
                    PackName = "调拨",
                    GoodsSum = list.Sum(m => m.goodsSum),
                    ShopGuid = transferModel.InShopGuid
                };
                //循环操作
                foreach (var item in list)
                {
                    //出库减少库存
                    var sourceStockOutModel = outStockSkuList.Find(m => m.SkuGuid == item.guid);
                    outStockSkuList.Find(m => m.SkuGuid == item.guid).Stock = sourceStockOutModel.Stock - item.goodsSum;

                    //根据条形码,查询商家条形码表是否存在,如果存在,则修改-增加库存,不存在,增加一条数据
                    var sourceStockSkuInModel = inStockSkuList.Find(m => m.SkuGuid == item.guid);
                    if (sourceStockSkuInModel != null)
                    {
                        inStockSkuList.Find(m => m.SkuGuid == item.guid).Stock = sourceStockSkuInModel.Stock + item.goodsSum;
                    }
                    else
                    {
                        newShopSkuList.Add(new ErpShopSku()
                        {
                            SkuGuid  = item.guid,
                            SkuCode  = goodsSkuList.Find(m => m.Guid == item.guid).Code,
                            ShopGuid = transferModel.InShopGuid,
                            Stock    = item.goodsSum
                        });
                    }

                    //入库
                    inOutLogList.Add(new ErpInOutLog()
                    {
                        Guid      = Guid.NewGuid().ToString(),
                        Types     = 2,
                        ShopGuid  = transferModel.InShopGuid,
                        PackGuid  = packModel.Guid,
                        GoodsGuid = item.guid,
                        GoodsSum  = item.goodsSum,
                        AddDate   = DateTime.Now,
                        AdminGuid = parm.GoodsGuid,
                        InTypes   = 2
                    });

                    //调拨单商品
                    listModel.Add(new ErpTransferGoods()
                    {
                        Guid         = Guid.NewGuid().ToString(),
                        TransferGuid = parm.TransferGuid,
                        GoodsGuid    = item.guid,
                        GoodsSum     = item.goodsSum
                    });
                }
                //判断商品总数是否大于调拨单商品数量
                var transgerModel = ErpTransferDb.GetById(parm.TransferGuid);
                if (transgerModel.GoodsSum < listModel.Sum(m => m.GoodsSum))
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.message    = "调拨数量不能大于调拨单总数~";
                    return(await Task.Run(() => res));
                }

                var result = Db.Ado.UseTran(() =>
                {
                    //增加一条打包日志
                    Db.Insertable(packModel).ExecuteCommand();
                    //增加打包里面的商品列表
                    Db.Insertable(inOutLogList).ExecuteCommand();
                    //增加调拨单里面的商品记录
                    Db.Insertable(listModel).ExecuteCommand();

                    //更新调拨  选择出库的商家条形码库存数
                    Db.Updateable(outStockSkuList).ExecuteCommand();
                    //更新调拨  选择入库的商家条形码的库存,有的增加,没有的增加一条数据
                    Db.Updateable(inStockSkuList).ExecuteCommand();
                    if (newShopSkuList.Count > 0)
                    {
                        Db.Insertable(newShopSkuList).ExecuteCommand();
                    }
                });
                res.statusCode = (int)ApiEnum.Status;
                if (!result.IsSuccess)
                {
                    res.statusCode = (int)ApiEnum.Error;
                    res.message    = result.ErrorMessage;
                }
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 修改一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > ModifyStatusAsync(ErpReturnGoods parm)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = (int)ApiEnum.Error
            };

            try
            {
                var model = ErpReturnGoodsDb.GetSingle(m => m.Guid == parm.Guid);
                if (model != null)
                {
                    //查询加盟商库存中,该条商品的信息
                    var shopGoods = ErpShopSkuDb.GetSingle(m => m.ShopGuid == model.ShopGuid && m.SkuGuid == model.GoodsGuid);
                    //查询平台  该条商品的信息
                    var platformGoods = ErpGoodsSkuDb.GetSingle(m => m.Guid == model.GoodsGuid);
                    //查询返货订单信息
                    var returnOrderModel = ErpReturnOrderDb.GetSingle(m => m.Guid == model.OrderGuid);
                    if (model.Status == 1)
                    {
                        //如果状态修改为非正常   需要增加加盟商库存   减少平台库存
                        model.Status = 2;
                        //加盟商增加
                        shopGoods.Stock += model.ReturnCount;
                        //需要判断平台库存是否足够
                        if (platformGoods.StockSum < model.ReturnCount)
                        {
                            res.message = "平台库存不足!";
                            return(await Task.Run(() => res));
                        }
                        //平台库存减少
                        platformGoods.StockSum -= model.ReturnCount;
                        //减少返货订单总数
                        returnOrderModel.GoodsSum -= model.ReturnCount;
                    }
                    else
                    {
                        //如果状态修改为非正常   需要减少加盟商库存  增加平台库存
                        model.Status = 1;
                        //需要判断加盟商库存是否足够
                        if (shopGoods.Stock < model.ReturnCount)
                        {
                            res.message = "加盟商库存不足!";
                            return(await Task.Run(() => res));
                        }
                        //加盟商减少
                        shopGoods.Stock -= model.ReturnCount;
                        //平台库存增加
                        platformGoods.StockSum += model.ReturnCount;
                        //增加返货订单总数
                        returnOrderModel.GoodsSum += model.ReturnCount;
                    }

                    var result = Db.Ado.UseTran(() =>
                    {
                        //修改加盟商信息
                        Db.Updateable(shopGoods).ExecuteCommand();
                        //修改平台库存
                        Db.Updateable(platformGoods).ExecuteCommand();
                        //修改返货订单信息
                        Db.Updateable(returnOrderModel).ExecuteCommand();
                        //修改返货商品
                        Db.Updateable(model).ExecuteCommand();
                    });
                    if (!result.IsSuccess)
                    {
                        res.message = result.ErrorMessage;
                    }
                    res.statusCode = (int)ApiEnum.Status;
                }
                else
                {
                    res.message = "没有查询到该条数据~";
                }
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(ErpSaleOrder parm, string goodsJson)
        {
            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();
                //判断销售订单字符串是否为空
                if (string.IsNullOrEmpty(goodsJson))
                {
                    res.message = "销售订单里面的商品不能为空~";
                    return(await Task.Run(() => res));
                }
                //判断用户信息存在,如果存在需要根据用户查询编号
                ErpShopUser userModel = null;
                if (!string.IsNullOrEmpty(parm.UserGuid))
                {
                    //判断是否存在
                    userModel = ErpShopUserDb.GetSingle(m => m.Mobile == parm.UserGuid);
                    if (userModel == null)
                    {
                        res.message = "会员不存在~";
                        return(await Task.Run(() => res));
                    }
                    parm.UserGuid = userModel.Guid;
                }

                var isStockSuccess = true;
                //解析字符串转换成List对象
                var roGoodsList = JsonConvert.DeserializeObject <List <ErpSaleOrderGoods> >(goodsJson);
                //验证销售商品的数量是否大于库存数量
                foreach (var item in roGoodsList.GroupBy(m => m.GoodsGuid).Select(m => new ErpSaleOrderGoods {
                    GoodsGuid = m.Key, Counts = m.Sum(g => g.Counts)
                }).ToList())
                {
                    var shopStockSum = Db.Queryable <ErpShopSku>()
                                       .Where(m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == item.GoodsGuid).First();
                    if (shopStockSum.Stock < item.Counts)
                    {
                        isStockSuccess = false;
                    }
                }
                if (!isStockSuccess)
                {
                    res.message = "商品库存数量";
                    return(await Task.Run(() => res));
                }

                //获得商品的所有id
                var goodIds = roGoodsList.Select(m => m.GoodsGuid).ToList();
                //根据商品获得列表
                var goodList = ErpGoodsSkuDb.GetList(m => goodIds.Contains(m.Guid));
                //根据店铺获得加盟商的库存信息
                var shopGoodsSkuList = ErpShopSkuDb.GetList(m => m.ShopGuid == parm.ShopGuid && goodIds.Contains(m.SkuGuid));
                //满减变量
                var fullJson = new List <ShopActivity>();
                //根据活动编号,查询活动详情,处理对应金额
                ErpShopActivity activityModel = null;
                if (!string.IsNullOrEmpty(parm.ActivityName))
                {
                    //查询活动
                    activityModel = ErpShopActivityDb.GetSingle(m => m.Guid == parm.ActivityName && m.Enable && !m.IsDel);
                    if (activityModel != null)
                    {
                        parm.ActivityGuid  = parm.ActivityName;
                        parm.ActivityName  = Utils.GetActivityMethod(activityModel.Method);
                        parm.ActivityTypes = Utils.GetActivityTypes(activityModel.Method);
                        if (!string.IsNullOrEmpty(activityModel.FullBack))
                        {
                            //满减======序列号满减对象
                            fullJson = JsonConvert.DeserializeObject <List <ShopActivity> >(activityModel.FullBack);
                        }
                    }
                }
                //根据活动算好订单金额,如果有活动,满减或者打折,最终金额会根据活动而变
                var roIndex = 0; //定义一个循环的标记
                foreach (var item in roGoodsList)
                {
                    roIndex++;
                    var skuItem = goodList.Find(m => m.Guid == item.GoodsGuid);
                    //增加到GoodsSku的销售数量
                    goodList.Find(m => m.Guid == item.GoodsGuid).SaleSum += item.Counts;
                    //修改加盟商条形码表中的库存减少,  销售数量增加
                    var shopSkuModel = shopGoodsSkuList.Find(m => m.SkuGuid == skuItem.Guid);
                    shopGoodsSkuList.Find(m => m.SkuGuid == item.GoodsGuid).Stock = shopSkuModel.Stock - item.Counts;
                    //修改加盟商条形码表中的销售数量   增加
                    shopGoodsSkuList.Find(m => m.SkuGuid == item.GoodsGuid).Sale = shopSkuModel.Sale + item.Counts;
                    //获得商品原价*购买商品的数量
                    parm.Money += Convert.ToDecimal(skuItem.SalePrice) * item.Counts;
                    //如果没有活动直接结算金额
                    if (activityModel == null)
                    {
                        if (parm.SaleType == 1)
                        {
                            parm.RealMoney += Convert.ToInt32(skuItem.SalePrice) * item.Counts;
                            item.Money      = Convert.ToInt32(skuItem.SalePrice);
                        }
                        else
                        {
                            item.Money = parm.RealMoney;
                        }
                    }
                    else
                    {
                        //统计非品牌活动,到下面去处理这个值
                        if (activityModel.Types != 2 && parm.SaleType == 1)
                        {
                            parm.RealMoney += Convert.ToInt32(skuItem.SalePrice) * item.Counts;
                        }
                    }
                    //整除销售计算价格,残次品价格是前端传过来的
                    if (activityModel != null && parm.SaleType == 1)
                    {
                        //按品牌——这里面只处理打折的,并且是按品牌的
                        if (activityModel.Method == 1 && activityModel.Types == 2)
                        {
                            if (skuItem.BrankGuid == activityModel.BrandGuid)
                            {
                                //品牌打折
                                var tempMoney = Convert.ToDecimal(skuItem.SalePrice) * item.Counts;
                                tempMoney       = tempMoney * (Convert.ToDecimal(activityModel.CountNum) / 100);
                                parm.RealMoney += tempMoney;
                                item.Money      = parm.RealMoney;
                            }
                            else
                            {
                                //不是该品牌部打折
                                parm.RealMoney += Convert.ToDecimal(skuItem.SalePrice) * item.Counts;
                                item.Money      = parm.RealMoney;
                            }
                        }
                        //按品牌——满减
                        else if (activityModel.Method == 2 && activityModel.Types == 2)
                        {
                            //查询该品牌价格是否满足满减需要
                            var brankMoney = goodList.Where(m => m.BrankGuid == activityModel.BrandGuid).Sum(m => Convert.ToInt32(m.SalePrice) * item.Counts);
                            var brankCount = goodList.Count(m => m.BrankGuid == activityModel.BrandGuid);
                            //是否满足品牌打折的要求
                            var isBrankOk = false;
                            //如果满足打折要求,满减值
                            var fullMoney = 0;
                            //循环判断符合满减对象
                            foreach (var fullItem in fullJson.OrderByDescending(m => m.fullbegin).ToList())
                            {
                                if (brankMoney >= fullItem.fullbegin)
                                {
                                    isBrankOk = true;
                                    fullMoney = fullItem.fullend;
                                    break;
                                }
                            }
                            //满足打折需求——根据品牌计算单个商品的价格  品牌平均分配价格
                            if (skuItem.BrankGuid == activityModel.BrandGuid && isBrankOk)
                            {
                                //单个商品的金额减满减值/品牌个数=订单详情商品的金额
                                item.Money      = Convert.ToDecimal(skuItem.SalePrice) * item.Counts - Convert.ToDecimal(fullMoney / brankCount);
                                parm.RealMoney += item.Money;
                            }
                            else
                            {
                                item.Money      = Convert.ToDecimal(skuItem.SalePrice) * item.Counts;
                                parm.RealMoney += item.Money;
                            }
                        }
                        //按品牌——买一增一
                        else if (activityModel.Method == 3 && activityModel.Types == 2)
                        {
                            //按品牌买一增一
                            if (skuItem.BrankGuid == activityModel.BrandGuid)
                            {
                                if (roIndex == 1)
                                {
                                    item.Money      = Convert.ToDecimal(skuItem.SalePrice) * item.Counts;
                                    parm.RealMoney += item.Money;
                                }
                                else
                                {
                                    item.Money = 0;
                                }
                            }
                            else
                            {
                                //不是该品牌,不参与活动   既然后是品牌买一赠一活动,实际上不应该出现非品牌的商品出现
                                item.Money      = Convert.ToDecimal(skuItem.SalePrice) * item.Counts;
                                parm.RealMoney += item.Money;
                            }
                        }
                        //按全部店铺——打折
                        else if (activityModel.Method == 1 && activityModel.Types != 2)
                        {
                            //全部商铺,也就是所有金额
                            var zhVal = Convert.ToDecimal(activityModel.CountNum) / 100;
                            item.Money = (Convert.ToDecimal(skuItem.SalePrice) * item.Counts) * zhVal;
                        }
                        //按全部店铺——满减
                        else if (activityModel.Method == 2 && activityModel.Types != 2)
                        {
                            var allMoney = goodList.Sum(m => Convert.ToInt32(m.SalePrice) * item.Counts);
                            var allCount = goodList.Count();
                            //是否满足品牌打折的要求
                            var isBrankOk = false;
                            //如果满足打折要求,满减值
                            var fullMoney = 0;
                            //循环判断符合满减对象
                            foreach (var fullItem in fullJson.OrderByDescending(m => m.fullbegin).ToList())
                            {
                                if (allMoney >= fullItem.fullbegin)
                                {
                                    isBrankOk = true;
                                    fullMoney = fullItem.fullend;
                                    break;
                                }
                            }
                            if (isBrankOk)
                            {
                                item.Money = Convert.ToDecimal(skuItem.SalePrice) * item.Counts - Convert.ToDecimal(fullMoney / allCount);
                            }
                        }
                        //按全部店铺——买一赠一
                        else if (activityModel.Method == 3 && activityModel.Types != 2)
                        {
                            item.Money = roIndex == 1 ? Convert.ToDecimal(skuItem.SalePrice) * item.Counts : 0;
                        }
                    }
                }
                //有活动,并且是正常销售的情况下   非按品牌
                if (activityModel != null && parm.SaleType == 1 && activityModel.Types != 2)
                {
                    //====打折/满减
                    if (activityModel.Method == 1)
                    {
                        //全部商铺,也就是所有金额
                        var zhVal = Convert.ToDecimal(activityModel.CountNum) / 100;
                        parm.RealMoney = Convert.ToDecimal(parm.RealMoney * zhVal);
                    }
                    else if (activityModel.Method == 2)
                    {
                        //循环判断符合满减对象
                        foreach (var item in fullJson.OrderByDescending(m => m.fullbegin).ToList())
                        {
                            if (parm.RealMoney >= item.fullbegin)
                            {
                                parm.RealMoney = parm.RealMoney - item.fullend;
                                break;
                            }
                        }
                    }
                    else if (activityModel.Method == 3)
                    {
                        //买一增一  循环购买商品,只读取第一件,第二个是赠品
                        for (int i = 0; i < roGoodsList.Count; i++)
                        {
                            if (i == 0)
                            {
                                parm.RealMoney = Convert.ToDecimal(goodList.Find(m => m.Guid == roGoodsList[i].GoodsGuid).SalePrice);
                                //给商品明细,第一条商品价格,第二价格为0元,不需要处理
                                roGoodsList[i].Money = parm.RealMoney;
                                break;
                            }
                        }
                    }
                }



                //查询今天销售数量
                var dayCount = ErpSaleOrderDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime));
                parm.Number = "SO-" + DateTime.Now.ToString("yyyyMMdd") + "-" + (1001 + dayCount);
                res.data    = parm.Number;
                for (int i = 0; i < roGoodsList.Count; i++)
                {
                    var item = roGoodsList[i];
                    item.OrderNumber = parm.Number;
                    item.Guid        = Guid.NewGuid().ToString();
                    item.ShopGuid    = parm.ShopGuid;
                }

                var result = Db.Ado.UseTran(() =>
                {
                    //添加订单
                    Db.Insertable(parm).ExecuteCommand();
                    //添加订单商品
                    Db.Insertable(roGoodsList).ExecuteCommand();
                    //根据商品修改商品的销售数量
                    Db.Updateable(goodList).ExecuteCommand();
                    //修改加盟商商品条形码的销售数量
                    Db.Updateable(shopGoodsSkuList).ExecuteCommand();
                    if (userModel != null)
                    {
                        //根据实付金额,计算积分值
                        userModel.Points = Convert.ToInt32(parm.RealMoney / 10);
                        //构建积分变动记录
                        var pointLogModel = new ErpUserPointLog()
                        {
                            Guid        = Guid.NewGuid().ToString(),
                            UserGuid    = userModel.Guid,
                            OperateGuid = parm.Guid,
                            Types       = 0,
                            Point       = userModel.Points,
                            Summary     = "[增加]-销售商品"
                        };
                        Db.Insertable(pointLogModel).ExecuteCommand();
                        //修改用户积分
                        Db.Updateable <ErpShopUser>().UpdateColumns(m => m.Points == m.Points + userModel.Points).Where(m => m.Guid == userModel.Guid).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));
        }
Ejemplo n.º 13
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));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(ErpSaleOrder parm, string goodsJson)
        {
            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();
                //判断销售订单字符串是否为空
                if (string.IsNullOrEmpty(goodsJson))
                {
                    res.message = "销售订单里面的商品不能为空~";
                    return(await Task.Run(() => res));
                }
                //判断用户信息存在,如果存在需要根据用户查询编号
                ErpShopUser userModel = null;
                if (!string.IsNullOrEmpty(parm.UserGuid))
                {
                    //判断是否存在
                    userModel = ErpShopUserDb.GetSingle(m => m.Mobile == parm.UserGuid);
                    if (userModel == null)
                    {
                        res.message = "会员不存在~";
                        return(await Task.Run(() => res));
                    }
                    parm.UserGuid = userModel.Guid;
                }

                var isStockSuccess = true;
                //解析字符串转换成List对象
                var roGoodsList = JsonConvert.DeserializeObject <List <ErpSaleOrderGoods> >(goodsJson);
                //验证销售商品的数量是否大于库存数量
                foreach (var item in roGoodsList.GroupBy(m => m.GoodsGuid).Select(m => new ErpSaleOrderGoods {
                    GoodsGuid = m.Key, Counts = m.Sum(g => g.Counts)
                }).ToList())
                {
                    var shopStockSum = Db.Queryable <ErpShopSku>()
                                       .Where(m => m.ShopGuid == parm.ShopGuid && m.SkuGuid == item.GoodsGuid).First();
                    if (shopStockSum.Stock < item.Counts)
                    {
                        isStockSuccess = false;
                    }
                }
                if (!isStockSuccess)
                {
                    res.message = "商品库存数量";
                    return(await Task.Run(() => res));
                }

                //根据活动编号,查询活动详情,处理对应金额
                ErpShopActivity activityModel = null;
                if (!string.IsNullOrEmpty(parm.ActivityName))
                {
                    //查询活动
                    activityModel = ErpShopActivityDb.GetById(parm.ActivityName);
                    if (activityModel != null)
                    {
                        parm.ActivityGuid  = parm.ActivityName;
                        parm.ActivityName  = activityModel.Method == 1 ? "打折" : "满减";
                        parm.ActivityTypes = activityModel.Method == 1 ? Convert.ToByte(2) : Convert.ToByte(3);
                    }
                }
                //根据活动算好订单金额,如果有活动,满减或者打折,最终金额会根据活动而变

                //获得商品的所有id
                var goodIds = roGoodsList.Select(m => m.GoodsGuid).ToList();
                //根据商品获得列表
                var goodList = ErpGoodsSkuDb.GetList(m => goodIds.Contains(m.Guid));
                //根据店铺获得加盟商的库存信息
                var shopGoodsSkuList = ErpShopSkuDb.GetList(m => m.ShopGuid == parm.ShopGuid && goodIds.Contains(m.SkuGuid));
                foreach (var item in goodList)
                {
                    foreach (var roitem in roGoodsList)
                    {
                        if (roitem.GoodsGuid == item.Guid)
                        {
                            //修改商品的销售数量
                            item.SaleSum += roitem.Counts;
                            //修改加盟商条形码表中的库存减少,  销售数量增加
                            var shopSkuModel = shopGoodsSkuList.Find(m => m.SkuGuid == roitem.GoodsGuid);
                            shopGoodsSkuList.Find(m => m.SkuGuid == roitem.GoodsGuid).Stock = shopSkuModel.Stock - roitem.Counts;
                            //修改加盟商条形码表中的销售数量   增加
                            shopGoodsSkuList.Find(m => m.SkuGuid == roitem.GoodsGuid).Sale = shopSkuModel.Sale + roitem.Counts;
                            //获得商品原价*购买商品的数量
                            parm.Money += Convert.ToDecimal(item.SalePrice) * roitem.Counts;
                            //整除销售计算价格,残次品价格是前端传过来的
                            if (parm.SaleType == 1)
                            {
                                //这里面只处理打折的,并且是按品牌的
                                if (activityModel != null && activityModel.Method == 1 && activityModel.Types == 2)
                                {
                                    if (item.BrankGuid == activityModel.BrandGuid)
                                    {
                                        //品牌打折
                                        var tempMoney = Convert.ToDecimal(item.SalePrice) * roitem.Counts;
                                        tempMoney       = tempMoney * (Convert.ToDecimal(activityModel.CountNum) / 100);
                                        parm.RealMoney += tempMoney;
                                    }
                                    else
                                    {
                                        //不是该品牌部打折
                                        parm.RealMoney += Convert.ToDecimal(item.SalePrice) * roitem.Counts;
                                    }
                                }
                                //else if (activityModel != null && activityModel.Method == 2 && activityModel.Types == 2) {
                                //    //品牌满减
                                //    if (item.BrankGuid == activityModel.BrandGuid)
                                //    {

                                //    }
                                //}
                                else
                                {
                                    parm.RealMoney += Convert.ToDecimal(item.SalePrice) * roitem.Counts;
                                }
                            }
                        }
                    }
                }
                if (activityModel != null && parm.SaleType == 1)
                {
                    //====打折/满减
                    if (activityModel.Method == 1)
                    {
                        //打折   实收金额=实收金额*(折扣值/100)
                        if (activityModel.Types == 0)
                        {
                            //全部商铺,也就是所有金额
                            var zhVal = Convert.ToDecimal(activityModel.CountNum) / 100;
                            parm.RealMoney = Convert.ToDecimal(parm.RealMoney * zhVal);
                        }
                    }
                    else
                    {
                        //满减======序列号满减对象
                        var fullJson = JsonConvert.DeserializeObject <List <ShopActivity> >(activityModel.FullBack);
                        //循环判断符合满减对象
                        foreach (var item in fullJson.OrderByDescending(m => m.fullbegin).ToList())
                        {
                            if (parm.RealMoney > item.fullbegin)
                            {
                                parm.RealMoney = parm.RealMoney - item.fullend;
                                break;
                            }
                        }
                    }
                }


                //根据实付金额,计算积分值
                if (userModel != null)
                {
                    userModel.Points = Convert.ToInt32(parm.RealMoney / 10);
                }

                //查询今天销售数量
                var dayCount = ErpSaleOrderDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime));
                parm.Number = "SO-" + DateTime.Now.ToString("yyyyMMdd") + "-" + (1001 + dayCount);
                res.data    = parm.Number;
                foreach (var item in roGoodsList)
                {
                    item.OrderNumber = parm.Number;
                    item.Guid        = Guid.NewGuid().ToString();
                    item.ShopGuid    = parm.ShopGuid;
                }

                var result = Db.Ado.UseTran(() =>
                {
                    //添加订单
                    Db.Insertable(parm).ExecuteCommand();
                    //添加订单商品
                    Db.Insertable(roGoodsList).ExecuteCommand();
                    //根据商品修改商品的销售数量
                    Db.Updateable(goodList).ExecuteCommand();
                    //修改加盟商商品条形码的销售数量
                    Db.Updateable(shopGoodsSkuList).ExecuteCommand();
                    if (userModel != null)
                    {
                        //修改用户积分
                        Db.Updateable <ErpShopUser>().UpdateColumns(m => m.Points == m.Points + userModel.Points).Where(m => m.Guid == userModel.Guid).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));
        }
Ejemplo n.º 15
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));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(ErpGoodsSku parm)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = 200
            };

            try
            {
                //判断是否存在
                var isExt = ErpGoodsSkuDb.IsAny(m => m.Code == parm.Code);
                if (isExt)
                {
                    res.statusCode = (int)ApiEnum.ParameterError;
                    res.message    = "该条形码已存在~";
                }
                else
                {
                    //构建Code
                    var codeType = SysCodeTypeDb.GetList(m => m.ParentGuid == "8d3158d6-e179-4046-99e9-53eb8c04ddb1").Select(m => m.Guid).ToList();
                    var codeList = SysCodeDb.GetList(m => codeType.Contains(m.ParentGuid));
                    parm.Code = codeList.Find(m => m.Guid == parm.BrankGuid).CodeType
                                + codeList.Find(m => m.Guid == parm.YearGuid).CodeType
                                + codeList.Find(m => m.Guid == parm.SeasonGuid).CodeType
                                + codeList.Find(m => m.Guid == parm.StyleGuid).CodeType
                                + codeList.Find(m => m.Guid == parm.BatchGuid).CodeType
                                + codeList.Find(m => m.Guid == parm.SizeGuid).CodeType
                                + parm.SalePrice
                                + "-" + parm.DisPrice;

                    //构建商品标题
                    var brankName = codeList.Find(m => m.Guid == parm.BrankGuid).Name;
                    var styleName = codeList.Find(m => m.Guid == parm.StyleGuid).Name;
                    var goodsName = brankName + codeList.Find(m => m.Guid == parm.SeasonGuid).Name + styleName;

                    //构建商品信息
                    var goodsModel = new ErpGoods()
                    {
                        Guid  = Guid.NewGuid().ToString(),
                        Title = goodsName,
                        Brank = brankName,
                        Style = styleName
                    };

                    parm.GoodsGuid = goodsModel.Guid;
                    parm.Guid      = Guid.NewGuid().ToString();

                    //事务保证数据一致性
                    Db.Ado.BeginTran();
                    var goodsres = ErpGoodsDb.Insert(goodsModel);
                    if (goodsres)
                    {
                        var dbres = ErpGoodsSkuDb.Insert(parm);
                        if (!dbres)
                        {
                            res.statusCode = (int)ApiEnum.Error;
                            res.message    = "插入数据失败~";
                        }
                    }
                    Db.Ado.CommitTran();
                }
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                res.statusCode = (int)ApiEnum.Error;
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
            }
            return(await Task.Run(() => res));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(ErpReturnOrder parm, string goodsJson)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = (int)ApiEnum.Error
            };

            try
            {
                parm.Guid = Guid.NewGuid().ToString();
                //判断返货订单字符串是否为空
                if (string.IsNullOrEmpty(goodsJson))
                {
                    res.message = "返货订单里面的商品不能为空~";
                    return(await Task.Run(() => res));
                }
                var isStockSuccess = true;
                //解析字符串转换成List对象
                var roGoodsList = JsonConvert.DeserializeObject <List <ErpReturnGoods> >(goodsJson);
                var guidArray   = roGoodsList.Select(m => m.GoodsGuid).ToList();
                //根据返货的商品,查询平台的条形码
                var goodsSkuList = ErpGoodsSkuDb.GetList(m => guidArray.Contains(m.Guid));
                //根据返货的商品,查询加盟商的条形码
                var shopsSkuList = ErpShopSkuDb.GetList(m => guidArray.Contains(m.SkuGuid) && m.ShopGuid == parm.ShopGuid);
                //验证返货商品的数量是否大于库存数量
                foreach (var item in roGoodsList.GroupBy(m => m.GoodsGuid).Select(m => new ErpReturnGoods {
                    GoodsGuid = m.Key, ReturnCount = m.Sum(g => g.ReturnCount)
                }).ToList())
                {
                    var shopStockSum = shopsSkuList.Find(m => m.SkuGuid == item.GoodsGuid);
                    if (shopStockSum.Stock < item.ReturnCount)
                    {
                        isStockSuccess = false;
                    }
                    //加盟商条形码表,减少返货的库存
                    shopsSkuList.Find(m => m.SkuGuid == item.GoodsGuid).Stock = shopStockSum.Stock - item.ReturnCount;
                    //平台条形码表,增加返货的库存
                    var goodsStock = goodsSkuList.Find(m => m.Guid == item.GoodsGuid);
                    goodsSkuList.Find(m => m.Guid == item.GoodsGuid).StockSum = goodsStock.StockSum + item.ReturnCount;
                }
                if (!isStockSuccess)
                {
                    res.message = "返货的商品数量大于库存数量";
                    return(await Task.Run(() => res));
                }
                foreach (var item in roGoodsList)
                {
                    item.OrderGuid = parm.Guid;
                    item.Guid      = Guid.NewGuid().ToString();
                    item.ShopGuid  = parm.ShopGuid;
                }
                parm.GoodsSum = roGoodsList.Sum(m => m.ReturnCount);
                //查询今天返货数量
                DateTime dayTime  = Convert.ToDateTime(DateTime.Now.AddDays(1).ToShortDateString() + " 00:00:00");
                var      dayCount = ErpReturnOrderDb.Count(m => SqlFunc.DateIsSame(m.AddDate, dayTime));
                parm.Number = "RO-" + DateTime.Now.ToString("yyyyMMdd") + "-" + (1001 + dayCount);
                var result = Db.Ado.UseTran(() =>
                {
                    //添加订单
                    Db.Insertable(parm).ExecuteCommand();
                    //添加订单商品
                    Db.Insertable(roGoodsList).ExecuteCommand();
                    //修改平台库存
                    Db.Updateable(goodsSkuList).ExecuteCommand();
                    //修改加盟商库存
                    Db.Updateable(shopsSkuList).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));
        }