public APIResult Add([FromBody] AddArgs args) { if (args.ShopId == 0) { throw new ArgumentNullException("ShopId"); } if (!args.StartDate.HasValue) { throw new ArgumentNullException("StartDate"); } if (!args.EndDate.HasValue) { throw new ArgumentNullException("EndDate"); } if (args.Items.Count == 0) { throw new Exception("请输入具体规则"); } CheckShopActor(args.ShopId, ShopActorType.超级管理员); ShopOrderMoneyOff shopOrderMoneyOff = new ShopOrderMoneyOff() { Name = args.Name, StartDate = args.StartDate.Value.Date, EndDate = args.EndDate.Value.Date, ShopId = args.ShopId, IsScanCode = args.IsScanCode, IsSelfOrder = args.IsSelfOrder, IsTakeout = args.IsTakeout, IsEnable = true, IsDel = false }; db.AddTo(shopOrderMoneyOff); db.SaveChanges(); //若在优惠期间,则开始优惠 DateTime now = DateTime.Now.Date; if (now >= shopOrderMoneyOff.StartDate.Value && now <= shopOrderMoneyOff.EndDate.Value) { ShopOrderMoneyOffCache cache = new ShopOrderMoneyOffCache() { ShopId = shopOrderMoneyOff.ShopId, MoneyOffId = shopOrderMoneyOff.Id }; db.AddTo(cache); } foreach (var item in args.Items) { ShopOrderMoneyOffRule rule = new ShopOrderMoneyOffRule() { MoneyOffId = shopOrderMoneyOff.Id, FullAmount = (int)Math.Floor(item.FullAmount * 100), Discount = (int)Math.Floor(item.Discount * 100), IsDel = false }; db.AddTo(rule); } db.SaveChanges(); return(Success()); }
public ActionResult GetShopOrderView(GetShopOrderViewArgsModel args) { var order = db.Set <ShopOrder>().Find(args.orderid); if (order == null) { throw new Exception("该订单不存在"); } var Oauth = db.Query <ShopOrderReceiver>() .Where(m => !m.IsDel) .Where(m => m.ReceiverOpenId == args.openid) .Where(m => m.ShopId == order.ShopId) .FirstOrDefault(); if (Oauth == null) { return(View("unauthorized")); } var items = db.Query <ShopOrderItem>() .Where(m => !m.IsDel) .Where(m => m.ShopOrderId == order.Id) .ToList(); if (items.Count == 0) { throw new Exception($"该订单出错,订单号为:{order.Id}"); } var orderitems = items.Select(m => { double p = Math.Round(m.SalePrice / 100d, 2); return(new ShopOrderItemInfo() { Name = m.CommodityName, Price = p, Count = m.Count, Amount = p * m.Count, SkuSummary = m.SkuSummary }); }).ToList(); string address = null; string takeway = null; string phone = null; string name = null; DateTime pickupTime = new DateTime(); if (order.IsTakeOut) { var takeout = db.Query <ShopOrderTakeout>() .Where(m => !m.IsDel && m.ShopOrderId == order.Id) .FirstOrDefault(); if (takeout != null) { address = takeout.Address; takeway = takeout.TakeWay.ToString(); phone = takeout.Phone; name = takeout.Name; pickupTime = takeout.PickupTime; } } if (!order.Payment.HasValue) { order.Payment = 0; } //其它费用 ShopOrderOtherFee otherFee = null; if (order.OtherFeeId.HasValue) { otherFee = db.GetSingle <ShopOrderOtherFee>(order.OtherFeeId.Value); } //满减折扣 ShopOrderMoneyOffRule moneyOff = null; if (order.MoneyOffRuleId.HasValue) { moneyOff = db.GetSingle <ShopOrderMoneyOffRule>(order.MoneyOffRuleId.Value); } Member member = memberDb.GetSingleMember(order.MemberId); GetShopOrderViewResultModel rtn = new GetShopOrderViewResultModel() { MemberId = order.MemberId, Id = order.Id, PayTime = order.PayTime, Address = address, ShopOrderItems = orderitems, OrderAmount = Math.Round(order.Amount / 100d, 2), ShopOrderOtherFee = otherFee, ShopOrderMoneyOffRule = moneyOff, Remark = order.Remark, TakeWay = takeway, PayAmount = Math.Round(order.Payment.Value / 100d, 2), Headimgurl = member.Avatar, NickName = member.NickName, Name = name, Phone = phone, OrderNumber = order.OrderNumber, PickupTime = pickupTime, PayWay = order.PayWay ?? "" }; if (order.ShopPartId.HasValue) { rtn.ShopPartName = db.Set <ShopPart>().Find(order.ShopPartId).Title; } else { rtn.ShopPartName = null; } if (order.ShopOrderSelfHelpId.HasValue) { rtn.ShopOrderSelfHelp = db.GetSingle <ShopOrderSelfHelp>(order.ShopOrderSelfHelpId.Value); } return(View(rtn)); }