/// <summary> /// 获取套餐信息 /// </summary> /// <param name="args"></param> /// <returns></returns> public APIResult GetComboSingle([FromBody] IdArgsModel args) { ShopBrandCommodity combo = db.GetSingle <ShopBrandCommodity>(args.Id); if (combo == null || combo.CategoryId != 0) { throw new Exception("套餐记录不存在"); } CheckShopBrandActor(combo.ShopBrandId, ShopBrandActorType.超级管理员); GetComboSingleDto rtn = new GetComboSingleDto() { Unit = combo.Unit, Price = combo.Price, Name = combo.Name, Cover = combo.Cover, IsScanCode = combo.IsScanCode, IsSelfOrder = combo.IsSelfOrder, IsTakeout = combo.IsTakeout }; rtn.Items = db.Query <ShopOrderComboItem>() .Where(m => !m.IsDel && m.Pid == combo.Id) .Select(m => new ComboItem() { CommodityName = m.CommodityName, SalePrice = m.SalePrice, Count = m.Count, Sku = m.Sku }).ToList(); return(Success(rtn)); }
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(); } var shopBrand = db.GetSingle <ShopBrand>(args.ShopBrandId); if (shopBrand == null) { throw new Exception("店铺品牌纪录不存在"); } var 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, 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, Category = category }; db.Add <ShopBrandCommodity>(model); db.SaveChanges(); return(Success()); }
/// <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()); }
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()); }