private void GetOrderProductsInfo(string cartItemIds) { CartHelper cartHelper = new CartHelper(); IEnumerable <ShoppingCartItem> cartItems = null; if (!string.IsNullOrWhiteSpace(cartItemIds)) { char[] chrArray = new char[] { ',' }; IEnumerable <long> nums = from t in cartItemIds.Split(chrArray) select long.Parse(t); cartItems = ServiceHelper.Create <ICartService>().GetCartItems(nums); } else { cartItems = cartHelper.GetCart(base.CurrentUser.Id).Items; } int cityId = 0; ShippingAddressInfo defaultUserShippingAddressByUserId = ServiceHelper.Create <IShippingAddressService>().GetDefaultUserShippingAddressByUserId(base.CurrentUser.Id); if (defaultUserShippingAddressByUserId != null) { cityId = Instance <IRegionService> .Create.GetCityId(defaultUserShippingAddressByUserId.RegionIdPath); } IProductService productService = ServiceHelper.Create <IProductService>(); IShopService shopService = ServiceHelper.Create <IShopService>(); List <CartItemModel> list = cartItems.Select <ShoppingCartItem, CartItemModel>((ShoppingCartItem item) => { ProductInfo product = productService.GetProduct(item.ProductId); SKUInfo sku = productService.GetSku(item.SkuId); return(new CartItemModel() { skuId = item.SkuId, id = product.Id, imgUrl = product.GetImage(ProductInfo.ImageSize.Size_100, 1), name = product.ProductName, price = sku.SalePrice, shopId = product.ShopId, count = item.Quantity }); }).ToList(); IEnumerable <IGrouping <long, CartItemModel> > groupings = from a in list group a by a.shopId; List <ShopCartItemModel> shopCartItemModels = new List <ShopCartItemModel>(); foreach (IGrouping <long, CartItemModel> nums1 in groupings) { IEnumerable <long> nums2 = from r in nums1 select r.id; IEnumerable <int> nums3 = from r in nums1 select r.count; ShopCartItemModel shopCartItemModel = new ShopCartItemModel() { shopId = nums1.Key }; if (ServiceHelper.Create <IVShopService>().GetVShopByShopId(shopCartItemModel.shopId) != null) { shopCartItemModel.vshopId = ServiceHelper.Create <IVShopService>().GetVShopByShopId(shopCartItemModel.shopId).Id; } else { shopCartItemModel.vshopId = 0; } shopCartItemModel.CartItemModels = ( from a in list where a.shopId == shopCartItemModel.shopId select a).ToList(); shopCartItemModel.ShopName = shopService.GetShop(shopCartItemModel.shopId, false).ShopName; if (cityId > 0) { shopCartItemModel.Freight = ServiceHelper.Create <IProductService>().GetFreight(nums2, nums3, cityId); } List <ShopBonusReceiveInfo> detailToUse = ServiceHelper.Create <IShopBonusService>().GetDetailToUse(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); List <CouponRecordInfo> userCoupon = ServiceHelper.Create <ICouponService>().GetUserCoupon(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); if (detailToUse.Count() > 0 && userCoupon.Count() > 0) { ShopBonusReceiveInfo shopBonusReceiveInfo = detailToUse.FirstOrDefault(); CouponRecordInfo couponRecordInfo = userCoupon.FirstOrDefault(); decimal?price = shopBonusReceiveInfo.Price; decimal num = couponRecordInfo.ChemCloud_Coupon.Price; if ((price.GetValueOrDefault() <= num ? true : !price.HasValue)) { shopCartItemModel.Coupon = new CouponModel() { CouponName = couponRecordInfo.ChemCloud_Coupon.CouponName, CouponId = couponRecordInfo.Id, CouponPrice = couponRecordInfo.ChemCloud_Coupon.Price, Type = 0 }; } else { shopCartItemModel.Coupon = new CouponModel() { CouponName = shopBonusReceiveInfo.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name, CouponId = shopBonusReceiveInfo.Id, CouponPrice = shopBonusReceiveInfo.Price.Value, Type = 1 }; } } else if (detailToUse.Count() <= 0 && userCoupon.Count() <= 0) { shopCartItemModel.Coupon = null; } else if (detailToUse.Count() <= 0 && userCoupon.Count() > 0) { CouponRecordInfo couponRecordInfo1 = userCoupon.FirstOrDefault(); shopCartItemModel.Coupon = new CouponModel() { CouponName = couponRecordInfo1.ChemCloud_Coupon.CouponName, CouponId = couponRecordInfo1.Id, CouponPrice = couponRecordInfo1.ChemCloud_Coupon.Price, Type = 0 }; } else if (detailToUse.Count() > 0 && userCoupon.Count() <= 0) { ShopBonusReceiveInfo shopBonusReceiveInfo1 = detailToUse.FirstOrDefault(); shopCartItemModel.Coupon = new CouponModel() { CouponName = shopBonusReceiveInfo1.ChemCloud_ShopBonusGrant.ChemCloud_ShopBonus.Name, CouponId = shopBonusReceiveInfo1.Id, CouponPrice = shopBonusReceiveInfo1.Price.Value, Type = 1 }; } decimal num1 = shopCartItemModel.CartItemModels.Sum <CartItemModel>((CartItemModel d) => d.price * d.count); decimal num2 = num1 - (shopCartItemModel.Coupon == null ? new decimal(0) : shopCartItemModel.Coupon.CouponPrice); decimal freeFreight = shopService.GetShop(shopCartItemModel.shopId, false).FreeFreight; shopCartItemModel.isFreeFreight = false; if (freeFreight > new decimal(0)) { shopCartItemModel.shopFreeFreight = freeFreight; if (num2 >= freeFreight) { shopCartItemModel.Freight = new decimal(0); shopCartItemModel.isFreeFreight = true; } } shopCartItemModels.Add(shopCartItemModel); } decimal num3 = ( from a in shopCartItemModels where a.Coupon != null select a).Sum <ShopCartItemModel>((ShopCartItemModel b) => b.Coupon.CouponPrice); ViewBag.products = shopCartItemModels; base.ViewBag.totalAmount = list.Sum <CartItemModel>((CartItemModel item) => item.price * item.count); base.ViewBag.Freight = shopCartItemModels.Sum <ShopCartItemModel>((ShopCartItemModel a) => a.Freight); dynamic viewBag = base.ViewBag; dynamic obj = ViewBag.totalAmount; viewBag.orderAmount = obj + ViewBag.Freight - num3; IMemberIntegralService memberIntegralService = ServiceHelper.Create <IMemberIntegralService>(); MemberIntegral memberIntegral = memberIntegralService.GetMemberIntegral(base.CurrentUser.Id); int num4 = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals); ViewBag.userIntegrals = num4; ViewBag.integralPerMoney = 0; ViewBag.memberIntegralInfo = memberIntegral; MemberIntegralExchangeRules integralChangeRule = memberIntegralService.GetIntegralChangeRule(); decimal num5 = new decimal(0); decimal num6 = new decimal(0); decimal viewBag1 = (decimal)ViewBag.totalAmount; if (integralChangeRule == null || integralChangeRule.IntegralPerMoney <= 0) { num5 = new decimal(0); num6 = new decimal(0); } else { if (((viewBag1 - num3) - Math.Round((decimal)num4 / integralChangeRule.IntegralPerMoney, 2)) <= new decimal(0)) { num5 = Math.Round(viewBag1 - num3, 2); num6 = Math.Round((viewBag1 - num3) * integralChangeRule.IntegralPerMoney); } else { num5 = Math.Round((decimal)num4 / integralChangeRule.IntegralPerMoney, 2); num6 = num4; } if (num5 <= new decimal(0)) { num5 = new decimal(0); num6 = new decimal(0); } } ViewBag.integralPerMoney = num5; ViewBag.userIntegrals = num6; }
private void GetOrderProductsInfo(string cartItemIds, long?regionId) { ShippingAddressInfo shippingAddressInfo = new ShippingAddressInfo(); shippingAddressInfo = (!regionId.HasValue ? ServiceHelper.Create <IShippingAddressService>().GetDefaultUserShippingAddressByUserId(base.CurrentUser.Id) : ServiceHelper.Create <IShippingAddressService>().GetUserShippingAddress(regionId.Value)); int cityId = 0; if (shippingAddressInfo != null) { cityId = Instance <IRegionService> .Create.GetCityId(shippingAddressInfo.RegionIdPath); } CartHelper cartHelper = new CartHelper(); IEnumerable <ShoppingCartItem> cartItems = null; if (!string.IsNullOrWhiteSpace(cartItemIds)) { char[] chrArray = new char[] { ',' }; IEnumerable <long> nums = from t in cartItemIds.Split(chrArray) select long.Parse(t); cartItems = ServiceHelper.Create <ICartService>().GetCartItems(nums); } else { cartItems = cartHelper.GetCart(base.CurrentUser.Id).Items; } IProductService productService = ServiceHelper.Create <IProductService>(); IShopService shopService = ServiceHelper.Create <IShopService>(); List <CartItemModel> list = cartItems.Select <ShoppingCartItem, CartItemModel>((ShoppingCartItem item) => { ProductInfo product = productService.GetProduct(item.ProductId); SKUInfo sku = productService.GetSku(item.SkuId); return(new CartItemModel() { skuId = item.SkuId, id = product.Id, imgUrl = product.GetImage(ProductInfo.ImageSize.Size_50, 1), name = product.ProductName, price = sku.SalePrice, shopId = product.ShopId, count = item.Quantity, productCode = product.ProductCode }); }).ToList(); IEnumerable <IGrouping <long, CartItemModel> > groupings = from a in list group a by a.shopId; List <ShopCartItemModel> shopCartItemModels = new List <ShopCartItemModel>(); foreach (IGrouping <long, CartItemModel> nums1 in groupings) { IEnumerable <long> nums2 = from r in nums1 select r.id; IEnumerable <int> nums3 = from r in nums1 select r.count; ShopCartItemModel shopCartItemModel = new ShopCartItemModel() { shopId = nums1.Key, Freight = (cityId <= 0 ? new decimal(0) : ServiceHelper.Create <IProductService>().GetFreight(nums2, nums3, cityId)), }; shopCartItemModel.CartItemModels = ( from a in list where a.shopId == shopCartItemModel.shopId select a).ToList(); shopCartItemModel.ShopName = shopService.GetShop(shopCartItemModel.shopId, false).ShopName; shopCartItemModel.UserCoupons = ServiceHelper.Create <ICouponService>().GetUserCoupon(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); shopCartItemModel.UserBonus = ServiceHelper.Create <IShopBonusService>().GetDetailToUse(shopCartItemModel.shopId, base.CurrentUser.Id, nums1.Sum <CartItemModel>((CartItemModel a) => a.price * a.count)); shopCartItemModels.Add(shopCartItemModel); } ViewBag.products = shopCartItemModels; base.ViewBag.totalAmount = list.Sum <CartItemModel>((CartItemModel item) => item.price * item.count); base.ViewBag.Freight = shopCartItemModels.Sum <ShopCartItemModel>((ShopCartItemModel a) => a.Freight); dynamic viewBag = base.ViewBag; dynamic obj = ViewBag.totalAmount; viewBag.orderAmount = obj + ViewBag.Freight; }