public APIResult Add([FromBody] AddArgsModel args) { if (string.IsNullOrEmpty(args.Value)) { throw new ArgumentNullException("Name"); } var parameter = db.GetSingle <ShopBrandCommodityParameter>(args.ParameterId); if (parameter == null) { throw new Exception("关联的属性不存在"); } var model = new ShopBrandCommodityParameterValue() { AddIp = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), Parameter = parameter, Value = args.Value }; db.Add <ShopBrandCommodityParameterValue>(model); 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.Status.HasValue) { args.Status = ShopBrandStatus.正常; } var model = new ShopBrand() { Flag = args.Flag, AddIp = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), Address = args.Address, Name = args.Name, Status = args.Status.Value, Detail = args.Detail }; db.Add <ShopBrand>(model); db.SaveChanges(); return(Success()); }
public APIResult Add([FromBody] AddArgsModel args) { try { if (string.IsNullOrEmpty(args.Question)) { throw new ArgumentNullException("Question"); } var isExit = wechatCoreDb.QueryRobotMessage() .Where(m => m.Question == args.Question) .Where(m => !m.IsDel) .Count() > 0; if (isExit) { throw new Exception("问题已经存在"); } var model = new RobotMessage() { Question = args.Question, QuestionType = args.QuestionType, Answer = args.Answer, Status = RobotMessageStatus.正常 }; wechatCoreDb.AddToRobotMessage(model); wechatCoreDb.SaveChanges(); return(Success()); } catch (Exception ex) { return(Error(ex.Message)); } }
public APIResult Add([FromBody] AddArgsModel args) { if (string.IsNullOrEmpty(args.MemberFlag)) { throw new ArgumentNullException("Name"); } var shopBrand = db.GetSingle <ShopBrand>(args.ShopBrandId); if (shopBrand == null) { throw new Exception("指定的商铺不存在"); } var member = memberDb.GetSingleMemberBase(args.MemberFlag); if (member == null) { throw new Exception("用户纪录不存在"); } var model = new ShopBrandActor() { ShopBrand = shopBrand, AddIp = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), MemberId = member.Id, ActorType = args.ActorType }; db.Add <ShopBrandActor>(model); 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(); } var shopBrand = db.GetSingle <ShopBrand>(args.ShopBrandId); if (shopBrand == null) { throw new Exception("店铺品牌纪录不存在"); } var model = new ShopBrandCommodityParameter() { AddIp = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), Flag = args.Flag, Name = args.Name, ShopBrand = shopBrand }; db.Add <ShopBrandCommodityParameter>(model); db.SaveChanges(); return(Success()); }
public APIResult Add([FromBody] AddArgsModel args) { if (!args.ShopId.HasValue) { throw new ArgumentNullException("ShopId"); } CheckShopActor(args.ShopId.Value, ShopActorType.超级管理员); //获取并验证店铺是否存在 var shop = db.GetSingle <Shop>(args.ShopId.Value); if (shop == null) { throw new Exception("指定的商铺不存在"); } //这里只是添加一个库存纪录,库存的参数在编辑处修改 var model = new ShopCallingQueueProduct() { Shop = shop, Status = ShopCallingQueueProductStatus.正常, Title = args.Title, Name = args.Name, Detail = args.Detail }; db.Add <ShopCallingQueueProduct>(model); db.SaveChanges(); return(Success()); }
public APIResult Add([FromBody] AddArgsModel args) { try { if (string.IsNullOrEmpty(args.Email)) { throw new ArgumentNullException("email"); } var model = new Member() { Email = args.Email, Password = MemberPasswordToMD5(args.Password), Truename = args.Truename, RegIP = GetIp(), RegTime = DateTime.Now, LastLoginIP = GetIp(), LastLoginTime = DateTime.Now, Status = MemberStatus.正常 }; memberDb.AddToMember(model); memberDb.SaveChanges(); return(Success()); } catch (Exception ex) { return(Error(ex.Message)); } }
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 brand = db.GetSingle <ShopBrand>(args.ShopBrandId); if (brand == null) { throw new Exception("指定的商铺品牌不存在"); } var model = new Shop() { Flag = args.Flag, ShopBrand = brand, AddIp = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), Address = args.Address, AddressGuide = args.AddressGuide, Detail = args.Detail, Latitude = args.Latitude, Longitude = args.Longitude, Name = args.Name, OpenTime = args.OpenTime, ScoreValue = args.ScoreValue, Tel = args.Tel, UsePerUser = args.UsePerUser, Logo = args.Logo, IsShowApplets = args.IsShowApplets }; if (model.Latitude.HasValue && model.Longitude.HasValue) { model.GeoHash = Geohash.Encode(model.Latitude.Value, model.Longitude.Value); } else { model.GeoHash = string.Empty; } db.Add <Shop>(model); 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(); } 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()); }
public APIResult Add([FromBody] AddArgsModel args) { try { var username = GetUsername(); _communityService.Add(args.Name); return(Success()); } catch (Exception ex) { _logger.LogError(0, ex, "Add有错误发生"); return(Error(ex.Message)); } }
public APIResult Add([FromBody] AddArgsModel args) { if (!args.ShopId.HasValue) { throw new ArgumentNullException("ShopId"); } CheckShopActor(args.ShopId.Value, ShopActorType.超级管理员); //判定商品中是否已经指定sku的库存 var query = db.Query <ShopCommodityStock>() .Where(m => !m.IsDel); var isExit = query.Where(m => m.ShopId == args.ShopId && m.SkuId == args.SkuId).Count() > 0; if (isExit) { throw new Exception("指定的规格已经添加到库存"); } var sku = db.GetSingle <ShopBrandCommoditySku>(args.SkuId); if (sku == null || sku.CommodityId != args.CommodityId) { throw new Exception("指定的规格不存在"); } var shop = db.GetSingle <Shop>(args.ShopId.Value); if (shop == null) { throw new Exception("指定的商铺不存在"); } //这里只是添加一个库存纪录,库存的参数在编辑处修改 var model = new ShopCommodityStock() { CostPrice = 0, SalePrice = 0, MarketPrice = 0, Shop = shop, Sku = sku, Stock = 0 }; db.Add <ShopCommodityStock>(model); db.SaveChanges(); return(Success()); }
public APIResult Add([FromBody] AddArgsModel args) { if (!args.ShopBrandId.HasValue) { throw new ArgumentNullException("ShopBrandId"); } var brandId = args.ShopBrandId.Value; CheckShopBrandActor(brandId, ShopBrandActorType.超级管理员); 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>(brandId); if (shopBrand == null) { throw new Exception("店铺品牌纪录不存在"); } var model = new ShopBrandCommodityCategory() { Name = args.Name, OrderWeight = args.OrderWeight, Detail = args.Detail, PId = args.PId, Flag = args.Flag, Ico = args.Ico, IsDel = false, Keywords = args.Keywords, Description = args.Description, ShopBrand = shopBrand }; db.Add <ShopBrandCommodityCategory>(model); db.SaveChanges(); return(Success <int>(model.Id)); }
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.Status.HasValue) { args.Status = CommercialDistrictStatus.正常; } var model = new CommercialDistrict() { Flag = args.Flag, AddIp = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), Address = args.Address, Name = args.Name, Status = args.Status.Value, Detail = args.Detail, Longitude = args.Longitude, Latitude = args.Latitude }; if (model.Latitude.HasValue && model.Longitude.HasValue) { model.GeoHash = Geohash.Encode(model.Latitude.Value, model.Longitude.Value); } else { model.GeoHash = string.Empty; } db.Add <CommercialDistrict>(model); db.SaveChanges(); return(Success()); }
public APIResult Add([FromBody] AddArgsModel args) { var commercialDistrict = db.GetSingle <CommercialDistrict>(args.CommercialDistrictId); if (commercialDistrict == null) { throw new Exception("商圈纪录不存在"); } var shop = db.GetSingle <Shop>(args.ShopId); if (shop == null) { throw new Exception("店铺纪录不存在"); } var isExit = db.Query <CommercialDistrictShop>() .Where(m => !m.IsDel) .Where(m => m.CommercialDistrictId == args.CommercialDistrictId && m.ShopId == args.ShopId) .Count() > 0; if (isExit) { throw new Exception("商圈的店铺纪录已经存在"); } var model = new CommercialDistrictShop() { AddIp = GetIp(), AddTime = DateTime.Now, AddUser = GetUsername(), CommercialDistrict = commercialDistrict, Shop = shop }; db.Add <CommercialDistrictShop>(model); db.SaveChanges(); return(Success()); }
public APIResult Add([FromBody] AddArgsModel args) { if (string.IsNullOrEmpty(args.Title)) { throw new ArgumentNullException("title"); } if (!args.ShopId.HasValue) { throw new ArgumentNullException("ShopBrandId"); } var shopId = args.ShopId.Value; CheckShopActor(shopId, ShopActorType.超级管理员); var shop = db.GetSingle <Shop>(shopId); if (shop == null) { throw new Exception("店铺纪录不存在"); } var model = new ShopPart() { Title = args.Title, Detail = args.Detail, Flag = System.Guid.NewGuid().ToString(), Shop = shop, IsDel = false, AddUser = GetUsername(), AddIp = GetIp(), AddTime = DateTime.Now }; db.Add <ShopPart>(model); db.SaveChanges(); return(Success <int>(model.Id)); }
public APIResult Add([FromBody] AddArgsModel args) { var memberId = GetMemberId(); var isExit = db.Query <ShopBooking>() .Where(m => !m.IsDel) .Where(m => m.ShopId == args.ShopId) .Where(m => m.MemberId == memberId) .Where(m => m.Status == ShopBookingStatus.待确认 || m.Status == ShopBookingStatus.确认成功) .Where(m => !m.IsUsed) .Count() > 0; if (isExit) { throw new Exception("你已经预定过,如果想变更,需要先取消再重新预定"); } var startTime = DateTime.Today; var endTime = startTime.AddDays(1); var model = new ShopBooking() { AddTime = DateTime.Now, MemberId = memberId, ShopId = args.ShopId, Users = args.Users, DinnerTime = args.DinnerTime, Nickname = args.Nickname, Phone = args.Phone, Remark = args.Remark, Status = ShopBookingStatus.待确认 }; db.AddTo <ShopBooking>(model); db.SaveChanges(); return(Success(model)); }
public APIResult Add([FromBody] AddArgsModel args) { //获取并验证店铺是否存在 var shop = db.GetSingle <Shop>(args.ShopId); if (shop == null) { throw new Exception("指定的商铺不存在"); } //这里只是添加一个库存纪录,库存的参数在编辑处修改 var model = new ShopCallingQueueProduct() { Shop = shop, Status = ShopCallingQueueProductStatus.正常, Title = args.Title, Detail = args.Detail }; db.Add <ShopCallingQueueProduct>(model); db.SaveChanges(); return(Success()); }
public APIResult Add([FromBody] AddArgsModel args) { var memberId = GetMemberId(); var model = new ShopComment() { AddTime = DateTime.Now, MemberId = memberId, ShopId = args.ShopId, KeyWord = args.KeyWord, Content = args.Content, Grade = args.Grade }; db.AddTo <ShopComment>(model); db.SaveChanges(); db.Query <ShopCommentPicture>() .Where(m => args.PicIds.IndexOf(m.Id) > -1) .ToList() .ForEach(m => m.ShopCommentId = model.Id); db.SaveChanges(); return(Success(model)); }
public APIResult Add([FromBody] AddArgsModel args) { //需要判定是否已经开放叫号 var flag = ShopCallingQueue.GetShopOpenStatusFlag(args.ShopId); var isOpen = db.GetSettingValue <bool>(flag); if (!isOpen) { throw new Exception("还未开放叫号,请等待"); } ShopCallingQueueProduct product = null; if (args.ProductId.HasValue) { product = db.Query <ShopCallingQueueProduct>() .Where(m => !m.IsDel) .Where(m => m.Status == ShopCallingQueueProductStatus.正常) .Where(m => m.Id == args.ProductId && m.ShopId == args.ShopId) .FirstOrDefault(); if (product == null) { throw new Exception("指定的人数设定不存在或者未开放"); } args.Title = product.Title; } var memberId = GetMemberId(); var isExit = db.Query <ShopCallingQueue>() .Where(m => !m.IsDel) .Where(m => m.MemberId == memberId) .Where(m => m.ShopId == args.ShopId) .Where(m => !m.IsUsed) .Where(m => m.Status != ShopCallingQueueStatus.取消) .Where(m => m.Status != ShopCallingQueueStatus.确认失败) .Where(m => DateTime.Now.Date.Equals(m.AddTime.Date)) .Count() > 0; if (isExit) { throw new Exception("你已经在排队中,如果想重新排队,需要先取消"); } var startTime = DateTime.Today; var endTime = startTime.AddDays(1); var model = new ShopCallingQueue() { AddTime = DateTime.Now, CanShareTable = args.CanShareTable, MemberId = memberId, ProductId = args.ProductId, ShopId = args.ShopId, Title = args.Title, Status = product == null ? ShopCallingQueueStatus.待确认 : ShopCallingQueueStatus.确认成功 }; lock (lockAddObject) {//锁定,用于保证每次生成的QueueNumber都是唯一的 var count = db.Query <ShopCallingQueue>() .Where(m => m.AddTime >= startTime && m.AddTime < endTime) .Count(); count++; //增加1,否则开始是从0开始 model.QueueIndex = count; model.QueueNumber = count; db.AddTo <ShopCallingQueue>(model); db.SaveChanges(); } return(Success(model)); }
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()); }
public APIResult Add([FromBody] AddArgsModel args) { //TODO:这里还需要进行锁操作,保证每个店铺的库存不是负数 if (args.Items == null || args.Items.Count <= 0) { throw new Exception("商品内容不能为空"); } bool isTakeOut = args.IsTakeOut == null ? false : args.IsTakeOut.Value; bool isThird = false; var memberId = GetMemberId(); var shop = db.Query <Shop>() .Where(m => !m.IsDel) .Where(m => m.Id == args.ShopId) .FirstOrDefault(); if (shop == null) { throw new Exception("商铺纪录不存在"); } ShopMember shopMember = ShopMemberServer.GetShopMember(db, shop.Id, memberId); var shopMemberSet = ShopMemberServer.GetShopMemberSet(db, shop.Id); bool IsTopUpDiscount = shopMemberSet == null ? false : shopMemberSet.IsTopUpDiscount; double memberDiscount = 1; if (shopMember != null) { var shopMemberLevel = db.GetSingle <ShopMemberLevel>(shopMember.ShopMemberLevelId); if (shopMemberLevel != null) { memberDiscount = shopMemberLevel.Discount; } } var shoptakeoutinfo = db.ShopTakeOutInfo.FirstOrDefault(r => r.ShopId == args.ShopId && !r.IsDel); if (shoptakeoutinfo != null && shoptakeoutinfo.TakeDistributionType == TakeDistributionType.达达配送 && isTakeOut && args.TakeWay == TakeWay.送货上门) { isThird = true; } var model = new ShopOrder() { AddTime = DateTime.Now, MemberId = memberId, ShopId = args.ShopId, Remark = args.Remark, AddUser = $"member{memberId}", AddIp = GetIp(), Flag = Guid.NewGuid().ToString(), IsTakeOut = isTakeOut, Status = ShopOrderStatus.待支付, takeDistributionType = isThird == true ? TakeDistributionType.达达配送 : TakeDistributionType.商家配送 }; ShopOrderServer shopOrderServer = new ShopOrderServer(model); db.AddTo(model); if (isTakeOut) { shopOrderServer.RecordTakeout(db, shop, memberId, args.TakeWay.Value, args.PickupTime); } else if (args.IsSelfHelp.HasValue && args.IsSelfHelp.Value) { shopOrderServer.RecordShopOrderSelfHelp(db, shop.Id, args.IsSelfHelpTakeOut ?? false); } else if (!string.IsNullOrEmpty(args.ShopPartFlag)) { shopOrderServer.RecordScancode(db, args.ShopPartFlag); } else { throw new Exception("请先扫描桌上二唯码"); } int cartCount = 0; args.Items.ForEach(m => cartCount += m.Count); shopOrderServer.RecordOtherFee(db, args.TakeWay, cartCount); var commodityIdAndCounts = new Dictionary <int, int>(); //商铺库存判断 foreach (var item in args.Items) { var stock = db.Query <ShopCommodityStock>() .Where(m => !m.IsDel) .Where(m => m.ShopId == shop.Id) .Where(m => m.Sku.Flag == item.SkuFlag) .Select(m => new { m.Id, m.Stock, IsCombo = m.Sku.Commodity.CategoryId == 0, //是否套餐 CommodityName = m.Sku.Commodity.Name, m.Sku.CommodityId, m.CostPrice, m.SalePrice, m.MarketPrice, HasVipPrice = m.Sku.Commodity.UseMemberPrice, SkuSummary = m.Sku.Summary }) .FirstOrDefault(); if (stock == null) { throw new Exception("商品不存在或者商铺商品未上架"); } if (stock.Stock <= 0 || stock.Stock < item.Count) { throw new Exception("库存不足"); } db.AddStock(stock.Id, -item.Count); //纪录下commodity的count if (commodityIdAndCounts.ContainsKey(stock.CommodityId)) { commodityIdAndCounts[stock.CommodityId] += item.Count; } else { commodityIdAndCounts.Add(stock.CommodityId, item.Count); } var orderItem = new ShopOrderItem() { CommodityName = stock.CommodityName, CommodityStockId = stock.Id, AddIp = model.AddIp, AddTime = model.AddTime, AddUser = model.AddUser, CostPrice = stock.CostPrice, SalePrice = (stock.HasVipPrice && !stock.IsCombo && (!IsTopUpDiscount || args.IsBalance)) ? ShopMemberServer.GetMemberPrice(stock.SalePrice, memberDiscount) : stock.SalePrice, PrimePrice = stock.SalePrice, ShopOrder = model, Count = item.Count, SkuSummary = stock.SkuSummary }; db.AddTo(orderItem); model.Amount += orderItem.SalePrice * orderItem.Count; } if (args.ComboPrice.HasValue) { model.Amount += args.ComboPrice.Value; } //这里尝试扣钱 //var memberAmount = db.GetMemberAmountList(memberId); //var availAmount = memberAmount.GetAvailAmount(); //if (availAmount >= model.Amount) //{ // memberAmount.DecreaseAvailAmount(model.Amount, 0, $"{shop.Name}消费", Newtonsoft.Json.JsonConvert.SerializeObject(new { shopId = shop.Id, orderFlag = model.Flag }), FinaceType.商品购买支出); // memberAmount.UpdateMemberAmountCache(); // model.PayTime = DateTime.Now; // //更新商品的销售量 // //注意,这里如果有一个品牌,多个店铺的情况,会出现销售额共享的情况 // var commodityIds = commodityIdAndCounts.Select(m => m.Key).ToList(); // var commoditys = db.Query<ShopBrandCommodity>() // .Where(m => commodityIds.Contains(m.Id)) // .ToList(); // foreach (var item in commoditys) // { // item.SalesForMonth += commodityIdAndCounts[item.Id]; // } // db.SaveChanges(); // AfterOrderPlacing(model, shop.Name); //} //else //{ // db.SaveChanges(); //} model.OrderNumber = shopOrderServer.GenerateOrderNumber(); shopOrderServer.ComputePayment(db); db.SaveChanges(); model.Shop = null; //不返回商店信息 return(Success(model)); }