Exemplo n.º 1
0
        /// <summary>
        /// 添加套餐
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public APIResult AddCombo([FromBody] AddComboArgsModel args)
        {
            if (args.ShopId == 0)
            {
                throw new Exception("ShopId不能为空");
            }
            Shop shop = db.GetSingle <Shop>(args.ShopId);

            CheckShopBrandActor(shop.ShopBrandId, ShopBrandActorType.超级管理员);

            ShopBrandCommodity combo = new ShopBrandCommodity()
            {
                AddIp         = GetIp(),
                SalesForMonth = 0,
                ShopBrandId   = shop.ShopBrandId,
                AddTime       = DateTime.Now,
                IsSelfOrder   = args.IsSelfOrder,
                IsScanCode    = args.IsScanCode,
                IsTakeout     = args.IsTakeout,
                Name          = args.Name,
                Price         = args.Price,
                Unit          = args.Unit,
                CategoryId    = 0,
                Cover         = args.Cover,
                Flag          = Guid.NewGuid().ToString()
            };

            db.Add(combo);
            db.SaveChanges();
            foreach (var item in args.Items)
            {
                ShopOrderComboItem comboItem = new ShopOrderComboItem()
                {
                    Pid           = combo.Id,
                    CommodityName = item.CommodityName,
                    Count         = item.Count,
                    SalePrice     = item.Count * item.SalePrice,
                    Sku           = item.Sku
                };
                db.Add(comboItem);
            }
            db.SaveChanges();
            return(Success());
        }
Exemplo n.º 2
0
        public APIResult Update([FromBody] UpdateArgsModel args)
        {
            if (string.IsNullOrEmpty(args.Name))
            {
                throw new ArgumentNullException("Name");
            }
            if (string.IsNullOrEmpty(args.Flag))
            {
                args.Flag = System.Guid.NewGuid().ToString();
            }
            var model = db.Query <ShopBrandCommodity>()
                        .Where(m => !m.IsDel)
                        .Where(m => m.Id == args.Id)
                        .FirstOrDefault();

            if (model == null)
            {
                throw new Exception("数据库记录不存在");
            }

            //在获取后检查是否拥有管理权限
            CheckShopBrandActor(model.ShopBrandId, ShopBrandActorType.超级管理员);

            ShopBrandCommodityCategory category;

            if (args.CategoryId == 0)
            {
                category = null;
            }
            else
            {
                category = db.GetSingle <ShopBrandCommodityCategory>(args.CategoryId);
                if (category == null)
                {
                    throw new Exception("店铺商品类别不存在");
                }
            }

            model.Category       = category;
            model.Detail         = args.Detail;
            model.Name           = args.Name;
            model.Cover          = args.Cover;
            model.IsRecommand    = args.IsRecommand;
            model.Price          = args.Price;
            model.SalesForMonth  = args.SalesForMonth;
            model.Summary        = args.Summary;
            model.Unit           = args.Unit;
            model.IsTakeout      = args.IsTakeout;
            model.IsScanCode     = args.IsScanCode;
            model.IsSelfOrder    = args.IsSelfOrder;
            model.Upvote         = args.Upvote;
            model.UseMemberPrice = args.UseMemberPrice;
            //model.DiningWay = args.DiningWay;

            if (args.CategoryId == 0) //套餐
            {
                foreach (var commodityId in args.CommodityIds)
                {
                    db.Query <ShopOrderComboItem>()
                    .Where(m => !m.IsDel && m.Pid == model.Id)
                    .ToList()
                    .ForEach(m => m.IsDel = true);
                    ShopOrderComboItem comboItem = new ShopOrderComboItem()
                    {
                        ParentCommodity = model,
                        CommodityId     = commodityId
                    };
                    db.Add(comboItem);
                }
            }

            db.SaveChanges();
            return(Success());
        }
Exemplo n.º 3
0
        public APIResult Add([FromBody] AddArgsModel args)
        {
            if (string.IsNullOrEmpty(args.Name))
            {
                throw new ArgumentNullException("Name");
            }
            if (string.IsNullOrEmpty(args.Flag))
            {
                args.Flag = System.Guid.NewGuid().ToString();
            }

            if (!args.ShopBrandId.HasValue)
            {
                throw new ArgumentNullException("ShopBrandId");
            }
            var brandId = args.ShopBrandId.Value;

            CheckShopBrandActor(brandId, ShopBrandActorType.超级管理员);

            var shopBrand = db.GetSingle <ShopBrand>(brandId);

            if (shopBrand == null)
            {
                throw new Exception("店铺品牌纪录不存在");
            }

            ShopBrandCommodityCategory category;

            if (args.CategoryId == 0)
            {
                category = null;
            }
            else
            {
                category = db.GetSingle <ShopBrandCommodityCategory>(args.CategoryId);
                if (category == null)
                {
                    throw new Exception("店铺商品类别不存在");
                }
            }

            var model = new ShopBrandCommodity()
            {
                Flag           = args.Flag,
                AddIp          = GetIp(),
                AddTime        = DateTime.Now,
                AddUser        = GetUsername(),
                Detail         = args.Detail,
                DiningWay      = args.DiningWay,
                Name           = args.Name,
                Cover          = args.Cover,
                IsRecommand    = args.IsRecommand,
                Price          = args.Price,
                SalesForMonth  = args.SalesForMonth,
                ShopBrand      = shopBrand,
                Summary        = args.Summary,
                Unit           = args.Unit,
                Upvote         = args.Upvote,
                IsSelfOrder    = args.IsSelfOrder,
                IsScanCode     = args.IsScanCode,
                IsTakeout      = args.IsTakeout,
                Category       = category,
                UseMemberPrice = args.UseMemberPrice
            };

            db.Add <ShopBrandCommodity>(model);

            if (args.CategoryId == 0) //套餐
            {
                foreach (var commodityId in args.CommodityIds)
                {
                    ShopOrderComboItem comboItem = new ShopOrderComboItem()
                    {
                        ParentCommodity = model,
                        CommodityId     = commodityId
                    };
                    db.Add(comboItem);
                }
            }

            db.SaveChanges();

            return(Success());
        }