/// <summary> /// 获取不同组织的商品信息 /// </summary> /// <param name="currentOrgGid"></param> /// <returns></returns> public ActionResult MallCartTablePartial(Guid? currentOrgGid) { MallCartInfo oMallCartInfo = new MallCartInfo(); if (currentOrgGid != null) { List<MallCart> listGroupMallCart = dbEntity.MallCarts.Include("OnSkuItem").Include("OnSale").Include("Organization").Where(p => p.OrgID == currentOrgGid && p.ChlID == LiveSession.channelID && p.UserID == LiveSession.userID && p.Deleted == false).ToList(); Guid oOrganizationGuid = (Guid)currentOrgGid; //拼接页面model需要的信息 MemberOrganization oMember = dbEntity.MemberOrganizations.Include("FullName").Where(p => p.Gid == oOrganizationGuid && p.Deleted == false).FirstOrDefault(); oMallCartInfo.organizationName = oMember.FullName.GetResource(LiveSession.Culture); oMallCartInfo.orgGid = oOrganizationGuid; //获取产品总数,数量为总数,不是商品类型的数量 decimal nProductCount = 0m; //获取金额,以及设置页面商品List decimal allSalePrice = 0; decimal allMarketPrice = 0; List<MallCartProduct> listMallProduct = new List<MallCartProduct>(); for (int j = 0; j < listGroupMallCart.Count; j++) { Guid onSkuGid = listGroupMallCart.ElementAt(j).OnSkuID; ProductOnUnitPrice oUnitPrice = dbEntity.ProductOnUnitPrices.Include("OnSkuItem.OnSale").Include("ShowUnit").Include("MarketPrice").Include("SalePrice").Where(p => p.OnSkuID == onSkuGid && p.Deleted == false).OrderByDescending(p => p.IsDefault).OrderByDescending(p => p.CreateTime).FirstOrDefault(); MallCartProduct oMallCartProduct = new MallCartProduct(); oMallCartProduct.mallCartGid = listGroupMallCart.ElementAt(j).Gid; //转换前的数量 oMallCartProduct.productCount = listGroupMallCart.ElementAt(j).SetQty; //折扣,现在默认为1,不打折 oMallCartProduct.productDiscount = 1; //套装模式 oMallCartProduct.productMode = (byte)listGroupMallCart.ElementAt(j).OnSale.Mode; //套装数量 oMallCartProduct.productSetCount = listGroupMallCart.ElementAt(j).SetQty; //标准计量单位下的数量 oMallCartProduct.productQuantity = listGroupMallCart.ElementAt(j).Quantity; //转换后的实际默认计量单位的数量 if (oUnitPrice.UnitRatio == 0) { oUnitPrice.UnitRatio = 1; } decimal nPercent = Decimal.Parse("1" + new string('0', oUnitPrice.Percision)); oMallCartProduct.productFactCount = Math.Ceiling(listGroupMallCart.ElementAt(j).Quantity / oUnitPrice.UnitRatio * nPercent ) / nPercent; //商品信息 oMallCartProduct.productName = listGroupMallCart.ElementAt(j).OnSkuItem.FullName.GetResource(LiveSession.Culture); oMallCartProduct.productPicture = listGroupMallCart.ElementAt(j).OnSkuItem.OnSale.Picture; //价格以及价格总计,总计按照实际从标准单位转换回来的数量计算 oMallCartProduct.productPriceSum = oUnitPrice.SalePrice.GetResource(globalCurrencyGid) * oMallCartProduct.productFactCount; oMallCartProduct.productSalePrice = oUnitPrice.SalePrice.GetResource(globalCurrencyGid); //计算合计 allMarketPrice = allMarketPrice + oUnitPrice.MarketPrice.GetResource(globalCurrencyGid) * oMallCartProduct.productFactCount; allSalePrice = allSalePrice + oUnitPrice.SalePrice.GetResource(globalCurrencyGid) * oMallCartProduct.productFactCount; //对应商品的计量单位 oMallCartProduct.defaultUnit = oUnitPrice.ShowUnit.Name.GetResource(LiveSession.Culture); oMallCartProduct.standardUnit = oUnitPrice.OnSkuItem.SkuItem.StandardUnit.Name.GetResource(LiveSession.Culture); listMallProduct.Add(oMallCartProduct); nProductCount = nProductCount + oMallCartProduct.productFactCount; } oMallCartInfo.productCount = nProductCount; oMallCartInfo.marketPriceSum = allMarketPrice; oMallCartInfo.salePriceSum = allSalePrice; oMallCartInfo.priceLower = allMarketPrice - allSalePrice; ViewBag.oMallCartProductList = listMallProduct; } return View(oMallCartInfo); }
/// <summary> /// 进入购物车结算界面,区分不同的组织 /// </summary> /// <returns></returns> public ActionResult Cart(Guid? memberAddGid) { //清空相关的全局变量 globalCouponList = new Dictionary<Guid, decimal>(); //清空全局商品的总执行价格 globalProductExacuteAmount = 0m; //清空全局订单商品的列表 globalOrderItemList = new Dictionary<Guid, OrderItem>(); //清空全局订单商品的数量 globalOrderItemPieces = 0m; //需要判断是否需要新建订单 oNewOrder = new OrderInformation(); //承运商信息清空 globalShipperGid = Guid.Empty; //将发票信息回复为默认 bInvoiceOrNot = false; //默认不使用承运商(快递或物流) bUseShipper = false; List<MallCart> listMallCart = dbEntity.MallCarts.Include("Organization").Include("Channel").Include("OnSale").Include("OnSkuItem").Include("CartType").Where(p => p.OrgID == globalOrgGid && p.ChlID == LiveSession.channelID && p.UserID == LiveSession.userID && p.Deleted == false).ToList(); if (listMallCart.Count > 0) { //收货人信息 List<MemberAddress> oUserAddressList = dbEntity.MemberAddresses.Where(p => p.UserID == LiveSession.userID && p.Deleted == false).ToList(); ViewBag.oAddressList = oUserAddressList; //交易类型信息 List<SelectListItem> oTransList = new List<SelectListItem>(); oTransList = GetSelectList(oNewOrder.TransTypeList); ViewBag.oTransList = oTransList; //支付信息 List<FinancePayType> listPayment = new List<FinancePayType>(); //取支付方式的交集 for (int i = 0; i < listMallCart.Count; i++) { for (int j = 0; j < listMallCart.ElementAt(i).OnSale.OnPayments.Count; j++) { if (!listPayment.Contains(listMallCart.ElementAt(i).OnSale.OnPayments.ElementAt(j).PayType)) { listPayment.Add(listMallCart.ElementAt(i).OnSale.OnPayments.ElementAt(j).PayType); } } } ViewBag.oPaymentList = listPayment; //券和积分的信息 List<MemberPoint> listMemberCoupon = dbEntity.MemberPoints.Include("Promotion").Include("Coupon").Include("Currency").Where(p => p.Ptype == (byte)ModelEnum.PointType.COUPON && p.aCurrency == globalCurrencyGid && p.UserID == LiveSession.userID && p.OrgID == globalOrgGid && p.Deleted == false && p.Pstatus != (byte)ModelEnum.PointStatus.NONE && p.StartTime <= DateTimeOffset.Now && p.EndTime >= DateTimeOffset.Now && p.Balance > 0 || p.Remain > 0).ToList(); List<MemberPoint> listArriveCoupon = new List<MemberPoint>(); foreach (var couponItem in listMemberCoupon) { listArriveCoupon.Add(couponItem); } List<MemberPoint> listMemberPoint = dbEntity.MemberPoints.Include("Promotion").Include("Coupon").Include("Currency").Where(p => p.Ptype == (byte)ModelEnum.PointType.POINT && p.Deleted == false && p.Pstatus != (byte)ModelEnum.PointStatus.NONE).ToList(); if (listMemberPoint != null) { ViewBag.pointList = listMemberPoint; } if (listArriveCoupon != null) { ViewBag.arriveCouponList = listArriveCoupon; } //物流信息 //独立页面 //发票信息 //从GeneralOptional表中取得,下拉框 GeneralOptional invoiceOption = dbEntity.GeneralOptionals.Include("OptionalItems").Where(p => p.Deleted == false && p.Otype == (byte)ModelEnum.OptionalType.ORDER && p.Code == "Invoice").FirstOrDefault(); List<SelectListItem> listInvoiceItem = new List<SelectListItem>(); if (invoiceOption != null) { for (int i = 0; i < invoiceOption.OptionalItems.Count; i++) { listInvoiceItem.Add(new SelectListItem { Text = invoiceOption.OptionalItems.ElementAt(i).Name.GetResource(LiveSession.Culture), Value = invoiceOption.OptionalItems.ElementAt(i).Gid.ToString() }); } } ViewBag.invoiceList = listInvoiceItem; //订单备注 //商品清单 List<MallCartProduct> listMallProduct = new List<MallCartProduct>(); for (int j = 0; j < listMallCart.Count; j++) { Guid onSkuGid = listMallCart.ElementAt(j).OnSkuID; ProductOnUnitPrice oUnitPrice = dbEntity.ProductOnUnitPrices.Include("OnSkuItem.OnSale").Include("ShowUnit").Include("MarketPrice").Include("SalePrice").Where(p => p.OnSkuID == onSkuGid && p.Deleted == false).OrderByDescending(p => p.IsDefault).OrderByDescending(p => p.CreateTime).FirstOrDefault(); MallCartProduct oMallCartProduct = new MallCartProduct(); oMallCartProduct.mallCartGid = listMallCart.ElementAt(j).Gid; //转换前的数量 oMallCartProduct.productCount = listMallCart.ElementAt(j).SetQty; //折扣,现在默认为1,不打折 oMallCartProduct.productDiscount = 1; //套装模式 oMallCartProduct.productMode = (byte)listMallCart.ElementAt(j).OnSale.Mode; //套装数量,默认计量单位的数量 oMallCartProduct.productSetCount = listMallCart.ElementAt(j).SetQty; //标准计量单位下的数量 oMallCartProduct.productQuantity = listMallCart.ElementAt(j).Quantity; //转换后的实际默认计量单位的数量 if (oUnitPrice.Percision == 0) { oUnitPrice.Percision = 1; } decimal nPercent = Decimal.Parse("1" + new string('0', oUnitPrice.Percision)); oMallCartProduct.productFactCount = Math.Ceiling(listMallCart.ElementAt(j).Quantity / oUnitPrice.UnitRatio * nPercent) / nPercent; //商品信息 oMallCartProduct.productName = listMallCart.ElementAt(j).OnSkuItem.FullName.GetResource(LiveSession.Culture); oMallCartProduct.productPicture = listMallCart.ElementAt(j).OnSkuItem.OnSale.Picture; //价格以及价格总计,总计按照实际从标准单位转换回来的数量计算 oMallCartProduct.productPriceSum = oUnitPrice.SalePrice.GetResource(globalCurrencyGid) * oMallCartProduct.productFactCount; oMallCartProduct.productSalePrice = oUnitPrice.SalePrice.GetResource(globalCurrencyGid); //对应商品的计量单位 oMallCartProduct.defaultUnit = oUnitPrice.ShowUnit.Name.GetResource(LiveSession.Culture); oMallCartProduct.standardUnit = oUnitPrice.OnSkuItem.SkuItem.StandardUnit.Name.GetResource(LiveSession.Culture); listMallProduct.Add(oMallCartProduct); globalProductExacuteAmount = globalProductExacuteAmount + oMallCartProduct.productPriceSum; //生成订单商品列表 OrderItem oNewOrderItem = new OrderItem(); oNewOrderItem.OnSkuID = onSkuGid; oNewOrderItem.SkuID = listMallCart.ElementAt(j).OnSkuItem.SkuItem.Gid; oNewOrderItem.Name = listMallCart.ElementAt(j).OnSkuItem.FullName.GetResource(LiveSession.Culture); //标准计量单位的数量 oNewOrderItem.Quantity = listMallCart.ElementAt(j).Quantity; oNewOrderItem.MarketPrice = oUnitPrice.MarketPrice.GetResource(globalCurrencyGid); oNewOrderItem.SalePrice = oUnitPrice.SalePrice.GetResource(globalCurrencyGid); oNewOrderItem.ExecutePrice = oMallCartProduct.productPriceSum / listMallCart.ElementAt(j).Quantity; globalOrderItemList.Add(listMallCart.ElementAt(j).Gid, oNewOrderItem); globalOrderItemPieces = globalOrderItemPieces + listMallCart.ElementAt(j).Quantity; } ViewBag.oProductItemList = listMallProduct; } oNewOrder.OrgID = globalOrgGid; oNewOrder.ChlID = LiveSession.channelID; oNewOrder.UserID = (Guid)LiveSession.userID; ViewBag.nCulture = LiveSession.Culture; return View(); }
/// <summary> /// 用户在购物车列表页面更新商品数量 /// </summary> /// <param name="mallCartGid"></param> /// <param name="changeNum"></param> /// <returns></returns> public string ChangeMallCartNum(Guid mallCartGid, decimal changeNum) { MallCart oMallCart = dbEntity.MallCarts.Include("OnSkuItem").Include("OnSale").Include("Organization").Where(p => p.Gid == mallCartGid && p.Deleted == false).FirstOrDefault(); if (oMallCart != null) { oMallCart.SetQty = changeNum; Guid onSkuGid = oMallCart.OnSkuID; ProductOnUnitPrice oUnitPrice = dbEntity.ProductOnUnitPrices.Include("OnSkuItem.OnSale").Include("ShowUnit").Include("MarketPrice").Include("SalePrice").Where(p => p.OnSkuID == onSkuGid && p.Deleted == false).OrderByDescending(p => p.IsDefault).OrderByDescending(p => p.CreateTime).FirstOrDefault(); MallCartProduct oMallCartProduct = new MallCartProduct(); oMallCartProduct.mallCartGid = oMallCart.Gid; //转换前的数量 oMallCartProduct.productCount = oMallCart.SetQty; //折扣,现在默认为1,不打折 oMallCartProduct.productDiscount = 1; //套装模式 oMallCartProduct.productMode = (byte)oMallCart.OnSale.Mode; //套装数量 oMallCartProduct.productSetCount = oMallCart.SetQty; //转换后的实际默认计量单位的数量 if (oUnitPrice.UnitRatio == 0m) { oUnitPrice.UnitRatio = 1m; } decimal nPercent = Decimal.Parse("1" + new string('0', oUnitPrice.Percision)); oMallCart.Quantity = Math.Ceiling(changeNum * oUnitPrice.UnitRatio * nPercent) / nPercent; //标准计量单位下的数量 oMallCartProduct.productQuantity = oMallCart.Quantity; //将修改后的数据存入数据库,套装数量以及转换后的数量 dbEntity.SaveChanges(); oMallCartProduct.productFactCount = Math.Ceiling(oMallCart.Quantity / oUnitPrice.UnitRatio * nPercent) / nPercent; //商品信息 oMallCartProduct.productName = oMallCart.OnSkuItem.FullName.GetResource(LiveSession.Culture); oMallCartProduct.productPicture = oMallCart.OnSkuItem.OnSale.Picture; //价格以及价格总计,总计按照实际从标准单位转换回来的数量计算 oMallCartProduct.productPriceSum = oUnitPrice.SalePrice.GetResource(globalCurrencyGid) * oMallCartProduct.productFactCount; oMallCartProduct.productSalePrice = oUnitPrice.SalePrice.GetResource(globalCurrencyGid); //对应商品的计量单位 oMallCartProduct.defaultUnit = oUnitPrice.ShowUnit.Name.GetResource(LiveSession.Culture); oMallCartProduct.standardUnit = oUnitPrice.OnSkuItem.SkuItem.StandardUnit.Name.GetResource(LiveSession.Culture); return "实际数量:" + oMallCartProduct.productQuantity.ToString("#0.00") + " (" + oMallCartProduct.standardUnit + ") = " + oMallCartProduct.productFactCount.ToString("#0.00") + " (" + oMallCartProduct.defaultUnit + ")" + "|" + oMallCartProduct.productPriceSum.ToString("#0.00"); } else { return ""; } }