Пример #1
0
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > ModifyStatusAsync(ErpShopActivity parm)
        {
            var isok = ErpShopActivityDb.Update(
                m => new ErpShopActivity()
            {
                Enable = parm.Enable
            }, m => m.Guid == parm.Guid);
            var res = new ApiResult <string>
            {
                success    = isok,
                statusCode = isok ? (int)ApiEnum.Status : (int)ApiEnum.Error,
                data       = isok ? "1" : "0"
            };

            return(await Task.Run(() => res));
        }
Пример #2
0
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(ErpShopActivity parm, ShopActivityParm fullParm)
        {
            var res = new ApiResult <string>()
            {
                data = "1", statusCode = 200
            };

            try
            {
                //判断该活动是否冲突
                var isExt = ErpShopActivityDb.IsAny(m => m.BeginDate >= parm.BeginDate && m.EndDate >= parm.EndDate && m.Method == parm.Method && m.ShopGuid == parm.ShopGuid);
                if (isExt)
                {
                    res.statusCode = (int)ApiEnum.ParameterError;
                    res.message    = "该活动已存在~";
                }
                else
                {
                    if (parm.Method == 2)
                    {
                        var actList = new List <ShopActivity>();
                        for (int i = 0; i < fullParm.fullbegin.Count; i++)
                        {
                            actList.Add(new ShopActivity()
                            {
                                fullbegin = !string.IsNullOrEmpty(fullParm.fullbegin[i])?int.Parse(fullParm.fullbegin[i]):0,
                                fullend   = !string.IsNullOrEmpty(fullParm.fullend[i]) ? int.Parse(fullParm.fullend[i]) : 0,
                            });
                        }
                        parm.FullBack = JsonConvert.SerializeObject(actList);
                    }
                    parm.Guid = Guid.NewGuid().ToString();
                    var dbres = ErpShopActivityDb.Insert(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));
        }
Пример #3
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));
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
0
 public async Task <ApiResult <string> > ModifyStatusAsync(ErpShopActivity parm)
 {
     return(await _activityService.ModifyStatusAsync(parm));
 }
Пример #7
0
 public async Task <ApiResult <string> > EditAct(ErpShopActivity parm, ShopActivityParm fullParm)
 {
     return(await _activityService.ModifyAsync(parm, fullParm));
 }