/// <summary> /// 提交订单 /// </summary> /// <returns></returns> public ActionResult SubmitOrder(long id, long?regionId, int count = 1) { GiftOrderConfirmPageModel data = new Models.GiftOrderConfirmPageModel(); List <GiftOrderItemInfo> gorditemlist = new List <GiftOrderItemInfo>(); GiftOrderItemInfo gorditem; //订单项 #region 礼品信息判断 //礼品信息 GiftInfo giftdata = _iGiftService.GetById(id); if (giftdata == null) { throw new HimallException("错误的礼品编号!"); } #endregion gorditem = new GiftOrderItemInfo(); //补充订单项 gorditem.GiftId = giftdata.Id; gorditem.GiftName = giftdata.GiftName; gorditem.GiftValue = giftdata.GiftValue; gorditem.ImagePath = giftdata.ImagePath; gorditem.OrderId = 0; gorditem.Quantity = count; gorditem.SaleIntegral = giftdata.NeedIntegral; gorditemlist.Add(gorditem); data.GiftList = gorditemlist; data.GiftValueTotal = (decimal)data.GiftList.Sum(d => d.Quantity * d.GiftValue); data.TotalAmount = (int)data.GiftList.Sum(d => d.SaleIntegral * d.Quantity); //用户地址 data.ShipAddress = GetShippingAddress(regionId); return(View(data)); }
public ActionResult SubmitOrder(long id, long?regionId, int count = 1) { GiftOrderConfirmPageModel giftOrderConfirmPageModel = new GiftOrderConfirmPageModel(); List <GiftOrderItemInfo> giftOrderItemInfos = new List <GiftOrderItemInfo>(); GiftInfo byId = giftser.GetById(id); if (byId == null) { throw new HimallException("错误的礼品编号!"); } GiftOrderItemInfo giftOrderItemInfo = new GiftOrderItemInfo() { GiftId = byId.Id, GiftName = byId.GiftName, GiftValue = byId.GiftValue, ImagePath = byId.ImagePath, OrderId = new long?(0), Quantity = count, SaleIntegral = new int?(byId.NeedIntegral) }; giftOrderItemInfos.Add(giftOrderItemInfo); giftOrderConfirmPageModel.GiftList = giftOrderItemInfos; GiftOrderConfirmPageModel value = giftOrderConfirmPageModel; decimal?nullable = giftOrderConfirmPageModel.GiftList.Sum <GiftOrderItemInfo>((GiftOrderItemInfo d) => { decimal quantity = d.Quantity; decimal?giftValue = d.GiftValue; if (!giftValue.HasValue) { return(null); } return(new decimal?(quantity * giftValue.GetValueOrDefault())); }); value.GiftValueTotal = nullable.Value; GiftOrderConfirmPageModel value1 = giftOrderConfirmPageModel; int?nullable1 = giftOrderConfirmPageModel.GiftList.Sum <GiftOrderItemInfo>((GiftOrderItemInfo d) => { int?saleIntegral = d.SaleIntegral; int quantity = d.Quantity; if (!saleIntegral.HasValue) { return(null); } return(new int?(saleIntegral.GetValueOrDefault() * quantity)); }); value1.TotalAmount = nullable1.Value; giftOrderConfirmPageModel.ShipAddress = GetShippingAddress(regionId); ViewBag.Logo = ServiceHelper.Create <ISiteSettingService>().GetSiteSettings().Logo; ViewBag.Step = 2; return(View(giftOrderConfirmPageModel)); }
public JsonResult OrderList(string skey, GiftOrderInfo.GiftOrderStatus?status, int rows, int page) { GiftsOrderQuery giftsOrderQuery = new GiftsOrderQuery() { skey = skey, status = status, PageSize = rows, PageNo = page }; PageModel <GiftOrderInfo> orders = orderser.GetOrders(giftsOrderQuery); List <GiftOrderInfo> list = orders.Models.ToList(); orderser.OrderAddUserInfo(list); IEnumerable <GiftOrderPageModel> giftOrderPageModels = list.Select <GiftOrderInfo, GiftOrderPageModel>((GiftOrderInfo d) => { GiftOrderItemInfo giftOrderItemInfo = d.ChemCloud_GiftOrderItem.FirstOrDefault(); return(new GiftOrderPageModel() { Id = d.Id, OrderStatus = d.OrderStatus, UserId = d.UserId, UserRemark = ClearHtmlString(d.UserRemark), ShipTo = d.ShipTo, CellPhone = d.CellPhone, TopRegionId = d.TopRegionId, RegionId = d.RegionId, RegionFullName = d.RegionFullName, Address = ClearHtmlString(d.Address), ExpressCompanyName = d.ExpressCompanyName, ShipOrderNumber = d.ShipOrderNumber, ShippingDate = d.ShippingDate, OrderDate = d.OrderDate, FinishDate = d.FinishDate, TotalIntegral = d.TotalIntegral, CloseReason = ClearHtmlString(d.CloseReason), FirstGiftId = giftOrderItemInfo.GiftId, FirstGiftName = ClearHtmlString(giftOrderItemInfo.GiftName), FirstGiftBuyQuantity = giftOrderItemInfo.Quantity, UserName = d.UserName }); }); var variable = new { rows = giftOrderPageModels.ToList(), total = orders.Total }; return(Json(variable)); }
/// <summary> /// 确认订单信息并提交 /// </summary> /// <param name="id"></param> /// <param name="count"></param> /// <returns></returns> public ActionResult SubmitOrder(long id, long?regionId, int count = 1) { #region 礼品信息判断 //礼品信息 var giftdata = GiftApplication.GetGift(id); if (giftdata == null) { throw new HimallException("错误的礼品编号!"); } #endregion var data = new GiftOrderConfirmPageModel(); var gorditemlist = new List <GiftOrderItemInfo>(); var gorditem = new GiftOrderItemInfo(); //补充订单项 gorditem.GiftId = giftdata.Id; gorditem.GiftName = giftdata.GiftName; gorditem.GiftValue = giftdata.GiftValue; gorditem.ImagePath = giftdata.ImagePath; gorditem.OrderId = 0; gorditem.Quantity = count; gorditem.SaleIntegral = giftdata.NeedIntegral; gorditemlist.Add(gorditem); data.GiftList = gorditemlist; data.GiftValueTotal = (decimal)data.GiftList.Sum(d => d.Quantity * d.GiftValue); data.TotalAmount = (int)data.GiftList.Sum(d => d.SaleIntegral * d.Quantity); //用户地址 data.ShipAddress = GetShippingAddress(regionId); //顶部信息 Logo ViewBag.Logo = SiteSettingApplication.SiteSettings.Logo;//获取Logo ViewBag.Step = 2; ViewBag.Keyword = SiteSettings.Keyword; return(View(data)); }
/// <summary> /// 创建订单 /// </summary> /// <param name="model"></param> /// <returns></returns> public GiftOrderInfo CreateOrder(GiftOrderModel model) { if (model.CurrentUser == null) { throw new HimallException("错误的用户信息"); } if (model.ReceiveAddress == null) { throw new HimallException("错误的收货人信息"); } GiftOrderInfo result = new GiftOrderInfo() { Id = GenerateOrderNumber(), UserId = model.CurrentUser.Id, RegionId = model.ReceiveAddress.RegionId, ShipTo = model.ReceiveAddress.ShipTo, Address = model.ReceiveAddress.Address + " " + model.ReceiveAddress.AddressDetail, RegionFullName = model.ReceiveAddress.RegionFullName, CellPhone = model.ReceiveAddress.Phone, TopRegionId = int.Parse(model.ReceiveAddress.RegionIdPath.Split(',')[0]), UserRemark = model.UserRemark, }; var giftOrderItemInfo = new List <GiftOrderItemInfo>(); DbFactory.Default .InTransaction(() => { //礼品信息处理,库存判断并减库存 foreach (var item in model.Gifts) { if (item.Counts < 1) { throw new HimallException("错误的兑换数量!"); } GiftInfo giftdata = DbFactory.Default.Get <GiftInfo>().Where(d => d.Id == item.GiftId).FirstOrDefault(); if (giftdata != null && giftdata.GetSalesStatus == GiftInfo.GiftSalesStatus.Normal) { if (giftdata.StockQuantity >= item.Counts) { giftdata.StockQuantity = giftdata.StockQuantity - item.Counts; //先减库存 giftdata.RealSales += item.Counts; //加销量 GiftOrderItemInfo gorditem = new GiftOrderItemInfo() { GiftId = giftdata.Id, GiftName = giftdata.GiftName, GiftValue = giftdata.GiftValue, ImagePath = giftdata.ImagePath, OrderId = result.Id, Quantity = item.Counts, SaleIntegral = giftdata.NeedIntegral }; giftOrderItemInfo.Add(gorditem); DbFactory.Default.Update(giftdata); } else { throw new HimallException("礼品库存不足!"); } } else { throw new HimallException("礼品不存在或已失效!"); } } //建立订单 result.TotalIntegral = giftOrderItemInfo.Sum(d => d.Quantity * d.SaleIntegral); result.OrderStatus = GiftOrderInfo.GiftOrderStatus.WaitDelivery; result.OrderDate = DateTime.Now; DbFactory.Default.Add(result); DbFactory.Default.AddRange(giftOrderItemInfo); //减少积分 var userdata = DbFactory.Default.Get <MemberInfo>().Where(d => d.Id == model.CurrentUser.Id).FirstOrDefault(); DeductionIntegral(userdata, result.Id, (int)result.TotalIntegral); }); return(result); }
public GiftOrderInfo CreateOrder(GiftOrderModel model) { if (model.CurrentUser == null) { throw new HimallException("错误的用户信息"); } if (model.ReceiveAddress == null) { throw new HimallException("错误的收货人信息"); } GiftOrderInfo giftOrderInfo = new GiftOrderInfo() { Id = GenerateOrderNumber(), UserId = model.CurrentUser.Id, RegionId = new int?(model.ReceiveAddress.RegionId), ShipTo = model.ReceiveAddress.ShipTo, Address = model.ReceiveAddress.Address, RegionFullName = model.ReceiveAddress.RegionFullName, CellPhone = model.ReceiveAddress.Phone }; string regionIdPath = model.ReceiveAddress.RegionIdPath; char[] chrArray = new char[] { ',' }; giftOrderInfo.TopRegionId = new int?(int.Parse(regionIdPath.Split(chrArray)[0])); giftOrderInfo.UserRemark = model.UserRemark; GiftOrderInfo now = giftOrderInfo; using (TransactionScope transactionScope = new TransactionScope()) { foreach (GiftOrderItemModel gift in model.Gifts) { if (gift.Counts < 1) { throw new HimallException("错误的兑换数量!"); } GiftInfo stockQuantity = context.GiftInfo.FirstOrDefault((GiftInfo d) => d.Id == gift.GiftId); if (stockQuantity == null || stockQuantity.GetSalesStatus != GiftInfo.GiftSalesStatus.Normal) { throw new HimallException("礼品不存在或己失效!"); } if (stockQuantity.StockQuantity < gift.Counts) { throw new HimallException("礼品库存不足!"); } stockQuantity.StockQuantity = stockQuantity.StockQuantity - gift.Counts; GiftInfo realSales = stockQuantity; realSales.RealSales = realSales.RealSales + gift.Counts; GiftOrderItemInfo giftOrderItemInfo = new GiftOrderItemInfo() { GiftId = stockQuantity.Id, GiftName = stockQuantity.GiftName, GiftValue = stockQuantity.GiftValue, ImagePath = stockQuantity.ImagePath, OrderId = new long?(now.Id), Quantity = gift.Counts, SaleIntegral = new int?(stockQuantity.NeedIntegral) }; now.Himall_GiftOrderItem.Add(giftOrderItemInfo); } now.TotalIntegral = now.Himall_GiftOrderItem.Sum <GiftOrderItemInfo>((GiftOrderItemInfo d) => { int quantity = d.Quantity; int?saleIntegral = d.SaleIntegral; if (!saleIntegral.HasValue) { return(null); } return(new int?(quantity * saleIntegral.GetValueOrDefault())); }); now.OrderStatus = GiftOrderInfo.GiftOrderStatus.WaitDelivery; now.OrderDate = DateTime.Now; context.GiftOrderInfo.Add(now); context.SaveChanges(); UserMemberInfo userMemberInfo = context.UserMemberInfo.FirstOrDefault((UserMemberInfo d) => d.Id == model.CurrentUser.Id); DeductionIntegral(userMemberInfo, now.Id, now.TotalIntegral.Value); transactionScope.Complete(); } return(now); }
/// <summary> /// 获取预约单项 /// </summary> /// <param name="id"></param> /// <returns></returns> public GiftOrderItemInfo GetOrderItemById(long id) { GiftOrderItemInfo result = Context.GiftOrderItemInfo.FirstOrDefault(d => d.Id == id); return(result); }
/// <summary> /// 创建预约单 /// </summary> /// <param name="model"></param> /// <returns></returns> public GiftOrderInfo CreateOrder(GiftOrderModel model) { if (model.CurrentUser == null) { throw new HimallException("错误的用户信息"); } if (model.ReceiveAddress == null) { throw new HimallException("错误的收货人信息"); } GiftOrderInfo result = new GiftOrderInfo() { Id = GenerateOrderNumber(), UserId = model.CurrentUser.Id, RegionId = model.ReceiveAddress.RegionId, ShipTo = model.ReceiveAddress.ShipTo, Address = model.ReceiveAddress.Address, RegionFullName = model.ReceiveAddress.RegionFullName, CellPhone = model.ReceiveAddress.Phone, TopRegionId = int.Parse(model.ReceiveAddress.RegionIdPath.Split(',')[0]), UserRemark = model.UserRemark }; using (TransactionScope scope = new TransactionScope()) { //礼品信息处理,库存判断并减库存 foreach (var item in model.Gifts) { if (item.Counts < 1) { throw new HimallException("错误的兑换数量!"); } GiftInfo giftdata = Context.GiftInfo.FirstOrDefault(d => d.Id == item.GiftId); if (giftdata != null && giftdata.GetSalesStatus == GiftInfo.GiftSalesStatus.Normal) { if (giftdata.StockQuantity >= item.Counts) { giftdata.StockQuantity = giftdata.StockQuantity - item.Counts; //先减库存 giftdata.RealSales += item.Counts; //加销量 GiftOrderItemInfo gorditem = new GiftOrderItemInfo() { GiftId = giftdata.Id, GiftName = giftdata.GiftName, GiftValue = giftdata.GiftValue, ImagePath = giftdata.ImagePath, OrderId = result.Id, Quantity = item.Counts, SaleIntegral = giftdata.NeedIntegral }; result.Himall_GiftOrderItem.Add(gorditem); } else { throw new HimallException("礼品库存不足!"); } } else { throw new HimallException("礼品不存在或已失效!"); } } //建立预约单 result.TotalIntegral = result.Himall_GiftOrderItem.Sum(d => d.Quantity * d.SaleIntegral); result.OrderStatus = GiftOrderInfo.GiftOrderStatus.WaitDelivery; result.OrderDate = DateTime.Now; Context.GiftOrderInfo.Add(result); Context.SaveChanges(); //减少积分 var userdata = Context.UserMemberInfo.FirstOrDefault(d => d.Id == model.CurrentUser.Id); DeductionIntegral(userdata, result.Id, (int)result.TotalIntegral); scope.Complete(); } return(result); }